import { Meta, Canvas, Controls } from '@storybook/addon-docs/blocks'
import * as ComboboxStories from './single.stories.tsx'

<Meta of={ComboboxStories} />

# GridEditorCombobox

```tsx
import { GridEditorCombobox } from '@planview/pv-grid'
```

The combobox cell editor uses the [Combobox](?path=/docs/pv-uikit-combobox--docs) component internally. It lets users add or edit a value from a set of predefined options, by either typing a value directly or by selecting one from the list.

**Note:** When using the `GridEditorCombobox` it is [good practice](https://design.planview.com/components/grid/grid-editors#combobox-editor) to use the `GridCellDefault` with `withCaret` set to true in the `Renderer` function.

<Canvas of={ComboboxStories.Default} />

### Props provided by the Grid (via `Editor`)

Additional props are provided by the grid that are not used by this editor.

<Controls include={['onConfirm', 'onCancel', 'tabIndex']} />

### Props to customize behavior

<Controls exclude={['onConfirm', 'onCancel', 'tabIndex']} />

## Usage with Column definition

This component should be used as part of a custom `Editor` method on the Column configuration.

```tsx
import { GridEditorCombobox, Column } from '@planview/pv-grid'

const privacyOptions: {
    label: string
    value: string
}[] = [
    {
        label: 'Private',
        value: 'private',
    },
    {
        label: 'Public',
        value: 'public',
    },
]

const EditableColumn: Column = {
    id: 'privacy',
    label: 'Combobox Editor',
    sortable: false,
    width: 300,
    cell: {
        editable: true,
        Renderer(props) {
            return <GridCellDefault {...props} withCaret />
        },
        Editor(props) {
            return (
                <GridEditorCombobox
                    {...props}
                    /**
                     * Note: value coming from the Editor will most likely be a string or numeric value
                     * so it is important to map the value to a `ComboboxOption` expected as `value`
                     * passed to the `GridEditorCombobox`
                     **/
                    value={privacyOptions.find((o) => o.value === props.value)}
                    clearable={false}
                    options={privacyOptions}
                />
            )
        },
    },
}
```

### With Avatars

<Canvas of={ComboboxStories.WithAvatars} />
