Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 46 additions & 5 deletions packages/react/src/components/Form/Form.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,32 @@ export default {
},
};

export const Default = () => {
const formArgs = {
ariaLabel: 'Sample form',
className: 'some-class',
};

const formArgTypes = {
ariaLabel: {
control: { type: 'text' },
description: 'Specify an accessible label for the form.',
},
className: {
control: { type: 'text' },
},
onSubmit: {
action: 'onSubmit',
},
};

export const Default = ({ ariaLabel, className, onSubmit }) => {
const handleSubmit = (event) => {
event.preventDefault();
onSubmit?.(event);
};

return (
<Form aria-label="sample form">
<Form aria-label={ariaLabel} className={className} onSubmit={handleSubmit}>
<Stack gap={7}>
<FormGroup className="some-class" legendText="Checkbox heading">
<Checkbox defaultChecked labelText="Checkbox label" id="checkbox-0" />
Expand Down Expand Up @@ -234,6 +257,12 @@ export const Default = () => {
);
};

Default.args = formArgs;
Default.argTypes = formArgTypes;
Default.parameters = {
controls: { include: Object.keys(formArgTypes) },
};

const items = [
{
id: 'option-0',
Expand Down Expand Up @@ -263,7 +292,11 @@ const items = [
];

export const withAILabel = (args) => {
const { revertActive, ...rest } = args;
const { ariaLabel, className, onSubmit, revertActive, ...rest } = args;
const handleSubmit = (event) => {
event.preventDefault();
onSubmit?.(event);
};
const aiLabel = (
<AILabel className="ai-label-container" revertActive={revertActive}>
<AILabelContent>
Expand Down Expand Up @@ -296,7 +329,10 @@ export const withAILabel = (args) => {
);
return (
<Stack gap={7} className="form-example">
<Form aria-label="sample form" className="ai-label-form">
<Form
aria-label={ariaLabel}
className={['ai-label-form', className].filter(Boolean).join(' ')}
onSubmit={handleSubmit}>
<Stack gap={7}>
<NumberInput {...numberInputProps} decorator={aiLabel} {...rest} />
<DatePicker datePickerType="single">
Expand Down Expand Up @@ -374,7 +410,10 @@ export const withAILabel = (args) => {
</Stack>
</Form>

<FluidForm aria-label="sample ai form" className="fluid-ai-label-form">
<FluidForm
aria-label={ariaLabel}
className={['fluid-ai-label-form', className].filter(Boolean).join(' ')}
onSubmit={handleSubmit}>
<div style={{ display: 'flex' }}>
<FluidDatePicker datePickerType="single" style={{ width: '100%' }}>
<FluidDatePickerInput
Expand Down Expand Up @@ -485,6 +524,7 @@ export const withAILabel = (args) => {
};

withAILabel.args = {
...formArgs,
revertActive: false,
invalid: false,
invalidText:
Expand All @@ -496,6 +536,7 @@ withAILabel.args = {
};

withAILabel.argTypes = {
...formArgTypes,
disabled: {
control: {
type: 'boolean',
Expand Down
Loading