@justeattakeaway/pie-button 0.15.0 → 0.16.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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +12 -0
- package/README.md +52 -50
- package/dist/index.js +68 -52
- package/dist/react.js +209 -223
- package/dist/types/packages/components/pie-button/src/defs.d.ts +31 -20
- 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 +5 -5
- package/dist/types/packages/components/pie-button/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/defs.ts +48 -20
- package/src/index.ts +15 -9
- package/test/accessibility/pie-button.spec.ts +10 -11
- package/test/component/pie-button.spec.ts +7 -5
- package/test/visual/pie-button.spec.ts +6 -5
- package/vite.config.js +1 -1
|
@@ -1,29 +1,40 @@
|
|
|
1
|
+
export interface ButtonProps {
|
|
2
|
+
/**
|
|
3
|
+
* the size of the button.
|
|
4
|
+
* @default medium
|
|
5
|
+
*/
|
|
6
|
+
size: 'xsmall' | 'small-expressive' | 'small-productive' | 'medium' | 'large';
|
|
7
|
+
/**
|
|
8
|
+
* The html button type to use.
|
|
9
|
+
* @default submit
|
|
10
|
+
*/
|
|
11
|
+
type: 'submit' | 'button' | 'reset' | 'menu';
|
|
12
|
+
/**
|
|
13
|
+
* the variant of the button.
|
|
14
|
+
* @default primary
|
|
15
|
+
*/
|
|
16
|
+
variant: 'primary' | 'secondary' | 'outline' | 'ghost';
|
|
17
|
+
/**
|
|
18
|
+
* If `true`, the button will be disabled.
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
disabled: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* If `true`, the button will span the full width.
|
|
24
|
+
* @default false
|
|
25
|
+
*/
|
|
26
|
+
isFullWidth: boolean;
|
|
27
|
+
}
|
|
1
28
|
/**
|
|
2
29
|
* Button size variants
|
|
3
30
|
*/
|
|
4
|
-
export declare
|
|
5
|
-
XSMALL = "xsmall",
|
|
6
|
-
SMALL_EXPRESSIVE = "small-expressive",
|
|
7
|
-
SMALL_PRODUCTIVE = "small-productive",
|
|
8
|
-
MEDIUM = "medium",
|
|
9
|
-
LARGE = "large"
|
|
10
|
-
}
|
|
31
|
+
export declare const buttonSizes: Array<ButtonProps['size']>;
|
|
11
32
|
/**
|
|
12
33
|
* Button style variants
|
|
13
34
|
*/
|
|
14
|
-
export declare
|
|
15
|
-
SUBMIT = "submit",
|
|
16
|
-
BUTTON = "button",
|
|
17
|
-
RESET = "reset",
|
|
18
|
-
MENU = "menu"
|
|
19
|
-
}
|
|
35
|
+
export declare const buttonVariants: Array<ButtonProps['variant']>;
|
|
20
36
|
/**
|
|
21
|
-
* Button
|
|
37
|
+
* Button type variants
|
|
22
38
|
*/
|
|
23
|
-
export declare
|
|
24
|
-
PRIMARY = "primary",
|
|
25
|
-
SECONDARY = "secondary",
|
|
26
|
-
OUTLINE = "outline",
|
|
27
|
-
GHOST = "ghost"
|
|
28
|
-
}
|
|
39
|
+
export declare const buttonTypes: Array<ButtonProps['type']>;
|
|
29
40
|
//# sourceMappingURL=defs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defs.d.ts","sourceRoot":"","sources":["../../../src/defs.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"defs.d.ts","sourceRoot":"","sources":["../../../src/defs.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IACxB;;;OAGG;IACH,IAAI,EAAE,QAAQ,GAAG,kBAAkB,GAAG,kBAAkB,GAAG,QAAQ,GAAG,OAAO,CAAC;IAC9E;;;OAGG;IACH,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;IAC7C;;;OAGG;IACH,OAAO,EAAE,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC;IACvD;;;OAGG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,WAAW,EAAE,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAMlD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,CAKxD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAKlD,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
2
|
+
import { ButtonProps, buttonSizes, buttonTypes, buttonVariants } from './defs';
|
|
3
|
+
export { type ButtonProps, buttonSizes, buttonTypes, buttonVariants, };
|
|
4
4
|
declare const componentSelector = "pie-button";
|
|
5
5
|
export declare class PieButton extends LitElement {
|
|
6
|
-
size:
|
|
7
|
-
type:
|
|
8
|
-
variant:
|
|
6
|
+
size: ButtonProps['size'];
|
|
7
|
+
type: ButtonProps['type'];
|
|
8
|
+
variant: ButtonProps['variant'];
|
|
9
9
|
disabled: boolean;
|
|
10
10
|
isFullWidth: boolean;
|
|
11
11
|
render(): import("lit-html").TemplateResult<1>;
|
|
@@ -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,WAAW,EAAE,WAAW,EAAE,cAAc,EACxD,MAAM,QAAQ,CAAC;AAGhB,OAAO,EACH,KAAK,WAAW,EAChB,WAAW,EACX,WAAW,EACX,cAAc,GACjB,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/defs.ts
CHANGED
|
@@ -1,30 +1,58 @@
|
|
|
1
|
+
export interface ButtonProps {
|
|
2
|
+
/**
|
|
3
|
+
* the size of the button.
|
|
4
|
+
* @default medium
|
|
5
|
+
*/
|
|
6
|
+
size: 'xsmall' | 'small-expressive' | 'small-productive' | 'medium' | 'large';
|
|
7
|
+
/**
|
|
8
|
+
* The html button type to use.
|
|
9
|
+
* @default submit
|
|
10
|
+
*/
|
|
11
|
+
type: 'submit' | 'button' | 'reset' | 'menu';
|
|
12
|
+
/**
|
|
13
|
+
* the variant of the button.
|
|
14
|
+
* @default primary
|
|
15
|
+
*/
|
|
16
|
+
variant: 'primary' | 'secondary' | 'outline' | 'ghost';
|
|
17
|
+
/**
|
|
18
|
+
* If `true`, the button will be disabled.
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
disabled: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* If `true`, the button will span the full width.
|
|
24
|
+
* @default false
|
|
25
|
+
*/
|
|
26
|
+
isFullWidth: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
1
29
|
/**
|
|
2
30
|
* Button size variants
|
|
3
31
|
*/
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
32
|
+
export const buttonSizes: Array<ButtonProps['size']> = [
|
|
33
|
+
'xsmall',
|
|
34
|
+
'small-expressive',
|
|
35
|
+
'small-productive',
|
|
36
|
+
'medium',
|
|
37
|
+
'large'
|
|
38
|
+
];
|
|
11
39
|
|
|
12
40
|
/**
|
|
13
41
|
* Button style variants
|
|
14
42
|
*/
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
43
|
+
export const buttonVariants: Array<ButtonProps['variant']> = [
|
|
44
|
+
'primary',
|
|
45
|
+
'secondary',
|
|
46
|
+
'outline',
|
|
47
|
+
'ghost',
|
|
48
|
+
];
|
|
21
49
|
|
|
22
50
|
/**
|
|
23
|
-
* Button
|
|
51
|
+
* Button type variants
|
|
24
52
|
*/
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
53
|
+
export const buttonTypes: Array<ButtonProps['type']> = [
|
|
54
|
+
'submit',
|
|
55
|
+
'button',
|
|
56
|
+
'reset',
|
|
57
|
+
'menu',
|
|
58
|
+
];
|
package/src/index.ts
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
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
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
ButtonProps, buttonSizes, buttonTypes, buttonVariants,
|
|
7
|
+
} from './defs';
|
|
7
8
|
|
|
8
9
|
// Valid values available to consumers
|
|
9
|
-
export {
|
|
10
|
+
export {
|
|
11
|
+
type ButtonProps,
|
|
12
|
+
buttonSizes,
|
|
13
|
+
buttonTypes,
|
|
14
|
+
buttonVariants,
|
|
15
|
+
};
|
|
10
16
|
|
|
11
17
|
const componentSelector = 'pie-button';
|
|
12
18
|
|
|
13
19
|
export class PieButton extends LitElement {
|
|
14
20
|
@property()
|
|
15
|
-
@validPropertyValues(componentSelector,
|
|
16
|
-
size
|
|
21
|
+
@validPropertyValues(componentSelector, buttonSizes, 'medium')
|
|
22
|
+
size: ButtonProps['size'] = 'medium';
|
|
17
23
|
|
|
18
24
|
@property()
|
|
19
|
-
@validPropertyValues(componentSelector,
|
|
20
|
-
type
|
|
25
|
+
@validPropertyValues(componentSelector, buttonTypes, 'submit')
|
|
26
|
+
type: ButtonProps['type'] = 'submit';
|
|
21
27
|
|
|
22
28
|
@property()
|
|
23
|
-
@validPropertyValues(componentSelector,
|
|
24
|
-
variant
|
|
29
|
+
@validPropertyValues(componentSelector, buttonVariants, 'primary')
|
|
30
|
+
variant: ButtonProps['variant'] = 'primary';
|
|
25
31
|
|
|
26
32
|
@property({ type: Boolean })
|
|
27
33
|
disabled = false;
|
|
@@ -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 '@justeattakeaway/pie-webc-core/src/test-helpers/get-all-prop-combos.ts';
|
|
3
|
+
import { getAllPropCombinations, splitCombinationsByPropertyValue } from '@justeattakeaway/pie-webc-core/src/test-helpers/get-all-prop-combos.ts';
|
|
4
|
+
import { PropObject, WebComponentPropValues } from '@justeattakeaway/pie-webc-core/src/test-helpers/defs.ts';
|
|
6
5
|
import { PieButton } from '@/index';
|
|
7
|
-
import {
|
|
6
|
+
import { buttonSizes, buttonVariants } from '@/defs';
|
|
8
7
|
|
|
9
8
|
const props: PropObject = {
|
|
10
|
-
variant:
|
|
11
|
-
size:
|
|
12
|
-
type:
|
|
9
|
+
variant: buttonVariants,
|
|
10
|
+
size: buttonSizes,
|
|
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,6 +1,11 @@
|
|
|
1
1
|
import { test, expect } from '@sand4rt/experimental-ct-web';
|
|
2
2
|
import { PieButton } from '@/index';
|
|
3
|
-
import {
|
|
3
|
+
import { ButtonProps } from '@/index';
|
|
4
|
+
|
|
5
|
+
const props: ButtonProps = {
|
|
6
|
+
size: 'large',
|
|
7
|
+
variant: 'primary',
|
|
8
|
+
}
|
|
4
9
|
|
|
5
10
|
test('should correctly work with native click events', async ({ mount }) => {
|
|
6
11
|
const messages: string[] = [];
|
|
@@ -8,10 +13,7 @@ test('should correctly work with native click events', async ({ mount }) => {
|
|
|
8
13
|
const component = await mount(
|
|
9
14
|
PieButton,
|
|
10
15
|
{
|
|
11
|
-
props
|
|
12
|
-
size: BUTTON_SIZE.LARGE,
|
|
13
|
-
variant: BUTTON_VARIANT.PRIMARY,
|
|
14
|
-
},
|
|
16
|
+
props,
|
|
15
17
|
slots: {
|
|
16
18
|
default: 'Click me!',
|
|
17
19
|
},
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { test } from '@sand4rt/experimental-ct-web';
|
|
2
|
+
import { getLitPercyOptions } from '@justeattakeaway/pie-webc-core/src/test-helpers/percy-lit-options.ts';
|
|
2
3
|
import percySnapshot from '@percy/playwright';
|
|
3
4
|
import type {
|
|
4
5
|
PropObject, WebComponentPropValues, WebComponentTestInput,
|
|
@@ -13,12 +14,12 @@ import {
|
|
|
13
14
|
WebComponentTestWrapper,
|
|
14
15
|
} from '@justeattakeaway/pie-webc-core/src/test-helpers/components/web-component-test-wrapper/WebComponentTestWrapper.ts';
|
|
15
16
|
import { PieButton } from '@/index';
|
|
16
|
-
import {
|
|
17
|
+
import { buttonSizes, buttonVariants } from '@/defs';
|
|
17
18
|
|
|
18
19
|
const props: PropObject = {
|
|
19
|
-
variant:
|
|
20
|
-
size:
|
|
21
|
-
type:
|
|
20
|
+
variant: buttonVariants,
|
|
21
|
+
size: buttonSizes,
|
|
22
|
+
type: 'button', // Changing the type does not affect the appearance of the button
|
|
22
23
|
isFullWidth: [true, false],
|
|
23
24
|
disabled: [true, false],
|
|
24
25
|
};
|
|
@@ -58,5 +59,5 @@ componentVariants.forEach((variant) => test(`Render all prop variations for Vari
|
|
|
58
59
|
);
|
|
59
60
|
}));
|
|
60
61
|
|
|
61
|
-
await percySnapshot(page, `PIE Button - Variant: ${variant}
|
|
62
|
+
await percySnapshot(page, `PIE Button - Variant: ${variant}`, getLitPercyOptions());
|
|
62
63
|
}));
|
package/vite.config.js
CHANGED