import * as React from 'react'
import type { StoryObj, Meta } from '@storybook/react-webpack5'
import { GridEditorDatePicker } from '.'
import { Grid } from '../grids'
import { GridCellDefault } from '../components'
import { PlusCircle } from '@planview/pv-icons'
import type { GridConfirmPayload } from '../types'
import type { InputType } from '@storybook/csf'
const hideControl: InputType = { control: false }
export default {
title: 'pv-grid/Components/Editors/GridEditorDatePicker',
component: GridEditorDatePicker,
parameters: {
controls: {
exclude: ['label', 'mode', 'rowId', 'columnId'],
},
},
argTypes: {
icon: {
options: ['no icon', 'with custom icon'],
mapping: {
'no icon': undefined,
'with custom icon': ,
},
control: {
type: 'radio',
},
},
columnId: hideControl,
rowId: hideControl,
tabIndex: hideControl,
value: hideControl,
},
} satisfies Meta
export const Default: StoryObj = {
render: function Component(args) {
const [rows, setRows] = React.useState([
{ id: '1', date: '2023-03-23' },
{ id: '2', date: '2023-06-07' },
{ id: '3', date: '2023-06-07' },
])
return (
)
},
Editor(props) {
return (
)
},
},
},
]}
rows={rows}
onCellChange={(
confirm: GridConfirmPayload<{ id: string }, 'date', string>
) => {
setRows((r) =>
r.map((row) => {
if (row.id === confirm.rowId) {
return {
...row,
date: confirm.nextValue,
}
}
return row
})
)
}}
/>
)
},
}
Default.parameters = {
docs: {
source: {
code: `
const [rows, setRows] = React.useState([
{ id: '1', date: '2023-03-23' },
{ id: '2', date: '2023-06-07' },
{ id: '3', date: '2023-06-07' },
])
return (
)
},
Editor(props) {
return (
)
},
},
},
]}
rows={rows}
onCellChange={(
confirm: GridConfirmPayload<{ id: string }, 'date', string>
) => {
setRows((r) =>
r.map((row) => {
if (row.id === confirm.rowId) {
return {
...row,
date: confirm.nextValue,
}
}
return row
})
)
}}
/>
)
`,
},
},
}