@justeattakeaway/pie-checkbox 0.2.0 → 0.3.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.
package/README.md CHANGED
@@ -15,7 +15,8 @@
15
15
  3. [Importing the component](#importing-the-component)
16
16
  4. [Peer Dependencies](#peer-dependencies)
17
17
  5. [Props](#props)
18
- 6. [Contributing](#contributing)
18
+ 6. [Events](#events)
19
+ 7. [Contributing](#contributing)
19
20
 
20
21
  ## pie-checkbox
21
22
 
@@ -74,18 +75,36 @@ import { PieCheckbox } from '@justeattakeaway/pie-checkbox/dist/react';
74
75
 
75
76
  | Property | Type | Default | Description |
76
77
  |---|---|---|---|
77
- | - | - | - | - |
78
+ | `name` | `string` | - | The name of the checkbox (used as a key/value pair with `value`). This is required in order to work properly with forms. |
79
+ | `value` | `string` | 'on' | The value of the input (used as a key/value pair in HTML forms with `name`). If not passed falls back to the html default value "on". |
80
+ | `required` | `boolean` | `false` | If true, the checkbox is required to be checked before submitting the form. If it is not in checked state, the component validity state will be invalid. |
81
+ | `label` | `string` | '' | Text associated with the checkbox. If there is no label to provide, make sure to pass label, labelledby or describedby to the aria property. |
82
+ | `disabled` | `boolean` | `false` | Indicates whether or not the checkbox is disabled. |
83
+ | `checked` | `boolean` | `false` | Indicates whether or not the checkbox is checked by default (when the page loads). |
84
+ | `indeterminate` | `boolean` | `false` | Indicates whether the checkbox visually shows a horizontal line in the box instead of a check/tick. 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. |
85
+ | `aria` | `object` | {} | accepts `label`, `labeledby` and `describedby` keys with string values. |
78
86
 
79
87
  In your markup or JSX, you can then use these to set the properties for the `pie-checkbox` component:
80
88
 
81
89
  ```html
82
90
  <!-- Native HTML -->
83
- <pie-checkbox></pie-checkbox>
91
+ <pie-checkbox
92
+ name="mycheckbox"
93
+ label="Checkbox Label">
94
+ </pie-checkbox>
84
95
 
85
96
  <!-- JSX -->
86
- <PieCheckbox></PieCheckbox>
97
+ <PieCheckbox
98
+ name="mycheckbox"
99
+ label="Checkbox Label">
100
+ </PieCheckbox>
87
101
  ```
88
102
 
103
+ ## Events
104
+ | Event | Type | Description |
105
+ |-------|------|-------------|
106
+ | `change` | `CustomEvent` | Triggered after the checked state of a checkbox changes. |
107
+
89
108
  ## Contributing
90
109
 
91
110
  Check out our [contributing guide](https://github.com/justeattakeaway/pie/wiki/Contributing-Guide) for more information on [local development](https://github.com/justeattakeaway/pie/wiki/Contributing-Guide#local-development) and how to run specific [component tests](https://github.com/justeattakeaway/pie/wiki/Contributing-Guide#testing).
@@ -105,6 +105,15 @@
105
105
  "default": "false",
106
106
  "attribute": "indeterminate"
107
107
  },
108
+ {
109
+ "kind": "field",
110
+ "name": "aria",
111
+ "type": {
112
+ "text": "CheckboxProps['aria']"
113
+ },
114
+ "privacy": "public",
115
+ "attribute": "aria"
116
+ },
108
117
  {
109
118
  "kind": "field",
110
119
  "name": "checkbox",
@@ -190,6 +199,13 @@
190
199
  },
191
200
  "default": "false",
192
201
  "fieldName": "indeterminate"
202
+ },
203
+ {
204
+ "name": "aria",
205
+ "type": {
206
+ "text": "CheckboxProps['aria']"
207
+ },
208
+ "fieldName": "aria"
193
209
  }
194
210
  ],
195
211
  "mixins": [
package/dist/index.d.ts CHANGED
@@ -4,6 +4,12 @@ import type { LitElement } from 'lit';
4
4
  import type { RTLInterface } from '@justeattakeaway/pie-webc-core';
5
5
  import type { TemplateResult } from 'lit-html';
6
6
 
7
+ export declare type AriaProps = {
8
+ label?: string;
9
+ labelledby?: string;
10
+ describedby?: string;
11
+ };
12
+
7
13
  export declare interface CheckboxProps {
8
14
  /**
9
15
  * The value of the checkbox (used as a key/value pair in HTML forms with `name`).
@@ -34,6 +40,10 @@ export declare interface CheckboxProps {
34
40
  * If true, the checkbox must be checked for the form to be submittable.
35
41
  */
36
42
  required?: boolean;
43
+ /**
44
+ * Various ARIA attributes.
45
+ */
46
+ aria?: AriaProps;
37
47
  }
38
48
 
39
49
  /**
@@ -53,6 +63,7 @@ export declare class PieCheckbox extends PieCheckbox_base implements CheckboxPro
53
63
  disabled?: CheckboxProps['disabled'];
54
64
  required?: CheckboxProps['required'];
55
65
  indeterminate?: CheckboxProps['indeterminate'];
66
+ aria: CheckboxProps['aria'];
56
67
  private checkbox?;
57
68
  /**
58
69
  * (Read-only) returns a ValidityState with the validity states that this element is in.
package/dist/index.js CHANGED
@@ -1,20 +1,20 @@
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}
1
+ import { LitElement as b, html as u, nothing as c, unsafeCSS as m } from "lit";
2
+ import { RtlMixin as f, wrapNativeEvent as v, defineCustomElement as g } from "@justeattakeaway/pie-webc-core";
3
+ import { property as i, query as $ } from "lit/decorators.js";
4
+ import { ifDefined as h } from "lit/directives/if-defined.js";
5
+ const x = `*,*:after,*:before{box-sizing:inherit}
6
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;
7
+ var C = Object.defineProperty, O = Object.getOwnPropertyDescriptor, r = (d, n, p, l) => {
8
+ for (var t = l > 1 ? void 0 : l ? O(n, p) : n, a = d.length - 1, s; a >= 0; a--)
9
+ (s = d[a]) && (t = (l ? s(n, p, t) : s(t)) || t);
10
+ return l && t && C(n, p, t), t;
11
11
  };
12
- const C = "pie-checkbox";
13
- class e extends y(d) {
12
+ const S = "pie-checkbox";
13
+ class e extends f(b) {
14
14
  constructor() {
15
- super(...arguments), this.required = !1, this.indeterminate = !1, this.handleChange = (o) => {
16
- const n = f(o);
17
- this.dispatchEvent(n);
15
+ super(...arguments), this.required = !1, this.indeterminate = !1, this.handleChange = (n) => {
16
+ const p = v(n);
17
+ this.dispatchEvent(p);
18
18
  };
19
19
  }
20
20
  /**
@@ -26,24 +26,28 @@ class e extends y(d) {
26
26
  }
27
27
  render() {
28
28
  const {
29
- checked: o,
30
- value: n,
31
- name: p,
29
+ checked: n,
30
+ value: p,
31
+ name: l,
32
32
  label: t,
33
33
  disabled: a,
34
34
  required: s,
35
- indeterminate: h
35
+ indeterminate: y,
36
+ aria: o
36
37
  } = this;
37
38
  return u`
38
39
  <label>
39
40
  <input
40
41
  type="checkbox"
41
- ?checked=${c(o)}
42
- .value=${c(n)}
43
- name=${c(p)}
42
+ ?checked=${h(n)}
43
+ .value=${h(p)}
44
+ name=${h(l)}
44
45
  ?disabled=${a}
45
46
  ?required=${s}
46
- .indeterminate=${h}
47
+ .indeterminate=${y}
48
+ aria-label=${(o == null ? void 0 : o.label) || c}
49
+ aria-labelledby=${t ? c : (o == null ? void 0 : o.labelledby) || c}
50
+ aria-describedby= ${(o == null ? void 0 : o.describedby) || c}
47
51
  @change=${this.handleChange}
48
52
  data-test-id="pie-checkbox"
49
53
  />
@@ -51,8 +55,8 @@ class e extends y(d) {
51
55
  </label>`;
52
56
  }
53
57
  }
54
- e.shadowRootOptions = { ...d.shadowRootOptions, delegatesFocus: !0 };
55
- e.styles = m(g);
58
+ e.shadowRootOptions = { ...b.shadowRootOptions, delegatesFocus: !0 };
59
+ e.styles = m(x);
56
60
  r([
57
61
  i({ type: String })
58
62
  ], e.prototype, "value", 2);
@@ -75,9 +79,12 @@ r([
75
79
  i({ type: Boolean })
76
80
  ], e.prototype, "indeterminate", 2);
77
81
  r([
78
- v("input")
82
+ i({ type: Object })
83
+ ], e.prototype, "aria", 2);
84
+ r([
85
+ $("input")
79
86
  ], e.prototype, "checkbox", 2);
80
- b(C, e);
87
+ g(S, e);
81
88
  export {
82
89
  e as PieCheckbox
83
90
  };
package/dist/react.d.ts CHANGED
@@ -5,6 +5,12 @@ import * as React_2 from 'react';
5
5
  import type { RTLInterface } from '@justeattakeaway/pie-webc-core';
6
6
  import type { TemplateResult } from 'lit-html';
7
7
 
8
+ export declare type AriaProps = {
9
+ label?: string;
10
+ labelledby?: string;
11
+ describedby?: string;
12
+ };
13
+
8
14
  export declare interface CheckboxProps {
9
15
  /**
10
16
  * The value of the checkbox (used as a key/value pair in HTML forms with `name`).
@@ -35,6 +41,10 @@ export declare interface CheckboxProps {
35
41
  * If true, the checkbox must be checked for the form to be submittable.
36
42
  */
37
43
  required?: boolean;
44
+ /**
45
+ * Various ARIA attributes.
46
+ */
47
+ aria?: AriaProps;
38
48
  }
39
49
 
40
50
  export declare const PieCheckbox: React_2.ForwardRefExoticComponent<CheckboxProps & React_2.RefAttributes<PieCheckbox_2> & ReactBaseType>;
@@ -56,6 +66,7 @@ declare class PieCheckbox_2 extends PieCheckbox_base implements CheckboxProps {
56
66
  disabled?: CheckboxProps['disabled'];
57
67
  required?: CheckboxProps['required'];
58
68
  indeterminate?: CheckboxProps['indeterminate'];
69
+ aria: CheckboxProps['aria'];
59
70
  private checkbox?;
60
71
  /**
61
72
  * (Read-only) returns a ValidityState with the validity states that this element is in.
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.2.0",
4
+ "version": "0.3.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
package/src/defs.ts CHANGED
@@ -1,3 +1,8 @@
1
+ export type AriaProps = {
2
+ label?: string;
3
+ labelledby?: string;
4
+ describedby?: string;
5
+ };
1
6
  export interface CheckboxProps {
2
7
  /**
3
8
  * The value of the checkbox (used as a key/value pair in HTML forms with `name`).
@@ -34,4 +39,9 @@ export interface CheckboxProps {
34
39
  * If true, the checkbox must be checked for the form to be submittable.
35
40
  */
36
41
  required?: boolean;
42
+
43
+ /**
44
+ * Various ARIA attributes.
45
+ */
46
+ aria?: AriaProps;
37
47
  }
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import {
2
- LitElement, html, unsafeCSS,
2
+ LitElement, html, unsafeCSS, nothing,
3
3
  } from 'lit';
4
4
  import {
5
5
  RtlMixin,
@@ -45,6 +45,9 @@ export class PieCheckbox extends RtlMixin(LitElement) implements CheckboxProps {
45
45
  @property({ type: Boolean })
46
46
  public indeterminate?: CheckboxProps['indeterminate'] = false;
47
47
 
48
+ @property({ type: Object })
49
+ public aria: CheckboxProps['aria'];
50
+
48
51
  @query('input')
49
52
  private checkbox?: HTMLInputElement;
50
53
 
@@ -77,7 +80,9 @@ export class PieCheckbox extends RtlMixin(LitElement) implements CheckboxProps {
77
80
  disabled,
78
81
  required,
79
82
  indeterminate,
83
+ aria,
80
84
  } = this;
85
+
81
86
  return html`
82
87
  <label>
83
88
  <input
@@ -88,6 +93,9 @@ export class PieCheckbox extends RtlMixin(LitElement) implements CheckboxProps {
88
93
  ?disabled=${disabled}
89
94
  ?required=${required}
90
95
  .indeterminate=${indeterminate}
96
+ aria-label=${aria?.label || nothing}
97
+ aria-labelledby=${label ? nothing : aria?.labelledby || nothing}
98
+ aria-describedby= ${aria?.describedby || nothing}
91
99
  @change=${this.handleChange}
92
100
  data-test-id="pie-checkbox"
93
101
  />