Files
o11y-components/apps/docs/stories/combobox-item.stories.tsx
zeekay 464e1eece0 State a version once
A version written into a manifest is written into every manifest that wants it,
which is how eslint came to exist in a hundred and four forms across this estate
and how a package came to resolve twice at run time. The catalog moves the number
out of the manifest: a manifest names the package, the workspace names the
version.

Four are held below their latest because the newer release cannot be used, and
the reason is recorded rather than the version alone: @noble/hashes 2 renamed
every subpath the web3 stack imports, @splinetool/runtime 2 depends on a package
that was never published, @dynamic-labs 5.4.1 the same, and react-resizable-panels
3 points its types condition at the bundle.
2026-09-15 11:45:32 -07:00

135 lines
3.4 KiB
TypeScript

import {
Combobox,
ComboboxCommand,
ComboboxContent,
ComboboxEmpty,
ComboboxInput,
ComboboxItem,
ComboboxList,
ComboboxTrigger,
} from '@signozhq/ui';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { useState } from 'react';
import { itemArgTypes } from './shared/command-combobox-arg-types.js';
const meta: Meta<typeof ComboboxItem> = {
title: 'Primitive Components/Combobox/ComboboxItem',
component: ComboboxItem,
argTypes: {
...itemArgTypes,
isSelected: {
control: 'boolean',
description: 'When true, shows a checkmark indicating the current selection.',
table: { category: 'State', type: { summary: 'boolean' } },
},
prefix: {
control: false,
description: 'Custom prefix. Pass null to hide the default check icon.',
table: { category: 'Content', type: { summary: 'React.ReactNode | null' } },
},
},
parameters: {
layout: 'fullscreen',
},
tags: ['autodocs'],
};
export default meta;
type Story = StoryObj<typeof ComboboxItem>;
const frameworks = [
{ value: 'react', label: 'React' },
{ value: 'vue', label: 'Vue' },
{ value: 'angular', label: 'Angular' },
];
export const Default: Story = {
args: {
children: 'React',
disabled: false,
isSelected: false,
},
render: (args) => {
const [value, setValue] = useState(args.isSelected ? 'react' : '');
const [open, setOpen] = useState(true);
return (
<div style={{ padding: 32, width: '100%', maxWidth: 384 }}>
<Combobox open={open} onOpenChange={setOpen}>
<ComboboxTrigger
placeholder="Select a framework..."
value={frameworks.find((f) => f.value === value)?.label || ''}
/>
{open && (
<ComboboxContent>
<ComboboxCommand>
<ComboboxInput placeholder="Search frameworks..." />
<ComboboxList>
{frameworks.map((f) => (
<ComboboxItem
key={f.value}
value={f.value}
onSelect={() => {
setValue(f.value);
setOpen(false);
}}
isSelected={value === f.value}
{...(f.value === 'react' ? args : {})}
>
{f.value === 'react' ? args.children : f.label}
</ComboboxItem>
))}
<ComboboxEmpty>No results.</ComboboxEmpty>
</ComboboxList>
</ComboboxCommand>
</ComboboxContent>
)}
</Combobox>
</div>
);
},
};
export const WithPrefixNull: Story = {
render: () => {
const [value, setValue] = useState('');
const [open, setOpen] = useState(true);
return (
<div style={{ padding: 32, width: '100%', maxWidth: 384 }}>
<Combobox open={open} onOpenChange={setOpen}>
<ComboboxTrigger
placeholder="Select a framework..."
value={frameworks.find((f) => f.value === value)?.label || ''}
/>
{open && (
<ComboboxContent>
<ComboboxCommand>
<ComboboxInput placeholder="Search frameworks..." />
<ComboboxList>
{frameworks.map((f) => (
<ComboboxItem
key={f.value}
value={f.value}
onSelect={() => {
setValue(f.value);
setOpen(false);
}}
isSelected={value === f.value}
prefix={null}
>
{f.label}
</ComboboxItem>
))}
<ComboboxEmpty>No results.</ComboboxEmpty>
</ComboboxList>
</ComboboxCommand>
</ComboboxContent>
)}
</Combobox>
</div>
);
},
};