import { action } from 'storybook/actions'; import React, { useState } from 'react'; import { Icon, Stack } from '../src/lib'; import { Button, ButtonGroup } from '../src/lib/next'; import { Wrapper, Title } from './common'; export default { title: 'Components/ButtonGroup', component: ButtonGroup, }; const SORT_OPTIONS = [ { value: 'name', label: 'Name' }, { value: 'managedData', label: 'Managed data' }, { value: 'version', label: 'Version' }, ] as const; const GROUP_OPTIONS = [ { value: 'label', label: 'Label' }, { value: 'health', label: 'Health' }, { value: 'version', label: 'Version' }, ] as const; /** * Single-select segmented control — provide `value` + `onChange` and give each * child `Button` a `value`. This is the "Sort by" use case from maestro: the * selected criterion is highlighted, and re-selecting it toggles the direction. */ export const SortBy = () => { const [sortBy, setSortBy] = useState('name'); const [direction, setDirection] = useState<'asc' | 'desc'>('asc'); const handleChange = (value: string) => { if (value === sortBy) { setDirection((current) => (current === 'asc' ? 'desc' : 'asc')); } else { setSortBy(value); setDirection('asc'); } }; return ( Sort by {SORT_OPTIONS.map((option) => (