import * as React from 'react' import type { StoryFn, Meta } from '@storybook/react-webpack5' import Field from './' import { Input, Textarea } from '@planview/pv-uikit' import { Board } from '@planview/pv-icons' import { border, borderRadius, spacingPx, text, theme, } from '@planview/pv-utilities' import styled from 'styled-components' export default { title: 'pv-form/Generic/Field', tags: ['autodocs'], component: Field, argTypes: { label: { control: { type: 'radio' }, options: ['string', 'configuration'], mapping: { string: 'My label', configuration: { text: 'Custom label', required: true, requiredTooltip: 'Hello world', iconTooltip: 'Tooltip over icon', icon: , }, }, }, }, args: { id: 'myId', label: 'My Label', error: '', warning: '', withAsterisk: false, count: '', }, parameters: { controls: { sort: 'requiredFirst', }, }, } satisfies Meta type Story = StoryFn export const Default: Story = (args) => ( {(props) => ( )} ) export const LabelToTheLeft: Story = (args) => ( {(props) => ( )} ) LabelToTheLeft.parameters = { controls: { exclude: ['labelPosition'], }, } export const FieldCountExample: Story = () => { const [text, setText] = React.useState('') const _error = text.includes('error') ? 'Please enter correct data' : text.length <= 40 ? '' : 'Too many characters.' return ( {({ id, ...props }) => ( )} ) } FieldCountExample.storyName = 'Example implementing field count' FieldCountExample.parameters = { controls: { disabled: true, hideNoControlsWarning: true, }, } export const WithError = Default.bind({}) WithError.args = { error: 'Some error message', } export const WithWarning = Default.bind({}) WithWarning.args = { warning: 'Some warning message', } const StyledContentEditable = styled.div` ${border.normal}; ${borderRadius.small}; padding: ${spacingPx.small}; ${text.regular}; color: ${theme.textPrimary}; ` /** * In this example, we mimic built in browser functionality * for a contenteditable element that isn't a form element and can't leverage native * label/field association. Click on the label and the contenteditable will be focused. */ export const FieldWithNonFormElement: Story = () => { const ref = React.useRef(null) return ( { ref.current?.focus() }} > {(fieldProps) => ( You can edit this contenteditable! )} ) } FieldWithNonFormElement.parameters = { controls: { disabled: true, hideNoControlsWarning: true, }, docs: { source: { code: ` const StyledContentEditable = styled.div\` \${border.normal}; \${borderRadius.small}; padding: \${spacingPx.small}; \${text.regular}; color: \${theme.textPrimary}; \` export const FieldWithNonFormElement: Story = () => { const ref = React.useRef(null) return ( { ref.current?.focus() }} > {(fieldProps) => ( You can edit this contenteditable! )} ) } `, }, }, }