@justeattakeaway/pie-switch 0.18.4 → 0.20.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
@@ -8,92 +8,15 @@
8
8
  </a>
9
9
  </p>
10
10
 
11
- # Table of Contents
12
-
13
- 1. [Introduction](#pie-switch)
14
- 2. [Installation](#installation)
15
- 3. [Importing the component](#importing-the-component)
16
- 4. [Peer Dependencies](#peer-dependencies)
17
- 5. [Props](#props)
18
- 6. [Events](#Events)
19
- 7. [Contributing](#contributing)
20
-
21
11
  ## pie-switch
22
12
 
23
13
  `pie-switch` is a Web Component built using the Lit library.
24
14
 
25
15
  This component can be easily integrated into various frontend frameworks and customized through a set of properties.
26
16
 
27
-
28
- ## Installation
29
-
30
- To install `pie-switch` in your application, run the following on your command line:
31
-
32
- ```bash
33
- # npm
34
- $ npm i @justeattakeaway/pie-switch
35
-
36
- # yarn
37
- $ yarn add @justeattakeaway/pie-switch
38
- ```
39
-
40
- For full information on using PIE components as part of an application, check out the [Getting Started Guide](https://github.com/justeattakeaway/pie/wiki/Getting-started-with-PIE-Web-Components).
41
-
42
-
43
- ### Importing the component
44
-
45
- #### JavaScript
46
- ```js
47
- // Default – for Native JS Applications, Vue, Angular, Svelte, etc.
48
- import { PieSwitch } from '@justeattakeaway/pie-switch';
49
-
50
- // If you don't need to reference the imported object, you can simply
51
- // import the module which registers the component as a custom element.
52
- import '@justeattakeaway/pie-switch';
53
- ```
54
-
55
- #### React
56
- ```js
57
- // React
58
- // For React, you will need to import our React-specific component build
59
- // which wraps the web component using ​@lit/react
60
- import { PieSwitch } from '@justeattakeaway/pie-switch/dist/react';
61
- ```
62
-
63
- > [!NOTE]
64
- > When using the React version of the component, please make sure to also
65
- > include React as a [peer dependency](#peer-dependencies) in your project.
66
-
67
-
68
- ## Peer Dependencies
69
-
70
17
  > [!IMPORTANT]
71
- > When using `pie-switch`, you will also need to include a couple of dependencies to ensure the component renders as expected. See [the PIE Wiki](https://github.com/justeattakeaway/pie/wiki/Getting-started-with-PIE-Web-Components#expected-dependencies) for more information and how to include these in your application.
72
-
73
-
74
- ## Props
75
-
76
- | Property | Type | Default | Description |
77
- |---|---|---|---|
78
- | isChecked | `Boolean` | false | Indicates whether the switch is on or off |
79
- | isDisabled | `Boolean` | false | Indicates whether the switch is disabled or not |
80
- | aria | `Object` | `undefined` | An object representing the aria labels `label` & `describedBy` that can be used on the switch;
81
-
82
- In your markup or JSX, you can then use these to set the properties for the `pie-switch` component:
83
-
84
- ```html
85
- <!-- Native HTML -->
86
- <pie-switch></pie-switch>
87
-
88
- <!-- JSX -->
89
- <PieSwitch></PieSwitch>
90
- ```
91
-
92
- ## Events
18
+ >For full information on using this component, please refer to our [documentation page](https://pie.design/components/switch/code/).
93
19
 
94
- | Event | Payload | Description |
95
- | ----- |-----| ----- |
96
- | `pie-switch-changed` | `this.isChecked` | Custom event to indicate a switch change. The event's detail contains the value of this.isChecked. |
97
20
 
98
21
  ## Contributing
99
22
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { CSSResult } from 'lit';
2
2
  import type { LitElement } from 'lit';
3
+ import type { PropertyValues } from 'lit';
3
4
  import type { TemplateResult } from 'lit';
4
5
 
5
6
  export declare type AriaProps = {
@@ -16,20 +17,65 @@ export declare const labelPlacements: readonly ["leading", "trailing"];
16
17
  *
17
18
  * @constant
18
19
  */
19
- export declare const ON_SWITCH_CHANGED_EVENT = "pie-switch-changed";
20
+ export declare const ON_SWITCH_CHANGED_EVENT = "change";
20
21
 
21
22
  /**
22
23
  * @tagname pie-switch
23
- * @event {CustomEvent} pie-switch-changed - when the switch checked state is changed.
24
+ * @event {CustomEvent} change - when the switch checked state is changed.
24
25
  */
25
26
  export declare class PieSwitch extends PieSwitch_base implements SwitchProps {
27
+ static formAssociated: boolean;
28
+ private readonly _internals;
29
+ private input?;
30
+ constructor();
31
+ protected firstUpdated(_changedProperties: PropertyValues<this>): void;
32
+ protected updated(_changedProperties: PropertyValues<this>): void;
26
33
  label?: string;
27
34
  labelPlacement: SwitchProps['labelPlacement'];
28
35
  aria: AriaProps;
29
- isChecked: boolean;
36
+ checked: boolean;
37
+ required: boolean;
38
+ value: string;
39
+ name?: string;
30
40
  isDisabled: boolean;
31
41
  static styles: CSSResult;
42
+ /**
43
+ * Ensures that the form value and validation state are in sync with the component.
44
+ */
45
+ private handleFormAssociation;
46
+ /**
47
+ * The onChange function updates the checkbox state and emits an event for consumers.
48
+ * @param {Event} event - This should be the change event that was listened for on an input element with `type="checkbox"`.
49
+ */
32
50
  onChange(event: Event): void;
51
+ /**
52
+ * Returns a boolean value which indicates validity of the value of the component. If the value is invalid, this method also fires the invalid event on the component.
53
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/checkValidity
54
+ * @returns boolean
55
+ */
56
+ checkValidity(): boolean;
57
+ /**
58
+ * If the value is invalid, this method also fires the invalid event on the element, and (if the event isn't canceled) reports the problem to the user.
59
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/reportValidity
60
+ * @returns boolean
61
+ */
62
+ reportValidity(): boolean;
63
+ /**
64
+ * Allows a consumer to set a custom validation message on the switch. An empty string counts as valid.
65
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setCustomValidity
66
+ */
67
+ setCustomValidity(message: string): void;
68
+ /**
69
+ * (Read-only) returns a ValidityState with the validity states that this element is in.
70
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity
71
+ */
72
+ get validity(): ValidityState;
73
+ /**
74
+ * (Read-only) Returns a string representing a localized message that describes the validation constraints that the control does not satisfy (if any).
75
+ * This string is empty if the component is valid.
76
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validationMessage
77
+ */
78
+ get validationMessage(): string;
33
79
  /**
34
80
  * Renders the label for a switch if provided.
35
81
  * if invalid value is passed, nothing gets rendered
@@ -52,9 +98,13 @@ export declare interface SwitchProps {
52
98
  /**
53
99
  * Same as the HTML checked attribute - indicates whether the switch is on or off
54
100
  */
55
- isChecked?: boolean;
101
+ checked?: boolean;
102
+ /**
103
+ * Same as the HTML required attribute - indicates whether the switch must be turned or not
104
+ */
105
+ required: boolean;
56
106
  /**
57
- * Same as the HTML checked attribute - indicates whether the switch disabled or not
107
+ * Same as the HTML disabled attribute - indicates whether the switch disabled or not
58
108
  */
59
109
  isDisabled?: boolean;
60
110
  /**
@@ -65,6 +115,14 @@ export declare interface SwitchProps {
65
115
  * The placement of the label such as leading or trailing
66
116
  */
67
117
  labelPlacement?: LabelPlacement;
118
+ /**
119
+ * Same as the HTML name attribute - indicates the name of the switch (for use with forms)
120
+ */
121
+ name?: string;
122
+ /**
123
+ * Same as the HTML value attribute - indicates the value of the switch (for use with forms). Defaults to 'on'.
124
+ */
125
+ value: string;
68
126
  }
69
127
 
70
128
  export { }