npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@commercetools-uikit/field-label

v19.16.0

Published

The FieldLabel component represents the label for a field in a form.

Downloads

27,527

Readme

FieldLabel

Description

The FieldLabel component represents the label for a field in a form. This component can also be used to better explain an input field and to guide the user to fill a form.

Installation

yarn add @commercetools-uikit/field-label
npm --save install @commercetools-uikit/field-label

Additionally install the peer dependencies (if not present)

yarn add react
npm --save install react

Usage

import { defineMessage, FormattedMessage } from 'react-intl';
import FlatButton from '@commercetools-uikit/flat-button';
import FieldLabel from '@commercetools-uikit/field-label';
import { WarningIcon } from '@commercetools-uikit/icons';

const messages = defineMessage();

const Example = () => (
  <FieldLabel
    title={<FormattedMessage {...messages.title} />}
    hasRequiredIndicator={true}
    onInfoButtonClick={() => {}}
    hint={<FormattedMessage {...messages.hint} />}
    hintIcon={<WarningIcon />}
    description={<FormattedMessage {...messages.description} />}
    badge={<FlatButton tone="primary" label="show" />}
    htmlFor="sampleInput"
    horizontalConstraint={7}
  />
);

export default Example;

Properties

| Props | Type | Required | Default | Description | | ---------------------- | ----------------------------------------------------------------------------------------------------- | :------: | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | title | unionPossible values:string , ReactNode | ✅ | | Title of the label | | hint | unionPossible values:string , ReactNode | | | Hint for the label. Provides a supplementary but important information regarding the behaviour of the input (e.g warn about uniqueness of a field, when it can only be set once), whereas description can describe it in more depth. Can also receive a hintIcon. | | description | unionPossible values:string , ReactNode | | | Provides a description for the title. | | onInfoButtonClick | FunctionSee signature. | | | Function called when info button is pressed. Info button will only be visible when this prop is passed. | | tone | unionPossible values:'primary' , 'inverted' | | | Indicates the tone to be applied to the label | | hintIcon | ReactElement | | | Icon to be displayed beside the hint text. Will only get rendered when hint is passed as well. | | badge | ReactNode | | | Badge to be displayed beside the label. Might be used to display additional information about the content of the field (E.g verified email) | | hasRequiredIndicator | boolean | | | Indicates if the labeled field is required in a form | | htmlFor | string | | | The for HTML attribute, used to reference form elements with the related attribute id or aria-labelledby. | | id | string | | | The id HTML attribute, used to reference non-form elements with the related attribute aria-labelledby. | | horizontalConstraint | unionPossible values:, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto' | | 'scale' | Horizontal size limit of the label. |

Signatures

Signature onInfoButtonClick

(
  event: MouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLButtonElement>
) => void

hintIcon

The hintIcon also accepts a custom color while defaulting to warning in the case above. The hintIcon does not support the size prop, and will always be rendered in the size medium.

<FieldLabel
  title={<FormattedMessage {...messages.title} />}
  hasRequiredIndicator={true}
  onInfoButtonClick={() => {}} />}
  hint={<FormattedMessage {...messages.hint} />}
- hintIcon={<WarningIcon />}
+ hintIcon={<WarningIcon color="primary" />}
  description={<FormattedMessage {...messages.description} />}
  badge={<FlatButton tone="primary" label="show" />}
  htmlFor="sampleInput"
  horizontalConstraint={7}
/>

hint vs description

Most fields will only use the description which provides more information about what the entered value will be used for.

The hint however is used to show additional information about the value the user enters. It can show the allowed characters. It can also show whether the entered value has errors (like a reference no longer existing in an attribute) when the form is loaded for the first time.

Neither of them should be used for form validation.

Dos and don'ts

Recommended to be used in vertical forms. (E.g input field below the label, and not besides).