Socket
Socket
Sign inDemoInstall

react-custom-checkbox

Package Overview
Dependencies
3
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-custom-checkbox

A simple and fully customizable React checkbox input component.


Version published
Weekly downloads
2.1K
decreased by-26.14%
Maintainers
1
Install size
74.5 kB
Created
Weekly downloads
 

Readme

Source

react-custom-checkbox

New Switch Component See More

A simple and fully customizable React checkbox input component.

NPM JavaScript Style Guide

Install

npm install --save react-custom-checkbox

Or

yarn add react-custom-checkbox

Demo Video

Usage

import React from "react";
import * as Icon from "react-icons/fi";
import Checkbox from "react-custom-checkbox";

const MyComponent = () => {
  return (
    <>
      <h4>Default:</h4>
      <Checkbox />
      <h4>Using Custom Icon:</h4>
      <Checkbox
        icon={<Icon.FiCheck color="#174A41" size={14} />}
        name="my-input"
        checked={true}
        onChange={(value, event) => {
          let p = {
            isTrue: value,
          };
          console.log(event);
          return alert(value);
        }}
        borderColor="#D7C629"
        style={{ cursor: "pointer" }}
        labelStyle={{ marginLeft: 5, userSelect: "none" }}
        label="Have you started using it?"
      />
      <h4>Using Image Icon:</h4>
      <Checkbox
        checked={true}
        icon={<img src={require("./check.png")} style={{ width: 24 }} alt="" />}
        borderColor="#D7C629"
        borderRadius={10}
        size={18}
        label="Get em!"
      />
      <h4>More Styling:</h4>
      <Checkbox
        checked={true}
        icon={
          <div
            style={{
              display: "flex",
              flex: 1,
              backgroundColor: "#174A41",
              alignSelf: "stretch",
            }}
          >
            <Icon.FiCheck color="white" size={20} />
          </div>
        }
        borderColor="#174A41"
        // borderWidth={0}
        borderRadius={20}
        style={{ overflow: "hidden" }}
        size={20}
        label="Coooool right?"
      />
    </>
  );
};

export default MyComponent;

Props

PropExplanationData Type(Sample) ValuesDefault
iconcustom check iconObject (jsx)* <img src={require("./check.png")} style={{ width: 24 }} alt="" /><div style={{ backgroundColor: "#D7C629", borderRadius: 5, padding: 5 }} />
checkedstate of checkboxBool_ true
_ false
false
disabledcheckbox input active/inactive stateBool_ true
_ false
false
labelcheckbox label textString_ "Cheese"
_ "Lettuce"
``
onChangefunction triggered when checked state changesFuncUsage
* (checked, event) => console.log(checked, event)
null
sizesize of checkboxNumber_ 30
_ 15
18
rightlabel position right?Bool_ true
_ false
false
namecheckbox input nameString_ "toppings"
_ "hobbies"
""
valuecheckbox input valueString_ "cheese"
_ "lettuce"
""
referencecheckbox input refFunc_ checkboxRef
_ this.checkboxRef
``
stylecheckbox css styleObject* {margin: 10}
{}
classNamecheckbox css class(es)String_ "p-5 mb-3"
_ "uk-margin"
""
borderColorcolor of checkbox borderString_ "red"
_ "#fff"
"#D7C629"
borderRadiusradius of checkbox borderNumber_ 10
_ 0
5
borderStylestyle of checkbox borderObject_ "solid"
_ "dashed"
* "dotted"
"solid"
borderWidththickness of checkbox borderNumber_ 4
_ 0
2
labelClassNamelabel text css class(es)String_ "p-5 mb-3"
_ "uk-margin"
""
labelStylelabel text css styleObject* {margin: 10}{ marginLeft: 5 }
containerClassNamecheckbox & label container css class(es)String_ "p-5 mb-3"
_ "uk-margin"
""
containerStylecheckbox & label container css styleObject* {margin: 10}{}

Switch Component

Demo Video

Usage

import React from "react";
import Switch from "react-custom-checkbox/switch";

const checkedTrackStyle = {
  opacity: 1,
  transition: 'all 0.25s ease-in-out',
}

const checkedIndicatorStyle = {
  background: '#44aa44',
  transform: 'translateX(30px)',
}

const checkedIconStyle = {
  opacity: 1,
  transition: 'all 0.25s ease-in-out',
}

const indicatorStyle = {
  alignItems: 'center',
  background: '#f34334',
  borderRadius: 24,
  bottom: 2,
  display: 'flex',
  height: 24,
  justifyContent: 'center',
  left: 2,
  outline: 'solid 2px transparent',
  position: 'absolute',
  transition: '0.25s',
  width: 24,
}

const trackStyle = {
  background: '#e5efe9',
  border: '1px solid #e6e6e6',
  borderRadius: 15,
  cursor: 'pointer',
  display: 'flex',
  height: 28,
  marginRight: 12,
  position: 'relative',
  width: 60,
}

const MyComponent = () => {
  const [switchOneCheck, setSwitchOneCheck] = React.useState(false);

  return (
    <>
      <h4>Default:</h4>
      <Switch />
      <h4>Using Custom Icon:</h4>
      <Switch
        icon={
          <svg viewBox="0 0 24 24" role="presentation" aria-hidden="true">
            <path d="M9.86 18a1 1 0 01-.73-.32l-4.86-5.17a1.001 1.001 0 011.46-1.37l4.12 4.39 8.41-9.2a1 1 0 111.48 1.34l-9.14 10a1 1 0 01-.73.33h-.01z"></path>
          </svg>
        }
      />
      <h4>Controlled with custom styles:</h4>
      <Switch
        checked={switchOneCheck}
        onChange={setSwitchOneCheck}
        indicatorStyle={indicatorStyle}
        trackStyle={trackStyle}
        checkedIconStyle={checkedIconStyle}
        checkedIndicatorStyle={checkedIndicatorStyle}
        checkedTrackStyle={checkedTrackStyle}
      />
    </>
  );
};

export default MyComponent;

Props

PropExplanationData Type(Sample) ValuesDefault
iconswitch button icon/elementObject (jsx)* <img src={require("./check.png")} style={{ width: 24 }} alt="" />``
checkedstate of switchBool_ true
_ false
false
disabledswitch input active/inactive stateBool_ true
_ false
false
onChangefunction triggered when checked state changesFuncUsage
* (checked, event) => console.log(checked, event)
null
nameswitch input nameString_ "toppings"
_ "hobbies"
""
valueswitch input valueString_ "cheese"
_ "lettuce"
""
referenceswitch input refFunc_ checkboxRef
_ this.checkboxRef
``
labelswitch label textString_ "Cheese"
_ "Lettuce"
``
isLabelRightlabel position right?Bool_ true
_ false
false
styleswitch css styleObject* {margin: 10}
{clip: 'rect(0 0 0 0)',clipPath: 'inset(50%)',height: 1,overflow: 'hidden',position: 'absolute',whiteSpace: 'nowrap',width: 1}
classNameswitch css class(es)String_ "p-5 mb-3"
_ "uk-margin"
""
iconClassNameswitch button icon/element css class(es)String_ "p-5 mb-3"
_ "uk-margin"
""
iconStyleswitch button icon/element css stylesObject* {margin: 10}{fill: '#fff',height: 20,width: 20,opacity: 0,transition: 'all 0.25s ease-in-out'}
checkedIconStyleswitch button icon/element css styles when checkedObject* {margin: 10}{opacity: 1,transition: 'all 0.25s ease-in-out'}
indicatorClassNameswitch button css class(es)String_ "p-5 mb-3"
_ "uk-margin"
""
indicatorStyleswitch button css stylesObject* {margin: 10}{alignItems: 'center',background: '#121943',borderRadius: 24,bottom: 2,display: 'flex',height: 24,justifyContent: 'center',left: 2,outline: 'solid 2px transparent',position: 'absolute',transition: '0.25s',width: 24}
checkedIndicatorStyleswitch button css styles when checkedObject* {margin: 10}{background: '#121943',transform: 'translateX(30px)'}
trackClassNameswitch track css class(es)String_ "p-5 mb-3"
_ "uk-margin"
""
trackStyleswitch track css stylesObject* {margin: 10}{background: '#e5efe9',border: '1px solid #5a72b5',borderRadius: 100,cursor: 'pointer',display: 'flex',height: 30,marginRight: 12,position: 'relative',width: 60}
checkedTrackStyleswitch track css styles when checkedObject* {margin: 10}{border: '1px solid transparent',boxShadow: '0px 0px 0px 2px #121943',opacity: 1,transition: 'all 0.25s ease-in-out'}
labelClassNamelabel text css class(es)String_ "p-5 mb-3"
_ "uk-margin"
""
labelStylelabel text css stylesObject* {margin: 10}``
containerClassNameswitch & label container css class(es)String_ "p-5 mb-3"
_ "uk-margin"
""
containerStyleswitch & label container css stylesObject* {margin: 10}{alignItems: 'center',borderRadius: 100,display: 'flex',fontWeight: 700,marginBottom: 16,}
wrapperClassNamewhole component wrapper css class(es)String_ "p-5 mb-3"
_ "uk-margin"
""
wrapperStylewhole component wrapper css stylesObject* {margin: 10}{ display: 'inline-block' }

License

MIT © BossBele

Keywords

FAQs

Last updated on 15 Jan 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc