@justeattakeaway/pie-button 0.16.0 → 0.17.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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +18 -0
- package/README.md +48 -41
- package/dist/index.js +45 -99
- package/dist/react.js +209 -223
- package/dist/types/packages/components/pie-button/src/defs.d.ts +28 -15
- package/dist/types/packages/components/pie-button/src/defs.d.ts.map +1 -1
- package/dist/types/packages/components/pie-button/src/index.d.ts +2 -2
- package/dist/types/packages/components/pie-button/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/button.scss +68 -18
- package/src/defs.ts +29 -34
- package/src/index.ts +7 -8
- package/test/accessibility/pie-button.spec.ts +10 -11
- package/test/component/pie-button.spec.ts +7 -4
- package/test/visual/pie-button.spec.ts +17 -15
- package/vite.config.js +1 -1
|
@@ -1,18 +1,31 @@
|
|
|
1
|
+
export declare const sizes: readonly ["xsmall", "small-productive", "small-expressive", "medium", "large"];
|
|
2
|
+
export declare const types: readonly ["submit", "button", "reset", "menu"];
|
|
3
|
+
export declare const variants: readonly ["primary", "secondary", "outline", "ghost"];
|
|
1
4
|
export interface ButtonProps {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
/**
|
|
6
|
+
* (Optional) What size the button should be.
|
|
7
|
+
* @default "medium"
|
|
8
|
+
*/
|
|
9
|
+
size: typeof sizes[number];
|
|
10
|
+
/**
|
|
11
|
+
* (Optional) What type attribute should be applied to the button. For example submit, button or menu.
|
|
12
|
+
* @default "submit"
|
|
13
|
+
*/
|
|
14
|
+
type: typeof types[number];
|
|
15
|
+
/**
|
|
16
|
+
* (Optional) What style variant the button should be such as primary, outline or ghost.
|
|
17
|
+
* @default "primary"
|
|
18
|
+
*/
|
|
19
|
+
variant: typeof variants[number];
|
|
20
|
+
/**
|
|
21
|
+
* (Optional) When true, the button element is disabled.
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
24
|
+
disabled: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* (Optional) When true, the button element will occupy the full width of its container.
|
|
27
|
+
* @default false
|
|
28
|
+
*/
|
|
29
|
+
isFullWidth: boolean;
|
|
5
30
|
}
|
|
6
|
-
/**
|
|
7
|
-
* Button size variants
|
|
8
|
-
*/
|
|
9
|
-
export declare const buttonSizes: ButtonProps['size'][];
|
|
10
|
-
/**
|
|
11
|
-
* Button style variants
|
|
12
|
-
*/
|
|
13
|
-
export declare const buttonVariants: ButtonProps['variant'][];
|
|
14
|
-
/**
|
|
15
|
-
* Button type variants
|
|
16
|
-
*/
|
|
17
|
-
export declare const buttonTypes: ButtonProps['type'][];
|
|
18
31
|
//# sourceMappingURL=defs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defs.d.ts","sourceRoot":"","sources":["../../../src/defs.ts"],"names":[],"mappings":"AAAA,MAAM,
|
|
1
|
+
{"version":3,"file":"defs.d.ts","sourceRoot":"","sources":["../../../src/defs.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,gFAAiF,CAAC;AACpG,eAAO,MAAM,KAAK,gDAAiD,CAAC;AACpE,eAAO,MAAM,QAAQ,uDAAwD,CAAC;AAE9E,MAAM,WAAW,WAAW;IACxB;;;OAGG;IACH,IAAI,EAAE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC;IAC3B;;;OAGG;IACH,IAAI,EAAE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC;IAC3B;;;OAGG;IACH,OAAO,EAAE,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC;IACjC;;;OAGG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,WAAW,EAAE,OAAO,CAAC;CACxB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
|
-
import { ButtonProps,
|
|
3
|
-
export { type ButtonProps,
|
|
2
|
+
import { ButtonProps, sizes, types, variants } from './defs';
|
|
3
|
+
export { type ButtonProps, sizes, types, variants, };
|
|
4
4
|
declare const componentSelector = "pie-button";
|
|
5
5
|
export declare class PieButton extends LitElement {
|
|
6
6
|
size: ButtonProps['size'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,KAAK,CAAC;AAIlD,OAAO,EACH,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EACtC,MAAM,QAAQ,CAAC;AAGhB,OAAO,EACH,KAAK,WAAW,EAChB,KAAK,EACL,KAAK,EACL,QAAQ,GACX,CAAC;AAEF,QAAA,MAAM,iBAAiB,eAAe,CAAC;AAEvC,qBAAa,SAAU,SAAQ,UAAU;IAGjC,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,CAAY;IAIrC,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,CAAY;IAIrC,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,CAAa;IAG5C,QAAQ,UAAS;IAGjB,WAAW,UAAS;IAExB,MAAM;IAkBN,MAAM,CAAC,MAAM,0BAAqB;CACrC;AAID,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,qBAAqB;QAC3B,CAAC,iBAAiB,CAAC,EAAE,SAAS,CAAC;KAClC;CACJ"}
|
package/package.json
CHANGED
package/src/button.scss
CHANGED
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
// currently this sets the primary button styles
|
|
29
29
|
--btn-bg-color: var(--dt-color-interactive-brand);
|
|
30
30
|
--btn-text-color: var(--dt-color-content-interactive-primary);
|
|
31
|
-
--btn-focus: var(--dt-color-focus-outer);
|
|
32
31
|
|
|
33
32
|
min-block-size: var(--btn-min-block-size);
|
|
34
33
|
padding: var(--btn-padding);
|
|
@@ -45,13 +44,59 @@
|
|
|
45
44
|
user-select: none;
|
|
46
45
|
|
|
47
46
|
&:focus-visible {
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
/*
|
|
48
|
+
TODO: This focus styling should be extracted out into a shared mixin to share among other components
|
|
49
|
+
Applying both shadows in a single declaration gives anti-aliasing artefacts.
|
|
50
|
+
box-shadow: 0 0 0 2px dt.$color-focus-inner, 0 0 0 4px dt.$color-focus-outer;
|
|
51
|
+
|
|
52
|
+
To prevent this, they should be separated so they don't bleed into each other,
|
|
53
|
+
i.e., one shadow on the element and another on a pseudo element like :after
|
|
54
|
+
*/
|
|
55
|
+
box-shadow: 0 0 0 2px var(--dt-color-focus-inner);
|
|
56
|
+
outline: none;
|
|
57
|
+
|
|
58
|
+
/*
|
|
59
|
+
Setting the position to relative prevents the pseudo-element from
|
|
60
|
+
anchoring instead to the nearest ancestor with a specified position.
|
|
61
|
+
|
|
62
|
+
You can override this if you need another value.
|
|
63
|
+
*/
|
|
64
|
+
position: relative;
|
|
65
|
+
|
|
66
|
+
&:after {
|
|
67
|
+
content: '';
|
|
68
|
+
display: block;
|
|
69
|
+
|
|
70
|
+
/*
|
|
71
|
+
The pseudo element has to be larger than the element itself, but not just by
|
|
72
|
+
2px (the thickness of the inner shadow), it has to be 1px larger than that to
|
|
73
|
+
account for the border thickness.
|
|
74
|
+
*/
|
|
75
|
+
position: absolute;
|
|
76
|
+
top: -3px;
|
|
77
|
+
left: -3px;
|
|
78
|
+
right: -3px;
|
|
79
|
+
bottom: -3px;
|
|
80
|
+
border-radius: var(--btn-border-radius);
|
|
81
|
+
|
|
82
|
+
box-shadow: 0 0 0 2px var(--dt-color-focus-outer);
|
|
83
|
+
}
|
|
50
84
|
}
|
|
51
85
|
|
|
52
86
|
// Variant
|
|
53
87
|
&[variant='primary'] {
|
|
54
88
|
@include button-interactive-states('--dt-color-interactive-brand');
|
|
89
|
+
|
|
90
|
+
&[size='xsmall'],
|
|
91
|
+
&[size='small-productive'] {
|
|
92
|
+
/**
|
|
93
|
+
* Where the font-size is smaller,
|
|
94
|
+
* update the button backgrounds so that the text is accessible
|
|
95
|
+
**/
|
|
96
|
+
--btn-bg-color: var(--dt-color-interactive-primary);
|
|
97
|
+
|
|
98
|
+
@include button-interactive-states('--dt-color-interactive-primary');
|
|
99
|
+
}
|
|
55
100
|
}
|
|
56
101
|
|
|
57
102
|
&[variant='secondary'] {
|
|
@@ -63,7 +108,7 @@
|
|
|
63
108
|
|
|
64
109
|
&[variant='outline'] {
|
|
65
110
|
--btn-bg-color: var(--dt-color-container-default);
|
|
66
|
-
--btn-text-color: var(--dt-color-content-interactive-
|
|
111
|
+
--btn-text-color: var(--dt-color-content-interactive-secondary);
|
|
67
112
|
|
|
68
113
|
border: 1px solid var(--dt-color-border-strong);
|
|
69
114
|
|
|
@@ -71,7 +116,7 @@
|
|
|
71
116
|
}
|
|
72
117
|
|
|
73
118
|
&[variant='ghost'] {
|
|
74
|
-
--btn-bg-color:
|
|
119
|
+
--btn-bg-color: transparent;
|
|
75
120
|
--btn-text-color: var(--dt-color-content-link);
|
|
76
121
|
|
|
77
122
|
@include button-interactive-states('--dt-color-container-default');
|
|
@@ -83,31 +128,37 @@
|
|
|
83
128
|
}
|
|
84
129
|
|
|
85
130
|
&[disabled] {
|
|
86
|
-
--btn-
|
|
87
|
-
--btn-text-color: var(--dt-color-content-disabled);
|
|
131
|
+
--btn-text-color: var(--dt-color-content-disabled) !important;
|
|
88
132
|
|
|
89
|
-
border: 1px solid var(--dt-color-disabled-01);
|
|
90
133
|
cursor: not-allowed;
|
|
91
|
-
}
|
|
92
134
|
|
|
93
|
-
|
|
94
|
-
|
|
135
|
+
// For every variant except ghost, set the disabled background color
|
|
136
|
+
&:not([variant='ghost']) {
|
|
137
|
+
--btn-bg-color: var(--dt-color-disabled-01) !important;
|
|
138
|
+
}
|
|
95
139
|
|
|
96
|
-
outline
|
|
140
|
+
// For outline variants, set the border to the disabled color
|
|
141
|
+
&[variant='outline'] {
|
|
142
|
+
border-color: var(--dt-color-disabled-01) !important;
|
|
143
|
+
}
|
|
97
144
|
}
|
|
98
145
|
|
|
99
146
|
&[size='xsmall'] {
|
|
100
147
|
--btn-padding: 6px var(--dt-spacing-b);
|
|
101
|
-
--btn-min-block-size: 32px;
|
|
102
148
|
--btn-font-size: calc(var(--dt-font-size-14) * 1px);
|
|
103
149
|
--btn-line-height: calc(var(--dt-font-size-14-line-height) * 1px);
|
|
104
150
|
}
|
|
105
151
|
|
|
106
|
-
&[size='small'] {
|
|
152
|
+
&[size='small-expressive'] {
|
|
153
|
+
--btn-padding: 6px var(--dt-spacing-d);
|
|
154
|
+
--btn-font-size: calc(var(--dt-font-size-20) * 1px);
|
|
155
|
+
--btn-line-height: calc(var(--dt-font-size-20-line-height) * 1px);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
&[size='small-productive'] {
|
|
107
159
|
--btn-padding: 8px var(--dt-spacing-d);
|
|
108
|
-
--btn-
|
|
109
|
-
--btn-
|
|
110
|
-
--btn-line-height: calc(var(--dt-font-size-19-line-height) * 1px);
|
|
160
|
+
--btn-font-size: calc(var(--dt-font-size-16) * 1px);
|
|
161
|
+
--btn-line-height: calc(var(--dt-font-size-16-line-height) * 1px);
|
|
111
162
|
}
|
|
112
163
|
|
|
113
164
|
&[size='medium'] {
|
|
@@ -116,7 +167,6 @@
|
|
|
116
167
|
|
|
117
168
|
&[size='large'] {
|
|
118
169
|
--btn-padding: 14px var(--dt-spacing-e);
|
|
119
|
-
--btn-min-block-size: 56px;
|
|
120
170
|
--btn-font-size: calc(var(--dt-font-size-20) * 1px);
|
|
121
171
|
--btn-line-height: calc(var(--dt-font-size-20-line-height) * 1px);
|
|
122
172
|
}
|
package/src/defs.ts
CHANGED
|
@@ -1,36 +1,31 @@
|
|
|
1
|
+
export const sizes = ['xsmall', 'small-productive', 'small-expressive', 'medium', 'large'] as const;
|
|
2
|
+
export const types = ['submit', 'button', 'reset', 'menu'] as const;
|
|
3
|
+
export const variants = ['primary', 'secondary', 'outline', 'ghost'] as const;
|
|
4
|
+
|
|
1
5
|
export interface ButtonProps {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
6
|
+
/**
|
|
7
|
+
* (Optional) What size the button should be.
|
|
8
|
+
* @default "medium"
|
|
9
|
+
*/
|
|
10
|
+
size: typeof sizes[number];
|
|
11
|
+
/**
|
|
12
|
+
* (Optional) What type attribute should be applied to the button. For example submit, button or menu.
|
|
13
|
+
* @default "submit"
|
|
14
|
+
*/
|
|
15
|
+
type: typeof types[number];
|
|
16
|
+
/**
|
|
17
|
+
* (Optional) What style variant the button should be such as primary, outline or ghost.
|
|
18
|
+
* @default "primary"
|
|
19
|
+
*/
|
|
20
|
+
variant: typeof variants[number];
|
|
21
|
+
/**
|
|
22
|
+
* (Optional) When true, the button element is disabled.
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
disabled: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* (Optional) When true, the button element will occupy the full width of its container.
|
|
28
|
+
* @default false
|
|
29
|
+
*/
|
|
30
|
+
isFullWidth: boolean;
|
|
5
31
|
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Button size variants
|
|
9
|
-
*/
|
|
10
|
-
export const buttonSizes: ButtonProps['size'][] = [
|
|
11
|
-
'xsmall',
|
|
12
|
-
'small-expressive',
|
|
13
|
-
'small-productive',
|
|
14
|
-
'medium',
|
|
15
|
-
'large'
|
|
16
|
-
];
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Button style variants
|
|
20
|
-
*/
|
|
21
|
-
export const buttonVariants: ButtonProps['variant'][] = [
|
|
22
|
-
'primary',
|
|
23
|
-
'secondary',
|
|
24
|
-
'outline',
|
|
25
|
-
'ghost',
|
|
26
|
-
];
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Button type variants
|
|
30
|
-
*/
|
|
31
|
-
export const buttonTypes: ButtonProps['type'][] = [
|
|
32
|
-
'submit',
|
|
33
|
-
'button',
|
|
34
|
-
'reset',
|
|
35
|
-
'menu',
|
|
36
|
-
];
|
package/src/index.ts
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
1
1
|
import { LitElement, html, unsafeCSS } from 'lit';
|
|
2
2
|
import { property } from 'lit/decorators.js';
|
|
3
3
|
import { validPropertyValues } from '@justeattakeaway/pie-webc-core';
|
|
4
|
-
|
|
5
4
|
import styles from './button.scss?inline';
|
|
6
5
|
import {
|
|
7
|
-
ButtonProps,
|
|
6
|
+
ButtonProps, sizes, types, variants,
|
|
8
7
|
} from './defs';
|
|
9
8
|
|
|
10
9
|
// Valid values available to consumers
|
|
11
10
|
export {
|
|
12
11
|
type ButtonProps,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
sizes,
|
|
13
|
+
types,
|
|
14
|
+
variants,
|
|
16
15
|
};
|
|
17
16
|
|
|
18
17
|
const componentSelector = 'pie-button';
|
|
19
18
|
|
|
20
19
|
export class PieButton extends LitElement {
|
|
21
20
|
@property()
|
|
22
|
-
@validPropertyValues(componentSelector,
|
|
21
|
+
@validPropertyValues(componentSelector, sizes, 'medium')
|
|
23
22
|
size: ButtonProps['size'] = 'medium';
|
|
24
23
|
|
|
25
24
|
@property()
|
|
26
|
-
@validPropertyValues(componentSelector,
|
|
25
|
+
@validPropertyValues(componentSelector, types, 'submit')
|
|
27
26
|
type: ButtonProps['type'] = 'submit';
|
|
28
27
|
|
|
29
28
|
@property()
|
|
30
|
-
@validPropertyValues(componentSelector,
|
|
29
|
+
@validPropertyValues(componentSelector, variants, 'primary')
|
|
31
30
|
variant: ButtonProps['variant'] = 'primary';
|
|
32
31
|
|
|
33
32
|
@property({ type: Boolean })
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import { test, expect } from '@sand4rt/experimental-ct-web';
|
|
2
2
|
import AxeBuilder from '@axe-core/playwright';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
} from '
|
|
6
|
-
import {
|
|
7
|
-
import { buttonSizes, buttonVariants } from '@/defs';
|
|
3
|
+
import { getAllPropCombinations, splitCombinationsByPropertyValue } from '@justeattakeaway/pie-webc-testing/src/helpers/get-all-prop-combos.ts';
|
|
4
|
+
import { PropObject, WebComponentPropValues } from '@justeattakeaway/pie-webc-testing/src/helpers/defs.ts';
|
|
5
|
+
import { PieButton } from '@/index';
|
|
6
|
+
import { sizes, variants } from '@/defs';
|
|
8
7
|
|
|
9
8
|
const props: PropObject = {
|
|
10
|
-
variant:
|
|
11
|
-
size:
|
|
9
|
+
variant: variants,
|
|
10
|
+
size: sizes,
|
|
12
11
|
type: 'button', // Changing the type does not affect the appearance of the button
|
|
13
12
|
isFullWidth: [true, false],
|
|
14
13
|
disabled: [true, false],
|
|
15
14
|
};
|
|
16
15
|
|
|
17
|
-
const componentPropsMatrix :
|
|
18
|
-
const componentPropsMatrixByVariant: Record<string,
|
|
16
|
+
const componentPropsMatrix : WebComponentPropValues[] = getAllPropCombinations(props);
|
|
17
|
+
const componentPropsMatrixByVariant: Record<string, WebComponentPropValues[]> = splitCombinationsByPropertyValue(componentPropsMatrix, 'variant');
|
|
19
18
|
const componentVariants: string[] = Object.keys(componentPropsMatrixByVariant);
|
|
20
19
|
|
|
21
20
|
componentVariants.forEach((variant) => test(`Render all prop variations for Variant: ${variant}`, async ({ page, mount }) => {
|
|
22
|
-
await Promise.all(componentPropsMatrixByVariant[variant].map(async (combo:
|
|
21
|
+
await Promise.all(componentPropsMatrixByVariant[variant].map(async (combo: WebComponentPropValues) => {
|
|
23
22
|
await mount(
|
|
24
23
|
PieButton,
|
|
25
24
|
{
|
|
@@ -31,7 +30,7 @@ componentVariants.forEach((variant) => test(`Render all prop variations for Vari
|
|
|
31
30
|
);
|
|
32
31
|
}));
|
|
33
32
|
|
|
34
|
-
const results = await new AxeBuilder
|
|
33
|
+
const results = await new AxeBuilder({ page })
|
|
35
34
|
.withTags(['wcag21a', 'wcag21aa', 'wcag143', 'cat.color', 'cat.aria'])
|
|
36
35
|
.disableRules(['color-contrast', 'color-contrast-enhanced'])
|
|
37
36
|
.analyze();
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { test, expect } from '@sand4rt/experimental-ct-web';
|
|
2
2
|
import { PieButton } from '@/index';
|
|
3
|
+
import { ButtonProps } from '@/index';
|
|
4
|
+
|
|
5
|
+
const props: ButtonProps = {
|
|
6
|
+
size: 'large',
|
|
7
|
+
variant: 'primary',
|
|
8
|
+
}
|
|
3
9
|
|
|
4
10
|
test('should correctly work with native click events', async ({ mount }) => {
|
|
5
11
|
const messages: string[] = [];
|
|
@@ -7,10 +13,7 @@ test('should correctly work with native click events', async ({ mount }) => {
|
|
|
7
13
|
const component = await mount(
|
|
8
14
|
PieButton,
|
|
9
15
|
{
|
|
10
|
-
props
|
|
11
|
-
size: 'large',
|
|
12
|
-
variant: 'primary',
|
|
13
|
-
},
|
|
16
|
+
props,
|
|
14
17
|
slots: {
|
|
15
18
|
default: 'Click me!',
|
|
16
19
|
},
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
import { test } from '@sand4rt/experimental-ct-web';
|
|
2
|
-
import { getLitPercyOptions } from '@justeattakeaway/pie-webc-core/src/test-helpers/percy-lit-options.ts';
|
|
3
2
|
import percySnapshot from '@percy/playwright';
|
|
4
3
|
import type {
|
|
5
4
|
PropObject, WebComponentPropValues, WebComponentTestInput,
|
|
6
|
-
} from '@justeattakeaway/pie-webc-
|
|
5
|
+
} from '@justeattakeaway/pie-webc-testing/src/helpers/defs.ts';
|
|
7
6
|
import {
|
|
8
7
|
getAllPropCombinations, splitCombinationsByPropertyValue,
|
|
9
|
-
} from '@justeattakeaway/pie-webc-
|
|
8
|
+
} from '@justeattakeaway/pie-webc-testing/src/helpers/get-all-prop-combos.ts';
|
|
10
9
|
import {
|
|
11
10
|
createTestWebComponent,
|
|
12
|
-
} from '@justeattakeaway/pie-webc-
|
|
11
|
+
} from '@justeattakeaway/pie-webc-testing/src/helpers/rendering.ts';
|
|
13
12
|
import {
|
|
14
13
|
WebComponentTestWrapper,
|
|
15
|
-
} from '@justeattakeaway/pie-webc-
|
|
14
|
+
} from '@justeattakeaway/pie-webc-testing/src/helpers/components/web-component-test-wrapper/WebComponentTestWrapper.ts';
|
|
16
15
|
import { PieButton } from '@/index';
|
|
17
|
-
import {
|
|
16
|
+
import { sizes, variants } from '@/defs';
|
|
18
17
|
|
|
19
18
|
const props: PropObject = {
|
|
20
|
-
variant:
|
|
21
|
-
size:
|
|
19
|
+
variant: variants,
|
|
20
|
+
size: sizes,
|
|
22
21
|
type: 'button', // Changing the type does not affect the appearance of the button
|
|
23
22
|
isFullWidth: [true, false],
|
|
24
23
|
disabled: [true, false],
|
|
@@ -33,14 +32,17 @@ const componentVariants: string[] = Object.keys(componentPropsMatrixByVariant);
|
|
|
33
32
|
|
|
34
33
|
// This ensures the component is registered in the DOM for each test
|
|
35
34
|
// This is not required if your tests mount the web component directly in the tests
|
|
36
|
-
test(
|
|
35
|
+
test.beforeEach(async ({ page, mount }) => {
|
|
37
36
|
await mount(
|
|
38
37
|
PieButton,
|
|
39
|
-
{
|
|
40
|
-
props: {},
|
|
41
|
-
slots: {},
|
|
42
|
-
},
|
|
38
|
+
{},
|
|
43
39
|
);
|
|
40
|
+
|
|
41
|
+
// Removing the element so it's not present in the tests (but is still registered in the DOM)
|
|
42
|
+
await page.evaluate(() => {
|
|
43
|
+
const element : Element | null = document.querySelector('pie-button');
|
|
44
|
+
element?.remove();
|
|
45
|
+
});
|
|
44
46
|
});
|
|
45
47
|
|
|
46
48
|
componentVariants.forEach((variant) => test(`Render all prop variations for Variant: ${variant}`, async ({ page, mount }) => {
|
|
@@ -53,11 +55,11 @@ componentVariants.forEach((variant) => test(`Render all prop variations for Vari
|
|
|
53
55
|
{
|
|
54
56
|
props: { propKeyValues },
|
|
55
57
|
slots: {
|
|
56
|
-
|
|
58
|
+
component: testComponent.renderedString.trim(),
|
|
57
59
|
},
|
|
58
60
|
},
|
|
59
61
|
);
|
|
60
62
|
}));
|
|
61
63
|
|
|
62
|
-
await percySnapshot(page, `PIE Button - Variant: ${variant}
|
|
64
|
+
await percySnapshot(page, `PIE Button - Variant: ${variant}`);
|
|
63
65
|
}));
|
package/vite.config.js
CHANGED