0.1.0 • Published 5 months ago

jb-checkbox v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

jb-checkbox

Published on webcomponents.org GitHub license NPM Downloads

checkbox web-component with smooth animation

  • customizable ui
  • check-animation
  • form & validation support

demo

usage

npm i jb-checkbox
<script>
  import 'jb-checkbox';
</script>
<jb-checkbox label="checkbox sample"/>
<!-- or if you want put custom html as a label -->
<jb-checkbox><div slot="label">checkbox sample</div></jb-checkbox>

get and set value

const checkBoxDom = document.querySelector('jb-checkbox');
checkBoxDom.value = true;
console.log(checkBoxDom.value);

disable checkbox

const checkBoxDom = document.querySelector('jb-checkbox');
checkBoxDom.disabled = true;
console.log(checkBoxDom.disabled);

or

<jb-checkbox disabled />

validation

jb-checkbox implement jb-validation inside to handle validation. so for more information you can read jb-validation documentation.
for simple usage you can set validation to your input:

    checkBoxDom.validation.list = [
        {
            validator:(value)=>{
              //value is boolean
             return value == true;
            },
            message: 'you must check mark before continue'
        }
    ]
    //return boolean of if all validation return true
  const result = checkBoxDom.checkValidity()
    

unlike other jb design system web-components jb-checkbox dont have any native wat to show validation error to the user and will only validate and return result for you to take an action as you like.

customize styles:

you have 2 way to customize style, 1. using ::part selector

jb-checkbox::part(label){
  font-size: 2rem;
}
jb-checkbox:states(checked)::part(label){
  font-weight: 800;
}

we have label, checkbox, check-bg, check-mark as a supported part in our component. you can also combine them with disabled, checked states for different style in different states.

  1. using css variable

here is the list of available css variables that you can use for your component

css variable namedescription
--jb-checkbox-label-colorlabel color
--jb-checkbox-check-bg-colorcheckbox background color
--jb-checkbox-check-bg-color-checkedcheckbox background color when checked
--jb-checkbox-check-bg-color-disabledcheckbox background color when disabled
--jb-checkbox-check-mark-colorcheck mark color
--jb-checkbox-check-mark-color-checkedcheck mark color when checked

Other Related Docs:

0.1.0

5 months ago

0.0.1

5 months ago