import * as React from 'react'
import type { StoryFn, Meta } from '@storybook/react-webpack5'
import { Toolbar, ToolbarSectionLeft, ToolbarSectionRight } from '..'
import { Board } from '@planview/pv-icons'
import { ListItem } from '@planview/pv-uikit'
import { ToolbarItem, ToolbarItemView, ToolbarItemCollapsedView } from '.'
export default {
title: 'pv-toolbar/Generic/ToolbarItem/ToolbarItemView',
tags: ['autodocs'],
component: ToolbarItemView,
argTypes: {
onHit: { action: 'hit button', table: { disable: true } },
},
parameters: {
controls: { disabled: true, hideNoControlsWarning: true },
docs: {
description: {
component: `
\`ToolbarItemView\`, always a child of the \`ToolbarItem\`, renders the component representation inside the toolbar when not collapsed into the more menu.
For the component to work properly you need to
1. Use the refObject passed as the first argument of the function
2. Spread the \`toolbarItemProps\` on the target element (the element you want to be navigable/focusable)
__Note:__ The props.toolbarItemProps include \`onClick\` and \`onKeyDown\` handlers that need to be applied to the element.
If you need to add your own event-handling, make sure to also call the handlers passed from \`toolbarItemProps\` (See example below)
### Usage
\`\`\`typescript
import { ToolbarItemView } from '@planview/pv-toolbar'
>
{(ref, props) => (
)}
\`\`\`
### Typing the ref
ToolbarItemViews props is generic and takes a __type__ -parameter \`T\`. The type should be of a focusable \`HTMLElement\`-type like \`HTMLButtonElement\`, \`HTMLInputElement\` etc...
\`\`\`typescript
>
....containing ref is of type "HTMLInputElement"
\`\`\`
`,
},
},
},
} satisfies Meta<
React.ComponentProps & {
onHit: (msg: string) => void
}
>
type StoryToolbarItemView = React.ComponentProps & {
onHit: (msg: string) => void
}
export const Default: StoryFn = ({ onHit }) => (
>
{(
ref,
{
showLabels,
toolbarItemProps: {
focused: _focused,
...toolbarItemProps
},
disabled,
}
) => (
)}
onHit('hit button')}
label="button"
/>
)
Default.storyName = 'ToolbarItemView'