import * as React from 'react' import type { StoryObj, StoryFn, Meta } from '@storybook/react-webpack5' import { GridEditorRadio } from '.' import { Grid } from '../grids' import type { Column, GridConfirmPayload } from '../types' import type { InputType } from '@storybook/csf' const hideControl: InputType = { control: false } export default { title: 'pv-grid/Components/Editors/GridEditorRadio', component: GridEditorRadio, parameters: { controls: { exclude: ['label', 'mode', 'rowId'], }, }, argTypes: { columnId: hideControl, rowId: hideControl, tabIndex: hideControl, value: hideControl, }, } satisfies Meta type Project = { id: string title: string isDefault: boolean } export const Default: StoryObj = { render: function Component() { const [rows, setRows] = React.useState([ { id: '1', title: 'Alpha Project', isDefault: true }, { id: '2', title: 'Beta Project', isDefault: false }, { id: '3', title: 'Gamma Project', isDefault: false }, ]) return ( ) => { setRows((r) => r.map((row) => ({ ...row, isDefault: confirm.columnId === 'isDefault' ? row.id === confirm.rowId : row.isDefault, })) ) }} /> ) }, parameters: { docs: { source: { code: ` const [rows, setRows] = React.useState([ { id: '1', title: 'Alpha Project', isDefault: true }, { id: '2', title: 'Beta Project', isDefault: false }, { id: '3', title: 'Gamma Project', isDefault: false }, ]) return ( ) => { setRows((r) => r.map((row) => ({ ...row, isDefault: confirm.columnId === 'isDefault' ? row.id === confirm.rowId : row.isDefault, })) ) }} /> ) `, }, }, }, } export const Disabled: StoryFn = () => { const [rows, setRows] = React.useState([ { id: '1', title: 'Alpha Project', isDefault: true }, { id: '2', title: 'Beta Project', isDefault: false }, { id: '3', title: 'Gamma Project', isDefault: false }, ]) const columns: Column[] = React.useMemo( () => [ { id: 'title', label: 'Project', width: 300, cell: { editable: true, }, }, { id: 'isDefault', label: 'Default', width: 80, cell: { editable: ({ row }) => row.id !== '2', hybridEditor: 'always', Editor: GridEditorRadio, }, }, ], [] ) return ( ) => { setRows((r) => r.map((row) => ({ ...row, isDefault: confirm.columnId === 'isDefault' ? row.id === confirm.rowId : row.isDefault, })) ) }} /> ) }