Skip to content
BigBang

Popular

    ↑↓Navigate↵OpenEscClose
    TR

    Components

    Label

    A label that names a control outside Field and carries the necessity marker.

    Storybook
    Storybook
    Source
    Source

    The example below loads live from Storybook; open it in Storybook to use the controls.

    Live example, StorybookOpen in Storybook

    Label renders a native <label>. htmlFor matches the control’s id; clicking the label moves focus to the control.

    import { Label } from '@bigbang/ui';
    export default function Default() {
    return (
    <div className="flex max-w-80 flex-col gap-xs">
    <Label htmlFor="label-default">Field label</Label>
    <input id="label-default" className="h-(--bigbang-input-height-md) w-full rounded-(--bigbang-input-radius) border border-line-input bg-surface-raised px-(--bigbang-input-padding-inline) type-body-md" />
    </div>
    );
    }

    required adds * and a visually hidden “required” to the label. necessityIndicator="optional" writes “(optional)” on fields that are not required. The marker is the same as in Field.

    import { Label, Provider } from '@bigbang/ui';
    export default function Necessity() {
    return (
    <Provider locale="en-GB">
    <div className="flex flex-col items-start gap-md">
    <Label required>Field label</Label>
    <Label necessityIndicator="optional">Field label</Label>
    </div>
    </Provider>
    );
    }

    size gives 14 px (label-md) or 12 px (label-sm).

    import { Label } from '@bigbang/ui';
    export default function Sizes() {
    return (
    <div className="flex flex-col items-start gap-md">
    <Label size="md">Field label</Label>
    <Label size="sm">Field label</Label>
    </div>
    );
    }

    When the control is inside the label, htmlFor is not needed. disabled shows the label faded; disable the control too.

    import { Label } from '@bigbang/ui';
    export default function Wrapping() {
    return (
    <div className="flex flex-col items-start gap-md">
    <Label className="gap-sm">
    <input type="checkbox" />
    Option label
    </Label>
    <Label className="gap-sm" disabled>
    <input type="checkbox" disabled />
    Option label
    </Label>
    </div>
    );
    }

    The colour comes from color-text-default, and from color-text-disabled when disabled.

    import { Label } from '@bigbang/ui';
    export default function Wrapping() {
    return (
    <div className="flex flex-col items-start gap-md">
    <Label className="gap-sm">
    <input type="checkbox" />
    Option label
    </Label>
    <Label className="gap-sm" disabled>
    <input type="checkbox" disabled />
    Option label
    </Label>
    </div>
    );
    }