New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@purpurds/checkbox

Package Overview
Dependencies
Maintainers
2
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@purpurds/checkbox

import { Meta, ArgTypes, Primary, Subtitle } from "@storybook/blocks";

  • 3.5.0
  • npm
  • Socket score

Version published
Weekly downloads
1.4K
decreased by-47.16%
Maintainers
2
Weekly downloads
 
Created
Source

import { Meta, ArgTypes, Primary, Subtitle } from "@storybook/blocks";

import * as CheckboxStories from "./src/checkbox.stories"; import packageInfo from "./package.json";

Checkbox

Version {packageInfo.version}

Showcase

Properties

Installation

Via NPM

Add the dependency to your consumer app like "@purpurds/checkbox": "x.y.z"

From outside the monorepo (build-time)

To install this package, you need to setup access to the artifactory. Click here to go to the guide on how to do that.


In MyApp.tsx

import "@purpurds/tokens/index.css";

and

import "@purpurds/checkbox/styles";

Examples

In MyComponent.tsx

Controlled.

For when you have to controll and use the state of the checkbox.

import { Checkbox } from "@purpurds/checkbox";

export const MyComponent = () => {
  const [checked, setChecked] = useState(false);
  return (
    <div>
      <Checkbox
        id="my-checkbox"
        checked={checked}
        onChange={setChecked}
        label="My checkbox"
        labelPosition="right"
      />
    </div>
  );
};
Indeterminate.

When using the Indeterminate state, the toggle must be controlled.

import { Checkbox } from "@purpurds/checkbox";

export const MyComponent = () => {
  const [checked, setChecked] = useState(false);

  return (
    <div>
      <Checkbox
        id="my-checkbox"
        checked={checked}
        onChange={setChecked}
        label="My checkbox"
        labelPosition="right"
      />
      <Button
        variant="primary"
        onClick={() =>
          setChecked((prevChecked) => (prevChecked === "indeterminate" ? false : "indeterminate"))
        }
      >
        Toggle indeterminate
      </Button>
    </div>
  );
};
Uncontrolled

For when you don't have to controll state of the checkbox, e.g. when in a form.

import { Checkbox } from "@purpurds/checkbox";

export const MyComponent = () => {
  /**
   * The checkbox will render checked, and handle it's state itself.
   *
   * Since it is rendered in a form, it will render a checkbox input under the hood
   * that reflects its value and state.
   */
  return (
    <form>
      <Checkbox id="my-checkbox" defaultChecked label="My uncontrolled checkbox" />
    </form>
  );
};

Use the aria-labelledby property and pass the id of the label.

import { Checkbox } from "@purpurds/checkbox";

export const MyComponent = () => {
  return (
    <div>
      <label id="my-custom-label" htmlFor="my-checkbox">
        Custom label
      </label>
      <Checkbox aria-labeledby="my-custom-label" id="my-checkbox" {...otherProps} />
    </div>
  );
};

If there should be no label at all, use the aria-label to label the checkbox for screen readers.

import { Checkbox } from "@purpurds/checkbox";

export const MyComponent = () => {
  return (
    <div>
      <Checkbox aria-label="checkbox some awesome stuff!" id="my-checkbox" {...otherProps} />
    </div>
  );
};

FAQs

Package last updated on 21 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc