import * as React from 'react' import type { StoryObj, StoryFn, Meta } from '@storybook/react-webpack5' import type { InputProps } from '.' import { Input } from '.' import { Comment } from '@planview/pv-icons' import { text } from '@planview/pv-utilities' import styled from 'styled-components' const StyledText = styled.p` ${text.regular}; ` export default { title: 'pv-form/Components/Input', tags: ['autodocs'], component: Input, argTypes: { value: { control: { type: 'text', }, }, limit: { options: [ 'none', 'number', 'always visible counter', 'no truncation', ], mapping: { none: undefined, number: 30, 'always visible counter': { value: 30, show: 'always', } satisfies InputProps['limit'], 'no truncation': { value: 30, truncate: false, } satisfies InputProps['limit'], }, control: { type: 'radio', }, table: { type: { summary: 'number | LimitConfig', }, }, }, }, parameters: { badges: ['intl'], }, } satisfies Meta const Template: StoryFn = (args) => export const Default = Template.bind({}) Default.args = { label: 'Sample label', placeholder: 'John Doe', } export const WithIcon = Template.bind({}) WithIcon.args = { label: 'Sample label', icon: , defaultValue: 'I really like this content', } export const WithAsterisk = Template.bind({}) WithAsterisk.args = { label: 'Field is required', withAsterisk: true, } export const WithAsteriskAndIcon = Template.bind({}) WithAsteriskAndIcon.args = { label: { text: 'Field is required with icon', required: true, requiredTooltip: 'This is required', iconTooltip: 'You may want to provide additional information using this mechanism', }, } export const LongLabelWithAsteriskAndIcon: StoryFn = (args) => (
) LongLabelWithAsteriskAndIcon.args = { label: { text: 'Field is required with icon that has such a long label that it wraps to three lines', required: true, requiredTooltip: 'This is required', iconTooltip: 'You may want to provide additional information using this mechanism', }, } export const WithLimit: StoryFn = (args) => (
The default behavior only shows the counter once get closer to the end. Once you are nearing the limit, the text will change to a warning color.
) WithLimit.args = { label: 'Sample label', defaultValue: 'Content', limit: 'number' as any, } export const Disabled = Template.bind({}) Disabled.args = { label: 'Sample label', disabled: true, value: 'I really like this content', } export const ReadOnly = Template.bind({}) ReadOnly.args = { label: 'Sample label', readOnly: true, value: 'I really like this content', } export const Error = Template.bind({}) Error.args = { label: 'Sample label', error: 'This is an error message', value: 'I really like this content', } export const Warning = Template.bind({}) Warning.args = { label: 'Sample label', warning: 'This is an warning message', value: 'I really like this content', } /** * Passing an array of strings into the `value` prop activates * a bulk editing mode that will display the count of unique values * and give a means of clearing all values at once with the clear button. * * If all values in the array are identical, then bulk editing mode will * not activate and the input will display that single value. * * Bulk editing is not supported with `defaultValue`. * * Bulk editing is localized internally and requires the component to be * a descendant of an `IntlProvider` from react-intl. See * [our localization page](/docs/localization--docs) for more information. */ export const BulkEditing: StoryObj = { args: { label: 'Sample label', }, argTypes: { value: { control: false, }, }, render: function BulkEditing(args) { const [value, setValue] = React.useState([ 'Jon', 'Eva', 'Adeline', ]) return ( { setValue(cbargs[0]) args?.onChange?.(...cbargs) }} /> ) }, }