@justeattakeaway/pie-checkbox 0.6.0 → 0.7.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/custom-elements.json +1 -19
- package/dist/index.d.ts +5 -5
- package/dist/index.js +92 -71
- package/dist/react.d.ts +5 -5
- package/package.json +3 -3
- package/src/checkbox.scss +298 -0
- package/src/defs.ts +5 -4
- package/src/index.ts +28 -8
package/custom-elements.json
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"type": {
|
|
27
27
|
"text": "DefaultProps"
|
|
28
28
|
},
|
|
29
|
-
"default": "{\n // a default value for the html <input type=\"checkbox\" /> value attribute.\n // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#value\n value: 'on',\n
|
|
29
|
+
"default": "{\n // a default value for the html <input type=\"checkbox\" /> value attribute.\n // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#value\n value: 'on',\n disabled: false,\n defaultChecked: false,\n checked: false,\n indeterminate: false,\n required: false,\n status: 'default',\n}"
|
|
30
30
|
}
|
|
31
31
|
],
|
|
32
32
|
"exports": [
|
|
@@ -117,9 +117,6 @@
|
|
|
117
117
|
{
|
|
118
118
|
"kind": "field",
|
|
119
119
|
"name": "required",
|
|
120
|
-
"type": {
|
|
121
|
-
"text": "CheckboxProps['required'] | undefined"
|
|
122
|
-
},
|
|
123
120
|
"privacy": "public",
|
|
124
121
|
"attribute": "required",
|
|
125
122
|
"reflects": true
|
|
@@ -127,9 +124,6 @@
|
|
|
127
124
|
{
|
|
128
125
|
"kind": "field",
|
|
129
126
|
"name": "indeterminate",
|
|
130
|
-
"type": {
|
|
131
|
-
"text": "CheckboxProps['indeterminate'] | undefined"
|
|
132
|
-
},
|
|
133
127
|
"privacy": "public",
|
|
134
128
|
"attribute": "indeterminate",
|
|
135
129
|
"reflects": true
|
|
@@ -163,9 +157,6 @@
|
|
|
163
157
|
{
|
|
164
158
|
"kind": "field",
|
|
165
159
|
"name": "status",
|
|
166
|
-
"type": {
|
|
167
|
-
"text": "CheckboxProps['status'] | undefined"
|
|
168
|
-
},
|
|
169
160
|
"privacy": "public",
|
|
170
161
|
"attribute": "status"
|
|
171
162
|
},
|
|
@@ -282,16 +273,10 @@
|
|
|
282
273
|
},
|
|
283
274
|
{
|
|
284
275
|
"name": "required",
|
|
285
|
-
"type": {
|
|
286
|
-
"text": "CheckboxProps['required'] | undefined"
|
|
287
|
-
},
|
|
288
276
|
"fieldName": "required"
|
|
289
277
|
},
|
|
290
278
|
{
|
|
291
279
|
"name": "indeterminate",
|
|
292
|
-
"type": {
|
|
293
|
-
"text": "CheckboxProps['indeterminate'] | undefined"
|
|
294
|
-
},
|
|
295
280
|
"fieldName": "indeterminate"
|
|
296
281
|
},
|
|
297
282
|
{
|
|
@@ -310,9 +295,6 @@
|
|
|
310
295
|
},
|
|
311
296
|
{
|
|
312
297
|
"name": "status",
|
|
313
|
-
"type": {
|
|
314
|
-
"text": "CheckboxProps['status'] | undefined"
|
|
315
|
-
},
|
|
316
298
|
"fieldName": "status"
|
|
317
299
|
}
|
|
318
300
|
],
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
|
|
2
2
|
import type { CSSResult } from 'lit';
|
|
3
3
|
import type { FormControlInterface } from '@justeattakeaway/pie-webc-core';
|
|
4
4
|
import type { GenericConstructor } from '@justeattakeaway/pie-webc-core';
|
|
@@ -60,7 +60,7 @@ export declare interface CheckboxProps {
|
|
|
60
60
|
status?: typeof statusTypes[number];
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
export declare type DefaultProps =
|
|
63
|
+
export declare type DefaultProps = ComponentDefaultProps<CheckboxProps, keyof Omit<CheckboxProps, 'label' | 'name' | 'aria' | 'assistiveText'>>;
|
|
64
64
|
|
|
65
65
|
export declare const defaultProps: DefaultProps;
|
|
66
66
|
|
|
@@ -80,12 +80,12 @@ export declare class PieCheckbox extends PieCheckbox_base implements CheckboxPro
|
|
|
80
80
|
checked: boolean;
|
|
81
81
|
defaultChecked: boolean;
|
|
82
82
|
disabled?: CheckboxProps['disabled'];
|
|
83
|
-
required
|
|
84
|
-
indeterminate
|
|
83
|
+
required: boolean;
|
|
84
|
+
indeterminate: boolean;
|
|
85
85
|
aria: CheckboxProps['aria'];
|
|
86
86
|
private checkbox;
|
|
87
87
|
assistiveText?: CheckboxProps['assistiveText'];
|
|
88
|
-
status
|
|
88
|
+
status: "default" | "error" | "success";
|
|
89
89
|
/**
|
|
90
90
|
* (Read-only) returns a ValidityState with the validity states that this element is in.
|
|
91
91
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
import { LitElement as
|
|
2
|
-
import { property as
|
|
3
|
-
import { ifDefined as
|
|
4
|
-
import { live as
|
|
5
|
-
import { FormControlMixin as
|
|
1
|
+
import { LitElement as g, html as u, nothing as h, unsafeCSS as w } from "lit";
|
|
2
|
+
import { property as c, query as $ } from "lit/decorators.js";
|
|
3
|
+
import { ifDefined as f } from "lit/directives/if-defined.js";
|
|
4
|
+
import { live as x } from "lit/directives/live.js";
|
|
5
|
+
import { FormControlMixin as C, RtlMixin as F, wrapNativeEvent as E, validPropertyValues as S, defineCustomElement as q } from "@justeattakeaway/pie-webc-core";
|
|
6
6
|
import "@justeattakeaway/pie-assistive-text";
|
|
7
|
-
const
|
|
8
|
-
`,
|
|
7
|
+
const A = `*,*:after,*:before{box-sizing:inherit}@keyframes checkboxCheck{0%{width:0;height:0;border-color:#fff;transform:translateZ(0) rotate(45deg)}33%{width:8px;height:0;transform:translateZ(0) rotate(45deg)}to{width:8px;height:16px;border-color:#fff;border-bottom-right-radius:2px;transform:translate3d(0,-16px,0) rotate(45deg)}}@keyframes scaleDown{0%{transform:scale(.7)}to{transform:scale(0)}}@keyframes scaleUp{0%{transform:scale(0)}33%{transform:scale(.5)}to{transform:scale(1)}}.c-checkbox-tick{content:"";display:flex;flex:0 0 auto;width:var(--checkbox-width);height:var(--checkbox-height);margin:var(--checkbox-margin);border:1px solid var(--checkbox-border-color);border-radius:var(--checkbox-radius);background-color:var(--checkbox-bg-color)}@media (prefers-reduced-motion: no-preference){.c-checkbox-tick{transition:background-color var(--dt-motion-timing-100) var(--checkbox-motion-easing);animation:scaleDown var(--dt-motion-timing-100) var(--checkbox-motion-easing)}}.c-checkbox-tick[data-pie-disabled]{--checkbox-bg-color: var(--dt-color-container-strong);--checkbox-border-color: var(--dt-color-disabled-01)}.c-checkbox-tick[data-pie-status=error]{--checkbox-border-color: var(--dt-color-support-error)}@media (prefers-reduced-motion: no-preference){.c-checkbox-tick[data-pie-checked]{animation:scaleUp var(--dt-motion-timing-100) var(--checkbox-motion-easing)}}.c-checkbox-tick[data-pie-checked]:not([data-pie-disabled]){--checkbox-bg-color: var(--dt-color-interactive-brand);--checkbox-border-color: var(--dt-color-interactive-brand)}.c-checkbox-tick[data-pie-checked][data-pie-status=error]{--checkbox-border-color: var(--dt-color-support-error);--checkbox-bg-color: var(--dt-color-support-error)}.c-checkbox-tick[data-pie-checked]:before{content:"";position:relative;top:55%;left:14%;border-right:2px solid transparent;border-bottom:2px solid transparent;transform:rotate(45deg);transform-origin:0% 100%;animation:checkboxCheck var(--dt-motion-timing-150) var(--checkbox-motion-easing) forwards}@media (prefers-reduced-motion: reduce){.c-checkbox-tick[data-pie-checked]:before{animation:none;width:8px;height:16px;border-color:#fff;border-bottom-right-radius:2px;transform:translate3d(0,-16px,0) rotate(45deg)}}@media only percy{.c-checkbox-tick[data-pie-checked]:before{animation:none;width:8px;height:16px;border-color:#fff;border-bottom-right-radius:2px;transform:translate3d(0,-16px,0) rotate(45deg)}}.c-checkbox-tick[data-pie-indeterminate]:not([data-pie-disabled]){--checkbox-bg-color: var(--dt-color-interactive-brand);--checkbox-border-color: var(--dt-color-interactive-brand)}.c-checkbox-tick[data-pie-indeterminate][data-pie-status=error]{--checkbox-border-color: var(--dt-color-support-error);--checkbox-bg-color: var(--dt-color-support-error)}.c-checkbox-tick[data-pie-indeterminate]:after{width:16px}@media (prefers-reduced-motion: no-preference){.c-checkbox-tick[data-pie-indeterminate]:after{transition:width var(--dt-motion-timing-100) var(--checkbox-motion-easing) var(--dt-motion-timing-100)}}.c-checkbox-text{display:inline;flex:1 1 auto;align-self:center;min-width:0;margin-inline-start:var(--checkbox-gap);white-space:normal;color:var(--checkbox-content-color);font-size:var(--checkbox-font-size);font-weight:var(--checkbox-font-weight)}.c-checkbox-tick:after{content:"";position:relative;top:47%;left:14%;width:0;height:2px;background-color:#fff}.c-checkbox{--checkbox-height: 24px;--checkbox-width: 24px;--checkbox-radius: var(--dt-radius-rounded-a);--checkbox-margin: 1px;--checkbox-gap: var(--dt-spacing-b);--checkbox-font-size: var(--dt-font-body-l-size);--checkbox-font-weight: var(--dt-font-weight-regular);--checkbox-bg-color: var(--dt-color-container-default);--checkbox-border-color: var(--dt-color-interactive-form);--checkbox-content-color: var(--dt-color-content-default);--checkbox-motion-easing: var(--dt-motion-easing-persistent-functional);display:flex;flex-direction:column}.c-checkbox input{display:block;position:absolute;height:1px;width:1px;overflow:hidden;clip:rect(1px,1px,1px,1px);clip-path:inset(1px);white-space:nowrap}.c-checkbox label{display:flex;max-width:100%;white-space:nowrap;cursor:pointer}.c-checkbox:hover .c-checkbox-tick{--checkbox-bg-color: hsl(var(--dt-color-container-default-h), var(--dt-color-container-default-s), calc(var(--dt-color-container-default-l) + calc(-1 * var(--dt-color-hover-01))));transition:background-color var(--dt-motion-timing-200) var(--checkbox-motion-easing)}.c-checkbox:active .c-checkbox-tick{--checkbox-bg-color: hsl(var(--dt-color-container-default-h), var(--dt-color-container-default-s), calc(var(--dt-color-container-default-l) + calc(-1 * var(--dt-color-active-01))));transition:background-color var(--dt-motion-timing-100) var(--checkbox-motion-easing)}.c-checkbox[data-pie-disabled] label{cursor:default;pointer-events:none}.c-checkbox input:focus-visible+label .c-checkbox-tick{box-shadow:0 0 0 2px var(--dt-color-focus-inner),0 0 0 4px var(--dt-color-focus-outer);outline:none}.c-checkbox[data-pie-disabled]:hover .c-checkbox-tick,.c-checkbox[data-pie-disabled]:active .c-checkbox-tick{--checkbox-bg-color: var(--dt-color-container-strong);--checkbox-border-color: var(--dt-color-disabled-01)}.c-checkbox[data-pie-status=error]:hover .c-checkbox-tick{--checkbox-bg-color: hsl(var(--dt-color-container-default-h), var(--dt-color-container-default-s), calc(var(--dt-color-container-default-l) + calc(-1 * var(--dt-color-hover-01))))}.c-checkbox[data-pie-status=error]:active .c-checkbox-tick{--checkbox-bg-color: hsl(var(--dt-color-container-default-h), var(--dt-color-container-default-s), calc(var(--dt-color-container-default-l) + calc(-1 * var(--dt-color-active-01))))}.c-checkbox[data-pie-checked]:not([data-pie-disabled]):hover .c-checkbox-tick,.c-checkbox[data-pie-indeterminate]:not([data-pie-disabled]):hover .c-checkbox-tick{--checkbox-bg-color: hsl(var(--dt-color-interactive-brand-h), var(--dt-color-interactive-brand-s), calc(var(--dt-color-interactive-brand-l) + calc(-1 * var(--dt-color-hover-01))));--checkbox-border-color: hsl(var(--dt-color-interactive-brand-h), var(--dt-color-interactive-brand-s), calc(var(--dt-color-interactive-brand-l) + calc(-1 * var(--dt-color-hover-01))))}.c-checkbox[data-pie-checked][data-pie-status=error]:hover .c-checkbox-tick,.c-checkbox[data-pie-indeterminate][data-pie-status=error]:hover .c-checkbox-tick{--checkbox-bg-color: hsl(var(--dt-color-support-error-h), var(--dt-color-support-error-s), calc(var(--dt-color-support-error-l) + calc(-1 * var(--dt-color-hover-01))));--checkbox-border-color: hsl(var(--dt-color-support-error-h), var(--dt-color-support-error-s), calc(var(--dt-color-support-error-l) + calc(-1 * var(--dt-color-hover-01))))}.c-checkbox[data-pie-checked]:not([data-pie-disabled]):active .c-checkbox-tick,.c-checkbox[data-pie-indeterminate]:not([data-pie-disabled]):active .c-checkbox-tick{--checkbox-bg-color: hsl(var(--dt-color-interactive-brand-h), var(--dt-color-interactive-brand-s), calc(var(--dt-color-interactive-brand-l) + calc(-1 * var(--dt-color-active-01))));--checkbox-border-color: hsl(var(--dt-color-interactive-brand-h), var(--dt-color-interactive-brand-s), calc(var(--dt-color-interactive-brand-l) + calc(-1 * var(--dt-color-active-01))))}.c-checkbox[data-pie-checked][data-pie-status=error]:active .c-checkbox-tick,.c-checkbox[data-pie-indeterminate][data-pie-status=error]:active .c-checkbox-tick{--checkbox-bg-color: hsl(var(--dt-color-support-error-h), var(--dt-color-support-error-s), calc(var(--dt-color-support-error-l) + calc(-1 * var(--dt-color-active-01))));--checkbox-border-color: hsl(var(--dt-color-support-error-h), var(--dt-color-support-error-s), calc(var(--dt-color-support-error-l) + calc(-1 * var(--dt-color-active-01))))}
|
|
8
|
+
`, O = ["default", "success", "error"], n = {
|
|
9
9
|
// a default value for the html <input type="checkbox" /> value attribute.
|
|
10
10
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#value
|
|
11
11
|
value: "on",
|
|
12
|
-
|
|
12
|
+
disabled: !1,
|
|
13
13
|
defaultChecked: !1,
|
|
14
|
-
indeterminate: !1,
|
|
15
14
|
checked: !1,
|
|
15
|
+
indeterminate: !1,
|
|
16
|
+
required: !1,
|
|
16
17
|
status: "default"
|
|
17
18
|
};
|
|
18
|
-
var
|
|
19
|
-
for (var
|
|
20
|
-
(
|
|
21
|
-
return
|
|
19
|
+
var P = Object.defineProperty, _ = Object.getOwnPropertyDescriptor, o = (b, e, d, i) => {
|
|
20
|
+
for (var r = i > 1 ? void 0 : i ? _(e, d) : e, a = b.length - 1, s; a >= 0; a--)
|
|
21
|
+
(s = b[a]) && (r = (i ? s(e, d, r) : s(r)) || r);
|
|
22
|
+
return i && r && P(e, d, r), r;
|
|
22
23
|
};
|
|
23
|
-
const
|
|
24
|
-
class t extends F(
|
|
24
|
+
const y = "pie-checkbox", m = "assistive-text";
|
|
25
|
+
class t extends C(F(g)) {
|
|
25
26
|
constructor() {
|
|
26
27
|
super(...arguments), this.value = n.value, this.checked = n.checked, this.defaultChecked = n.defaultChecked, this.required = n.required, this.indeterminate = n.indeterminate, this.status = n.status;
|
|
27
28
|
}
|
|
@@ -58,10 +59,10 @@ class t extends F(E(y)) {
|
|
|
58
59
|
* @param {Event} event - This should be the change event that was listened for on an input element with `type="checkbox"`.
|
|
59
60
|
*/
|
|
60
61
|
handleChange(e) {
|
|
61
|
-
const { checked:
|
|
62
|
-
this.checked =
|
|
63
|
-
const
|
|
64
|
-
this.dispatchEvent(
|
|
62
|
+
const { checked: d } = e == null ? void 0 : e.currentTarget;
|
|
63
|
+
this.checked = d;
|
|
64
|
+
const i = E(e);
|
|
65
|
+
this.dispatchEvent(i), this.handleFormAssociation();
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
68
|
* Called when the form that contains this component is reset.
|
|
@@ -78,79 +79,99 @@ class t extends F(E(y)) {
|
|
|
78
79
|
render() {
|
|
79
80
|
const {
|
|
80
81
|
checked: e,
|
|
81
|
-
value:
|
|
82
|
-
name:
|
|
83
|
-
label:
|
|
84
|
-
disabled:
|
|
85
|
-
required:
|
|
86
|
-
indeterminate:
|
|
87
|
-
aria:
|
|
88
|
-
assistiveText:
|
|
89
|
-
status:
|
|
82
|
+
value: d,
|
|
83
|
+
name: i,
|
|
84
|
+
label: r,
|
|
85
|
+
disabled: a,
|
|
86
|
+
required: s,
|
|
87
|
+
indeterminate: p,
|
|
88
|
+
aria: l,
|
|
89
|
+
assistiveText: k,
|
|
90
|
+
status: v
|
|
90
91
|
} = this;
|
|
91
|
-
return
|
|
92
|
-
<
|
|
92
|
+
return u`
|
|
93
|
+
<div
|
|
94
|
+
class="c-checkbox"
|
|
95
|
+
data-pie-status=${!a && v}
|
|
96
|
+
?data-pie-disabled=${x(a)}
|
|
97
|
+
?data-pie-checked=${e}
|
|
98
|
+
?data-pie-indeterminate=${p && !e}>
|
|
93
99
|
<input
|
|
94
100
|
type="checkbox"
|
|
95
|
-
|
|
96
|
-
.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
?
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
aria-
|
|
103
|
-
aria-
|
|
101
|
+
id="inputId"
|
|
102
|
+
.value=${d}
|
|
103
|
+
.checked=${x(e)}
|
|
104
|
+
name=${f(i)}
|
|
105
|
+
?disabled=${a}
|
|
106
|
+
?required=${s}
|
|
107
|
+
.indeterminate=${p}
|
|
108
|
+
aria-label=${(l == null ? void 0 : l.label) || h}
|
|
109
|
+
aria-labelledby=${r ? h : (l == null ? void 0 : l.labelledby) || h}
|
|
110
|
+
aria-describedby=${f(k ? m : void 0)}
|
|
104
111
|
@change=${this.handleChange}
|
|
105
112
|
data-test-id="checkbox-input"
|
|
106
113
|
/>
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
114
|
+
<label for="inputId" data-test-id="checkbox-component">
|
|
115
|
+
<span
|
|
116
|
+
class="c-checkbox-tick"
|
|
117
|
+
?data-pie-checked=${e}
|
|
118
|
+
?data-pie-disabled=${x(a)}
|
|
119
|
+
data-pie-status=${!a && v}
|
|
120
|
+
?data-pie-indeterminate=${p && !e}></span>
|
|
121
|
+
<span class="c-checkbox-text">${r}</span>
|
|
122
|
+
</label>
|
|
123
|
+
${k ? u`
|
|
124
|
+
<pie-assistive-text
|
|
125
|
+
id="${m}"
|
|
126
|
+
variant=${v}
|
|
127
|
+
data-test-id="pie-checkbox-assistive-text">
|
|
128
|
+
${k}
|
|
129
|
+
</pie-assistive-text>` : h}
|
|
130
|
+
</div>`;
|
|
110
131
|
}
|
|
111
132
|
}
|
|
112
|
-
t.shadowRootOptions = { ...
|
|
113
|
-
t.styles =
|
|
114
|
-
|
|
115
|
-
|
|
133
|
+
t.shadowRootOptions = { ...g.shadowRootOptions, delegatesFocus: !0 };
|
|
134
|
+
t.styles = w(A);
|
|
135
|
+
o([
|
|
136
|
+
c({ type: String })
|
|
116
137
|
], t.prototype, "value", 2);
|
|
117
|
-
|
|
118
|
-
|
|
138
|
+
o([
|
|
139
|
+
c({ type: String })
|
|
119
140
|
], t.prototype, "label", 2);
|
|
120
|
-
|
|
121
|
-
|
|
141
|
+
o([
|
|
142
|
+
c({ type: String })
|
|
122
143
|
], t.prototype, "name", 2);
|
|
123
|
-
|
|
124
|
-
|
|
144
|
+
o([
|
|
145
|
+
c({ type: Boolean, reflect: !0 })
|
|
125
146
|
], t.prototype, "checked", 2);
|
|
126
|
-
|
|
127
|
-
|
|
147
|
+
o([
|
|
148
|
+
c({ type: Boolean, reflect: !0 })
|
|
128
149
|
], t.prototype, "defaultChecked", 2);
|
|
129
|
-
|
|
130
|
-
|
|
150
|
+
o([
|
|
151
|
+
c({ type: Boolean, reflect: !0 })
|
|
131
152
|
], t.prototype, "disabled", 2);
|
|
132
|
-
|
|
133
|
-
|
|
153
|
+
o([
|
|
154
|
+
c({ type: Boolean, reflect: !0 })
|
|
134
155
|
], t.prototype, "required", 2);
|
|
135
|
-
|
|
136
|
-
|
|
156
|
+
o([
|
|
157
|
+
c({ type: Boolean, reflect: !0 })
|
|
137
158
|
], t.prototype, "indeterminate", 2);
|
|
138
|
-
|
|
139
|
-
|
|
159
|
+
o([
|
|
160
|
+
c({ type: Object })
|
|
140
161
|
], t.prototype, "aria", 2);
|
|
141
|
-
|
|
142
|
-
|
|
162
|
+
o([
|
|
163
|
+
$('input[type="checkbox"]')
|
|
143
164
|
], t.prototype, "checkbox", 2);
|
|
144
|
-
|
|
145
|
-
|
|
165
|
+
o([
|
|
166
|
+
c({ type: String })
|
|
146
167
|
], t.prototype, "assistiveText", 2);
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
168
|
+
o([
|
|
169
|
+
c({ type: String }),
|
|
170
|
+
S(y, O, n.status)
|
|
150
171
|
], t.prototype, "status", 2);
|
|
151
|
-
|
|
172
|
+
q(y, t);
|
|
152
173
|
export {
|
|
153
174
|
t as PieCheckbox,
|
|
154
175
|
n as defaultProps,
|
|
155
|
-
|
|
176
|
+
O as statusTypes
|
|
156
177
|
};
|
package/dist/react.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
|
|
2
2
|
import type { CSSResult } from 'lit';
|
|
3
3
|
import type { FormControlInterface } from '@justeattakeaway/pie-webc-core';
|
|
4
4
|
import type { GenericConstructor } from '@justeattakeaway/pie-webc-core';
|
|
@@ -61,7 +61,7 @@ export declare interface CheckboxProps {
|
|
|
61
61
|
status?: typeof statusTypes[number];
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
export declare type DefaultProps =
|
|
64
|
+
export declare type DefaultProps = ComponentDefaultProps<CheckboxProps, keyof Omit<CheckboxProps, 'label' | 'name' | 'aria' | 'assistiveText'>>;
|
|
65
65
|
|
|
66
66
|
export declare const defaultProps: DefaultProps;
|
|
67
67
|
|
|
@@ -83,12 +83,12 @@ declare class PieCheckbox_2 extends PieCheckbox_base implements CheckboxProps {
|
|
|
83
83
|
checked: boolean;
|
|
84
84
|
defaultChecked: boolean;
|
|
85
85
|
disabled?: CheckboxProps['disabled'];
|
|
86
|
-
required
|
|
87
|
-
indeterminate
|
|
86
|
+
required: boolean;
|
|
87
|
+
indeterminate: boolean;
|
|
88
88
|
aria: CheckboxProps['aria'];
|
|
89
89
|
private checkbox;
|
|
90
90
|
assistiveText?: CheckboxProps['assistiveText'];
|
|
91
|
-
status
|
|
91
|
+
status: "default" | "error" | "success";
|
|
92
92
|
/**
|
|
93
93
|
* (Read-only) returns a ValidityState with the validity states that this element is in.
|
|
94
94
|
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justeattakeaway/pie-checkbox",
|
|
3
3
|
"description": "PIE Design System Checkbox built using Web Components",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"cem-plugin-module-file-extensions": "0.0.5"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@justeattakeaway/pie-assistive-text": "0.5.
|
|
44
|
-
"@justeattakeaway/pie-webc-core": "0.
|
|
43
|
+
"@justeattakeaway/pie-assistive-text": "0.5.1",
|
|
44
|
+
"@justeattakeaway/pie-webc-core": "0.24.0"
|
|
45
45
|
},
|
|
46
46
|
"volta": {
|
|
47
47
|
"extends": "../../../package.json"
|
package/src/checkbox.scss
CHANGED
|
@@ -1 +1,299 @@
|
|
|
1
1
|
@use '@justeattakeaway/pie-css/scss' as p;
|
|
2
|
+
|
|
3
|
+
@keyframes checkboxCheck {
|
|
4
|
+
0% {
|
|
5
|
+
width: 0;
|
|
6
|
+
height: 0;
|
|
7
|
+
border-color: #fff;
|
|
8
|
+
|
|
9
|
+
transform: translate3d(0, 0, 0) rotate(45deg);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
33% {
|
|
13
|
+
width: 8px;
|
|
14
|
+
height: 0;
|
|
15
|
+
|
|
16
|
+
transform: translate3d(0, 0, 0) rotate(45deg);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
100% {
|
|
20
|
+
width: 8px;
|
|
21
|
+
height: 16px;
|
|
22
|
+
border-color: #fff;
|
|
23
|
+
border-bottom-right-radius: 2px;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
transform: translate3d(0, -16px, 0) rotate(45deg);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@keyframes scaleDown {
|
|
31
|
+
0% {
|
|
32
|
+
transform: scale(0.7);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
100% {
|
|
36
|
+
transform: scale(0);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@keyframes scaleUp {
|
|
41
|
+
0% {
|
|
42
|
+
transform: scale(0);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
33% {
|
|
46
|
+
transform: scale(0.5);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
100% {
|
|
50
|
+
transform: scale(1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.c-checkbox-tick {
|
|
55
|
+
content: "";
|
|
56
|
+
display: flex;
|
|
57
|
+
|
|
58
|
+
flex: 0 0 auto;
|
|
59
|
+
|
|
60
|
+
width: var(--checkbox-width);
|
|
61
|
+
height: var(--checkbox-height);
|
|
62
|
+
|
|
63
|
+
margin: var(--checkbox-margin);
|
|
64
|
+
|
|
65
|
+
border: 1px solid var(--checkbox-border-color);
|
|
66
|
+
border-radius: var(--checkbox-radius);
|
|
67
|
+
background-color: var(--checkbox-bg-color);
|
|
68
|
+
|
|
69
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
70
|
+
transition: background-color var(--dt-motion-timing-100) var(--checkbox-motion-easing);
|
|
71
|
+
|
|
72
|
+
animation: scaleDown var(--dt-motion-timing-100) var(--checkbox-motion-easing);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
&[data-pie-disabled] {
|
|
76
|
+
--checkbox-bg-color: var(--dt-color-container-strong);
|
|
77
|
+
--checkbox-border-color: var(--dt-color-disabled-01);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
&[data-pie-status="error"] {
|
|
81
|
+
--checkbox-border-color: var(--dt-color-support-error);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
&[data-pie-checked] {
|
|
85
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
86
|
+
animation: scaleUp var(--dt-motion-timing-100) var(--checkbox-motion-easing);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
&:not([data-pie-disabled]) {
|
|
90
|
+
--checkbox-bg-color: var(--dt-color-interactive-brand);
|
|
91
|
+
--checkbox-border-color: var(--dt-color-interactive-brand);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
&[data-pie-status="error"] {
|
|
95
|
+
--checkbox-border-color: var(--dt-color-support-error);
|
|
96
|
+
--checkbox-bg-color: var(--dt-color-support-error);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
&[data-pie-checked]:before {
|
|
101
|
+
content: "";
|
|
102
|
+
|
|
103
|
+
position: relative;
|
|
104
|
+
top: 55%;
|
|
105
|
+
left: 14%;
|
|
106
|
+
|
|
107
|
+
border-right: 2px solid transparent;
|
|
108
|
+
border-bottom: 2px solid transparent;
|
|
109
|
+
|
|
110
|
+
transform: rotate(45deg);
|
|
111
|
+
transform-origin: 0% 100%;
|
|
112
|
+
|
|
113
|
+
animation: checkboxCheck var(--dt-motion-timing-150) var(--checkbox-motion-easing) forwards;
|
|
114
|
+
|
|
115
|
+
@media (prefers-reduced-motion: reduce) {
|
|
116
|
+
animation: none;
|
|
117
|
+
width: 8px;
|
|
118
|
+
height: 16px;
|
|
119
|
+
border-color: #fff;
|
|
120
|
+
border-bottom-right-radius: 2px;
|
|
121
|
+
|
|
122
|
+
transform: translate3d(0, -16px, 0) rotate(45deg);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@media only percy {
|
|
126
|
+
animation: none;
|
|
127
|
+
|
|
128
|
+
width: 8px;
|
|
129
|
+
height: 16px;
|
|
130
|
+
border-color: #fff;
|
|
131
|
+
border-bottom-right-radius: 2px;
|
|
132
|
+
|
|
133
|
+
transform: translate3d(0, -16px, 0) rotate(45deg);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
&[data-pie-indeterminate] {
|
|
138
|
+
&:not([data-pie-disabled]) {
|
|
139
|
+
--checkbox-bg-color: var(--dt-color-interactive-brand);
|
|
140
|
+
--checkbox-border-color: var(--dt-color-interactive-brand);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
&[data-pie-status="error"] {
|
|
144
|
+
--checkbox-border-color: var(--dt-color-support-error);
|
|
145
|
+
--checkbox-bg-color: var(--dt-color-support-error);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
&[data-pie-indeterminate]:after {
|
|
150
|
+
width: 16px;
|
|
151
|
+
|
|
152
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
153
|
+
transition: width var(--dt-motion-timing-100) var(--checkbox-motion-easing) var(--dt-motion-timing-100);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.c-checkbox-text {
|
|
159
|
+
display: inline;
|
|
160
|
+
flex: 1 1 auto;
|
|
161
|
+
align-self: center;
|
|
162
|
+
min-width: 0;
|
|
163
|
+
margin-inline-start: var(--checkbox-gap);
|
|
164
|
+
white-space: normal;
|
|
165
|
+
color: var(--checkbox-content-color);
|
|
166
|
+
font-size: var(--checkbox-font-size);
|
|
167
|
+
font-weight: var(--checkbox-font-weight);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// initial styles for indeterminate state
|
|
171
|
+
.c-checkbox-tick:after {
|
|
172
|
+
content: "";
|
|
173
|
+
|
|
174
|
+
position: relative;
|
|
175
|
+
top: 47%;
|
|
176
|
+
left: 14%;
|
|
177
|
+
width: 0;
|
|
178
|
+
height: 2px;
|
|
179
|
+
background-color: white;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.c-checkbox {
|
|
183
|
+
--checkbox-height: 24px;
|
|
184
|
+
--checkbox-width: 24px;
|
|
185
|
+
--checkbox-radius: var(--dt-radius-rounded-a);
|
|
186
|
+
--checkbox-margin: 1px;
|
|
187
|
+
--checkbox-gap: var(--dt-spacing-b);
|
|
188
|
+
--checkbox-font-size: var(--dt-font-body-l-size);
|
|
189
|
+
--checkbox-font-weight: var(--dt-font-weight-regular);
|
|
190
|
+
--checkbox-bg-color: var(--dt-color-container-default);
|
|
191
|
+
--checkbox-border-color: var(--dt-color-interactive-form);
|
|
192
|
+
--checkbox-content-color: var(--dt-color-content-default);
|
|
193
|
+
--checkbox-motion-easing: var(--dt-motion-easing-persistent-functional);
|
|
194
|
+
|
|
195
|
+
display: flex;
|
|
196
|
+
flex-direction: column;
|
|
197
|
+
|
|
198
|
+
input {
|
|
199
|
+
display: block;
|
|
200
|
+
position: absolute;
|
|
201
|
+
height: 1px;
|
|
202
|
+
width: 1px;
|
|
203
|
+
overflow: hidden;
|
|
204
|
+
clip: rect(1px, 1px, 1px, 1px);
|
|
205
|
+
clip-path: inset(1px);
|
|
206
|
+
white-space: nowrap;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
label {
|
|
210
|
+
display: flex;
|
|
211
|
+
max-width: 100%;
|
|
212
|
+
white-space: nowrap;
|
|
213
|
+
cursor: pointer;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
&:hover {
|
|
217
|
+
.c-checkbox-tick {
|
|
218
|
+
--checkbox-bg-color: hsl(var(--dt-color-container-default-h), var(--dt-color-container-default-s), calc(var(--dt-color-container-default-l) + calc(-1 * var(--dt-color-hover-01))));
|
|
219
|
+
|
|
220
|
+
transition: background-color var(--dt-motion-timing-200) var(--checkbox-motion-easing);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
&:active {
|
|
225
|
+
.c-checkbox-tick {
|
|
226
|
+
--checkbox-bg-color: hsl(var(--dt-color-container-default-h), var(--dt-color-container-default-s), calc(var(--dt-color-container-default-l) + calc(-1 * var(--dt-color-active-01))));
|
|
227
|
+
|
|
228
|
+
transition: background-color var(--dt-motion-timing-100) var(--checkbox-motion-easing);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
&[data-pie-disabled] {
|
|
233
|
+
label {
|
|
234
|
+
cursor: default;
|
|
235
|
+
pointer-events: none;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
input:focus-visible + label {
|
|
240
|
+
.c-checkbox-tick {
|
|
241
|
+
@include p.focus;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
&[data-pie-disabled] {
|
|
246
|
+
&:hover,
|
|
247
|
+
&:active {
|
|
248
|
+
.c-checkbox-tick {
|
|
249
|
+
--checkbox-bg-color: var(--dt-color-container-strong);
|
|
250
|
+
--checkbox-border-color: var(--dt-color-disabled-01);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
&[data-pie-status="error"] {
|
|
256
|
+
&:hover {
|
|
257
|
+
.c-checkbox-tick {
|
|
258
|
+
--checkbox-bg-color: hsl(var(--dt-color-container-default-h), var(--dt-color-container-default-s), calc(var(--dt-color-container-default-l) + calc(-1 * var(--dt-color-hover-01))));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
&:active {
|
|
263
|
+
.c-checkbox-tick {
|
|
264
|
+
--checkbox-bg-color: hsl(var(--dt-color-container-default-h), var(--dt-color-container-default-s), calc(var(--dt-color-container-default-l) + calc(-1 * var(--dt-color-active-01))));
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
&[data-pie-checked],
|
|
270
|
+
&[data-pie-indeterminate] {
|
|
271
|
+
&:not([data-pie-disabled]):hover {
|
|
272
|
+
.c-checkbox-tick {
|
|
273
|
+
--checkbox-bg-color: hsl(var(--dt-color-interactive-brand-h), var(--dt-color-interactive-brand-s), calc(var(--dt-color-interactive-brand-l) + calc(-1 * var(--dt-color-hover-01))));
|
|
274
|
+
--checkbox-border-color: hsl(var(--dt-color-interactive-brand-h), var(--dt-color-interactive-brand-s), calc(var(--dt-color-interactive-brand-l) + calc(-1 * var(--dt-color-hover-01))));
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
&[data-pie-status="error"]:hover {
|
|
279
|
+
.c-checkbox-tick {
|
|
280
|
+
--checkbox-bg-color: hsl(var(--dt-color-support-error-h), var(--dt-color-support-error-s), calc(var(--dt-color-support-error-l) + calc(-1 * var(--dt-color-hover-01))));
|
|
281
|
+
--checkbox-border-color: hsl(var(--dt-color-support-error-h), var(--dt-color-support-error-s), calc(var(--dt-color-support-error-l) + calc(-1 * var(--dt-color-hover-01))));
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
&:not([data-pie-disabled]):active {
|
|
286
|
+
.c-checkbox-tick {
|
|
287
|
+
--checkbox-bg-color: hsl(var(--dt-color-interactive-brand-h), var(--dt-color-interactive-brand-s), calc(var(--dt-color-interactive-brand-l) + calc(-1 * var(--dt-color-active-01))));
|
|
288
|
+
--checkbox-border-color: hsl(var(--dt-color-interactive-brand-h), var(--dt-color-interactive-brand-s), calc(var(--dt-color-interactive-brand-l) + calc(-1 * var(--dt-color-active-01))));
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
&[data-pie-status="error"]:active {
|
|
293
|
+
.c-checkbox-tick {
|
|
294
|
+
--checkbox-bg-color: hsl(var(--dt-color-support-error-h), var(--dt-color-support-error-s), calc(var(--dt-color-support-error-l) + calc(-1 * var(--dt-color-active-01))));
|
|
295
|
+
--checkbox-border-color: hsl(var(--dt-color-support-error-h), var(--dt-color-support-error-s), calc(var(--dt-color-support-error-l) + calc(-1 * var(--dt-color-active-01))));
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
package/src/defs.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
|
|
2
2
|
|
|
3
3
|
export const statusTypes = ['default', 'success', 'error'] as const;
|
|
4
4
|
|
|
@@ -64,15 +64,16 @@ export interface CheckboxProps {
|
|
|
64
64
|
status?: typeof statusTypes[number];
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
export type DefaultProps =
|
|
67
|
+
export type DefaultProps = ComponentDefaultProps<CheckboxProps, keyof Omit<CheckboxProps, 'label' | 'name' | 'aria' | 'assistiveText'>>;
|
|
68
68
|
|
|
69
69
|
export const defaultProps: DefaultProps = {
|
|
70
70
|
// a default value for the html <input type="checkbox" /> value attribute.
|
|
71
71
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#value
|
|
72
72
|
value: 'on',
|
|
73
|
-
|
|
73
|
+
disabled: false,
|
|
74
74
|
defaultChecked: false,
|
|
75
|
-
indeterminate: false,
|
|
76
75
|
checked: false,
|
|
76
|
+
indeterminate: false,
|
|
77
|
+
required: false,
|
|
77
78
|
status: 'default',
|
|
78
79
|
};
|
package/src/index.ts
CHANGED
|
@@ -49,10 +49,10 @@ export class PieCheckbox extends FormControlMixin(RtlMixin(LitElement)) implemen
|
|
|
49
49
|
public disabled?: CheckboxProps['disabled'];
|
|
50
50
|
|
|
51
51
|
@property({ type: Boolean, reflect: true })
|
|
52
|
-
public required
|
|
52
|
+
public required = defaultProps.required;
|
|
53
53
|
|
|
54
54
|
@property({ type: Boolean, reflect: true })
|
|
55
|
-
public indeterminate
|
|
55
|
+
public indeterminate = defaultProps.indeterminate;
|
|
56
56
|
|
|
57
57
|
@property({ type: Object })
|
|
58
58
|
public aria: CheckboxProps['aria'];
|
|
@@ -65,7 +65,7 @@ export class PieCheckbox extends FormControlMixin(RtlMixin(LitElement)) implemen
|
|
|
65
65
|
|
|
66
66
|
@property({ type: String })
|
|
67
67
|
@validPropertyValues(componentSelector, statusTypes, defaultProps.status)
|
|
68
|
-
public status
|
|
68
|
+
public status = defaultProps.status;
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* (Read-only) returns a ValidityState with the validity states that this element is in.
|
|
@@ -155,24 +155,44 @@ export class PieCheckbox extends FormControlMixin(RtlMixin(LitElement)) implemen
|
|
|
155
155
|
} = this;
|
|
156
156
|
|
|
157
157
|
return html`
|
|
158
|
-
<
|
|
158
|
+
<div
|
|
159
|
+
class="c-checkbox"
|
|
160
|
+
data-pie-status=${!disabled && status}
|
|
161
|
+
?data-pie-disabled=${live(disabled)}
|
|
162
|
+
?data-pie-checked=${checked}
|
|
163
|
+
?data-pie-indeterminate=${indeterminate && !checked}>
|
|
159
164
|
<input
|
|
160
165
|
type="checkbox"
|
|
166
|
+
id="inputId"
|
|
161
167
|
.value=${value}
|
|
162
168
|
.checked=${live(checked)}
|
|
163
169
|
name=${ifDefined(name)}
|
|
164
170
|
?disabled=${disabled}
|
|
165
171
|
?required=${required}
|
|
166
|
-
.indeterminate=${
|
|
172
|
+
.indeterminate=${indeterminate}
|
|
167
173
|
aria-label=${aria?.label || nothing}
|
|
168
174
|
aria-labelledby=${label ? nothing : aria?.labelledby || nothing}
|
|
169
175
|
aria-describedby=${ifDefined(assistiveText ? assistiveTextIdValue : undefined)}
|
|
170
176
|
@change=${this.handleChange}
|
|
171
177
|
data-test-id="checkbox-input"
|
|
172
178
|
/>
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
179
|
+
<label for="inputId" data-test-id="checkbox-component">
|
|
180
|
+
<span
|
|
181
|
+
class="c-checkbox-tick"
|
|
182
|
+
?data-pie-checked=${checked}
|
|
183
|
+
?data-pie-disabled=${live(disabled)}
|
|
184
|
+
data-pie-status=${!disabled && status}
|
|
185
|
+
?data-pie-indeterminate=${indeterminate && !checked}></span>
|
|
186
|
+
<span class="c-checkbox-text">${label}</span>
|
|
187
|
+
</label>
|
|
188
|
+
${assistiveText ? html`
|
|
189
|
+
<pie-assistive-text
|
|
190
|
+
id="${assistiveTextIdValue}"
|
|
191
|
+
variant=${status}
|
|
192
|
+
data-test-id="pie-checkbox-assistive-text">
|
|
193
|
+
${assistiveText}
|
|
194
|
+
</pie-assistive-text>` : nothing}
|
|
195
|
+
</div>`;
|
|
176
196
|
}
|
|
177
197
|
|
|
178
198
|
// Renders a `CSSResult` generated from SCSS by Vite
|