@justeattakeaway/pie-webc-core 21.0.0 → 22.0.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/dist/index.d.ts +296 -0
- package/dist/internals.d.ts +8 -0
- package/dist/internals.js +11 -0
- package/package.json +20 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Context carrying a `ContextualAria` from a provider down to a consuming component. `undefined`
|
|
5
|
+
* when no ancestor provides ARIA (for example a standalone control).
|
|
6
|
+
*
|
|
7
|
+
* Why a context rather than ARIA props on each component:
|
|
8
|
+
* - it lets a wrapper name a control it does not own, carrying a resolved string across the shadow
|
|
9
|
+
* boundary that `aria-labelledby` / `aria-describedby` IDREFs cannot cross;
|
|
10
|
+
* - it reaches consumers at any depth below the provider without prop drilling through the layers
|
|
11
|
+
* in between;
|
|
12
|
+
* - it decouples provider from consumer (neither needs a reference to, or knowledge of, the other)
|
|
13
|
+
* and is extensible by adding optional fields that consumers opt into.
|
|
14
|
+
* It is always a fallback behind a control's own ARIA props.
|
|
15
|
+
*/
|
|
16
|
+
export declare const ariaContext: {
|
|
17
|
+
__context__: ContextualAria | undefined;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* An interface representing the structure of a class that has been extended
|
|
22
|
+
* with the AssociatedLabelMixin.
|
|
23
|
+
* @interface
|
|
24
|
+
*/
|
|
25
|
+
export declare interface AssociatedLabelInterface {
|
|
26
|
+
/** The text content of the element's associated `<label>`(s) */
|
|
27
|
+
readonly associatedLabelText?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A mixin that mirrors the text content of a form-associated custom element's associated
|
|
32
|
+
* `<label>`(s) onto an `associatedLabelText` property.
|
|
33
|
+
*
|
|
34
|
+
* Safari doesn't compute the accessible name of a form-associated
|
|
35
|
+
* custom element from its associated `<label>` the way others do, so we need to use
|
|
36
|
+
* `associatedLabelText` as a fallback `aria-label`.
|
|
37
|
+
* https://bugs.webkit.org/show_bug.cgi?id=259124
|
|
38
|
+
*
|
|
39
|
+
*
|
|
40
|
+
* The class this mixin is applied to must already provide `_internals: ElementInternals`
|
|
41
|
+
* (for example via `FormControlMixin`), and must call `super.firstUpdated()` if it overrides
|
|
42
|
+
* `firstUpdated`.
|
|
43
|
+
*
|
|
44
|
+
* @param superClass - The LitElement class (with `_internals`) to extend.
|
|
45
|
+
* @returns A new class extending both the provided LitElement and AssociatedLabelInterface.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* import { html } from 'lit';
|
|
50
|
+
* import { FormControlMixin, AssociatedLabelMixin } from '@justeattakeaway/pie-webc-core';
|
|
51
|
+
*
|
|
52
|
+
* class MyFormElement extends AssociatedLabelMixin(FormControlMixin(LitElement)) {
|
|
53
|
+
* render () {
|
|
54
|
+
* return html`<input aria-label="${this.associatedLabelText}">`;
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare const AssociatedLabelMixin: <T extends GenericConstructor<LitElement & {
|
|
60
|
+
_internals: ElementInternals;
|
|
61
|
+
}>>(superClass: T) => GenericConstructor<AssociatedLabelInterface> & T;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* This type should be used when defining the default props for a component.
|
|
65
|
+
* It is a generic type that takes two type parameters:
|
|
66
|
+
* - `T` is the type of the props object that the default props are being defined for.
|
|
67
|
+
* - `K` is the type of the keys in `T` that should be required in the default props.
|
|
68
|
+
* By default, `K` is set to be all the keys in `T`. This means that all the keys in `T` will be required in the default props.
|
|
69
|
+
* You can override this by specifying a subset of the keys in `T` that should be required in the default props.
|
|
70
|
+
*
|
|
71
|
+
* @example ```tsx
|
|
72
|
+
* interface MyComponentProps {
|
|
73
|
+
* a: string;
|
|
74
|
+
* b?: number;
|
|
75
|
+
* c: boolean;
|
|
76
|
+
* }
|
|
77
|
+
* const allProps: ComponentDefaultProps<MyComponentProps> = {
|
|
78
|
+
* a: 'default value',
|
|
79
|
+
* b: 42,
|
|
80
|
+
* c: true,
|
|
81
|
+
* };
|
|
82
|
+
*
|
|
83
|
+
* const pickProps: ComponentDefaultProps<MyComponentProps, 'a'> = {
|
|
84
|
+
* a: 'default value',
|
|
85
|
+
* };
|
|
86
|
+
*
|
|
87
|
+
* const omitProps: ComponentDefaultProps<MyComponentProps, keyof Omit<MyComponentProps, 'a'>> = {
|
|
88
|
+
* b: 42,
|
|
89
|
+
* c: true,
|
|
90
|
+
* };
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export declare type ComponentDefaultProps<T, K extends keyof T = keyof T> = Readonly<Required<Pick<T, K>>>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* A bag of accessible-name/description values an ancestor component can supply to a descendant
|
|
97
|
+
* across the shadow boundary (where `aria-labelledby` / `aria-describedby` IDREFs cannot reach).
|
|
98
|
+
* Restricted to string ARIA that can be applied directly to an element.
|
|
99
|
+
*
|
|
100
|
+
* This is deliberately an extensible bag: any provider can set it (for example a `pie-list-item`
|
|
101
|
+
* stitching its text), and any component can consume it and decide for itself what to do with each
|
|
102
|
+
* field, applying it to whichever element carries its semantics. Extend it with further optional
|
|
103
|
+
* string/boolean ARIA as needed; a consumer simply ignores fields it does not apply. There is no
|
|
104
|
+
* shared "apply" helper on purpose: where and how each field maps is component-specific (a radio
|
|
105
|
+
* names its host, a checkbox its internal input), so each subscriber owns that logic even if a
|
|
106
|
+
* little set/remove code is repeated. That keeps the contract open to new ARIA without a central
|
|
107
|
+
* mapper having to know how every component applies it.
|
|
108
|
+
*/
|
|
109
|
+
export declare interface ContextualAria {
|
|
110
|
+
label?: string;
|
|
111
|
+
description?: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Mixin to add `delegatesFocus: true` to a LitElement's shadow root options.
|
|
116
|
+
* This is useful for custom elements that act like form controls, allowing focus
|
|
117
|
+
* to be automatically delegated to the first focusable element inside the shadow DOM.
|
|
118
|
+
*
|
|
119
|
+
* @param superClass - The LitElement class to extend.
|
|
120
|
+
* @returns A class extending the provided LitElement with the delegatesFocus behaviour.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* import { LitElement, html } from 'lit';
|
|
125
|
+
* import { DelegatesFocusMixin } from './path-to-DelegatesFocusMixin'; // Update the import path
|
|
126
|
+
*
|
|
127
|
+
* // Create a new component using the DelegatesFocusMixin
|
|
128
|
+
* class MyCustomInput extends DelegatesFocusMixin(LitElement) {
|
|
129
|
+
* render() {
|
|
130
|
+
* // The focus will automatically go to the input when the component is focused
|
|
131
|
+
* return html`<input>`;
|
|
132
|
+
* }
|
|
133
|
+
* }
|
|
134
|
+
*
|
|
135
|
+
* customElements.define('my-custom-input', MyCustomInput);
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export declare const DelegatesFocusMixin: <T extends GenericConstructor<LitElement>>(superClass: T) => T;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Dispatch a custom event.
|
|
142
|
+
*
|
|
143
|
+
* To be used whenever we have custom events we want to
|
|
144
|
+
* bubble up through the component.
|
|
145
|
+
* Bubbles and composed event props are set to true.
|
|
146
|
+
* @param {Element} element The element to dispatch the event from.
|
|
147
|
+
* @param {string} eventType
|
|
148
|
+
* @param {any} detail
|
|
149
|
+
*/
|
|
150
|
+
export declare function dispatchCustomEvent(element: Element, eventType: string, detail?: CustomEventInit['detail']): void;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Interface for FormControl behavior.
|
|
154
|
+
*/
|
|
155
|
+
export declare interface FormControlInterface {
|
|
156
|
+
_internals: ElementInternals;
|
|
157
|
+
get form(): HTMLFormElement | null;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Mixin to add form control behaviors to a LitElement.
|
|
162
|
+
* This mixin adds properties and methods to handle form-associated custom elements.
|
|
163
|
+
*
|
|
164
|
+
* @param superClass - The LitElement class to extend with form control functionality.
|
|
165
|
+
* @returns A class extending both the provided LitElement and _FormControlInterface.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* import { LitElement, html } from 'lit';
|
|
170
|
+
* import { FormControlMixin } from './path-to-FormControlMixin'; // Update the import path
|
|
171
|
+
*
|
|
172
|
+
* // Create a new component using the FormControlMixin
|
|
173
|
+
* class MyFormElement extends FormControlMixin(LitElement) {
|
|
174
|
+
* render() {
|
|
175
|
+
* return html`<div>Form-associated element with form: ${this.form ? 'attached' : 'detached'}</div>`;
|
|
176
|
+
* }
|
|
177
|
+
* }
|
|
178
|
+
*
|
|
179
|
+
* customElements.define('my-form-element', MyFormElement);
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
export declare const FormControlMixin: <T extends GenericConstructor<LitElement>>(superClass: T) => GenericConstructor<FormControlInterface> & T;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* A type representing a constructor of any class.
|
|
186
|
+
* @typedef {new (...args: any[]) => T} Constructor
|
|
187
|
+
* @template T
|
|
188
|
+
*/
|
|
189
|
+
export declare type GenericConstructor<T> = new (...args: any[]) => T;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Detects whether the current browser is Safari.
|
|
193
|
+
*/
|
|
194
|
+
export declare function isSafari(): boolean;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Context a container uses to tell its descendants it is disabled, so they can reflect it (for
|
|
198
|
+
* example a disabled `pie-radio-group` / `pie-checkbox-group` suppressing a `pie-list-item`'s
|
|
199
|
+
* interactive hover and active states). Defaults to `false` when no ancestor provides it.
|
|
200
|
+
*
|
|
201
|
+
* This is deliberately generic: any disabling ancestor can provide it and any descendant can
|
|
202
|
+
* consume it. Like `ariaContext`, it crosses shadow boundaries and reaches descendants at any depth
|
|
203
|
+
* without prop drilling, and decouples the provider from the consumer.
|
|
204
|
+
*/
|
|
205
|
+
export declare const parentDisabledContext: {
|
|
206
|
+
__context__: boolean;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
export declare interface PIEInputElement {
|
|
210
|
+
focusTarget: HTMLElement;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* An interface representing the structure of RTL related class.
|
|
215
|
+
* @interface
|
|
216
|
+
*/
|
|
217
|
+
export declare interface RTLInterface {
|
|
218
|
+
/** A boolean indicating whether the text direction is right-to-left. */
|
|
219
|
+
isRTL: boolean;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* A mixin to extend LitElement with right-to-left (RTL) text direction handling.
|
|
224
|
+
* This mixin adds a read-only `isRTL` property to the class it's applied to,
|
|
225
|
+
* allowing you to easily determine the text direction within your component.
|
|
226
|
+
*
|
|
227
|
+
* @function
|
|
228
|
+
* @param {GenericConstructor<LitElement>} superClass - The LitElement class to extend with RTL functionality.
|
|
229
|
+
* @returns {GenericConstructor<RTLInterface> & T} - A new class extending both LitElement and RTLInterface.
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* import { LitElement, html } from 'lit';
|
|
234
|
+
* import { RtlMixin } from './RtlMixin'; // Adjust the import path as needed
|
|
235
|
+
*
|
|
236
|
+
* class MyElement extends RtlMixin(LitElement) {
|
|
237
|
+
* render() {
|
|
238
|
+
* return html`<p>Text direction is ${this.isRTL ? 'right-to-left' : 'left-to-right'}</p>`;
|
|
239
|
+
* }
|
|
240
|
+
* }
|
|
241
|
+
*
|
|
242
|
+
* customElements.define('my-element', MyElement);
|
|
243
|
+
* ```
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```typescript
|
|
247
|
+
* import { LitElement, html } from 'lit';
|
|
248
|
+
* import { RtlMixin } from './RtlMixin'; // Adjust the import path as needed
|
|
249
|
+
*
|
|
250
|
+
* class MyStyledElement extends RtlMixin(LitElement) {
|
|
251
|
+
* render() {
|
|
252
|
+
* return html`<div class="foo" ?data-is-rtl=${this.isRTL}>Content</div>`;
|
|
253
|
+
* }
|
|
254
|
+
* }
|
|
255
|
+
*
|
|
256
|
+
* customElements.define('my-styled-element', MyStyledElement);
|
|
257
|
+
* ```
|
|
258
|
+
*
|
|
259
|
+
* The corresponding SCSS to leverage the `data-is-rtl` attribute:
|
|
260
|
+
* ```scss
|
|
261
|
+
* .foo[data-is-rtl] {
|
|
262
|
+
* background-color: red;
|
|
263
|
+
* text-align: right;
|
|
264
|
+
* }
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
export declare const RtlMixin: <T extends GenericConstructor<LitElement>>(superClass: T) => GenericConstructor<RTLInterface> & T;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Custom decorator that wraps Lit's customElement decorator with error handling.
|
|
271
|
+
* Logs a warning if the custom element has already been defined, including version info of the already registered component if available.
|
|
272
|
+
*
|
|
273
|
+
* @param {string} elementSelector - Custom element tag name.
|
|
274
|
+
* @returns {ClassDecorator}
|
|
275
|
+
*/
|
|
276
|
+
export declare function safeCustomElement(elementSelector: string): ClassDecorator;
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* A decorator for specifying a list of valid values for a property.
|
|
280
|
+
* If this property's setter is called with an invalid value, an error is logged and the default value will be assigned instead.
|
|
281
|
+
* @param validValues - The array of valid values
|
|
282
|
+
* @param defaultValue - The value to fall back on
|
|
283
|
+
* @returns - The decorator function
|
|
284
|
+
*/
|
|
285
|
+
export declare const validPropertyValues: <T>(componentName: string, validValues: readonly T[], defaultValue: T) => (target: object, propertyKey: string) => void;
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Wraps the native event in a custom event. This is useful for native events that have `composed` set to `false`
|
|
289
|
+
* as these cannot propagate outside of the shadow DOM.
|
|
290
|
+
* @param event - The native event.
|
|
291
|
+
*/
|
|
292
|
+
export declare function wrapNativeEvent(event: Event): CustomEvent<{
|
|
293
|
+
sourceEvent: Event;
|
|
294
|
+
}>;
|
|
295
|
+
|
|
296
|
+
export { }
|
package/package.json
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justeattakeaway/pie-webc-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "22.0.1",
|
|
4
4
|
"description": "PIE design system base classes, mixins and utilities for web components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"typesVersions": {
|
|
10
|
+
"*": {
|
|
11
|
+
"src/internals/PieElement": [
|
|
12
|
+
"dist/internals.d.ts"
|
|
13
|
+
],
|
|
14
|
+
"src/internals/PieElement.js": [
|
|
15
|
+
"dist/internals.d.ts"
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
7
19
|
"author": "Just Eat Takeaway.com - Design System Team",
|
|
8
20
|
"license": "Apache-2.0",
|
|
9
21
|
"files": [
|
|
@@ -13,12 +25,16 @@
|
|
|
13
25
|
"src/interfaces",
|
|
14
26
|
"src/mixins",
|
|
15
27
|
"src/types",
|
|
16
|
-
"index.ts"
|
|
28
|
+
"src/index.ts",
|
|
29
|
+
"index.ts",
|
|
30
|
+
"dist",
|
|
31
|
+
"**/*.d.ts"
|
|
17
32
|
],
|
|
18
33
|
"scripts": {
|
|
19
34
|
"build": "run -T vite build",
|
|
20
35
|
"lint:scripts": "run -T eslint .",
|
|
21
36
|
"lint:scripts:fix": "run -T eslint . --fix",
|
|
37
|
+
"watch": "run -T vite build --watch",
|
|
22
38
|
"test": "run -T vitest run --config ../../../vite.config.js",
|
|
23
39
|
"test:ci": "yarn test",
|
|
24
40
|
"test:browsers": "run -T playwright test -c ./playwright-lit.config.ts",
|
|
@@ -33,6 +49,7 @@
|
|
|
33
49
|
"@justeattakeaway/pie-css": "1.x"
|
|
34
50
|
},
|
|
35
51
|
"devDependencies": {
|
|
36
|
-
"@justeattakeaway/pie-components-config": "0.21.
|
|
52
|
+
"@justeattakeaway/pie-components-config": "0.21.5",
|
|
53
|
+
"@justeattakeaway/pie-monorepo-utils": "0.9.11"
|
|
37
54
|
}
|
|
38
55
|
}
|