@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.
@@ -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 enum BUTTON_SIZE {
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 enum BUTTON_TYPE {
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 style variants
37
+ * Button type variants
22
38
  */
23
- export declare enum BUTTON_VARIANT {
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;;GAEG;AACH,oBAAY,WAAW;IACnB,MAAM,WAAW;IACjB,gBAAgB,qBAAqB;IACrC,gBAAgB,qBAAqB;IACrC,MAAM,WAAW;IACjB,KAAK,UAAU;CAClB;AAED;;GAEG;AACH,oBAAY,WAAW;IACnB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,IAAI,SAAS;CAChB;AAED;;GAEG;AACH,oBAAY,cAAc;IACtB,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,OAAO,YAAY;IACnB,KAAK,UAAU;CAClB"}
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 { BUTTON_SIZE, BUTTON_TYPE, BUTTON_VARIANT } from './defs';
3
- export { BUTTON_SIZE, BUTTON_TYPE, BUTTON_VARIANT };
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: BUTTON_SIZE;
7
- type: BUTTON_TYPE;
8
- variant: BUTTON_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;AAKlD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAGlE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,CAAC;AAEpD,QAAA,MAAM,iBAAiB,eAAe,CAAC;AAEvC,qBAAa,SAAU,SAAQ,UAAU;IAGjC,IAAI,EAAG,WAAW,CAAsB;IAIxC,IAAI,EAAG,WAAW,CAAsB;IAIxC,OAAO,EAAG,cAAc,CAA0B;IAGlD,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"}
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-button",
3
- "version": "0.15.0",
3
+ "version": "0.16.1",
4
4
  "description": "PIE design system button built using web components",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
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 enum BUTTON_SIZE {
5
- XSMALL = 'xsmall',
6
- SMALL_EXPRESSIVE = 'small-expressive',
7
- SMALL_PRODUCTIVE = 'small-productive',
8
- MEDIUM = 'medium',
9
- LARGE = 'large'
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 enum BUTTON_TYPE {
16
- SUBMIT = 'submit',
17
- BUTTON = 'button',
18
- RESET = 'reset',
19
- MENU = 'menu'
20
- }
43
+ export const buttonVariants: Array<ButtonProps['variant']> = [
44
+ 'primary',
45
+ 'secondary',
46
+ 'outline',
47
+ 'ghost',
48
+ ];
21
49
 
22
50
  /**
23
- * Button style variants
51
+ * Button type variants
24
52
  */
25
- export enum BUTTON_VARIANT {
26
- PRIMARY = 'primary',
27
- SECONDARY = 'secondary',
28
- OUTLINE = 'outline',
29
- GHOST = 'ghost'
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 { BUTTON_SIZE, BUTTON_TYPE, BUTTON_VARIANT } from './defs';
5
+ import {
6
+ ButtonProps, buttonSizes, buttonTypes, buttonVariants,
7
+ } from './defs';
7
8
 
8
9
  // Valid values available to consumers
9
- export { BUTTON_SIZE, BUTTON_TYPE, BUTTON_VARIANT };
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, Object.values(BUTTON_SIZE), BUTTON_SIZE.MEDIUM)
16
- size : BUTTON_SIZE = BUTTON_SIZE.MEDIUM;
21
+ @validPropertyValues(componentSelector, buttonSizes, 'medium')
22
+ size: ButtonProps['size'] = 'medium';
17
23
 
18
24
  @property()
19
- @validPropertyValues(componentSelector, Object.values(BUTTON_TYPE), BUTTON_TYPE.SUBMIT)
20
- type : BUTTON_TYPE = BUTTON_TYPE.SUBMIT;
25
+ @validPropertyValues(componentSelector, buttonTypes, 'submit')
26
+ type: ButtonProps['type'] = 'submit';
21
27
 
22
28
  @property()
23
- @validPropertyValues(componentSelector, Object.values(BUTTON_VARIANT), BUTTON_VARIANT.PRIMARY)
24
- variant : BUTTON_VARIANT = BUTTON_VARIANT.PRIMARY;
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
- PropObject, Combination, getAllPropCombinations, splitCombinationsByPropertyValue,
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 { BUTTON_TYPE, BUTTON_SIZE, BUTTON_VARIANT } from '@/defs';
6
+ import { buttonSizes, buttonVariants } from '@/defs';
8
7
 
9
8
  const props: PropObject = {
10
- variant: Object.values(BUTTON_VARIANT),
11
- size: Object.values(BUTTON_SIZE),
12
- type: BUTTON_TYPE.BUTTON, // Changing the type does not affect the appearance of the button
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 : Combination[] = getAllPropCombinations(props);
18
- const componentPropsMatrixByVariant: Record<string, Combination[]> = splitCombinationsByPropertyValue(componentPropsMatrix, 'variant');
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: Combination) => {
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.default({ page })
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 { BUTTON_SIZE, BUTTON_VARIANT } from '@/defs';
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 { BUTTON_SIZE, BUTTON_TYPE, BUTTON_VARIANT } from '@/defs';
17
+ import { buttonSizes, buttonVariants } from '@/defs';
17
18
 
18
19
  const props: PropObject = {
19
- variant: Object.values(BUTTON_VARIANT),
20
- size: Object.values(BUTTON_SIZE),
21
- type: BUTTON_TYPE.BUTTON, // Changing the type does not affect the appearance of the button
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
@@ -1,3 +1,3 @@
1
- import viteConfig from '@justeattakeaway/pie-components-config/vite.config'; // eslint-disable-line import/no-extraneous-dependencies
1
+ import viteConfig from '@justeattakeaway/pie-components-config/vite.config';
2
2
 
3
3
  export default viteConfig;