summaryrefslogtreecommitdiffstats
path: root/src/components/atoms/forms/label.tsx
blob: ce4c70f332d749918893596e9e14988f1f130b8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { FC, ReactNode } from 'react';
import styles from './label.module.scss';

export type LabelProps = {
  /**
   * The label body.
   */
  children: ReactNode;
  /**
   * Add classnames to the label.
   */
  className?: string;
  /**
   * The field id.
   */
  htmlFor?: string;
  /**
   * Is the field required? Default: false.
   */
  required?: boolean;
  /**
   * The label size. Default: small.
   */
  size?: 'medium' | 'small';
};

/**
 * Label Component
 *
 * Render a HTML label element.
 */
const Label: FC<LabelProps> = ({
  children,
  className = '',
  required = false,
  size = 'small',
  ...props
}) => {
  const sizeClass = styles[`label--${size}`];

  return (
    <label className={`${styles.label} ${sizeClass} ${className}`} {...props}>
      {children}
      {required && <span className={styles.required}> *</span>}
    </label>
  );
};

export default Label;
ff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { IntlProvider } from 'react-intl';
import Widget from './widget';

/**
 * Widget - Storybook Meta
 */
export default {
  title: 'Molecules/Layout/Widget',
  component: Widget,
  args: {
    withBorders: false,
  },
  argTypes: {
    children: {
      control: {
        type: 'text',
      },
      description: 'The widget body',
      type: {
        name: 'string',
        required: true,
      },
    },
    expanded: {
      control: {
        type: 'boolean',
      },
      description: 'The widget state (expanded or collapsed)',
      table: {
        category: 'Options',
        defaultValue: { summary: true },
      },
      type: {
        name: 'boolean',
        required: false,
      },
    },
    level: {
      control: {
        type: 'number',
        min: 1,
        max: 6,
      },
      description: 'The heading level.',
      type: {
        name: 'number',
        required: true,
      },
    },
    title: {
      control: {
        type: 'text',
      },
      description: 'The widget title.',
      type: {
        name: 'string',
        required: true,
      },
    },
    withBorders: {
      control: {
        type: 'boolean',
      },
      description: 'Define if the content should have borders.',
      table: {
        category: 'Options',
        defaultValue: { summary: false },
      },
      type: {
        name: 'boolean',
        required: false,
      },
    },
  },
  decorators: [
    (Story) => (
      <IntlProvider locale="en">
        <Story />
      </IntlProvider>
    ),
  ],
} as ComponentMeta<typeof Widget>;

const Template: ComponentStory<typeof Widget> = (args) => <Widget {...args} />;

/**
 * Widget Stories - Expanded
 */
export const Expanded = Template.bind({});
Expanded.args = {
  children: 'Widget body',
  expanded: true,
  level: 2,
  title: 'Widget title',
};

/**
 * Widget Stories - Collapsed
 */
export const Collapsed = Template.bind({});
Collapsed.args = {
  children: 'Widget body',
  expanded: false,
  level: 2,
  title: 'Widget title',
};