import * as React from 'react'
import type { StoryObj, Meta } from '@storybook/react-webpack5'
import { GridEditorComboboxTreeMulti } from '.'
import { Grid } from '../../grids'
import { GridCellChips } from '../../components'
import { PlusCircle } from '@planview/pv-icons'
import type { CellEditorParams, GridConfirmPayload } from '../../types'
import type { InputType } from '@storybook/csf'
import type { ComboboxTreeOption } from '@planview/pv-uikit'
const hideControl: InputType = { control: false }
export default {
title: 'pv-grid/Components/Editors/GridEditorComboboxTreeMulti',
component: GridEditorComboboxTreeMulti,
parameters: {
controls: {
exclude: ['label', 'mode', 'rowId', 'columnId'],
},
},
argTypes: {
columnId: hideControl,
rowId: hideControl,
tabIndex: hideControl,
value: hideControl,
icon: {
options: ['no icon', 'with custom icon'],
mapping: {
'no icon': undefined,
'with custom icon': ,
},
control: {
type: 'radio',
},
},
options: {
control: false,
},
},
} satisfies Meta
const options: ComboboxTreeOption[] = [
{
label: 'Team A',
value: 'avatar-1',
avatar: 'img/avatars/400-8.jpg',
children: [
{
label: 'Alice',
value: 'avatar-1-1',
avatar: 'img/avatars/400-8.jpg',
},
{
label: 'Bob',
value: 'avatar-1-2',
avatar: 'img/avatars/400-8.jpg',
},
],
},
{
label: 'Team B',
value: 'avatar-2',
avatar: 'img/avatars/400-9.jpg',
children: [
{
label: 'Charlie',
value: 'avatar-2-1',
avatar: 'img/avatars/400-9.jpg',
},
{
label: 'David',
value: 'avatar-2-2',
avatar: 'img/avatars/400-9.jpg',
},
],
},
]
type UserRow = {
id: string
user: ComboboxTreeOption[]
}
function UserComboboxEditor(
props: CellEditorParams
): React.JSX.Element {
return (
)
}
export const Default: StoryObj> = {
render: function Component(args) {
const [rows, setRows] = React.useState([
{
id: '1',
user: [
{
label: 'Bob',
value: 'avatar-1-2',
avatar: 'img/avatars/400-8.jpg',
},
],
},
{ id: '2', user: [] },
{
id: '3',
user: [
{
label: 'Charlie',
value: 'avatar-2-1',
avatar: 'img/avatars/400-9.jpg',
},
{
label: 'David',
value: 'avatar-2-2',
avatar: 'img/avatars/400-9.jpg',
},
],
},
])
/* This is a storybook concern so its intentionally left out of code examples */
const MappedComponent = React.useCallback(
(props: CellEditorParams) => (
),
[args]
)
return (
},
Editor: MappedComponent,
},
},
]}
rows={rows}
onCellChange={(
confirm: GridConfirmPayload<
UserRow,
'user',
ComboboxTreeOption[]
>
) => {
setRows((r) =>
r.map((row) => {
if (row.id === confirm.rowId) {
return {
...row,
user: confirm.nextValue,
}
}
return row
})
)
}}
/>
)
},
}