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

@anatoliygatt/heart-switch

v1.0.13

Published

A heart-shaped toggle switch component for React.

Downloads

98

Readme

📖 Table of Contents

🚀 Getting Started

⚡️ Quick Start

npm install @anatoliygatt/heart-switch @emotion/react @emotion/styled
import { useState } from 'react';
import { HeartSwitch } from '@anatoliygatt/heart-switch';

function Example() {
  const [checked, setChecked] = useState(false);
  return (
    <HeartSwitch
      size="lg"
      inactiveTrackFillColor="#cffafe"
      inactiveTrackStrokeColor="#22d3ee"
      activeTrackFillColor="#06b6d4"
      activeTrackStrokeColor="#0891b2"
      inactiveThumbColor="#ecfeff"
      activeThumbColor="#ecfeff"
      checked={checked}
      onChange={(event) => {
        setChecked(event.target.checked);
      }}
    />
  );
}

💻 Live Demo

Open in CodeSandbox

⚙️ Configuration

HeartSwitch supports the following props:

| Prop | Type | Default value | Description | | ------------------------ | ------ | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | size | string | sm | The size of the toggle switch. There are 3 available sizes:sm — 36x25pxmd — 54x37.5pxlg — 72x50px | | inactiveTrackFillColor | string | #ffffff | The fill color of the track when the toggle switch is in an inactive/off state. | | inactiveTrackStrokeColor | string | #d1d1d1 | The stroke color of the track when the toggle switch is in an inactive/off state. | | activeTrackFillColor | string | #ff708f | The fill color of the track when the toggle switch is in an active/on state. | | activeTrackStrokeColor | string | #ff4e74 | The stroke color of the track when the toggle switch is in an active/on state. | | disabledTrackFillColor | string | #f2f2f2 | The fill color of the track when the toggle switch is in a disabled state. | | disabledTrackStrokeColor | string | #d1d1d1 | The stroke color of the track when the toggle switch is in a disabled state. | | invalidTrackFillColor | string | #ffffff | The fill color of the track when the toggle switch is in an invalid state. | | invalidTrackStrokeColor | string | #d1d1d1 | The stroke color of the track when the toggle switch is in an invalid state. | | inactiveThumbColor | string | #ffffff | The color of the thumb when the toggle switch is in an inactive/off state. | | activeThumbColor | string | #ffffff | The color of the thumb when the toggle switch is in an active/on state. | | disabledThumbColor | string | #ffffff | The color of the thumb when the toggle switch is in a disabled state. | | invalidThumbColor | string | #ffffff | The color of the thumb when the toggle switch is in an invalid state. | | thumbShadowColor | string | rgb(23 23 23 / 0.25) | The color of the thumb's shadow. | | thumbFocusRingColor | string | rgb(59 130 246 / 0.5) | The color of the thumb's focus ring. |

The majority of the native <input type="checkbox" /> attributes are also supported; namely, autoFocus, checked, defaultChecked, disabled, form, name, required, value, id, title, tabIndex, aria-disabled, aria-label, aria-describedby, aria-labelledby, onBlur, onChange, onFocus and onInvalid.

HeartSwitch also supports ref forwarding. If ref is passed, it will be forwarded to the underlying <input type="checkbox" /> element. It can be especially useful when we want to use HeartSwitch as an uncontrolled component.

♿️ Accessibility

In order to comply with the web accessibility standards, we must make use of an aria-label or aria-labelledby attribute, like so:

function AccessibleExample() {
  return <HeartSwitch aria-label="Accept Terms and Conditions" />;
}

Also, it is recommended to use an aria-disabled instead of a disabled attribute to make HeartSwitch immutable but focusable, like so:

function AccessibleAndDisabledExample() {
  return (
    <HeartSwitch
      aria-label="Accept Terms and Conditions"
      aria-disabled="true"
    />
  );
}

👨🏼‍⚖️ License

MIT