GithubHelp home page GithubHelp logo

anatoliygatt / heart-switch Goto Github PK

View Code? Open in Web Editor NEW
436.0 2.0 16.0 5.37 MB

❤️ A heart-shaped toggle switch component for React.

Home Page: https://heart-switch.netlify.app

License: MIT License

Shell 0.55% TypeScript 99.45%
react component react-component toggle switch toggle-switch accessible javascript typescript

heart-switch's Introduction


heart-switch Demo

heart-switch

A heart-shaped toggle switch component for React. Inspired by Tore Bernhoft's I heart toggle Dribbble shot and Aaron Iker's Codepen.


Github CI Workflow Status NPM Version License


📖 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 — 36x25px
  • md — 54x37.5px
  • lg — 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

heart-switch's People

Contributors

anatoliygatt avatar dependabot[bot] avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

heart-switch's Issues

Your VSCode settings

Hi Anatoli! Would you mind sharing your VSCode settings, like the extensions you use etc.

Loader states

Hi, this is great work.
I think it would be a great idea to also incorporate a isLoading prop to control any loading states? Wdyt @anatoliygatt ?

Suggestion: Providing a CDN option

As I currently see, the only option to use this heart-switch is by installing it using NodeJS as a package, but there are many people who would like to use this switch and are not able to since they work on static domains (GitHub Pages for example) so having a CDN can help them to use this and quite possibly increase the popularity of this repository.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.