diff --git a/packages/core/src/components/field-label/field-label.scss b/packages/core/src/components/field-label/field-label.scss new file mode 100644 index 000000000..7be50fb0c --- /dev/null +++ b/packages/core/src/components/field-label/field-label.scss @@ -0,0 +1,19 @@ +@use '../../helpers'; + +@mixin FieldLabel() { + .ods-field-label { + @include helpers.font('300-regular'); + + color: helpers.color('content-main'); + display: flex; + flex-flow: column wrap; + padding-top: helpers.space(0.5); + + + .ods-input, + + .ods-textarea, + > .ods-input, + > .ods-textarea { + margin-top: helpers.space(0.5); + } + } +} diff --git a/packages/core/src/components/index.scss b/packages/core/src/components/index.scss index 195878250..a1ee33bbf 100644 --- a/packages/core/src/components/index.scss +++ b/packages/core/src/components/index.scss @@ -2,6 +2,8 @@ @forward './button/button'; @use './checkbox/checkbox'; @forward './checkbox/checkbox'; +@use './field-label/field-label'; +@forward './field-label/field-label'; @use './helper-text/helper-text'; @forward './helper-text/helper-text'; @use './icon/icon'; @@ -18,6 +20,7 @@ @mixin components() { @include button.Button(); @include checkbox.Checkbox(); + @include field-label.FieldLabel(); @include helper-text.HelperText(); @include icon.Icon(); @include input.Input(); diff --git a/packages/react/src/components/field-label/field-label.stories.tsx b/packages/react/src/components/field-label/field-label.stories.tsx new file mode 100644 index 000000000..8c3127d4f --- /dev/null +++ b/packages/react/src/components/field-label/field-label.stories.tsx @@ -0,0 +1,90 @@ +import { + FieldLabel, + FieldLabelProps, + HelperText, + Input, + Textarea, +} from '@onfido/castor-react'; +import React from 'react'; +import { Meta, omit, Story } from '../../../../../docs'; + +export default { + title: 'React/FieldLabel', + component: FieldLabel, + argTypes: { + ...omit('className', 'style'), + children: { control: 'text' }, + }, + args: { + children: 'Label', + }, +} as Meta; + +export const Playground: Story = (props: FieldLabelProps) => ( + +); + +interface FieldLabelWithHelperTextProps extends FieldLabelProps { + label: string; + helperText: string; +} + +export const WithHelperText = ({ + label, + helperText, + ...restFieldLabelProps +}: FieldLabelWithHelperTextProps) => ( + + {label} + {helperText} + +); +WithHelperText.argTypes = omit('children'); +WithHelperText.args = { + label: 'Label', + helperText: 'Helper text', +}; + +interface FieldLabelWithInputProps extends FieldLabelProps { + id: string; + label: string; +} + +export const WithInput = ({ + id, + label, + ...restFieldLabelProps +}: FieldLabelWithInputProps) => ( + <> + + {label} + + + +); +WithInput.args = { + id: 'field-label-with-input', + label: 'Label', +}; + +interface FieldLabelWithTextareaProps extends FieldLabelProps { + id: string; + label: string; +} + +export const WithTexarea = ({ + id, + label, + ...restFieldLabelProps +}: FieldLabelWithTextareaProps) => ( + <> + + {label} + + +); +WithHelperText.argTypes = omit('children'); +WithHelperText.args = { + label: 'Label', + helperText: 'Helper text', +}; diff --git a/packages/react/src/components/textarea/textarea.tsx b/packages/react/src/components/textarea/textarea.tsx index 473709df5..62843b521 100755 --- a/packages/react/src/components/textarea/textarea.tsx +++ b/packages/react/src/components/textarea/textarea.tsx @@ -1,29 +1,47 @@ import { c, classy, m, TextareaProps as BaseProps } from '@onfido/castor'; -import React from 'react'; +import React, { useState } from 'react'; +import { FieldLabelWrapper } from '../../internal'; import { withRef } from '../../utils'; +const idPrefix = 'castor_textarea'; +let idCount = 0; + export const Textarea = withRef( ( { + id: externalId, resize = 'vertical', rows = 3, invalid, + children, className, style, ...restProps }: TextareaProps, ref: TextareaProps['ref'] - ): JSX.Element => ( -