Components
Segment group

Segment Group

Organizes and navigates between sections in a view.

Usage

import * as SegmentGroup from '~/components/ui/segment-group'

export const Demo = (props: SegmentGroup.RootProps) => {
  const options = [
    { id: 'overview', label: 'Overview' },
    { id: 'customers', label: 'Customers' },
    { id: 'premium', label: 'Premium', disabled: true },
    { id: 'settings', label: 'Settings' },
  ]
  return (
    <SegmentGroup.Root defaultValue="customers" {...props}>
      {options.map((option) => (
        <SegmentGroup.Item key={option.id} value={option.id} disabled={option.disabled}>
          <SegmentGroup.ItemControl />
          <SegmentGroup.ItemText>{option.label}</SegmentGroup.ItemText>
        </SegmentGroup.Item>
      ))}
      <SegmentGroup.Indicator />
    </SegmentGroup.Root>
  )
}

Installation

1

Add Component

Insert code snippet into your project. Update import paths as needed.

import { SegmentGroup } from '@ark-ui/react/segment-group'
import type { ComponentProps } from 'react'
import { styled } from 'styled-system/jsx'
import { segmentGroup } from 'styled-system/recipes'
import { createStyleContext } from '~/lib/create-style-context'

const { withProvider, withContext } = createStyleContext(segmentGroup)

export const Root = withProvider(styled(SegmentGroup.Root), 'root')
export const Indicator = withContext(styled(SegmentGroup.Indicator), 'indicator')
export const Item = withContext(styled(SegmentGroup.Item), 'item')
export const ItemControl = withContext(styled(SegmentGroup.ItemControl), 'itemControl')
export const ItemText = withContext(styled(SegmentGroup.ItemText), 'itemText')
export const Label = withContext(styled(SegmentGroup.Label), 'label')

export interface RootProps extends ComponentProps<typeof Root> {}
export interface IndicatorProps extends ComponentProps<typeof Indicator> {}
export interface ItemProps extends ComponentProps<typeof Item> {}
export interface ItemControlProps extends ComponentProps<typeof ItemControl> {}
export interface ItemTextProps extends ComponentProps<typeof ItemText> {}
export interface LabelProps extends ComponentProps<typeof Label> {}
2

Add Recipe

This step is necessary only if you do not use any of the Park UI plugins.

import { segmentGroupAnatomy } from '@ark-ui/anatomy'
import { defineSlotRecipe } from '@pandacss/dev'

export const segmentGroup = defineSlotRecipe({
  className: 'segmentGroup',
  slots: segmentGroupAnatomy.keys(),
  base: {
    root: {
      alignItems: 'flex-start',
      colorPalette: 'accent',
      display: 'flex',
      flexDirection: {
        _horizontal: 'row',
        _vertical: 'column',
      },
      gap: {
        _horizontal: '4',
        _vertical: '1',
      },
      borderBottomWidth: {
        _horizontal: '1px',
      },
      borderLeftWidth: {
        _vertical: '1px',
      },
    },
    indicator: {
      borderColor: 'colorPalette.default',
      _horizontal: {
        bottom: '0',
        borderBottomWidth: '2px',
        transform: 'translateY(1px)',
        width: 'var(--width)',
      },
      _vertical: {
        borderLeftWidth: '2px',
        height: 'var(--height)',
        transform: 'translateX(-1px)',
      },
    },
    item: {
      color: 'fg.muted',
      cursor: 'pointer',
      fontWeight: 'medium',
      transitionDuration: 'normal',
      transitionProperty: 'color',
      transitionTimingFunction: 'default',
      _hover: {
        color: 'fg.default',
      },
      _checked: {
        fontWeight: 'semibold',
        color: 'fg.default',
        _hover: {
          color: 'fg.default',
        },
      },
      _disabled: {
        color: 'fg.disabled',
        cursor: 'not-allowed',
        _hover: {
          color: 'fg.disabled',
        },
      },
      px: {
        _horizontal: '1',
        _vertical: '3',
      },
      pb: {
        _horizontal: '3',
      },
      py: {
        _vertical: '1.5',
      },
    },
  },
  defaultVariants: {
    size: 'md',
  },
  variants: {
    size: {
      sm: {
        item: {
          textStyle: 'sm',
        },
      },
      md: {
        item: {
          textStyle: 'md',
        },
      },
    },
  },
})

On this page