@justeattakeaway/pie-text-input 0.22.1 → 0.23.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 +8 -115
- package/custom-elements.json +3 -3
- package/dist/index.d.ts +4 -4
- package/dist/index.js +67 -59
- package/dist/react.d.ts +4 -4
- package/package.json +5 -5
- package/src/defs.ts +5 -4
- package/src/index.ts +10 -3
package/README.md
CHANGED
|
@@ -8,17 +8,6 @@
|
|
|
8
8
|
</a>
|
|
9
9
|
</p>
|
|
10
10
|
|
|
11
|
-
# Table of Contents
|
|
12
|
-
|
|
13
|
-
1. [Introduction](#pie-text-input)
|
|
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. [Slots](#slots)
|
|
20
|
-
8. [Contributing](#contributing)
|
|
21
|
-
|
|
22
11
|
## pie-text-input
|
|
23
12
|
|
|
24
13
|
`pie-text-input` is a Web Component built using the Lit library.
|
|
@@ -33,117 +22,21 @@ To install `pie-text-input` in your application, run the following on your comma
|
|
|
33
22
|
_Note: Versions of this component prior to v0.19.0 were named `pie-input`._
|
|
34
23
|
|
|
35
24
|
```bash
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
$ yarn add @justeattakeaway/pie-text-input
|
|
25
|
+
npm i @justeattakeaway/pie-text-input
|
|
26
|
+
```
|
|
27
|
+
```bash
|
|
28
|
+
yarn add @justeattakeaway/pie-text-input
|
|
41
29
|
```
|
|
42
30
|
|
|
43
31
|
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).
|
|
44
32
|
|
|
33
|
+
## Documentation
|
|
45
34
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
#### JavaScript
|
|
49
|
-
```js
|
|
50
|
-
// Default – for Native JS Applications, Vue, Angular, Svelte, etc.
|
|
51
|
-
import { PieTextInput } from '@justeattakeaway/pie-text-input';
|
|
35
|
+
Visit [Text Input | PIE Design System](https://pie.design/components/text-input/code) to view more information on this component.
|
|
52
36
|
|
|
53
|
-
|
|
54
|
-
// import the module which registers the component as a custom element.
|
|
55
|
-
import '@justeattakeaway/pie-text-input';
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
#### React
|
|
59
|
-
```js
|
|
60
|
-
// React
|
|
61
|
-
// For React, you will need to import our React-specific component build
|
|
62
|
-
// which wraps the web component using @lit/react
|
|
63
|
-
import { PieTextInput } from '@justeattakeaway/pie-text-input/dist/react';
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
> [!NOTE]
|
|
67
|
-
> When using the React version of the component, please make sure to also
|
|
68
|
-
> include React as a [peer dependency](#peer-dependencies) in your project.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
## Peer Dependencies
|
|
72
|
-
|
|
73
|
-
> [!IMPORTANT]
|
|
74
|
-
> When using `pie-text-input`, 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.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
## Props
|
|
78
|
-
|
|
79
|
-
| Property | Type | Default | Description |
|
|
80
|
-
|----------|------|---------|-------------|
|
|
81
|
-
| `autocomplete` | `string` | - | Allows the user to enable or disable autocomplete functionality on the input field. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete) for more information and values. |
|
|
82
|
-
| `autoFocus` | `boolean` | - | If true, the input will be focused on the first render. No more than one element in the document or dialog may have the autofocus attribute. If applied to multiple elements the first one will receive focus. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus) for more information. |
|
|
83
|
-
| `inputmode` | `'none'`, `'text'`, `'tel'`, `'url'`, `'email'`, `'numeric'`, `'decimal'`, `'search'` | - | Provides a hint to browsers as to the type of virtual keyboard configuration to use when editing this element. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#inputmode) for more information. |
|
|
84
|
-
| `maxlength` | `number` | - | Maximum length (number of characters) of value. Only applies to types: `text`, `url`, `tel`, `email`, and `password`. |
|
|
85
|
-
| `minlength` | `number` | - | Minimum length (number of characters) of value. Only applies to types: `text`, `url`, `tel`, `email`, and `password`. |
|
|
86
|
-
| `name` | `string` | - | The name of the input (used as a key/value pair with `value`). This is required in order to work properly with forms. |
|
|
87
|
-
| `pattern` | `string` | - | Specifies a regular expression the form control's value should match. |
|
|
88
|
-
| `placeholder` | `string` | - | The placeholder text to display when the input is empty. Only applies to types: `text`, `url`, `tel`, `email`, and `password`. |
|
|
89
|
-
| `readonly` | `boolean` | - | When true, the user cannot edit the control. Not the same as disabled. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/readonly) for more information. |
|
|
90
|
-
| `type` | `'text'`, `'number'`, `'password'`, `'url'`, `'email'`, `'tel'` | `text` | The type of HTML input to render. |
|
|
91
|
-
| `value` | `string` | `''` | The value of the input (used as a key/value pair in HTML forms with `name`). |
|
|
92
|
-
| `assistiveText` | `string` | `''` | Allows assistive text to be displayed below the input element. |
|
|
93
|
-
| `status` | `'error'`, `'success'` | `undefined` | The status of the input component / assistive text. If you use `status` you must provide an `assistiveText` prop value for accessibility purposes. |
|
|
94
|
-
| `step` | `number` | - | An optional amount that value should be incremented or decremented by when using the up and down arrows in the input. Only applies when type is `number`. |
|
|
95
|
-
| `min` | `number` | - | The minimum value of the input. Only applies when type is `number`. If the value provided is lower, the input is invalid. |
|
|
96
|
-
| `max` | `number` | - | The maximum value of the input. Only applies when type is `number`. If the value provided is higher, the input is invalid. |
|
|
97
|
-
| `size` | `'small'`, `'medium'`, `'large'` | `medium` | The size of the input field. Can be `small`, `medium`, or `large`. Defaults to `medium`. |
|
|
98
|
-
| `required` | `boolean` | `false` | If true, the input is required to have a value before submitting the form. If there is no value, then the component validity state will be invalid. |
|
|
99
|
-
|
|
100
|
-
In your markup or JSX, you can then use these to set the properties for the `pie-text-input` component:
|
|
101
|
-
|
|
102
|
-
```html
|
|
103
|
-
<!-- Native HTML -->
|
|
104
|
-
<pie-text-input
|
|
105
|
-
autocomplete="on"
|
|
106
|
-
autoFocus
|
|
107
|
-
inputmode="text"
|
|
108
|
-
maxlength="8"
|
|
109
|
-
minlength="4"
|
|
110
|
-
name="myinput"
|
|
111
|
-
pattern="[a-z]{4,8}"
|
|
112
|
-
placeholder="Please enter a value"
|
|
113
|
-
readonly
|
|
114
|
-
type="text"
|
|
115
|
-
value="">
|
|
116
|
-
</pie-text-input>
|
|
117
|
-
|
|
118
|
-
<!-- JSX -->
|
|
119
|
-
<PieTextInput
|
|
120
|
-
autocomplete="on"
|
|
121
|
-
autoFocus
|
|
122
|
-
inputmode="text"
|
|
123
|
-
maxlength={8}
|
|
124
|
-
minlength={4}
|
|
125
|
-
name="myinput"
|
|
126
|
-
pattern="[a-z]{4,8}"
|
|
127
|
-
placeholder="Please enter a value"
|
|
128
|
-
readonly
|
|
129
|
-
type="text"
|
|
130
|
-
value="">
|
|
131
|
-
</PieTextInput>
|
|
132
|
-
```
|
|
37
|
+
## Questions
|
|
133
38
|
|
|
134
|
-
|
|
135
|
-
| Event | Type | Description |
|
|
136
|
-
|-------|------|-------------|
|
|
137
|
-
| `change` | `CustomEvent` | Triggered when the input loses focus after it's value has changed. |
|
|
138
|
-
| `input` | `InputEvent` | Triggered when the input value is changed. |
|
|
139
|
-
|
|
140
|
-
## Slots
|
|
141
|
-
| Slot | Description |
|
|
142
|
-
|------|-------------|
|
|
143
|
-
| `leadingText` | Short text to display at the start of the input. Wrap the text in a `<span>`. Do not use with `leadingIcon` at the same time. |
|
|
144
|
-
| `leadingIcon` | An icon to display at the start of the input. Do not use with `leadingText` at the same time. |
|
|
145
|
-
| `trailingText` | Short text to display at the end of the input. Wrap the text in a `<span>`. Do not use with `trailingIcon` at the same time. |
|
|
146
|
-
| `trailingIcon` | An icon to display at the end of the input. Do not use with `trailingText` at the same time. |
|
|
39
|
+
Please head to [FAQs | PIE Design System](https://pie.design/support/contact-us/) to see our FAQs and get in touch.
|
|
147
40
|
|
|
148
41
|
## Contributing
|
|
149
42
|
|
package/custom-elements.json
CHANGED
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"kind": "variable",
|
|
33
33
|
"name": "statusTypes",
|
|
34
34
|
"type": {
|
|
35
|
-
"text": "['success', 'error']"
|
|
35
|
+
"text": "['default', 'success', 'error']"
|
|
36
36
|
},
|
|
37
|
-
"default": "['success', 'error']"
|
|
37
|
+
"default": "['default', 'success', 'error']"
|
|
38
38
|
},
|
|
39
39
|
{
|
|
40
40
|
"kind": "variable",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"type": {
|
|
51
51
|
"text": "DefaultProps"
|
|
52
52
|
},
|
|
53
|
-
"default": "{\n type: 'text',\n value: '',\n size: 'medium',\n}",
|
|
53
|
+
"default": "{\n type: 'text',\n value: '',\n size: 'medium',\n status: 'default',\n}",
|
|
54
54
|
"description": "Default values for optional properties that have default fallback values in the component."
|
|
55
55
|
}
|
|
56
56
|
],
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type { TemplateResult } from 'lit-html';
|
|
|
11
11
|
/**
|
|
12
12
|
* The default values for the `TextInputProps` that are required (i.e. they have a fallback value in the component).
|
|
13
13
|
*/
|
|
14
|
-
declare type DefaultProps = ComponentDefaultPropsGeneric<TextInputProps, 'type' | 'value' | 'size'>;
|
|
14
|
+
declare type DefaultProps = ComponentDefaultPropsGeneric<TextInputProps, 'type' | 'value' | 'size' | 'status'>;
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Default values for optional properties that have default fallback values in the component.
|
|
@@ -94,7 +94,7 @@ declare const PieTextInput_base: GenericConstructor<FormControlInterface> & Gene
|
|
|
94
94
|
|
|
95
95
|
export declare const sizes: readonly ["small", "medium", "large"];
|
|
96
96
|
|
|
97
|
-
export declare const statusTypes: readonly ["success", "error"];
|
|
97
|
+
export declare const statusTypes: readonly ["default", "success", "error"];
|
|
98
98
|
|
|
99
99
|
export declare interface TextInputProps {
|
|
100
100
|
/**
|
|
@@ -155,11 +155,11 @@ export declare interface TextInputProps {
|
|
|
155
155
|
*/
|
|
156
156
|
defaultValue?: string;
|
|
157
157
|
/**
|
|
158
|
-
* An optional assistive text to display below the input element.
|
|
158
|
+
* An optional assistive text to display below the input element. Must be provided when the status is success or error.
|
|
159
159
|
*/
|
|
160
160
|
assistiveText?: string;
|
|
161
161
|
/**
|
|
162
|
-
* The status of the input component / assistive text
|
|
162
|
+
* The status of the input component / assistive text. Can be default, success or error.
|
|
163
163
|
*/
|
|
164
164
|
status?: typeof statusTypes[number];
|
|
165
165
|
/**
|
package/dist/index.js
CHANGED
|
@@ -2,17 +2,18 @@ import { LitElement as pt, html as ut, nothing as At, unsafeCSS as Vt } from "li
|
|
|
2
2
|
import { property as u, query as mt } from "lit/decorators.js";
|
|
3
3
|
import { ifDefined as m } from "lit/directives/if-defined.js";
|
|
4
4
|
import { live as J } from "lit/directives/live.js";
|
|
5
|
-
import { FormControlMixin as Nt, RtlMixin as Lt, wrapNativeEvent as $t, validPropertyValues as
|
|
5
|
+
import { FormControlMixin as Nt, RtlMixin as Lt, wrapNativeEvent as $t, validPropertyValues as ft, defineCustomElement as Ot } from "@justeattakeaway/pie-webc-core";
|
|
6
6
|
import "@justeattakeaway/pie-assistive-text";
|
|
7
7
|
const Pt = `*,*:after,*:before{box-sizing:inherit}.c-textInput{--input-padding-block: var(--dt-spacing-c);--input-padding-inline: var(--dt-spacing-d);--input-gap: var(--dt-spacing-d);--input-text-color: var(--dt-color-content-default);--input-text-color-leading-trailing-content: var(--dt-color-content-default);--input-text-color-placeholder: var(--dt-color-content-subdued);--input-border-color: var(--dt-color-interactive-form);--input-container-color: var(--dt-color-container-default);--input-radius: var(--dt-radius-rounded-c);--input-font-size: var(--dt-font-body-l-size);--input-height: 48px;--input-cursor: text;--icon-display-override: block;--icon-size-override: 24px;height:var(--input-height);border:1px solid var(--input-border-color);border-radius:var(--input-radius);padding-inline-start:var(--input-padding-inline);padding-inline-end:var(--input-padding-inline);padding-block-start:var(--input-padding-block);padding-block-end:var(--input-padding-block);line-height:24px;font-size:var(--input-font-size);display:flex;flex-wrap:nowrap;align-items:center;background-color:var(--input-container-color);color:var(--input-text-color-leading-trailing-content);cursor:var(--input-cursor)}.c-textInput[data-pie-size=large]{--input-padding-block: var(--dt-spacing-d);--input-height: 56px}.c-textInput[data-pie-size=small]{--input-padding-block: var(--dt-spacing-b);--input-height: 40px}.c-textInput[data-pie-status=error]{--input-border-color: var(--dt-color-support-error)}.c-textInput ::slotted([slot=leadingText]),.c-textInput ::slotted([slot=leadingIcon]){margin-inline-end:var(--input-gap)}.c-textInput ::slotted([slot=trailingText]),.c-textInput ::slotted([slot=trailingIcon]){margin-inline-start:var(--input-gap)}@supports (gap: var(--input-gap)){.c-textInput{gap:var(--input-gap)}.c-textInput ::slotted([slot=leadingText]),.c-textInput ::slotted([slot=leadingIcon]){margin-inline-end:0}.c-textInput ::slotted([slot=trailingText]),.c-textInput ::slotted([slot=trailingIcon]){margin-inline-start:0}}.c-textInput:not([data-pie-disabled]) ::slotted([slot=leadingIcon]),.c-textInput:not([data-pie-disabled]) ::slotted([slot=trailingIcon]){color:var(--dt-color-content-subdued)}@media (hover: hover){.c-textInput:hover{--input-container-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-textInput[data-pie-readonly]{--input-container-color: var(--dt-color-disabled-01);--input-border-color: var(--dt-color-interactive-form)}.c-textInput[data-pie-disabled][data-pie-readonly],.c-textInput[data-pie-disabled]{--input-container-color: var(--dt-color-disabled-01);--input-border-color: var(--dt-color-disabled-01);--input-text-color: var(--dt-color-content-disabled);--input-text-color-placeholder: var(--dt-color-content-disabled);--input-text-color-leading-trailing-content: var(--dt-color-content-disabled);--input-cursor: auto}.c-textInput:focus-within{box-shadow:0 0 0 2px var(--dt-color-focus-inner),0 0 0 4px var(--dt-color-focus-outer);outline:none}input{border:0;outline:0;height:24px;padding:0;color:var(--input-text-color);width:100%;font-size:var(--input-font-size);font-family:inherit;background:none;cursor:inherit;-webkit-appearance:none;-moz-appearance:none;appearance:none}input::placeholder{color:var(--input-text-color-placeholder)}input:disabled{-webkit-text-fill-color:var(--input-text-color);color:var(--input-text-color);-webkit-opacity:1;opacity:1}input[type=number]:not([step])::-webkit-inner-spin-button,input[type=number]:not([step])::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}input[type=number]:not([step]){-moz-appearance:textfield}
|
|
8
|
-
`, Rt = ["text", "number", "password", "url", "email", "tel"], Gt = ["none", "text", "tel", "url", "email", "numeric", "decimal", "search"], _t = ["success", "error"], Jt = ["small", "medium", "large"],
|
|
8
|
+
`, Rt = ["text", "number", "password", "url", "email", "tel"], Gt = ["none", "text", "tel", "url", "email", "numeric", "decimal", "search"], _t = ["default", "success", "error"], Jt = ["small", "medium", "large"], T = {
|
|
9
9
|
type: "text",
|
|
10
10
|
value: "",
|
|
11
|
-
size: "medium"
|
|
11
|
+
size: "medium",
|
|
12
|
+
status: "default"
|
|
12
13
|
};
|
|
13
14
|
(function() {
|
|
14
15
|
(function(E) {
|
|
15
|
-
const s = /* @__PURE__ */ new WeakMap(),
|
|
16
|
+
const s = /* @__PURE__ */ new WeakMap(), h = /* @__PURE__ */ new WeakMap(), g = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakMap(), C = /* @__PURE__ */ new WeakMap(), y = /* @__PURE__ */ new WeakMap(), V = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap(), N = /* @__PURE__ */ new WeakMap(), L = /* @__PURE__ */ new WeakMap(), $ = /* @__PURE__ */ new WeakMap(), F = /* @__PURE__ */ new WeakMap(), b = /* @__PURE__ */ new WeakMap(), S = {
|
|
16
17
|
ariaAtomic: "aria-atomic",
|
|
17
18
|
ariaAutoComplete: "aria-autocomplete",
|
|
18
19
|
ariaBusy: "aria-busy",
|
|
@@ -56,16 +57,16 @@ const Pt = `*,*:after,*:before{box-sizing:inherit}.c-textInput{--input-padding-b
|
|
|
56
57
|
ariaValueText: "aria-valuetext",
|
|
57
58
|
role: "role"
|
|
58
59
|
}, H = (e, t) => {
|
|
59
|
-
for (let a in
|
|
60
|
+
for (let a in S) {
|
|
60
61
|
t[a] = null;
|
|
61
62
|
let i = null;
|
|
62
|
-
const o =
|
|
63
|
+
const o = S[a];
|
|
63
64
|
Object.defineProperty(t, a, {
|
|
64
65
|
get() {
|
|
65
66
|
return i;
|
|
66
67
|
},
|
|
67
68
|
set(n) {
|
|
68
|
-
i = n, e.isConnected ? e.setAttribute(o, n) :
|
|
69
|
+
i = n, e.isConnected ? e.setAttribute(o, n) : k.set(e, t);
|
|
69
70
|
}
|
|
70
71
|
});
|
|
71
72
|
}
|
|
@@ -97,12 +98,12 @@ const Pt = `*,*:after,*:before{box-sizing:inherit}.c-textInput{--input-padding-b
|
|
|
97
98
|
e.forEach((t) => {
|
|
98
99
|
const { addedNodes: a, removedNodes: i } = t, o = Array.from(a), n = Array.from(i);
|
|
99
100
|
o.forEach((r) => {
|
|
100
|
-
var
|
|
101
|
-
if (c.has(r) && r.constructor.formAssociated && O(r),
|
|
102
|
-
const p =
|
|
103
|
-
Object.keys(
|
|
104
|
-
r.setAttribute(
|
|
105
|
-
}),
|
|
101
|
+
var f;
|
|
102
|
+
if (c.has(r) && r.constructor.formAssociated && O(r), k.has(r)) {
|
|
103
|
+
const p = k.get(r);
|
|
104
|
+
Object.keys(S).filter((v) => p[v] !== null).forEach((v) => {
|
|
105
|
+
r.setAttribute(S[v], p[v]);
|
|
106
|
+
}), k.delete(r);
|
|
106
107
|
}
|
|
107
108
|
if (b.has(r)) {
|
|
108
109
|
const p = b.get(r);
|
|
@@ -118,14 +119,14 @@ const Pt = `*,*:after,*:before{box-sizing:inherit}.c-textInput{--input-padding-b
|
|
|
118
119
|
for (; v; )
|
|
119
120
|
O(v), v = x.nextNode();
|
|
120
121
|
}
|
|
121
|
-
r.localName === "fieldset" && ((
|
|
122
|
+
r.localName === "fieldset" && ((f = R.observe) === null || f === void 0 || f.call(R, r, Y), P(r, !0));
|
|
122
123
|
}), n.forEach((r) => {
|
|
123
|
-
const
|
|
124
|
-
|
|
124
|
+
const f = c.get(r);
|
|
125
|
+
f && g.get(f) && Z(f), C.has(r) && C.get(r).disconnect();
|
|
125
126
|
});
|
|
126
127
|
});
|
|
127
128
|
}
|
|
128
|
-
function
|
|
129
|
+
function ht(e) {
|
|
129
130
|
e.forEach((t) => {
|
|
130
131
|
const { removedNodes: a } = t;
|
|
131
132
|
a.forEach((i) => {
|
|
@@ -136,7 +137,7 @@ const Pt = `*,*:after,*:before{box-sizing:inherit}.c-textInput{--input-padding-b
|
|
|
136
137
|
}
|
|
137
138
|
const gt = (e) => {
|
|
138
139
|
var t, a;
|
|
139
|
-
const i = new MutationObserver(
|
|
140
|
+
const i = new MutationObserver(ht);
|
|
140
141
|
!((t = window == null ? void 0 : window.ShadyDOM) === null || t === void 0) && t.inUse && e.mode && e.host && (e = e.host), (a = i.observe) === null || a === void 0 || a.call(i, e, { childList: !0 }), $.set(e, i);
|
|
141
142
|
};
|
|
142
143
|
z() && new MutationObserver(W);
|
|
@@ -175,7 +176,7 @@ const Pt = `*,*:after,*:before{box-sizing:inherit}.c-textInput{--input-padding-b
|
|
|
175
176
|
const o = y.get(e);
|
|
176
177
|
if (e.noValidate)
|
|
177
178
|
return;
|
|
178
|
-
o.size && Array.from(o).reverse().map((
|
|
179
|
+
o.size && Array.from(o).reverse().map((f) => c.get(f).reportValidity()).includes(!1) && a.preventDefault();
|
|
179
180
|
}
|
|
180
181
|
});
|
|
181
182
|
}, xt = (e) => {
|
|
@@ -275,10 +276,10 @@ const Pt = `*,*:after,*:before{box-sizing:inherit}.c-textInput{--input-padding-b
|
|
|
275
276
|
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
276
277
|
return i === "a" ? o.call(e, a) : o ? o.value = a : t.set(e, a), a;
|
|
277
278
|
}
|
|
278
|
-
var
|
|
279
|
+
var A;
|
|
279
280
|
class St {
|
|
280
281
|
constructor(t) {
|
|
281
|
-
|
|
282
|
+
A.set(this, void 0), kt(this, A, t, "f");
|
|
282
283
|
for (let a = 0; a < t.length; a++) {
|
|
283
284
|
let i = t[a];
|
|
284
285
|
this[a] = i, i.hasAttribute("name") && (this[i.getAttribute("name")] = i);
|
|
@@ -286,10 +287,10 @@ const Pt = `*,*:after,*:before{box-sizing:inherit}.c-textInput{--input-padding-b
|
|
|
286
287
|
Object.freeze(this);
|
|
287
288
|
}
|
|
288
289
|
get length() {
|
|
289
|
-
return rt(this,
|
|
290
|
+
return rt(this, A, "f").length;
|
|
290
291
|
}
|
|
291
|
-
[(
|
|
292
|
-
return rt(this,
|
|
292
|
+
[(A = /* @__PURE__ */ new WeakMap(), Symbol.iterator)]() {
|
|
293
|
+
return rt(this, A, "f")[Symbol.iterator]();
|
|
293
294
|
}
|
|
294
295
|
item(t) {
|
|
295
296
|
return this[t] == null ? null : this[t];
|
|
@@ -314,10 +315,10 @@ const Pt = `*,*:after,*:before{box-sizing:inherit}.c-textInput{--input-padding-b
|
|
|
314
315
|
const { get: o } = Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, "elements");
|
|
315
316
|
Object.defineProperty(HTMLFormElement.prototype, "elements", {
|
|
316
317
|
get(...n) {
|
|
317
|
-
const r = o.call(this, ...n),
|
|
318
|
-
if (
|
|
318
|
+
const r = o.call(this, ...n), f = Array.from(y.get(this) || []);
|
|
319
|
+
if (f.length === 0)
|
|
319
320
|
return r;
|
|
320
|
-
const p = Array.from(r).concat(
|
|
321
|
+
const p = Array.from(r).concat(f).sort((x, v) => x.compareDocumentPosition ? x.compareDocumentPosition(v) & 2 ? 1 : -1 : 0);
|
|
321
322
|
return new St(p);
|
|
322
323
|
}
|
|
323
324
|
});
|
|
@@ -330,13 +331,13 @@ const Pt = `*,*:after,*:before{box-sizing:inherit}.c-textInput{--input-padding-b
|
|
|
330
331
|
if (!t || !t.tagName || t.tagName.indexOf("-") === -1)
|
|
331
332
|
throw new TypeError("Illegal constructor");
|
|
332
333
|
const a = t.getRootNode(), i = new Et();
|
|
333
|
-
this.states = new j(t), s.set(this, t),
|
|
334
|
+
this.states = new j(t), s.set(this, t), h.set(this, i), c.set(t, this), H(t, this), yt(t, this), Object.seal(this), a instanceof DocumentFragment && gt(a);
|
|
334
335
|
}
|
|
335
336
|
checkValidity() {
|
|
336
337
|
const t = s.get(this);
|
|
337
338
|
if (w(t, "Failed to execute 'checkValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !this.willValidate)
|
|
338
339
|
return !0;
|
|
339
|
-
const a =
|
|
340
|
+
const a = h.get(this);
|
|
340
341
|
if (!a.valid) {
|
|
341
342
|
const i = new Event("invalid", {
|
|
342
343
|
bubbles: !1,
|
|
@@ -389,13 +390,13 @@ const Pt = `*,*:after,*:before{box-sizing:inherit}.c-textInput{--input-padding-b
|
|
|
389
390
|
if (w(o, "Failed to execute 'setValidity' on 'ElementInternals': The target element is not a form-associated custom element."), !t)
|
|
390
391
|
throw new TypeError("Failed to execute 'setValidity' on 'ElementInternals': 1 argument required, but only 0 present.");
|
|
391
392
|
L.set(this, i);
|
|
392
|
-
const n =
|
|
393
|
+
const n = h.get(this), r = {};
|
|
393
394
|
for (const x in t)
|
|
394
395
|
r[x] = t[x];
|
|
395
396
|
Object.keys(r).length === 0 && Mt(n);
|
|
396
|
-
const
|
|
397
|
-
delete
|
|
398
|
-
const { valid: p } = It(n,
|
|
397
|
+
const f = Object.assign(Object.assign({}, n), r);
|
|
398
|
+
delete f.valid;
|
|
399
|
+
const { valid: p } = It(n, f, this.form);
|
|
399
400
|
if (!p && !a)
|
|
400
401
|
throw new DOMException("Failed to execute 'setValidity' on 'ElementInternals': The second argument should not be empty if one or more flags in the first argument are true.");
|
|
401
402
|
M.set(this, p ? "" : a), o.isConnected ? (o.toggleAttribute("internals-invalid", !p), o.toggleAttribute("internals-valid", p), o.setAttribute("aria-invalid", `${!p}`)) : b.set(o, this);
|
|
@@ -410,7 +411,7 @@ const Pt = `*,*:after,*:before{box-sizing:inherit}.c-textInput{--input-padding-b
|
|
|
410
411
|
}
|
|
411
412
|
get validity() {
|
|
412
413
|
const t = s.get(this);
|
|
413
|
-
return w(t, "Failed to read the 'validity' property from 'ElementInternals': The target element is not a form-associated custom element."),
|
|
414
|
+
return w(t, "Failed to read the 'validity' property from 'ElementInternals': The target element is not a form-associated custom element."), h.get(this);
|
|
414
415
|
}
|
|
415
416
|
get willValidate() {
|
|
416
417
|
const t = s.get(this);
|
|
@@ -456,7 +457,7 @@ const Pt = `*,*:after,*:before{box-sizing:inherit}.c-textInput{--input-padding-b
|
|
|
456
457
|
if (i.formAssociated) {
|
|
457
458
|
const n = i.prototype.connectedCallback;
|
|
458
459
|
i.prototype.connectedCallback = function() {
|
|
459
|
-
|
|
460
|
+
F.has(this) || (F.set(this, !0), this.hasAttribute("disabled") && B(this, !0)), n != null && n.apply(this), ot(this);
|
|
460
461
|
};
|
|
461
462
|
}
|
|
462
463
|
t.call(this, a, i, o);
|
|
@@ -476,7 +477,7 @@ const Pt = `*,*:after,*:before{box-sizing:inherit}.c-textInput{--input-padding-b
|
|
|
476
477
|
const o = a.apply(this, i);
|
|
477
478
|
if (N.set(this, o), z()) {
|
|
478
479
|
const n = new MutationObserver(W);
|
|
479
|
-
window.ShadyDOM ? n.observe(this, q) : n.observe(o, q),
|
|
480
|
+
window.ShadyDOM ? n.observe(this, q) : n.observe(o, q), C.set(this, n);
|
|
480
481
|
}
|
|
481
482
|
return o;
|
|
482
483
|
};
|
|
@@ -489,19 +490,19 @@ const Pt = `*,*:after,*:before{box-sizing:inherit}.c-textInput{--input-padding-b
|
|
|
489
490
|
return !!customElements.polyfillWrapFlushCallback || (Ft() ? typeof window < "u" && !window.CustomStateSet && K(HTMLElement.prototype.attachInternals) : dt(!1)), E.forceCustomStateSetPolyfill = K, E.forceElementInternalsPolyfill = dt, Object.defineProperty(E, "__esModule", { value: !0 }), E;
|
|
490
491
|
})({});
|
|
491
492
|
})();
|
|
492
|
-
var Dt = Object.defineProperty, zt = Object.getOwnPropertyDescriptor, d = (E, s,
|
|
493
|
-
for (var c = g > 1 ? void 0 : g ? zt(s,
|
|
494
|
-
(I = E[M]) && (c = (g ? I(s,
|
|
495
|
-
return g && c && Dt(s,
|
|
493
|
+
var Dt = Object.defineProperty, zt = Object.getOwnPropertyDescriptor, d = (E, s, h, g) => {
|
|
494
|
+
for (var c = g > 1 ? void 0 : g ? zt(s, h) : s, M = E.length - 1, I; M >= 0; M--)
|
|
495
|
+
(I = E[M]) && (c = (g ? I(s, h, c) : I(c)) || c);
|
|
496
|
+
return g && c && Dt(s, h, c), c;
|
|
496
497
|
};
|
|
497
498
|
const X = "pie-text-input", Q = "assistive-text";
|
|
498
499
|
class l extends Nt(Lt(pt)) {
|
|
499
500
|
constructor() {
|
|
500
|
-
super(...arguments), this.type =
|
|
501
|
+
super(...arguments), this.type = T.type, this.value = T.value, this.status = T.status, this.size = T.size, this.required = !1, this.handleInput = (s) => {
|
|
501
502
|
this.value = s.target.value, this._internals.setFormValue(this.value);
|
|
502
503
|
}, this.handleChange = (s) => {
|
|
503
|
-
const
|
|
504
|
-
this.dispatchEvent(
|
|
504
|
+
const h = $t(s);
|
|
505
|
+
this.dispatchEvent(h);
|
|
505
506
|
};
|
|
506
507
|
}
|
|
507
508
|
/**
|
|
@@ -525,7 +526,7 @@ class l extends Nt(Lt(pt)) {
|
|
|
525
526
|
* Resets the value to the default value.
|
|
526
527
|
*/
|
|
527
528
|
formResetCallback() {
|
|
528
|
-
this.value = this.defaultValue ??
|
|
529
|
+
this.value = this.defaultValue ?? T.value, this.input && (this.input.value = this.value), this._internals.setFormValue(this.value);
|
|
529
530
|
}
|
|
530
531
|
firstUpdated(s) {
|
|
531
532
|
super.firstUpdated(s), this._internals.setFormValue(this.value);
|
|
@@ -536,21 +537,21 @@ class l extends Nt(Lt(pt)) {
|
|
|
536
537
|
render() {
|
|
537
538
|
const {
|
|
538
539
|
assistiveText: s,
|
|
539
|
-
autocomplete:
|
|
540
|
+
autocomplete: h,
|
|
540
541
|
autoFocus: g,
|
|
541
542
|
disabled: c,
|
|
542
543
|
inputmode: M,
|
|
543
544
|
maxlength: I,
|
|
544
|
-
minlength:
|
|
545
|
+
minlength: C,
|
|
545
546
|
min: y,
|
|
546
547
|
max: V,
|
|
547
|
-
name:
|
|
548
|
+
name: k,
|
|
548
549
|
pattern: N,
|
|
549
550
|
step: L,
|
|
550
551
|
placeholder: $,
|
|
551
|
-
readonly:
|
|
552
|
+
readonly: F,
|
|
552
553
|
status: b,
|
|
553
|
-
type:
|
|
554
|
+
type: S,
|
|
554
555
|
value: H,
|
|
555
556
|
size: O,
|
|
556
557
|
required: P
|
|
@@ -562,7 +563,7 @@ class l extends Nt(Lt(pt)) {
|
|
|
562
563
|
data-pie-size=${m(O)}
|
|
563
564
|
data-pie-status=${m(b)}
|
|
564
565
|
?data-pie-disabled=${J(c)}
|
|
565
|
-
?data-pie-readonly=${
|
|
566
|
+
?data-pie-readonly=${F}>
|
|
566
567
|
<!-- The reason for separate slots for icons and text is that we cannot programmatically be aware of the
|
|
567
568
|
HTML used inside of the slot without breaking SSR in consuming applications (icons need to use different colours than text content)
|
|
568
569
|
Therefore, we provide two slots and advise consumers do not attempt to use both leading/trailing at the same time
|
|
@@ -570,21 +571,21 @@ class l extends Nt(Lt(pt)) {
|
|
|
570
571
|
<slot name="leadingIcon"></slot>
|
|
571
572
|
<slot name="leadingText"></slot>
|
|
572
573
|
<input
|
|
573
|
-
type=${m(
|
|
574
|
+
type=${m(S)}
|
|
574
575
|
.value=${J(H)}
|
|
575
|
-
name=${m(
|
|
576
|
+
name=${m(k)}
|
|
576
577
|
?disabled=${J(c)}
|
|
577
578
|
pattern=${m(N)}
|
|
578
579
|
step=${m(L)}
|
|
579
|
-
minlength=${m(
|
|
580
|
+
minlength=${m(C)}
|
|
580
581
|
maxlength=${m(I)}
|
|
581
582
|
min=${m(y)}
|
|
582
583
|
max=${m(V)}
|
|
583
|
-
autocomplete=${m(
|
|
584
|
+
autocomplete=${m(h)}
|
|
584
585
|
?autofocus=${g}
|
|
585
586
|
inputmode=${m(M)}
|
|
586
587
|
placeholder=${m($)}
|
|
587
|
-
?readonly=${
|
|
588
|
+
?readonly=${F}
|
|
588
589
|
?required=${P}
|
|
589
590
|
aria-describedby=${m(s ? Q : void 0)}
|
|
590
591
|
aria-invalid=${b === "error" ? "true" : "false"}
|
|
@@ -599,14 +600,21 @@ class l extends Nt(Lt(pt)) {
|
|
|
599
600
|
<slot name="trailingIcon"></slot>
|
|
600
601
|
<slot name="trailingText"></slot>
|
|
601
602
|
</div>
|
|
602
|
-
${s ? ut
|
|
603
|
+
${s ? ut`
|
|
604
|
+
<pie-assistive-text
|
|
605
|
+
id="${Q}"
|
|
606
|
+
variant=${m(b)}
|
|
607
|
+
data-test-id="pie-text-input-assistive-text">
|
|
608
|
+
${s}
|
|
609
|
+
</pie-assistive-text>
|
|
610
|
+
` : At}`;
|
|
603
611
|
}
|
|
604
612
|
}
|
|
605
613
|
l.shadowRootOptions = { ...pt.shadowRootOptions, delegatesFocus: !0 };
|
|
606
614
|
l.styles = Vt(Pt);
|
|
607
615
|
d([
|
|
608
616
|
u({ type: String, reflect: !0 }),
|
|
609
|
-
|
|
617
|
+
ft(X, Rt, T.type)
|
|
610
618
|
], l.prototype, "type", 2);
|
|
611
619
|
d([
|
|
612
620
|
u({ type: String })
|
|
@@ -649,7 +657,7 @@ d([
|
|
|
649
657
|
], l.prototype, "assistiveText", 2);
|
|
650
658
|
d([
|
|
651
659
|
u({ type: String }),
|
|
652
|
-
|
|
660
|
+
ft(X, _t, T.status)
|
|
653
661
|
], l.prototype, "status", 2);
|
|
654
662
|
d([
|
|
655
663
|
u({ type: Number })
|
|
@@ -675,7 +683,7 @@ d([
|
|
|
675
683
|
Ot(X, l);
|
|
676
684
|
export {
|
|
677
685
|
l as PieTextInput,
|
|
678
|
-
|
|
686
|
+
T as defaultProps,
|
|
679
687
|
Gt as inputModes,
|
|
680
688
|
Jt as sizes,
|
|
681
689
|
_t as statusTypes,
|
package/dist/react.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import type { TemplateResult } from 'lit-html';
|
|
|
12
12
|
/**
|
|
13
13
|
* The default values for the `TextInputProps` that are required (i.e. they have a fallback value in the component).
|
|
14
14
|
*/
|
|
15
|
-
declare type DefaultProps = ComponentDefaultPropsGeneric<TextInputProps, 'type' | 'value' | 'size'>;
|
|
15
|
+
declare type DefaultProps = ComponentDefaultPropsGeneric<TextInputProps, 'type' | 'value' | 'size' | 'status'>;
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Default values for optional properties that have default fallback values in the component.
|
|
@@ -104,7 +104,7 @@ declare type ReactBaseType = React_2.InputHTMLAttributes<HTMLInputElement>;
|
|
|
104
104
|
|
|
105
105
|
export declare const sizes: readonly ["small", "medium", "large"];
|
|
106
106
|
|
|
107
|
-
export declare const statusTypes: readonly ["success", "error"];
|
|
107
|
+
export declare const statusTypes: readonly ["default", "success", "error"];
|
|
108
108
|
|
|
109
109
|
export declare interface TextInputProps {
|
|
110
110
|
/**
|
|
@@ -165,11 +165,11 @@ export declare interface TextInputProps {
|
|
|
165
165
|
*/
|
|
166
166
|
defaultValue?: string;
|
|
167
167
|
/**
|
|
168
|
-
* An optional assistive text to display below the input element.
|
|
168
|
+
* An optional assistive text to display below the input element. Must be provided when the status is success or error.
|
|
169
169
|
*/
|
|
170
170
|
assistiveText?: string;
|
|
171
171
|
/**
|
|
172
|
-
* The status of the input component / assistive text
|
|
172
|
+
* The status of the input component / assistive text. Can be default, success or error.
|
|
173
173
|
*/
|
|
174
174
|
status?: typeof statusTypes[number];
|
|
175
175
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justeattakeaway/pie-text-input",
|
|
3
3
|
"description": "PIE Design System Input built using Web Components",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.23.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"**/*.d.ts"
|
|
14
14
|
],
|
|
15
15
|
"pieMetadata": {
|
|
16
|
-
"componentStatus": "
|
|
16
|
+
"componentStatus": "beta"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "run -T vite build",
|
|
@@ -37,12 +37,12 @@
|
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@custom-elements-manifest/analyzer": "0.9.0",
|
|
39
39
|
"@justeattakeaway/pie-components-config": "0.16.0",
|
|
40
|
-
"@justeattakeaway/pie-icons-webc": "0.24.
|
|
41
|
-
"@justeattakeaway/pie-wrapper-react": "0.14.
|
|
40
|
+
"@justeattakeaway/pie-icons-webc": "0.24.1",
|
|
41
|
+
"@justeattakeaway/pie-wrapper-react": "0.14.1",
|
|
42
42
|
"cem-plugin-module-file-extensions": "0.0.5"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@justeattakeaway/pie-assistive-text": "0.
|
|
45
|
+
"@justeattakeaway/pie-assistive-text": "0.5.0",
|
|
46
46
|
"@justeattakeaway/pie-webc-core": "0.23.0",
|
|
47
47
|
"element-internals-polyfill": "1.3.11"
|
|
48
48
|
},
|
package/src/defs.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type ComponentDefaultPropsGeneric } from '@justeattakeaway/pie-webc-cor
|
|
|
2
2
|
|
|
3
3
|
export const types = ['text', 'number', 'password', 'url', 'email', 'tel'] as const;
|
|
4
4
|
export const inputModes = ['none', 'text', 'tel', 'url', 'email', 'numeric', 'decimal', 'search'] as const;
|
|
5
|
-
export const statusTypes = ['success', 'error'] as const;
|
|
5
|
+
export const statusTypes = ['default', 'success', 'error'] as const;
|
|
6
6
|
export const sizes = ['small', 'medium', 'large'] as const;
|
|
7
7
|
|
|
8
8
|
export interface TextInputProps {
|
|
@@ -77,12 +77,12 @@ export interface TextInputProps {
|
|
|
77
77
|
defaultValue?: string;
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
|
-
* An optional assistive text to display below the input element.
|
|
80
|
+
* An optional assistive text to display below the input element. Must be provided when the status is success or error.
|
|
81
81
|
*/
|
|
82
82
|
assistiveText?: string;
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
|
-
* The status of the input component / assistive text
|
|
85
|
+
* The status of the input component / assistive text. Can be default, success or error.
|
|
86
86
|
*/
|
|
87
87
|
status?: typeof statusTypes[number];
|
|
88
88
|
|
|
@@ -115,7 +115,7 @@ export interface TextInputProps {
|
|
|
115
115
|
/**
|
|
116
116
|
* The default values for the `TextInputProps` that are required (i.e. they have a fallback value in the component).
|
|
117
117
|
*/
|
|
118
|
-
type DefaultProps = ComponentDefaultPropsGeneric<TextInputProps, 'type' | 'value' | 'size'>;
|
|
118
|
+
type DefaultProps = ComponentDefaultPropsGeneric<TextInputProps, 'type' | 'value' | 'size' | 'status'>;
|
|
119
119
|
|
|
120
120
|
/**
|
|
121
121
|
* Default values for optional properties that have default fallback values in the component.
|
|
@@ -124,4 +124,5 @@ export const defaultProps: DefaultProps = {
|
|
|
124
124
|
type: 'text',
|
|
125
125
|
value: '',
|
|
126
126
|
size: 'medium',
|
|
127
|
+
status: 'default',
|
|
127
128
|
};
|
package/src/index.ts
CHANGED
|
@@ -78,8 +78,8 @@ export class PieTextInput extends FormControlMixin(RtlMixin(LitElement)) impleme
|
|
|
78
78
|
public assistiveText?: TextInputProps['assistiveText'];
|
|
79
79
|
|
|
80
80
|
@property({ type: String })
|
|
81
|
-
@validPropertyValues(componentSelector, statusTypes,
|
|
82
|
-
public status?: TextInputProps['status'];
|
|
81
|
+
@validPropertyValues(componentSelector, statusTypes, defaultProps.status)
|
|
82
|
+
public status?: TextInputProps['status'] = defaultProps.status;
|
|
83
83
|
|
|
84
84
|
@property({ type: Number })
|
|
85
85
|
public step?: TextInputProps['step'];
|
|
@@ -239,7 +239,14 @@ export class PieTextInput extends FormControlMixin(RtlMixin(LitElement)) impleme
|
|
|
239
239
|
<slot name="trailingIcon"></slot>
|
|
240
240
|
<slot name="trailingText"></slot>
|
|
241
241
|
</div>
|
|
242
|
-
${assistiveText ? html
|
|
242
|
+
${assistiveText ? html`
|
|
243
|
+
<pie-assistive-text
|
|
244
|
+
id="${assistiveTextIdValue}"
|
|
245
|
+
variant=${ifDefined(status)}
|
|
246
|
+
data-test-id="pie-text-input-assistive-text">
|
|
247
|
+
${assistiveText}
|
|
248
|
+
</pie-assistive-text>
|
|
249
|
+
` : nothing}`;
|
|
243
250
|
}
|
|
244
251
|
|
|
245
252
|
// Renders a `CSSResult` generated from SCSS by Vite
|