ProductPromotion
Logo

React.JS

made by https://0x3d.site

GitHub - anatoliygatt/heart-switch: ❤️ A heart-shaped toggle switch component for React.
❤️ A heart-shaped toggle switch component for React. - anatoliygatt/heart-switch
Visit Site

GitHub - anatoliygatt/heart-switch: ❤️ A heart-shaped toggle switch component for React.

GitHub - anatoliygatt/heart-switch: ❤️ A heart-shaped toggle switch component for React.

📖 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

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory