@c2n/checkbox 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -0
- package/dist/checkbox.js +104 -0
- package/package.json +106 -0
- package/types/src/checkbox.d.ts +31 -0
- package/types/src/checkbox.d.ts.map +1 -0
- package/types/src/index.d.ts +2 -0
- package/types/src/index.d.ts.map +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Checkbox
|
|
2
|
+
|
|
3
|
+
Following m3 specs : https://m3.material.io/components/switch/specs
|
|
4
|
+
|
|
5
|
+
## States
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
### Matrix of states
|
|
10
|
+
|
|
11
|
+
| Interaction/mode | Selected | Unselected | Indeterminate |
|
|
12
|
+
| ---------------- | -------- | ---------- | ------------- |
|
|
13
|
+
| Enabled | | | |
|
|
14
|
+
| Hover | | | |
|
|
15
|
+
| Focus | | | |
|
|
16
|
+
| Pressed | | | |
|
|
17
|
+
| Error | | | |
|
|
18
|
+
| Disabled | | | |
|
|
19
|
+
|
|
20
|
+
## Theme properties
|
|
21
|
+
|
|
22
|
+
- border-radius
|
|
23
|
+
- background-color
|
|
24
|
+
- border-color
|
|
25
|
+
- icon-color
|
|
26
|
+
- state-color
|
|
27
|
+
- state-opacity
|
package/dist/checkbox.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { unsafeCSS as l, LitElement as k, html as s } from "lit";
|
|
2
|
+
import { query as x, property as t, state as p, customElement as u } from "lit/decorators.js";
|
|
3
|
+
import { ifDefined as r } from "lit/directives/if-defined.js";
|
|
4
|
+
const m = `:host{display:inline-flex}.c2-checkbox{display:inline-flex;position:relative;line-height:0;white-space:nowrap;cursor:pointer;vertical-align:bottom;z-index:0;align-items:center;justify-content:center;flex-direction:column;width:var(--c2-checkbox-touch-target-size, 48px);height:var(--c2-checkbox-touch-target-size, 48px)}.c2-checkbox-input{position:absolute;margin:0;padding:0;opacity:0;cursor:inherit;width:var(--c2-checkbox-touch-target-size, 48px);height:var(--c2-checkbox-touch-target-size, 48px)}.c2-checkbox__background{display:inline-flex;position:absolute;align-items:center;justify-content:center;box-sizing:border-box;border-style:solid;background-color:transparent;pointer-events:none;will-change:background-color,border-color;transition:transition-exit(background-color),transition-exit(border-color);width:var(--c2-checkbox-container-width, 18px);height:var(--c2-checkbox-container-height, 18px);border-radius:var(--c2-checkbox-container-border-radius, 5px)}::slotted(svg[slot=checkmark]),.c2-checkbox__checkmark{position:absolute;width:var(--c2-checkbox-checkmark-size, 14px);height:var(--c2-checkbox-checkmark-size, 14px);transition:transition-exit(opacity,0ms,.18s);opacity:0}::slotted(svg[slot=mixedmark]),.c2-checkbox__mixedmark{position:absolute;width:var(--c2-checkbox-mixedmark-size, 14px);height:var(--c2-checkbox-mixedmark-size, 14px);transform:scaleX(0) rotate(0);opacity:0;transition:transition-exit(opacity),transition-exit(transform)}.c2-checkbox-state-layer{position:absolute;width:var(--c2-checkbox-state-layer-size, 40px);height:var(--c2-checkbox-state-layer-size, 40px);border-radius:var(--c2-checkbox-state-layer-border-radius, 9999px);background-color:transparent;opacity:0;pointer-events:none;will-change:background-color,opacity}.c2-checkbox-input:not(:checked):not(:indeterminate):enabled~.c2-checkbox__background{border-width:var(--c2-checkbox-container-border-width, 1.5px);border-color:var(--c2-checkbox-container-border-color, #bcbcc6)}.c2-checkbox-input:indeterminate:enabled~.c2-checkbox__background{border-width:0;background-color:var(--c2-checkbox-container-enabled-selected-color, #476ef9)}.c2-checkbox-input:indeterminate:enabled~.c2-checkbox__background ::slotted(svg[slot=checkmark]),.c2-checkbox-input:indeterminate:enabled~.c2-checkbox__background .c2-checkbox__checkmark{opacity:0}.c2-checkbox-input:indeterminate:enabled~.c2-checkbox__background ::slotted(svg[slot=mixedmark]),.c2-checkbox-input:indeterminate:enabled~.c2-checkbox__background .c2-checkbox__mixedmark{opacity:1;transform:scaleX(1) rotate(0);color:var(--c2-checkbox-mixedmark-color, #fff)}.c2-checkbox-input:checked:enabled~.c2-checkbox__background{border-width:0;background-color:var(--c2-checkbox-container-enabled-selected-color, #476ef9)}.c2-checkbox-input:checked:enabled~.c2-checkbox__background ::slotted(svg[slot=checkmark]),.c2-checkbox-input:checked:enabled~.c2-checkbox__background .c2-checkbox__checkmark{opacity:1;color:var(--c2-checkbox-checkmark-color, #fff)}.c2-checkbox-input:not(:checked):not(:indeterminate):disabled~.c2-checkbox__background{border-width:var(--c2-checkbox-container-border-width, 1.5px);border-color:var(--c2-checkbox-container-border-color, #bcbcc6);opacity:var(--c2-checkbox-disabled-opacity, .38)}.c2-checkbox-input:indeterminate:disabled~.c2-checkbox__background{border-width:0;background-color:var(--c2-checkbox-container-enabled-selected-color, #476ef9);opacity:var(--c2-checkbox-disabled-opacity, .38)}.c2-checkbox-input:indeterminate:disabled~.c2-checkbox__background ::slotted(svg[slot=checkmark]),.c2-checkbox-input:indeterminate:disabled~.c2-checkbox__background .c2-checkbox__checkmark{opacity:0}.c2-checkbox-input:indeterminate:disabled~.c2-checkbox__background ::slotted(svg[slot=mixedmark]),.c2-checkbox-input:indeterminate:disabled~.c2-checkbox__background .c2-checkbox__mixedmark{opacity:1;transform:scaleX(1) rotate(0);color:var(--c2-checkbox-mixedmark-color, #fff)}.c2-checkbox-input:checked:disabled~.c2-checkbox__background{border-width:0;background-color:var(--c2-checkbox-container-enabled-selected-color, #476ef9);opacity:var(--c2-checkbox-disabled-opacity, .38)}.c2-checkbox-input:checked:disabled~.c2-checkbox__background ::slotted(svg[slot=checkmark]),.c2-checkbox-input:checked:disabled~.c2-checkbox__background .c2-checkbox__checkmark{opacity:1;color:var(--c2-checkbox-checkmark-color, #fff)}.c2-checkbox-input:not(:checked):not(:indeterminate):enabled:hover~.c2-checkbox-state-layer{background-color:var(--c2-checkbox-state-layer-hover-unselected-color, #bcbcc6);opacity:var(--c2-checkbox-state-layer-hover-opacity, .08)}.c2-checkbox-input:indeterminate:enabled:hover~.c2-checkbox-state-layer{background-color:var(--c2-checkbox-state-layer-hover-indeterminate-color, #476ef9);opacity:var(--c2-checkbox-state-layer-hover-opacity, .08)}.c2-checkbox-input:checked:enabled:hover~.c2-checkbox-state-layer{background-color:var(--c2-checkbox-state-layer-hover-indeterminate-color, #476ef9);opacity:var(--c2-checkbox-state-layer-hover-opacity, .08)}.c2-checkbox-input:not(:checked):not(:indeterminate):enabled:focus~.c2-checkbox-state-layer{background-color:var(--c2-checkbox-state-layer-hover-unselected-color, #bcbcc6);opacity:var(--c2-checkbox-state-layer-hover-opacity, .08)}.c2-checkbox-input:indeterminate:enabled:focus~.c2-checkbox-state-layer{background-color:var(--c2-checkbox-state-layer-hover-indeterminate-color, #476ef9);opacity:var(--c2-checkbox-state-layer-hover-opacity, .08)}.c2-checkbox-input:checked:enabled:focus~.c2-checkbox-state-layer{background-color:var(--c2-checkbox-state-layer-hover-indeterminate-color, #476ef9);opacity:var(--c2-checkbox-state-layer-hover-opacity, .08)}.c2-checkbox__background--marked{transition:background-color 90ms cubic-bezier(0,0,.2,1),border-color 90ms cubic-bezier(0,0,.2,1)}
|
|
5
|
+
`;
|
|
6
|
+
var v = Object.defineProperty, y = Object.getOwnPropertyDescriptor, c = (a, i, b, n) => {
|
|
7
|
+
for (var o = n > 1 ? void 0 : n ? y(i, b) : i, h = a.length - 1, d; h >= 0; h--)
|
|
8
|
+
(d = a[h]) && (o = (n ? d(i, b, o) : d(o)) || o);
|
|
9
|
+
return n && o && v(i, b, o), o;
|
|
10
|
+
};
|
|
11
|
+
let e = class extends k {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments), this.checked = !1, this.indeterminate = !1, this.disabled = !1, this.name = "", this.showFocusRing = !1;
|
|
14
|
+
}
|
|
15
|
+
render() {
|
|
16
|
+
const a = this.indeterminate ? "mixed" : void 0;
|
|
17
|
+
return s`
|
|
18
|
+
<div class="c2-checkbox">
|
|
19
|
+
${this.renderStateLayer()}
|
|
20
|
+
<input
|
|
21
|
+
class="c2-checkbox-input"
|
|
22
|
+
type="checkbox"
|
|
23
|
+
name="${r(this.name)}"
|
|
24
|
+
aria-checked="${r(a)}"
|
|
25
|
+
aria-label="${r(this.ariaLabel)}"
|
|
26
|
+
aria-labelledby="${r(this.ariaLabelledBy)}"
|
|
27
|
+
aria-describedby="${r(this.ariaDescribedBy)}"
|
|
28
|
+
?disabled="${this.disabled}"
|
|
29
|
+
.indeterminate="${this.indeterminate}"
|
|
30
|
+
?checked="${this.checked}"
|
|
31
|
+
@change="${this.handleChange}"
|
|
32
|
+
@focus="${this.handleFocus}"
|
|
33
|
+
@blur="${this.handleBlur}"
|
|
34
|
+
/>
|
|
35
|
+
<div class="c2-checkbox__background">
|
|
36
|
+
<slot name="checkmark">
|
|
37
|
+
<svg class="c2-checkbox__checkmark" viewBox="0 0 24 24">
|
|
38
|
+
<path fill="currentColor" d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z" />
|
|
39
|
+
</svg>
|
|
40
|
+
</slot>
|
|
41
|
+
<slot name="mixedmark">
|
|
42
|
+
<svg class="c2-checkbox__mixedmark" c2-checkbox__mixedmark viewBox="0 0 24 24">
|
|
43
|
+
<path fill="currentColor" d="M19 13H5v-2h14v2z" />
|
|
44
|
+
</svg>
|
|
45
|
+
</slot>
|
|
46
|
+
</div>
|
|
47
|
+
<div class="c2-checkbox-state-layer"></div>
|
|
48
|
+
</div>
|
|
49
|
+
`;
|
|
50
|
+
}
|
|
51
|
+
renderCheckBox() {
|
|
52
|
+
}
|
|
53
|
+
renderStateLayer() {
|
|
54
|
+
return s``;
|
|
55
|
+
}
|
|
56
|
+
handleChange() {
|
|
57
|
+
this.checked = this.formElement.checked, this.indeterminate = this.formElement.indeterminate, this.dispatchEvent(
|
|
58
|
+
new Event("change", {
|
|
59
|
+
bubbles: !0,
|
|
60
|
+
composed: !0
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
handleFocus() {
|
|
65
|
+
this.showFocusRing = !0;
|
|
66
|
+
}
|
|
67
|
+
handleBlur() {
|
|
68
|
+
this.showFocusRing = !1;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
e.styles = l(m);
|
|
72
|
+
c([
|
|
73
|
+
x("input")
|
|
74
|
+
], e.prototype, "formElement", 2);
|
|
75
|
+
c([
|
|
76
|
+
t({ type: Boolean, reflect: !0 })
|
|
77
|
+
], e.prototype, "checked", 2);
|
|
78
|
+
c([
|
|
79
|
+
t({ type: Boolean, reflect: !0 })
|
|
80
|
+
], e.prototype, "indeterminate", 2);
|
|
81
|
+
c([
|
|
82
|
+
t({ type: Boolean, reflect: !0 })
|
|
83
|
+
], e.prototype, "disabled", 2);
|
|
84
|
+
c([
|
|
85
|
+
t({ type: String })
|
|
86
|
+
], e.prototype, "name", 2);
|
|
87
|
+
c([
|
|
88
|
+
t({ type: String, attribute: "aria-label" })
|
|
89
|
+
], e.prototype, "ariaLabel", 2);
|
|
90
|
+
c([
|
|
91
|
+
t({ type: String, attribute: "aria-labelledby" })
|
|
92
|
+
], e.prototype, "ariaLabelledBy", 2);
|
|
93
|
+
c([
|
|
94
|
+
t({ type: String, attribute: "aria-describedby" })
|
|
95
|
+
], e.prototype, "ariaDescribedBy", 2);
|
|
96
|
+
c([
|
|
97
|
+
p()
|
|
98
|
+
], e.prototype, "showFocusRing", 2);
|
|
99
|
+
e = c([
|
|
100
|
+
u("c2-checkbox")
|
|
101
|
+
], e);
|
|
102
|
+
export {
|
|
103
|
+
e as Checkbox
|
|
104
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@c2n/checkbox",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/checkbox.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./dist/checkbox.js"
|
|
8
|
+
},
|
|
9
|
+
"types": "types/src/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"types"
|
|
13
|
+
],
|
|
14
|
+
"keywords": [
|
|
15
|
+
"checkbox",
|
|
16
|
+
"web component",
|
|
17
|
+
"lit"
|
|
18
|
+
],
|
|
19
|
+
"author": "code2nguyen@gmail.com",
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"lint": "npm run lint:lit-analyzer && npm run lint:eslint",
|
|
25
|
+
"lint:eslint": "eslint 'src/**/*.ts'",
|
|
26
|
+
"lint:lit-analyzer": "lit-analyzer",
|
|
27
|
+
"dev": "vite",
|
|
28
|
+
"build": "tsc && vite build"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@c2n/wc-utils": "0.0.1",
|
|
32
|
+
"lit": "2.3.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "5.33.1",
|
|
36
|
+
"@typescript-eslint/parser": "5.33.1",
|
|
37
|
+
"eslint": "8.22.0",
|
|
38
|
+
"lit-analyzer": "1.2.1",
|
|
39
|
+
"prettier": "2.7.1",
|
|
40
|
+
"typescript": "4.7.4",
|
|
41
|
+
"vite": "3.0.8"
|
|
42
|
+
},
|
|
43
|
+
"prettier": {
|
|
44
|
+
"singleQuote": true,
|
|
45
|
+
"printWidth": 160,
|
|
46
|
+
"tabWidth": 2,
|
|
47
|
+
"semi": false
|
|
48
|
+
},
|
|
49
|
+
"eslintConfig": {
|
|
50
|
+
"root": true,
|
|
51
|
+
"extends": [
|
|
52
|
+
"eslint:recommended",
|
|
53
|
+
"plugin:@typescript-eslint/eslint-recommended",
|
|
54
|
+
"plugin:@typescript-eslint/recommended"
|
|
55
|
+
],
|
|
56
|
+
"parser": "@typescript-eslint/parser",
|
|
57
|
+
"parserOptions": {
|
|
58
|
+
"ecmaVersion": 2020,
|
|
59
|
+
"sourceType": "module"
|
|
60
|
+
},
|
|
61
|
+
"plugins": [
|
|
62
|
+
"@typescript-eslint"
|
|
63
|
+
],
|
|
64
|
+
"env": {
|
|
65
|
+
"browser": true
|
|
66
|
+
},
|
|
67
|
+
"rules": {
|
|
68
|
+
"no-prototype-builtins": "off",
|
|
69
|
+
"@typescript-eslint/ban-types": "off",
|
|
70
|
+
"@typescript-eslint/explicit-function-return-type": "off",
|
|
71
|
+
"@typescript-eslint/explicit-module-boundary-types": "off",
|
|
72
|
+
"@typescript-eslint/no-explicit-any": "error",
|
|
73
|
+
"@typescript-eslint/no-empty-function": "off",
|
|
74
|
+
"@typescript-eslint/no-non-null-assertion": "off",
|
|
75
|
+
"@typescript-eslint/no-unused-vars": [
|
|
76
|
+
"warn",
|
|
77
|
+
{
|
|
78
|
+
"argsIgnorePattern": "^_"
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
},
|
|
82
|
+
"overrides": [
|
|
83
|
+
{
|
|
84
|
+
"files": [
|
|
85
|
+
"rollup.config.js",
|
|
86
|
+
"web-test-runner.config.js"
|
|
87
|
+
],
|
|
88
|
+
"env": {
|
|
89
|
+
"node": true
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"files": [
|
|
94
|
+
"*_test.ts",
|
|
95
|
+
"**/custom_typings/*.ts",
|
|
96
|
+
"packages/labs/ssr/src/test/integration/tests/**",
|
|
97
|
+
"packages/labs/ssr/src/lib/util/parse5-utils.ts"
|
|
98
|
+
],
|
|
99
|
+
"rules": {
|
|
100
|
+
"@typescript-eslint/no-explicit-any": "off"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
},
|
|
105
|
+
"gitHead": "4619709f27a44f40e20b8df23b5ec0fe391b35ac"
|
|
106
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
/**
|
|
3
|
+
* An example element.
|
|
4
|
+
*
|
|
5
|
+
* @slot - This element has a slot
|
|
6
|
+
* @csspart button - The button
|
|
7
|
+
*/
|
|
8
|
+
export declare class Checkbox extends LitElement {
|
|
9
|
+
protected formElement: HTMLInputElement;
|
|
10
|
+
checked: boolean;
|
|
11
|
+
indeterminate: boolean;
|
|
12
|
+
disabled: boolean;
|
|
13
|
+
name: string;
|
|
14
|
+
ariaLabel: string;
|
|
15
|
+
ariaLabelledBy: undefined | string;
|
|
16
|
+
ariaDescribedBy: undefined | string;
|
|
17
|
+
protected showFocusRing: boolean;
|
|
18
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
19
|
+
protected renderCheckBox(): void;
|
|
20
|
+
protected renderStateLayer(): import("lit-html").TemplateResult<1>;
|
|
21
|
+
protected handleChange(): void;
|
|
22
|
+
protected handleFocus(): void;
|
|
23
|
+
protected handleBlur(): void;
|
|
24
|
+
static styles: import("lit").CSSResult;
|
|
25
|
+
}
|
|
26
|
+
declare global {
|
|
27
|
+
interface HTMLElementTagNameMap {
|
|
28
|
+
'c2-checkbox': Checkbox;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=checkbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkbox.d.ts","sourceRoot":"","sources":["../../src/checkbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,KAAK,CAAA;AAIjD;;;;;GAKG;AACH,qBACa,QAAS,SAAQ,UAAU;IACtB,SAAS,CAAC,WAAW,EAAG,gBAAgB,CAAA;IAEZ,OAAO,UAAQ;IAEf,aAAa,UAAQ;IAErB,QAAQ,UAAQ;IAEhC,IAAI,SAAK;IAG5B,SAAS,EAAG,MAAM,CAAA;IAG3B,cAAc,EAAG,SAAS,GAAG,MAAM,CAAA;IAGnC,eAAe,EAAG,SAAS,GAAG,MAAM,CAAA;IAE3B,SAAS,CAAC,aAAa,UAAQ;IAE/B,MAAM;IAsCf,SAAS,CAAC,cAAc;IAExB,SAAS,CAAC,gBAAgB;IAI1B,SAAS,CAAC,YAAY;IAWtB,SAAS,CAAC,WAAW;IAIrB,SAAS,CAAC,UAAU;IAIpB,OAAgB,MAAM,0BAAoB;CAC3C;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,aAAa,EAAE,QAAQ,CAAA;KACxB;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA"}
|