@justeattakeaway/pie-assistive-text 0.1.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.
- package/README.md +17 -7
- package/custom-elements.json +59 -3
- package/dist/index.d.ts +14 -1
- package/dist/index.js +47 -8
- package/dist/react.d.ts +14 -1
- package/dist/react.js +14 -8
- package/package.json +4 -3
- package/src/assistive-text.scss +27 -0
- package/src/defs.ts +8 -3
- package/src/index.ts +38 -4
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
3. [Importing the component](#importing-the-component)
|
|
16
16
|
4. [Peer Dependencies](#peer-dependencies)
|
|
17
17
|
5. [Props](#props)
|
|
18
|
+
6. [Slots](#slots)
|
|
18
19
|
6. [Contributing](#contributing)
|
|
19
20
|
|
|
20
21
|
## pie-assistive-text
|
|
@@ -63,29 +64,38 @@ import { PieAssistiveText } from '@justeattakeaway/pie-assistive-text/dist/react
|
|
|
63
64
|
> When using the React version of the component, please make sure to also
|
|
64
65
|
> include React as a [peer dependency](#peer-dependencies) in your project.
|
|
65
66
|
|
|
66
|
-
|
|
67
67
|
## Peer Dependencies
|
|
68
68
|
|
|
69
69
|
> [!IMPORTANT]
|
|
70
70
|
> When using `pie-assistive-text`, 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.
|
|
71
|
-
|
|
72
|
-
|
|
73
71
|
## Props
|
|
74
72
|
|
|
75
73
|
| Property | Type | Default | Description |
|
|
76
74
|
|---|---|---|---|
|
|
77
|
-
|
|
|
75
|
+
| `variant` | `string` | `default` | Sets the type of message displayed to one of three potential options: `error`, `success` or `default`. `error` and `success` include an icon and are used for validation messages. `default` provides users with extra context and guidance. |
|
|
76
|
+
|
|
77
|
+
## Slots
|
|
78
|
+
|
|
79
|
+
| Property | Description |
|
|
80
|
+
|---|---|
|
|
81
|
+
| `default` | The default, unnamed slot is used to pass in text to the component. |
|
|
78
82
|
|
|
79
83
|
In your markup or JSX, you can then use these to set the properties for the `pie-assistive-text` component:
|
|
80
84
|
|
|
81
85
|
```html
|
|
82
86
|
<!-- Native HTML -->
|
|
83
|
-
<pie-assistive-text
|
|
87
|
+
<pie-assistive-text
|
|
88
|
+
variant="success">
|
|
89
|
+
Your request has been submitted.
|
|
90
|
+
</pie-assistive-text>
|
|
84
91
|
|
|
85
92
|
<!-- JSX -->
|
|
86
|
-
<PieAssistiveText
|
|
93
|
+
<PieAssistiveText
|
|
94
|
+
variant="error">
|
|
95
|
+
Password contains too few characters.
|
|
96
|
+
</PieAssistiveText>
|
|
87
97
|
```
|
|
88
98
|
|
|
89
99
|
## Contributing
|
|
90
100
|
|
|
91
|
-
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).
|
|
101
|
+
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).
|
package/custom-elements.json
CHANGED
|
@@ -11,8 +11,26 @@
|
|
|
11
11
|
{
|
|
12
12
|
"kind": "javascript-module",
|
|
13
13
|
"path": "src/defs.js",
|
|
14
|
-
"declarations": [
|
|
15
|
-
|
|
14
|
+
"declarations": [
|
|
15
|
+
{
|
|
16
|
+
"kind": "variable",
|
|
17
|
+
"name": "variants",
|
|
18
|
+
"type": {
|
|
19
|
+
"text": "['default', 'error', 'success']"
|
|
20
|
+
},
|
|
21
|
+
"default": "['default', 'error', 'success']"
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"exports": [
|
|
25
|
+
{
|
|
26
|
+
"kind": "js",
|
|
27
|
+
"name": "variants",
|
|
28
|
+
"declaration": {
|
|
29
|
+
"name": "variants",
|
|
30
|
+
"module": "src/defs.js"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
]
|
|
16
34
|
},
|
|
17
35
|
{
|
|
18
36
|
"kind": "javascript-module",
|
|
@@ -22,7 +40,45 @@
|
|
|
22
40
|
"kind": "class",
|
|
23
41
|
"description": "",
|
|
24
42
|
"name": "PieAssistiveText",
|
|
25
|
-
"
|
|
43
|
+
"slots": [
|
|
44
|
+
{
|
|
45
|
+
"description": "Default slot",
|
|
46
|
+
"name": ""
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
"members": [
|
|
50
|
+
{
|
|
51
|
+
"kind": "field",
|
|
52
|
+
"name": "variant",
|
|
53
|
+
"type": {
|
|
54
|
+
"text": "AssistiveTextProps['variant'] | undefined"
|
|
55
|
+
},
|
|
56
|
+
"privacy": "public",
|
|
57
|
+
"default": "'default'",
|
|
58
|
+
"attribute": "variant"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"kind": "method",
|
|
62
|
+
"name": "renderIcon",
|
|
63
|
+
"privacy": "private",
|
|
64
|
+
"return": {
|
|
65
|
+
"type": {
|
|
66
|
+
"text": "TemplateResult"
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"description": "Renders the assistive-text icon content."
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
"attributes": [
|
|
73
|
+
{
|
|
74
|
+
"name": "variant",
|
|
75
|
+
"type": {
|
|
76
|
+
"text": "AssistiveTextProps['variant'] | undefined"
|
|
77
|
+
},
|
|
78
|
+
"default": "'default'",
|
|
79
|
+
"fieldName": "variant"
|
|
80
|
+
}
|
|
81
|
+
],
|
|
26
82
|
"superclass": {
|
|
27
83
|
"name": "LitElement",
|
|
28
84
|
"package": "lit"
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
1
1
|
import type { CSSResult } from 'lit';
|
|
2
2
|
import type { LitElement } from 'lit';
|
|
3
|
-
import type { TemplateResult } from 'lit
|
|
3
|
+
import type { TemplateResult } from 'lit';
|
|
4
4
|
|
|
5
5
|
export declare interface AssistiveTextProps {
|
|
6
|
+
/**
|
|
7
|
+
* What variant the assistive text should be such as default, error or success.
|
|
8
|
+
*/
|
|
9
|
+
variant?: typeof variants[number];
|
|
6
10
|
}
|
|
7
11
|
|
|
8
12
|
/**
|
|
9
13
|
* @tagname pie-assistive-text
|
|
14
|
+
* @slot - Default slot
|
|
10
15
|
*/
|
|
11
16
|
export declare class PieAssistiveText extends LitElement implements AssistiveTextProps {
|
|
17
|
+
variant?: AssistiveTextProps['variant'];
|
|
18
|
+
/**
|
|
19
|
+
* Renders the assistive-text icon content.
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
private renderIcon;
|
|
12
23
|
render(): TemplateResult<1>;
|
|
13
24
|
static styles: CSSResult;
|
|
14
25
|
}
|
|
15
26
|
|
|
27
|
+
export declare const variants: readonly ["default", "error", "success"];
|
|
28
|
+
|
|
16
29
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,52 @@
|
|
|
1
|
-
import { unsafeCSS as
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { unsafeCSS as p, LitElement as f, html as i, nothing as l } from "lit";
|
|
2
|
+
import { property as d } from "lit/decorators.js";
|
|
3
|
+
import { validPropertyValues as x, defineCustomElement as m } from "@justeattakeaway/pie-webc-core";
|
|
4
|
+
import { ifDefined as u } from "lit/directives/if-defined.js";
|
|
5
|
+
import "@justeattakeaway/pie-icons-webc/IconAlertCircle";
|
|
6
|
+
import "@justeattakeaway/pie-icons-webc/IconCheckCircle";
|
|
7
|
+
const h = `.c-assistiveText{--assistive-text-color: var(--dt-color-content-default);margin:0;padding-block-start:var(--dt-spacing-a);color:var(--assistive-text-color);font-family:var(--dt-font-body-s-family);font-weight:var(--dt-font-body-s-weight);font-size:calc(var(--dt-font-body-s-size) * 1px);line-height:calc(var(--dt-font-body-s-line-height) * 1px);gap:var(--dt-spacing-b);display:flex;align-items:flex-start}.c-assistiveText[variant=success]{--assistive-text-color: var(--dt-color-content-positive)}.c-assistiveText[variant=error]{--assistive-text-color: var(--dt-color-content-error)}.c-assistiveText .c-assistiveText-icon{display:inline-flex}
|
|
8
|
+
`, y = ["default", "error", "success"];
|
|
9
|
+
var g = Object.defineProperty, T = Object.getOwnPropertyDescriptor, b = (r, t, o, e) => {
|
|
10
|
+
for (var s = e > 1 ? void 0 : e ? T(t, o) : t, a = r.length - 1, n; a >= 0; a--)
|
|
11
|
+
(n = r[a]) && (s = (e ? n(t, o, s) : n(s)) || s);
|
|
12
|
+
return e && s && g(t, o, s), s;
|
|
13
|
+
};
|
|
14
|
+
const v = "pie-assistive-text";
|
|
15
|
+
class c extends f {
|
|
16
|
+
constructor() {
|
|
17
|
+
super(...arguments), this.variant = "default";
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Renders the assistive-text icon content.
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
renderIcon() {
|
|
24
|
+
const { variant: t } = this;
|
|
25
|
+
return i`
|
|
26
|
+
${t === "success" ? i`<icon-check-circle class="c-assistiveText-icon" size="s" />` : l}
|
|
27
|
+
${t === "error" ? i`<icon-alert-circle class="c-assistiveText-icon" size="s" />` : l}`;
|
|
28
|
+
}
|
|
5
29
|
render() {
|
|
6
|
-
|
|
30
|
+
const {
|
|
31
|
+
variant: t
|
|
32
|
+
} = this;
|
|
33
|
+
return i`
|
|
34
|
+
<p
|
|
35
|
+
class="c-assistiveText"
|
|
36
|
+
data-test-id="pie-assistive-text"
|
|
37
|
+
variant=${u(t)}>
|
|
38
|
+
${this.renderIcon()}
|
|
39
|
+
<slot></slot>
|
|
40
|
+
</p>`;
|
|
7
41
|
}
|
|
8
42
|
}
|
|
9
|
-
|
|
10
|
-
|
|
43
|
+
c.styles = p(h);
|
|
44
|
+
b([
|
|
45
|
+
d(),
|
|
46
|
+
x(v, y, "default")
|
|
47
|
+
], c.prototype, "variant", 2);
|
|
48
|
+
m(v, c);
|
|
11
49
|
export {
|
|
12
|
-
|
|
50
|
+
c as PieAssistiveText,
|
|
51
|
+
y as variants
|
|
13
52
|
};
|
package/dist/react.d.ts
CHANGED
|
@@ -1,21 +1,34 @@
|
|
|
1
1
|
import type { CSSResult } from 'lit';
|
|
2
2
|
import type { LitElement } from 'lit';
|
|
3
3
|
import * as React_2 from 'react';
|
|
4
|
-
import type { TemplateResult } from 'lit
|
|
4
|
+
import type { TemplateResult } from 'lit';
|
|
5
5
|
|
|
6
6
|
export declare interface AssistiveTextProps {
|
|
7
|
+
/**
|
|
8
|
+
* What variant the assistive text should be such as default, error or success.
|
|
9
|
+
*/
|
|
10
|
+
variant?: typeof variants[number];
|
|
7
11
|
}
|
|
8
12
|
|
|
9
13
|
export declare const PieAssistiveText: React_2.ForwardRefExoticComponent<AssistiveTextProps & React_2.RefAttributes<PieAssistiveText_2> & ReactBaseType>;
|
|
10
14
|
|
|
11
15
|
/**
|
|
12
16
|
* @tagname pie-assistive-text
|
|
17
|
+
* @slot - Default slot
|
|
13
18
|
*/
|
|
14
19
|
declare class PieAssistiveText_2 extends LitElement implements AssistiveTextProps {
|
|
20
|
+
variant?: AssistiveTextProps['variant'];
|
|
21
|
+
/**
|
|
22
|
+
* Renders the assistive-text icon content.
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
private renderIcon;
|
|
15
26
|
render(): TemplateResult<1>;
|
|
16
27
|
static styles: CSSResult;
|
|
17
28
|
}
|
|
18
29
|
|
|
19
30
|
declare type ReactBaseType = React_2.HTMLAttributes<HTMLElement>;
|
|
20
31
|
|
|
32
|
+
export declare const variants: readonly ["default", "error", "success"];
|
|
33
|
+
|
|
21
34
|
export { }
|
package/dist/react.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { createComponent as
|
|
3
|
-
import { PieAssistiveText as
|
|
1
|
+
import * as t from "react";
|
|
2
|
+
import { createComponent as e } from "@lit/react";
|
|
3
|
+
import { PieAssistiveText as i } from "./index.js";
|
|
4
|
+
import { variants as T } from "./index.js";
|
|
4
5
|
import "lit";
|
|
6
|
+
import "lit/decorators.js";
|
|
5
7
|
import "@justeattakeaway/pie-webc-core";
|
|
6
|
-
|
|
8
|
+
import "lit/directives/if-defined.js";
|
|
9
|
+
import "@justeattakeaway/pie-icons-webc/IconAlertCircle";
|
|
10
|
+
import "@justeattakeaway/pie-icons-webc/IconCheckCircle";
|
|
11
|
+
const s = e({
|
|
7
12
|
displayName: "PieAssistiveText",
|
|
8
|
-
elementClass:
|
|
9
|
-
react:
|
|
13
|
+
elementClass: i,
|
|
14
|
+
react: t,
|
|
10
15
|
tagName: "pie-assistive-text",
|
|
11
16
|
events: {}
|
|
12
|
-
}),
|
|
17
|
+
}), c = s;
|
|
13
18
|
export {
|
|
14
|
-
|
|
19
|
+
c as PieAssistiveText,
|
|
20
|
+
T as variants
|
|
15
21
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justeattakeaway/pie-assistive-text",
|
|
3
3
|
"description": "PIE Design System Assistive Text built using Web Components",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -31,11 +31,12 @@
|
|
|
31
31
|
"license": "Apache-2.0",
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@custom-elements-manifest/analyzer": "0.9.0",
|
|
34
|
-
"@justeattakeaway/pie-components-config": "
|
|
34
|
+
"@justeattakeaway/pie-components-config": "0.11.0",
|
|
35
35
|
"cem-plugin-module-file-extensions": "0.0.5"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@justeattakeaway/pie-webc
|
|
38
|
+
"@justeattakeaway/pie-icons-webc": "0.17.2",
|
|
39
|
+
"@justeattakeaway/pie-webc-core": "0.17.1"
|
|
39
40
|
},
|
|
40
41
|
"volta": {
|
|
41
42
|
"extends": "../../../package.json"
|
package/src/assistive-text.scss
CHANGED
|
@@ -1 +1,28 @@
|
|
|
1
1
|
@use '@justeattakeaway/pie-css/scss' as p;
|
|
2
|
+
|
|
3
|
+
.c-assistiveText {
|
|
4
|
+
--assistive-text-color: var(--dt-color-content-default);
|
|
5
|
+
|
|
6
|
+
margin: 0;
|
|
7
|
+
padding-block-start: var(--dt-spacing-a);
|
|
8
|
+
color: var(--assistive-text-color);
|
|
9
|
+
font-family: var(--dt-font-body-s-family);
|
|
10
|
+
font-weight: var(--dt-font-body-s-weight);
|
|
11
|
+
font-size: #{p.font-size(--dt-font-body-s-size)};
|
|
12
|
+
line-height: #{p.line-height(--dt-font-body-s-line-height)};
|
|
13
|
+
gap: var(--dt-spacing-b);
|
|
14
|
+
display: flex;
|
|
15
|
+
align-items: flex-start;
|
|
16
|
+
|
|
17
|
+
&[variant='success'] {
|
|
18
|
+
--assistive-text-color: var(--dt-color-content-positive);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
&[variant='error'] {
|
|
22
|
+
--assistive-text-color: var(--dt-color-content-error);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.c-assistiveText-icon {
|
|
26
|
+
display: inline-flex;
|
|
27
|
+
}
|
|
28
|
+
}
|
package/src/defs.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export interface AssistiveTextProps {
|
|
1
|
+
export const variants = ['default', 'error', 'success'] as const;
|
|
2
|
+
|
|
3
|
+
export interface AssistiveTextProps {
|
|
4
|
+
/**
|
|
5
|
+
* What variant the assistive text should be such as default, error or success.
|
|
6
|
+
*/
|
|
7
|
+
variant?: typeof variants[number];
|
|
8
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
LitElement, html, unsafeCSS, nothing, TemplateResult,
|
|
3
|
+
} from 'lit';
|
|
4
|
+
|
|
5
|
+
import { property } from 'lit/decorators.js';
|
|
6
|
+
import { validPropertyValues, defineCustomElement } from '@justeattakeaway/pie-webc-core';
|
|
7
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
8
|
+
import '@justeattakeaway/pie-icons-webc/IconAlertCircle';
|
|
9
|
+
import '@justeattakeaway/pie-icons-webc/IconCheckCircle';
|
|
2
10
|
|
|
3
|
-
import { defineCustomElement } from '@justeattakeaway/pie-webc-core';
|
|
4
11
|
import styles from './assistive-text.scss?inline';
|
|
5
|
-
import { AssistiveTextProps } from './defs';
|
|
12
|
+
import { AssistiveTextProps, variants } from './defs';
|
|
6
13
|
|
|
7
14
|
// Valid values available to consumers
|
|
8
15
|
export * from './defs';
|
|
@@ -11,10 +18,37 @@ const componentSelector = 'pie-assistive-text';
|
|
|
11
18
|
|
|
12
19
|
/**
|
|
13
20
|
* @tagname pie-assistive-text
|
|
21
|
+
* @slot - Default slot
|
|
14
22
|
*/
|
|
15
23
|
export class PieAssistiveText extends LitElement implements AssistiveTextProps {
|
|
24
|
+
@property()
|
|
25
|
+
@validPropertyValues(componentSelector, variants, 'default')
|
|
26
|
+
public variant?: AssistiveTextProps['variant'] = 'default';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Renders the assistive-text icon content.
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
private renderIcon (): TemplateResult {
|
|
33
|
+
const { variant } = this;
|
|
34
|
+
return html`
|
|
35
|
+
${variant === 'success' ? html`<icon-check-circle class="c-assistiveText-icon" size="s" />` : nothing}
|
|
36
|
+
${variant === 'error' ? html`<icon-alert-circle class="c-assistiveText-icon" size="s" />` : nothing}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
16
39
|
render () {
|
|
17
|
-
|
|
40
|
+
const {
|
|
41
|
+
variant,
|
|
42
|
+
} = this;
|
|
43
|
+
|
|
44
|
+
return html`
|
|
45
|
+
<p
|
|
46
|
+
class="c-assistiveText"
|
|
47
|
+
data-test-id="pie-assistive-text"
|
|
48
|
+
variant=${ifDefined(variant)}>
|
|
49
|
+
${this.renderIcon()}
|
|
50
|
+
<slot></slot>
|
|
51
|
+
</p>`;
|
|
18
52
|
}
|
|
19
53
|
|
|
20
54
|
// Renders a `CSSResult` generated from SCSS by Vite
|