@justeattakeaway/pie-checkbox 0.0.0 → 0.2.0

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.
@@ -22,7 +22,176 @@
22
22
  "kind": "class",
23
23
  "description": "",
24
24
  "name": "PieCheckbox",
25
- "members": [],
25
+ "slots": [
26
+ {
27
+ "description": "Default slot (checkbox label)",
28
+ "name": ""
29
+ }
30
+ ],
31
+ "members": [
32
+ {
33
+ "kind": "field",
34
+ "name": "shadowRootOptions",
35
+ "type": {
36
+ "text": "object"
37
+ },
38
+ "static": true,
39
+ "default": "{ ...LitElement.shadowRootOptions, delegatesFocus: true }"
40
+ },
41
+ {
42
+ "kind": "field",
43
+ "name": "value",
44
+ "type": {
45
+ "text": "CheckboxProps['value']"
46
+ },
47
+ "privacy": "public",
48
+ "attribute": "value"
49
+ },
50
+ {
51
+ "kind": "field",
52
+ "name": "label",
53
+ "type": {
54
+ "text": "CheckboxProps['label'] | undefined"
55
+ },
56
+ "privacy": "public",
57
+ "attribute": "label"
58
+ },
59
+ {
60
+ "kind": "field",
61
+ "name": "name",
62
+ "type": {
63
+ "text": "CheckboxProps['name'] | undefined"
64
+ },
65
+ "privacy": "public",
66
+ "attribute": "name"
67
+ },
68
+ {
69
+ "kind": "field",
70
+ "name": "checked",
71
+ "type": {
72
+ "text": "CheckboxProps['checked'] | undefined"
73
+ },
74
+ "privacy": "public",
75
+ "attribute": "checked"
76
+ },
77
+ {
78
+ "kind": "field",
79
+ "name": "disabled",
80
+ "type": {
81
+ "text": "CheckboxProps['disabled'] | undefined"
82
+ },
83
+ "privacy": "public",
84
+ "attribute": "disabled",
85
+ "reflects": true
86
+ },
87
+ {
88
+ "kind": "field",
89
+ "name": "required",
90
+ "type": {
91
+ "text": "CheckboxProps['required'] | undefined"
92
+ },
93
+ "privacy": "public",
94
+ "default": "false",
95
+ "attribute": "required",
96
+ "reflects": true
97
+ },
98
+ {
99
+ "kind": "field",
100
+ "name": "indeterminate",
101
+ "type": {
102
+ "text": "CheckboxProps['indeterminate'] | undefined"
103
+ },
104
+ "privacy": "public",
105
+ "default": "false",
106
+ "attribute": "indeterminate"
107
+ },
108
+ {
109
+ "kind": "field",
110
+ "name": "checkbox",
111
+ "type": {
112
+ "text": "HTMLInputElement | undefined"
113
+ },
114
+ "privacy": "private"
115
+ },
116
+ {
117
+ "kind": "field",
118
+ "name": "validity",
119
+ "type": {
120
+ "text": "ValidityState"
121
+ },
122
+ "privacy": "public",
123
+ "description": "(Read-only) returns a ValidityState with the validity states that this element is in.\nhttps://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity",
124
+ "readonly": true
125
+ },
126
+ {
127
+ "kind": "field",
128
+ "name": "handleChange",
129
+ "privacy": "private",
130
+ "description": "The onChange function updates the checkbox state and emits an event for consumers.",
131
+ "parameters": [
132
+ {
133
+ "description": "This should be the change event that was listened for on an input element with `type=\"checkbox\"`.",
134
+ "name": "event",
135
+ "type": {
136
+ "text": "Event"
137
+ }
138
+ }
139
+ ]
140
+ }
141
+ ],
142
+ "attributes": [
143
+ {
144
+ "name": "value",
145
+ "type": {
146
+ "text": "CheckboxProps['value']"
147
+ },
148
+ "fieldName": "value"
149
+ },
150
+ {
151
+ "name": "label",
152
+ "type": {
153
+ "text": "CheckboxProps['label'] | undefined"
154
+ },
155
+ "fieldName": "label"
156
+ },
157
+ {
158
+ "name": "name",
159
+ "type": {
160
+ "text": "CheckboxProps['name'] | undefined"
161
+ },
162
+ "fieldName": "name"
163
+ },
164
+ {
165
+ "name": "checked",
166
+ "type": {
167
+ "text": "CheckboxProps['checked'] | undefined"
168
+ },
169
+ "fieldName": "checked"
170
+ },
171
+ {
172
+ "name": "disabled",
173
+ "type": {
174
+ "text": "CheckboxProps['disabled'] | undefined"
175
+ },
176
+ "fieldName": "disabled"
177
+ },
178
+ {
179
+ "name": "required",
180
+ "type": {
181
+ "text": "CheckboxProps['required'] | undefined"
182
+ },
183
+ "default": "false",
184
+ "fieldName": "required"
185
+ },
186
+ {
187
+ "name": "indeterminate",
188
+ "type": {
189
+ "text": "CheckboxProps['indeterminate'] | undefined"
190
+ },
191
+ "default": "false",
192
+ "fieldName": "indeterminate"
193
+ }
194
+ ],
26
195
  "mixins": [
27
196
  {
28
197
  "name": "RtlMixin",
package/dist/index.d.ts CHANGED
@@ -5,12 +5,65 @@ import type { RTLInterface } from '@justeattakeaway/pie-webc-core';
5
5
  import type { TemplateResult } from 'lit-html';
6
6
 
7
7
  export declare interface CheckboxProps {
8
+ /**
9
+ * The value of the checkbox (used as a key/value pair in HTML forms with `name`).
10
+ */
11
+ value?: string;
12
+ /**
13
+ * The label value of the component
14
+ */
15
+ label?: string;
16
+ /**
17
+ * The name of the checkbox (used as a key/value pair with `value`). This is required in order to work properly with forms.
18
+ */
19
+ name?: string;
20
+ /**
21
+ * Same as the HTML disabled attribute - indicates whether or not the checkbox is disabled.
22
+ */
23
+ disabled?: boolean;
24
+ /**
25
+ * Same as the HTML checked attribute - indicates whether or not the checkbox is checked by default (when the page loads).
26
+ */
27
+ checked?: boolean;
28
+ /**
29
+ * Indicates whether the checkbox visually shows a horizontal line in the box instead of a check/tick.
30
+ * It has no impact on whether the checkbox's value is used in a form submission. That is decided by the checked state, regardless of the indeterminate state.
31
+ */
32
+ indeterminate?: boolean;
33
+ /**
34
+ * If true, the checkbox must be checked for the form to be submittable.
35
+ */
36
+ required?: boolean;
8
37
  }
9
38
 
10
39
  /**
11
40
  * @tagname pie-checkbox
41
+ * @slot - Default slot (checkbox label)
12
42
  */
13
43
  export declare class PieCheckbox extends PieCheckbox_base implements CheckboxProps {
44
+ static shadowRootOptions: {
45
+ delegatesFocus: boolean;
46
+ mode: ShadowRootMode;
47
+ slotAssignment?: SlotAssignmentMode | undefined;
48
+ };
49
+ value: CheckboxProps['value'];
50
+ label?: CheckboxProps['label'];
51
+ name?: CheckboxProps['name'];
52
+ checked?: CheckboxProps['checked'];
53
+ disabled?: CheckboxProps['disabled'];
54
+ required?: CheckboxProps['required'];
55
+ indeterminate?: CheckboxProps['indeterminate'];
56
+ private checkbox?;
57
+ /**
58
+ * (Read-only) returns a ValidityState with the validity states that this element is in.
59
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity
60
+ */
61
+ get validity(): ValidityState;
62
+ /**
63
+ * The onChange function updates the checkbox state and emits an event for consumers.
64
+ * @param {Event} event - This should be the change event that was listened for on an input element with `type="checkbox"`.
65
+ */
66
+ private handleChange;
14
67
  render(): TemplateResult<1>;
15
68
  static styles: CSSResult;
16
69
  }
package/dist/index.js CHANGED
@@ -1,14 +1,83 @@
1
- import { LitElement as t, html as o, unsafeCSS as n } from "lit";
2
- import { RtlMixin as i, defineCustomElement as r } from "@justeattakeaway/pie-webc-core";
3
- const s = `*,*:after,*:before{box-sizing:inherit}
4
- `, l = "pie-checkbox";
5
- class e extends i(t) {
1
+ import { LitElement as d, html as u, unsafeCSS as m } from "lit";
2
+ import { RtlMixin as y, wrapNativeEvent as f, defineCustomElement as b } from "@justeattakeaway/pie-webc-core";
3
+ import { property as i, query as v } from "lit/decorators.js";
4
+ import { ifDefined as c } from "lit/directives/if-defined.js";
5
+ const g = `*,*:after,*:before{box-sizing:inherit}
6
+ `;
7
+ var x = Object.defineProperty, $ = Object.getOwnPropertyDescriptor, r = (l, o, n, p) => {
8
+ for (var t = p > 1 ? void 0 : p ? $(o, n) : o, a = l.length - 1, s; a >= 0; a--)
9
+ (s = l[a]) && (t = (p ? s(o, n, t) : s(t)) || t);
10
+ return p && t && x(o, n, t), t;
11
+ };
12
+ const C = "pie-checkbox";
13
+ class e extends y(d) {
14
+ constructor() {
15
+ super(...arguments), this.required = !1, this.indeterminate = !1, this.handleChange = (o) => {
16
+ const n = f(o);
17
+ this.dispatchEvent(n);
18
+ };
19
+ }
20
+ /**
21
+ * (Read-only) returns a ValidityState with the validity states that this element is in.
22
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity
23
+ */
24
+ get validity() {
25
+ return this.checkbox.validity;
26
+ }
6
27
  render() {
7
- return o`<h1 data-test-id="pie-checkbox">Hello world!</h1>`;
28
+ const {
29
+ checked: o,
30
+ value: n,
31
+ name: p,
32
+ label: t,
33
+ disabled: a,
34
+ required: s,
35
+ indeterminate: h
36
+ } = this;
37
+ return u`
38
+ <label>
39
+ <input
40
+ type="checkbox"
41
+ ?checked=${c(o)}
42
+ .value=${c(n)}
43
+ name=${c(p)}
44
+ ?disabled=${a}
45
+ ?required=${s}
46
+ .indeterminate=${h}
47
+ @change=${this.handleChange}
48
+ data-test-id="pie-checkbox"
49
+ />
50
+ ${t}
51
+ </label>`;
8
52
  }
9
53
  }
10
- e.styles = n(s);
11
- r(l, e);
54
+ e.shadowRootOptions = { ...d.shadowRootOptions, delegatesFocus: !0 };
55
+ e.styles = m(g);
56
+ r([
57
+ i({ type: String })
58
+ ], e.prototype, "value", 2);
59
+ r([
60
+ i({ type: String })
61
+ ], e.prototype, "label", 2);
62
+ r([
63
+ i({ type: String })
64
+ ], e.prototype, "name", 2);
65
+ r([
66
+ i({ type: Boolean })
67
+ ], e.prototype, "checked", 2);
68
+ r([
69
+ i({ type: Boolean, reflect: !0 })
70
+ ], e.prototype, "disabled", 2);
71
+ r([
72
+ i({ type: Boolean, reflect: !0 })
73
+ ], e.prototype, "required", 2);
74
+ r([
75
+ i({ type: Boolean })
76
+ ], e.prototype, "indeterminate", 2);
77
+ r([
78
+ v("input")
79
+ ], e.prototype, "checkbox", 2);
80
+ b(C, e);
12
81
  export {
13
82
  e as PieCheckbox
14
83
  };
package/dist/react.d.ts CHANGED
@@ -6,14 +6,67 @@ import type { RTLInterface } from '@justeattakeaway/pie-webc-core';
6
6
  import type { TemplateResult } from 'lit-html';
7
7
 
8
8
  export declare interface CheckboxProps {
9
+ /**
10
+ * The value of the checkbox (used as a key/value pair in HTML forms with `name`).
11
+ */
12
+ value?: string;
13
+ /**
14
+ * The label value of the component
15
+ */
16
+ label?: string;
17
+ /**
18
+ * The name of the checkbox (used as a key/value pair with `value`). This is required in order to work properly with forms.
19
+ */
20
+ name?: string;
21
+ /**
22
+ * Same as the HTML disabled attribute - indicates whether or not the checkbox is disabled.
23
+ */
24
+ disabled?: boolean;
25
+ /**
26
+ * Same as the HTML checked attribute - indicates whether or not the checkbox is checked by default (when the page loads).
27
+ */
28
+ checked?: boolean;
29
+ /**
30
+ * Indicates whether the checkbox visually shows a horizontal line in the box instead of a check/tick.
31
+ * It has no impact on whether the checkbox's value is used in a form submission. That is decided by the checked state, regardless of the indeterminate state.
32
+ */
33
+ indeterminate?: boolean;
34
+ /**
35
+ * If true, the checkbox must be checked for the form to be submittable.
36
+ */
37
+ required?: boolean;
9
38
  }
10
39
 
11
40
  export declare const PieCheckbox: React_2.ForwardRefExoticComponent<CheckboxProps & React_2.RefAttributes<PieCheckbox_2> & ReactBaseType>;
12
41
 
13
42
  /**
14
43
  * @tagname pie-checkbox
44
+ * @slot - Default slot (checkbox label)
15
45
  */
16
46
  declare class PieCheckbox_2 extends PieCheckbox_base implements CheckboxProps {
47
+ static shadowRootOptions: {
48
+ delegatesFocus: boolean;
49
+ mode: ShadowRootMode;
50
+ slotAssignment?: SlotAssignmentMode | undefined;
51
+ };
52
+ value: CheckboxProps['value'];
53
+ label?: CheckboxProps['label'];
54
+ name?: CheckboxProps['name'];
55
+ checked?: CheckboxProps['checked'];
56
+ disabled?: CheckboxProps['disabled'];
57
+ required?: CheckboxProps['required'];
58
+ indeterminate?: CheckboxProps['indeterminate'];
59
+ private checkbox?;
60
+ /**
61
+ * (Read-only) returns a ValidityState with the validity states that this element is in.
62
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity
63
+ */
64
+ get validity(): ValidityState;
65
+ /**
66
+ * The onChange function updates the checkbox state and emits an event for consumers.
67
+ * @param {Event} event - This should be the change event that was listened for on an input element with `type="checkbox"`.
68
+ */
69
+ private handleChange;
17
70
  render(): TemplateResult<1>;
18
71
  static styles: CSSResult;
19
72
  }
package/dist/react.js CHANGED
@@ -3,13 +3,15 @@ import { createComponent as o } from "@lit/react";
3
3
  import { PieCheckbox as t } from "./index.js";
4
4
  import "lit";
5
5
  import "@justeattakeaway/pie-webc-core";
6
- const c = o({
6
+ import "lit/decorators.js";
7
+ import "lit/directives/if-defined.js";
8
+ const i = o({
7
9
  displayName: "PieCheckbox",
8
10
  elementClass: t,
9
11
  react: e,
10
12
  tagName: "pie-checkbox",
11
13
  events: {}
12
- }), p = c;
14
+ }), x = i;
13
15
  export {
14
- p as PieCheckbox
16
+ x as PieCheckbox
15
17
  };
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.0.0",
4
+ "version": "0.2.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -40,7 +40,7 @@
40
40
  "cem-plugin-module-file-extensions": "0.0.5"
41
41
  },
42
42
  "dependencies": {
43
- "@justeattakeaway/pie-webc-core": "0.21.1"
43
+ "@justeattakeaway/pie-webc-core": "0.22.0"
44
44
  },
45
45
  "volta": {
46
46
  "extends": "../../../package.json"
package/src/defs.ts CHANGED
@@ -1,3 +1,37 @@
1
- // TODO - please remove the eslint disable comment below when you add props to this interface
2
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
3
- export interface CheckboxProps {}
1
+ export interface CheckboxProps {
2
+ /**
3
+ * The value of the checkbox (used as a key/value pair in HTML forms with `name`).
4
+ */
5
+ value?: string;
6
+
7
+ /**
8
+ * The label value of the component
9
+ */
10
+ label?: string;
11
+
12
+ /**
13
+ * The name of the checkbox (used as a key/value pair with `value`). This is required in order to work properly with forms.
14
+ */
15
+ name?: string;
16
+
17
+ /**
18
+ * Same as the HTML disabled attribute - indicates whether or not the checkbox is disabled.
19
+ */
20
+ disabled?: boolean;
21
+
22
+ /**
23
+ * Same as the HTML checked attribute - indicates whether or not the checkbox is checked by default (when the page loads).
24
+ */
25
+ checked?: boolean;
26
+
27
+ /**
28
+ * Indicates whether the checkbox visually shows a horizontal line in the box instead of a check/tick.
29
+ * It has no impact on whether the checkbox's value is used in a form submission. That is decided by the checked state, regardless of the indeterminate state.
30
+ */
31
+ indeterminate?: boolean;
32
+
33
+ /**
34
+ * If true, the checkbox must be checked for the form to be submittable.
35
+ */
36
+ required?: boolean;
37
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,13 @@
1
- import { LitElement, html, unsafeCSS } from 'lit';
2
- import { RtlMixin, defineCustomElement } from '@justeattakeaway/pie-webc-core';
1
+ import {
2
+ LitElement, html, unsafeCSS,
3
+ } from 'lit';
4
+ import {
5
+ RtlMixin,
6
+ defineCustomElement,
7
+ wrapNativeEvent,
8
+ } from '@justeattakeaway/pie-webc-core';
9
+ import { property, query } from 'lit/decorators.js';
10
+ import { ifDefined } from 'lit/directives/if-defined.js';
3
11
 
4
12
  import styles from './checkbox.scss?inline';
5
13
  import { CheckboxProps } from './defs';
@@ -11,10 +19,80 @@ const componentSelector = 'pie-checkbox';
11
19
 
12
20
  /**
13
21
  * @tagname pie-checkbox
22
+ * @slot - Default slot (checkbox label)
14
23
  */
15
24
  export class PieCheckbox extends RtlMixin(LitElement) implements CheckboxProps {
25
+ static shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true };
26
+
27
+ @property({ type: String })
28
+ public value: CheckboxProps['value'];
29
+
30
+ @property({ type: String })
31
+ public label?: CheckboxProps['label'];
32
+
33
+ @property({ type: String })
34
+ public name?: CheckboxProps['name'];
35
+
36
+ @property({ type: Boolean })
37
+ public checked?: CheckboxProps['checked'];
38
+
39
+ @property({ type: Boolean, reflect: true })
40
+ public disabled?: CheckboxProps['disabled'];
41
+
42
+ @property({ type: Boolean, reflect: true })
43
+ public required?: CheckboxProps['required'] = false;
44
+
45
+ @property({ type: Boolean })
46
+ public indeterminate?: CheckboxProps['indeterminate'] = false;
47
+
48
+ @query('input')
49
+ private checkbox?: HTMLInputElement;
50
+
51
+ /**
52
+ * (Read-only) returns a ValidityState with the validity states that this element is in.
53
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity
54
+ */
55
+ public get validity (): ValidityState {
56
+ return (this.checkbox as HTMLInputElement).validity;
57
+ }
58
+
59
+ /**
60
+ * The onChange function updates the checkbox state and emits an event for consumers.
61
+ * @param {Event} event - This should be the change event that was listened for on an input element with `type="checkbox"`.
62
+ */
63
+ private handleChange = (event: Event) => {
64
+ // This is because some events set `composed` to `false`.
65
+ // Reference: https://javascript.info/shadow-dom-events#event-composed
66
+ const customChangeEvent = wrapNativeEvent(event);
67
+
68
+ this.dispatchEvent(customChangeEvent);
69
+ };
70
+
16
71
  render () {
17
- return html`<h1 data-test-id="pie-checkbox">Hello world!</h1>`;
72
+ const {
73
+ checked,
74
+ value,
75
+ name,
76
+ label,
77
+ disabled,
78
+ required,
79
+ indeterminate,
80
+ } = this;
81
+ return html`
82
+ <label>
83
+ <input
84
+ type="checkbox"
85
+ ?checked=${ifDefined(checked)}
86
+ .value=${ifDefined(value)}
87
+ name=${ifDefined(name)}
88
+ ?disabled=${disabled}
89
+ ?required=${required}
90
+ .indeterminate=${indeterminate}
91
+ @change=${this.handleChange}
92
+ data-test-id="pie-checkbox"
93
+ />
94
+ ${label}
95
+ </label>`;
18
96
  }
19
97
 
20
98
  // Renders a `CSSResult` generated from SCSS by Vite