diff --git a/tools/ui-components/src/form-control/form-control.stories.tsx b/tools/ui-components/src/form-control/form-control.stories.tsx index 76e8eec250a..d4dc12e8ba5 100644 --- a/tools/ui-components/src/form-control/form-control.stories.tsx +++ b/tools/ui-components/src/form-control/form-control.stories.tsx @@ -4,7 +4,33 @@ import { FormControl, FormControlProps, FormControlVariationProps } from '.'; const story = { title: 'Example/FormControl', - component: FormControl + component: FormControl, + parameters: { + controls: { + include: [ + 'className', + 'id', + 'onChange', + 'value', + 'componentClass', + 'placeholder', + 'required', + 'type' + ] + } + }, + argTypes: { + className: { control: { type: 'text' } }, + id: { control: { type: 'text' } }, + onChange: { action: 'changed' }, + value: { control: { type: 'text' } }, + componentClass: { + options: ['input', 'textarea'] + }, + placeholder: { control: { type: 'text' } }, + required: { control: 'boolean' }, + type: { options: ['text', 'email', 'url'] } + } }; const DefaultTemplate: Story = args => { diff --git a/tools/ui-components/src/form-control/form-control.tsx b/tools/ui-components/src/form-control/form-control.tsx index 7a8fcbc8a87..1c00b0f70ac 100644 --- a/tools/ui-components/src/form-control/form-control.tsx +++ b/tools/ui-components/src/form-control/form-control.tsx @@ -2,18 +2,55 @@ import React from 'react'; import { FormControlFeedback as Feedback } from './form-control-feedback'; import { FormControlStatic as Static } from './form-control-static'; -import { FormControlProps } from './types'; +import { FormControlProps, FormControlElement } from './types'; -const FormControl = React.forwardRef( - ({ className, id, testId }, ref): JSX.Element => { - const defaultClasses = - 'outline-0 block w-full h-8 py-1.5 px-2.5 text-md text-default-foreground-primary ' + +// Uses controlId from if not explicitly specified. +// type Only relevant if componentClass is 'input'. + +const FormControl = React.forwardRef( + ( + { + className, + id, + testId, + onChange, + value, + // eslint-disable-next-line @typescript-eslint/naming-convention + componentClass: Component = 'input', + placeholder, + name, + required, + type + }, + ref + ): JSX.Element => { + let defaultClasses = + 'outline-0 block w-full py-1.5 px-2.5 text-md text-default-foreground-primary ' + 'bg-default-background-primary bg-none rounded-none border-1 border-solid ' + 'border-default-background-quaternary shadow-none ' + 'transition ease-in-out duration-150 focus:border-default-foreground-tertiary'; - const classes = [defaultClasses, className].join(' '); - return ; + let variantClass; + if (Component === 'textarea') variantClass = 'h-auto'; + else defaultClasses += 'h-8'; + + //row and componentClass + const classes = [defaultClasses, variantClass, className].join(' '); + + return ( + + ); } ); const MainFormControl = Object.assign(FormControl, { Feedback, Static }); diff --git a/tools/ui-components/src/form-control/types.ts b/tools/ui-components/src/form-control/types.ts index 78256b78eb8..d26f2c1b1d6 100644 --- a/tools/ui-components/src/form-control/types.ts +++ b/tools/ui-components/src/form-control/types.ts @@ -1,7 +1,20 @@ -export interface FormControlProps { +import React from 'react'; + +export type FormControlElement = HTMLInputElement | HTMLTextAreaElement; + +export interface FormControlProps + extends React.HTMLAttributes { className?: string; id?: string; testId?: string; + onChange?: React.ChangeEventHandler; + value?: string; + componentClass?: typeof React.Component; + placeholder?: string; + name?: string; + required?: boolean; + rows?: number; + type?: 'text' | 'email' | 'url'; } export interface FormControlVariationProps {