Skip to content

Commit

Permalink
Make CheckBox align with Styling Guide #75
Browse files Browse the repository at this point in the history
  • Loading branch information
cwpeng committed Aug 3, 2021
1 parent 0593ae7 commit 7ef2b8c
Showing 1 changed file with 89 additions and 2 deletions.
91 changes: 89 additions & 2 deletions wc/components/CheckBox.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*
import WComponent, { DOM, AttributeParser } from "../WComponent.js";
const stylesheet=`
.checkbox{
Expand Down Expand Up @@ -54,7 +55,6 @@ class CheckBox extends WComponent{
this.getDefaultValueByName("disabled")
);
}
/*
attributeChangedCallback(name, oldValue, newValue){
console.log(name, oldValue, newValue);
if(name==="checked"){
Expand All @@ -65,7 +65,6 @@ class CheckBox extends WComponent{
this.render();
}
}
*/
toggle(){
if(this.disabled){
return;
Expand All @@ -92,4 +91,92 @@ class CheckBox extends WComponent{
}
}
CheckBox.prototype.stylesheet=stylesheet;
export default CheckBox;
*/
import WComponent, { DOM, AttributeParser } from "../WComponent.js";
const stylesheet=`
label {
cursor: pointer;
display: inline-flex;
align-items: center;
}
input {
width: 0; hieght: 0;
}
.icon {
color: var(--color-gray-30);
margin-right: 5px;
}
.icon:before {
content: '\\f292';
font-family: var(--icon-font-regular);
font-size: var(--icon-font-size);
vertical-align: middle;
}
.icon:hover {
color: var(--color-primary-60);
}
input:checked + .icon:before {
content: '\\f28e';
font-family: var(--icon-font-filled)
}
input:checked + .icon,
input:checked:active + .icon {
color: var(--color-primary-60);
}
input:checked + .icon:hover {
color: var(--color-primary-40);
}
input:disabled:checked + .icon:before {
content: '\\f28e';
font-family: var(--icon-font-regular)
}
input:disabled + .icon,
input:disabled:active + .icon {
color: var(--color-gray-10);
}
input:disabled + .icon:hover {
color: var(--color-gray-10);
}
input:disabled + .icon + slot {
color: var(--color-gray-30);
}
`;
class CheckBox extends WComponent{
static defaultValues = {
checked: false,
disabled: false
};

constructor() {
super();
}

render(){
const checked = AttributeParser.parseBoolAttr(
this.getAttribute('checked'),
this.getDefaultValueByName('checked')
);
const disabled = AttributeParser.parseBoolAttr(
this.getAttribute('disabled'),
this.getDefaultValueByName('disabled')
);

const ctn = DOM.create('label', null, this.shadowRoot);

const checkboxProps = { type: 'checkbox' };
const checkboxAttrs = {};
if(checked) { checkboxAttrs.checked = true; }
if(disabled) { checkboxAttrs.disabled = true; }
DOM.create('input', { props: checkboxProps, attrs: checkboxAttrs }, ctn);

const iconProps = { className: 'icon' };
DOM.create('span', { props: iconProps }, ctn);

DOM.create('slot', {}, ctn);
}
}
CheckBox.prototype.stylesheet=stylesheet;
export default CheckBox;

0 comments on commit 7ef2b8c

Please sign in to comment.