import * as React from 'react' import type { StoryObj, StoryFn, Meta } from '@storybook/react-webpack5' import type { InputNumericProps } from '.' import { InputNumeric } from '.' import { Plan } from '@planview/pv-icons' import { color } from '@planview/pv-utilities' export default { title: 'pv-form/Components/InputNumeric', tags: ['autodocs'], component: InputNumeric, argTypes: { defaultValue: { control: { type: 'number' }, }, value: { control: { type: 'number' }, }, withAsterisk: { table: { category: 'Label' }, }, label: { table: { category: 'Label' }, }, labelPosition: { table: { category: 'Label' }, }, showCounter: { table: { category: 'Deprecated' }, }, limit: { options: [ 'none', 'number', 'always visible counter', 'no truncation', ], mapping: { none: undefined, number: 20, 'always visible counter': { value: 20, show: 'always', } satisfies InputNumericProps['limit'], 'no truncation': { value: 20, truncate: false, } satisfies InputNumericProps['limit'], }, control: { type: 'radio', }, table: { type: { summary: 'number | LimitConfig', }, category: 'Field', }, }, onChange: { action: 'value change', table: { category: 'Callbacks' }, }, onFocus: { action: 'focus', table: { category: 'Callbacks' }, }, onBlur: { action: 'blur', table: { category: 'Callbacks' }, }, onKeyDown: { action: 'keydown', table: { category: 'Callbacks' }, }, onClear: { action: 'value cleared', table: { category: 'Callbacks' }, }, placeholder: { control: { type: 'text' }, table: { category: 'Field' }, }, type: { control: { type: 'radio' }, options: ['undefined', 'numeric', 'currency', 'percentage'], mapping: { undefined: undefined, }, table: { category: 'Field' }, }, decimalSeparator: { control: { type: 'radio' }, options: ['.', ','], table: { category: 'Decimals' }, }, maximumFractionDigits: { table: { category: 'Decimals' }, }, disabled: { table: { category: 'State' }, }, error: { table: { category: 'State' }, }, selected: { table: { category: 'State' }, }, readOnly: { table: { category: 'State' }, }, focus: { table: { category: 'State' }, }, icon: { control: { type: 'radio' }, options: [ 'undefined (will use type to determine what icon to use)', 'with customized icon', ], mapping: { 'undefined (will use type to determine what icon to use)': undefined, 'with customized icon': , }, }, nativeProps: { table: { category: 'Field' }, }, id: { table: { category: 'Field' }, }, tabIndex: { table: { category: 'Field' }, }, maxLength: { table: { category: 'Field' }, }, clearable: { table: { category: 'Field' }, }, iconColor: { table: { category: 'Deprecated', }, }, password: { table: { category: 'Deprecated', }, }, }, parameters: { badges: ['intl'], }, } satisfies Meta const Template: StoryFn = (args) => ( ) export const Default = Template.bind({}) Default.args = { label: 'Sample label', placeholder: 'Enter numeric value', } 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 Disabled = Template.bind({}) Disabled.args = { label: 'Sample label', disabled: true, value: 2, } export const ReadOnly = Template.bind({}) ReadOnly.args = { label: 'Sample label', readOnly: true, value: 2, } export const Error = Template.bind({}) Error.args = { label: 'Sample label', error: 'This is an error message', value: 2, } export const Warning = Template.bind({}) Warning.args = { label: 'Sample label', warning: 'This is an warning message', value: 2, } export const NegativeValue = Template.bind({}) NegativeValue.args = { defaultValue: -23, } /** * Example of setting the number of allowed fraction digits after the decimal point using `maximumFractionDigits` prop. */ export const MaximumFractionDigits = Template.bind({}) MaximumFractionDigits.args = { maximumFractionDigits: 6, defaultValue: 12.123456, } /** * Example of using max and min to set a range accepted by the input. The value is corrected on blur or enter key down. */ export const MaxAndMinValues = Template.bind({}) MaxAndMinValues.args = { placeholder: 'Enter value between 10 and 20', min: 10, max: 20, defaultValue: '', } /** * 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([ '1.0', '2', '1000', ]) return ( { setValue(cbargs[0]) args?.onChange?.(...cbargs) }} /> ) }, }