'use client'; import { useMemo } from 'react'; import { Filter, Plus, Settings } from 'lucide-react'; import { Button } from '@kit/ui/button'; import { ButtonGroup, ButtonGroupSeparator, ButtonGroupText, } from '@kit/ui/button-group'; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from '@kit/ui/card'; import { Label } from '@kit/ui/label'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@kit/ui/select'; import { Separator } from '@kit/ui/separator'; import { Switch } from '@kit/ui/switch'; import { cn } from '@kit/ui/utils'; import { formatCodeBlock, generatePropsString, useStoryControls, } from '../lib/story-utils'; import { ComponentStoryLayout } from './story-layout'; import { SimpleStorySelect } from './story-select'; interface ButtonGroupControls { orientation: 'horizontal' | 'vertical'; size: 'sm' | 'default' | 'lg'; withLabel: boolean; withSeparator: boolean; withFilter: boolean; withPrimary: boolean; withSelect: boolean; fullWidth: boolean; } const orientationOptions = [ { value: 'horizontal', label: 'Horizontal', description: 'Buttons arranged side-by-side', }, { value: 'vertical', label: 'Vertical', description: 'Stack buttons vertically', }, ] as const; const sizeOptions = [ { value: 'sm', label: 'Small', description: 'Compact 36px controls', }, { value: 'default', label: 'Default', description: 'Standard 40px controls', }, { value: 'lg', label: 'Large', description: 'Spacious 44px controls', }, ] as const; export function ButtonGroupStory() { const { controls, updateControl } = useStoryControls({ orientation: 'horizontal', size: 'sm', withLabel: false, withSeparator: false, withFilter: false, withPrimary: false, withSelect: false, fullWidth: false, }); const buttonGroupPropsString = useMemo( () => generatePropsString( { orientation: controls.orientation, className: controls.fullWidth ? 'w-full' : undefined, }, { orientation: 'horizontal', className: undefined, }, ), [controls.fullWidth, controls.orientation], ); const generatedCode = useMemo(() => { const separatorOrientation = controls.orientation === 'vertical' ? 'horizontal' : 'vertical'; const buttonSizeProp = controls.size === 'default' ? '' : ` size="${controls.size}"`; const selectTriggerClasses = [ 'w-[140px] justify-between', controls.size === 'sm' ? 'h-9 text-sm' : null, controls.size === 'lg' ? 'h-11 text-base' : null, ] .filter(Boolean) .join(' '); const labelClasses = [ 'min-w-[120px] justify-between', controls.size === 'sm' ? 'text-sm' : null, controls.size === 'lg' ? 'text-base' : null, 'gap-2', ] .filter(Boolean) .join(' '); let code = ``; if (controls.withLabel) { code += `\n `; code += `\n Views`; code += `\n `; code += `\n `; } code += `\n `; code += `\n `; code += `\n `; if (controls.withSeparator) { code += `\n `; } if (controls.withFilter) { code += `\n `; } if (controls.withSelect) { code += `\n `; } if (controls.withPrimary) { code += `\n `; code += `\n `; code += `\n New view`; code += `\n `; } code += `\n`; return formatCodeBlock(code, [ "import { Filter, Plus, Settings } from 'lucide-react';", "import { Button } from '@kit/ui/button';", "import { ButtonGroup, ButtonGroupSeparator, ButtonGroupText } from '@kit/ui/button-group';", "import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@kit/ui/select';", ]); }, [buttonGroupPropsString, controls]); const separatorOrientation = controls.orientation === 'vertical' ? 'horizontal' : 'vertical'; const preview = (
{controls.withLabel && ( Views )} {controls.withSeparator && ( )} {controls.withFilter && ( )} {controls.withPrimary && ( )}
); const controlsPanel = ( <>
updateControl('orientation', value)} options={orientationOptions} />
updateControl('size', value)} options={sizeOptions} />
updateControl('withLabel', checked)} />
updateControl('withFilter', checked)} />
updateControl('withPrimary', checked)} />
); const examples = ( Button group sizes Mirror the documentation examples with small, default, and large buttons. ); return ( ); } export default ButtonGroupStory;