@justeattakeaway/pie-button 0.11.0 → 0.12.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.
@@ -3,9 +3,9 @@ transforming...
3
3
  ✓ 4 modules transformed.
4
4
  rendering chunks...
5
5
  computing gzip size...
6
- dist/index.js 4.12 kB │ gzip: 1.65 kB
6
+ dist/index.js 4.32 kB │ gzip: 1.65 kB
7
7
  
8
8
  [vite:dts] Start generate declaration files...
9
- ✓ built in 8.92s
10
- [vite:dts] Declaration files built in 8276ms.
9
+ ✓ built in 19.30s
10
+ [vite:dts] Declaration files built in 18529ms.
11
11
  
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [Changed] - extended readme file to mention props, events and enum exports ([#434](https://github.com/justeattakeaway/pie/pull/434)) by [@jamieomaguire](https://github.com/jamieomaguire)
8
+
9
+ - [Changed] - Prevent hover and active status on disabled btns and change outline to border for safari support ([#434](https://github.com/justeattakeaway/pie/pull/434)) by [@jamieomaguire](https://github.com/jamieomaguire)
10
+
11
+ - [Removed] - custom event handler and updated tests accordingly ([#434](https://github.com/justeattakeaway/pie/pull/434)) by [@jamieomaguire](https://github.com/jamieomaguire)
12
+
13
+ - [Added] - isFullWidth prop to button ([#434](https://github.com/justeattakeaway/pie/pull/434)) by [@jamieomaguire](https://github.com/jamieomaguire)
14
+
3
15
  ## 0.11.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -8,9 +8,24 @@
8
8
  </a>
9
9
  </p>
10
10
 
11
- # pie-button
11
+ # Table of Contents
12
12
 
13
- This button is a Web Component built using Lit.
13
+ 1. [Introduction](#pie-button)
14
+ 2. [Local Development](#local-development)
15
+ 3. [Props](#props)
16
+ 4. [Events](#events)
17
+ - [HTML example](#html)
18
+ - [Vue example (using Nuxt 3)](#vue-templates-using-nuxt-3)
19
+ - [React example (using Next 13)](#react-templates-using-next-13)
20
+ 5. [TypeScript Enum Exports](#typescript-enum-exports)
21
+ 6. [Testing](#testing)
22
+ - [Browser Tests](#browser-tests)
23
+ - [Visual Tests](#visual-tests)
24
+
25
+
26
+ ## `pie-button`
27
+
28
+ `pie-button` is a Web Component built using the Lit library. It offers a simple and accessible button component for web applications. This component can be easily integrated into various frontend frameworks and customized through a set of properties. For TypeScript projects, it also provides exported enums for type safety and autocompletion.
14
29
 
15
30
  ## Local development
16
31
 
@@ -34,9 +49,65 @@ Local dev server using Vite (with hot module reloading)
34
49
  ```
35
50
  yarn dev
36
51
  ```
52
+ ## Props
53
+
54
+ | Property | Type | Default | Description |
55
+ |-------------|-----------|-----------------|----------------------------------------------------------------------|
56
+ | size | `String` | `BUTTON_SIZE.MEDIUM` | Size of the button, one of `BUTTON_SIZE` enum values (TypeScript Enum) or a raw string value such as `'large'` |
57
+ | type | `String` | `BUTTON_TYPE.SUBMIT` | Type of the button, one of `BUTTON_TYPE` enum values (TypeScript Enum) or a raw string value such as `'submit'` |
58
+ | variant | `String` | `BUTTON_VARIANT.PRIMARY` | Variant of the button, one of `BUTTON_VARIANT` enum values (TypeScript Enum) or a raw string value such as `'primary'` |
59
+ | disabled | `Boolean` | `false` | If `true`, disables the button. |
60
+ | isFullWidth | `Boolean` | `false` | If `true`, sets the button width to 100% of it's container. |
61
+
62
+
63
+ ## Events
64
+
65
+ This component does not use any custom event handlers. In order to add event listening to this component, you can treat it like a native HTML element in your application.
66
+
67
+ For example, to add a click handler in various templates:
68
+
69
+ ### HTML
70
+ ```html
71
+ <!-- Other attributes omitted for clarity -->
72
+ <pie-button onclick="e => console.log(e)">Click me!</pie-button>
73
+ ```
37
74
 
75
+ ### Vue templates (using Nuxt 3)
76
+ ```html
77
+ <!-- Other attributes omitted for clarity -->
78
+ <pie-button @click="handleClick">Click me!</pie-button>
79
+ ```
80
+
81
+ ### React templates (using Next 13)
82
+ ```html
83
+ <!-- Other attributes omitted for clarity -->
84
+ <PieButton onClick={handleClick}>increment</PieButton>
85
+
86
+ ```
38
87
 
39
- ## Running tests
88
+ ## TypeScript Enum Exports
89
+
90
+ For TypeScript projects, we export three enums related to button properties: `BUTTON_SIZE`, `BUTTON_TYPE`, and `BUTTON_VARIANT`. You can import and use these enums to set the corresponding property values for the `pie-button` component. This ensures better type safety and autocompletion in your project.
91
+
92
+ Here's an example of how to import and use the enums in a TypeScript project:
93
+
94
+ ```typescript
95
+ import { BUTTON_SIZE, BUTTON_TYPE, BUTTON_VARIANT } from '@justeattakeaway/pie-button';
96
+
97
+ // Using the enums to set property values
98
+ const myButtonSize = BUTTON_SIZE.LARGE;
99
+ const myButtonType = BUTTON_TYPE.RESET;
100
+ const myButtonVariant = BUTTON_VARIANT.SECONDARY;
101
+ ```
102
+
103
+ In your markup or JSX, you can then use these variables to set the properties for the pie-button component:
104
+
105
+ ```html
106
+ <PieButton size={myButtonSize} type={myButtonType} variant={myButtonVariant}>Click me!</PieButton>
107
+ ```
108
+
109
+
110
+ ## Testing
40
111
 
41
112
  ### Browser tests
42
113
 
@@ -51,6 +122,3 @@ Run at the root of the monorepo:
51
122
  ```
52
123
  yarn test:visual --filter=pie-button
53
124
  ```
54
-
55
-
56
-
package/dist/index.js CHANGED
@@ -1,74 +1,81 @@
1
- import { unsafeCSS as f, LitElement as g, html as h } from "lit";
2
- import { classMap as v } from "lit/directives/class-map.js";
3
- import { property as p, customElement as m } from "lit/decorators.js";
4
- const x = `.o-btn{border-radius:50rem;border:none;font-family:JetSansDigital;cursor:pointer;user-select:none;outline:none}.o-btn:focus-visible{outline:2px solid #4996fd}.o-btn--xsmall{min-block-size:32px;padding:6px 8px;font-size:14px;font-weight:700;line-height:20px}.o-btn--small-productive{min-block-size:40px;padding:8px 16px;font-size:16px;font-weight:700;line-height:24px}.o-btn--small-expressive{min-block-size:40px;padding:6px 16px;font-size:20px;font-weight:700;line-height:28px}.o-btn--medium{min-block-size:48px;padding:10px 24px;font-size:20px;font-weight:700;line-height:28px}.o-btn--large{min-block-size:56px;padding:14px 24px;font-size:20px;font-weight:700;line-height:28px}.o-btn--primary{background-color:#f36805;color:#fff}.o-btn--primary:hover{background-color:#df5f05}.o-btn--primary:active{background-color:#b74e04}.o-btn--secondary{background-color:#f5f3f1;color:#242e30}.o-btn--secondary:hover{background-color:#ede9e5}.o-btn--secondary:active{background-color:#dcd4cd}.o-btn--outline{background-color:#fff;color:#303d3f;outline:1px solid #dbd9d7}.o-btn--outline:hover{background-color:#f5f5f5}.o-btn--outline:active{background-color:#e0e0e0}.o-btn--ghost{background-color:#fff;color:#242e30}.o-btn--ghost:hover{background-color:#f5f5f5}.o-btn--ghost:active{background-color:#e0e0e0}.o-btn.o-btn--is-disabled{background-color:#efedea;color:#8c999b;outline:1px solid #efedea;cursor:default}.o-btn.o-btn--is-disabled:hover{background-color:#e6e3de}.o-btn.o-btn--is-disabled:active{background-color:#d5cfc7}.o-btn.o-btn--is-disabled.o-btn--ghost{background-color:#fff;outline:none}
5
- `, u = (o, n) => function(i, t) {
1
+ import { unsafeCSS as f, LitElement as h, html as g } from "lit";
2
+ import { classMap as m } from "lit/directives/class-map.js";
3
+ import { property as a, customElement as x } from "lit/decorators.js";
4
+ const v = `.o-btn{border-radius:50rem;border:none;font-family:JetSansDigital;cursor:pointer;user-select:none;outline:none}.o-btn:focus-visible{outline:2px solid #4996fd}.o-btn--xsmall{min-block-size:32px;padding:6px 8px;font-size:14px;font-weight:700;line-height:20px}.o-btn--small-productive{min-block-size:40px;padding:8px 16px;font-size:16px;font-weight:700;line-height:24px}.o-btn--small-expressive{min-block-size:40px;padding:6px 16px;font-size:20px;font-weight:700;line-height:28px}.o-btn--medium{min-block-size:48px;padding:10px 24px;font-size:20px;font-weight:700;line-height:28px}.o-btn--large{min-block-size:56px;padding:14px 24px;font-size:20px;font-weight:700;line-height:28px}.o-btn--primary{background-color:#f36805;color:#fff}.o-btn--primary:hover:not(:disabled){background-color:#df5f05}.o-btn--primary:active:not(:disabled){background-color:#b74e04}.o-btn--secondary{background-color:#f5f3f1;color:#242e30}.o-btn--secondary:hover:not(:disabled){background-color:#ede9e5}.o-btn--secondary:active:not(:disabled){background-color:#dcd4cd}.o-btn--outline{background-color:#fff;color:#303d3f;border:1px solid #dbd9d7}.o-btn--outline:hover:not(:disabled){background-color:#f5f5f5}.o-btn--outline:active:not(:disabled){background-color:#e0e0e0}.o-btn--ghost{background-color:#fff;color:#242e30}.o-btn--ghost:hover:not(:disabled){background-color:#f5f5f5}.o-btn--ghost:active:not(:disabled){background-color:#e0e0e0}.o-btn.o-btn--is-disabled{background-color:#efedea;color:#8c999b;border:1px solid #efedea;cursor:not-allowed}.o-btn.o-btn--is-disabled:hover:not(:disabled){background-color:#e6e3de}.o-btn.o-btn--is-disabled:active:not(:disabled){background-color:#d5cfc7}.o-btn.o-btn--is-disabled.o-btn--ghost{background-color:#fff;outline:none}.o-btn--fullWidth{inline-size:100%}
5
+ `, u = (o, n) => function(r, t) {
6
6
  const e = `#${t}`;
7
- Object.defineProperty(i, t, {
7
+ Object.defineProperty(r, t, {
8
8
  get() {
9
9
  return this[e];
10
10
  },
11
- set(r) {
12
- const s = this[e];
13
- o.includes(r) ? this[e] = r : (console.error(
14
- `[pie-button] Invalid value "${r}" provided for property "${t}".`,
11
+ set(i) {
12
+ const d = this[e];
13
+ o.includes(i) ? this[e] = i : (console.error(
14
+ `[pie-button] Invalid value "${i}" provided for property "${t}".`,
15
15
  `Must be one of: ${o.join(" | ")}.`,
16
16
  `Falling back to default value: "${n}"`
17
- ), this[e] = n), this.requestUpdate(t, s);
17
+ ), this[e] = n), this.requestUpdate(t, d);
18
18
  }
19
19
  });
20
20
  };
21
- var a = /* @__PURE__ */ ((o) => (o.XSMALL = "xsmall", o.SMALL_EXPRESSIVE = "small-expressive", o.SMALL_PRODUCTIVE = "small-productive", o.MEDIUM = "medium", o.LARGE = "large", o))(a || {}), d = /* @__PURE__ */ ((o) => (o.SUBMIT = "submit", o.BUTTON = "button", o.RESET = "reset", o.MENU = "menu", o))(d || {}), b = /* @__PURE__ */ ((o) => (o.PRIMARY = "primary", o.SECONDARY = "secondary", o.OUTLINE = "outline", o.GHOST = "ghost", o))(b || {}), y = Object.defineProperty, k = Object.getOwnPropertyDescriptor, c = (o, n, i, t) => {
22
- for (var e = t > 1 ? void 0 : t ? k(n, i) : n, r = o.length - 1, s; r >= 0; r--)
23
- (s = o[r]) && (e = (t ? s(n, i, e) : s(e)) || e);
24
- return t && e && y(n, i, e), e;
21
+ var b = /* @__PURE__ */ ((o) => (o.XSMALL = "xsmall", o.SMALL_EXPRESSIVE = "small-expressive", o.SMALL_PRODUCTIVE = "small-productive", o.MEDIUM = "medium", o.LARGE = "large", o))(b || {}), c = /* @__PURE__ */ ((o) => (o.SUBMIT = "submit", o.BUTTON = "button", o.RESET = "reset", o.MENU = "menu", o))(c || {}), p = /* @__PURE__ */ ((o) => (o.PRIMARY = "primary", o.SECONDARY = "secondary", o.OUTLINE = "outline", o.GHOST = "ghost", o))(p || {}), y = Object.defineProperty, M = Object.getOwnPropertyDescriptor, l = (o, n, r, t) => {
22
+ for (var e = t > 1 ? void 0 : t ? M(n, r) : n, i = o.length - 1, d; i >= 0; i--)
23
+ (d = o[i]) && (e = (t ? d(n, r, e) : d(e)) || e);
24
+ return t && e && y(n, r, e), e;
25
25
  };
26
- let l = class extends g {
26
+ let s = class extends h {
27
27
  constructor() {
28
- super(...arguments), this.size = a.MEDIUM, this.type = d.SUBMIT, this.variant = b.PRIMARY, this.disabled = !1;
28
+ super(...arguments), this.size = b.MEDIUM, this.type = c.SUBMIT, this.variant = p.PRIMARY, this.disabled = !1, this.isFullWidth = !1;
29
29
  }
30
30
  render() {
31
- const { size: o, type: n, variant: i, disabled: t } = this, e = {
31
+ const {
32
+ size: o,
33
+ type: n,
34
+ variant: r,
35
+ disabled: t,
36
+ isFullWidth: e
37
+ } = this, i = {
32
38
  "o-btn": !0,
33
39
  [`o-btn--${o}`]: o,
34
- [`o-btn--${i}`]: i,
35
- "o-btn--is-disabled": t
36
- }, r = () => {
37
- const s = new CustomEvent("CustomEvent", { detail: "WC event dispatched" });
38
- console.info("WC event dispatched"), this.dispatchEvent(s);
40
+ [`o-btn--${r}`]: r,
41
+ "o-btn--is-disabled": t,
42
+ "o-btn--fullWidth": e
39
43
  };
40
- return h`
44
+ return g`
41
45
  <button
42
- class=${v(e)}
46
+ class=${m(i)}
43
47
  type=${n}
44
48
  ?disabled=${t}
45
- @click="${r}">
49
+ ?isFullWidth=${e}>
46
50
  <slot></slot>
47
51
  </button>`;
48
52
  }
49
53
  };
50
- l.styles = f(x);
51
- c([
52
- p(),
53
- u(Object.values(a), a.MEDIUM)
54
- ], l.prototype, "size", 2);
55
- c([
56
- p(),
57
- u(Object.values(d), d.SUBMIT)
58
- ], l.prototype, "type", 2);
59
- c([
60
- p(),
61
- u(Object.values(b), b.PRIMARY)
62
- ], l.prototype, "variant", 2);
63
- c([
64
- p({ type: Boolean, reflect: !0 })
65
- ], l.prototype, "disabled", 2);
66
- l = c([
67
- m("pie-button")
68
- ], l);
54
+ s.styles = f(v);
55
+ l([
56
+ a(),
57
+ u(Object.values(b), b.MEDIUM)
58
+ ], s.prototype, "size", 2);
59
+ l([
60
+ a(),
61
+ u(Object.values(c), c.SUBMIT)
62
+ ], s.prototype, "type", 2);
63
+ l([
64
+ a(),
65
+ u(Object.values(p), p.PRIMARY)
66
+ ], s.prototype, "variant", 2);
67
+ l([
68
+ a({ type: Boolean, reflect: !0 })
69
+ ], s.prototype, "disabled", 2);
70
+ l([
71
+ a({ type: Boolean, reflect: !0 })
72
+ ], s.prototype, "isFullWidth", 2);
73
+ s = l([
74
+ x("pie-button")
75
+ ], s);
69
76
  export {
70
- a as BUTTON_SIZE,
71
- d as BUTTON_TYPE,
72
- b as BUTTON_VARIANT,
73
- l as PieButton
77
+ b as BUTTON_SIZE,
78
+ c as BUTTON_TYPE,
79
+ p as BUTTON_VARIANT,
80
+ s as PieButton
74
81
  };
@@ -6,6 +6,7 @@ export declare class PieButton extends LitElement {
6
6
  type: BUTTON_TYPE;
7
7
  variant: BUTTON_VARIANT;
8
8
  disabled: boolean;
9
+ isFullWidth: boolean;
9
10
  render(): import("lit-html").TemplateResult<1>;
10
11
  static styles: import("lit").CSSResult;
11
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,KAAK,CAAC;AAMlD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAGlE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,CAAC;AAEpD,qBACa,SAAU,SAAQ,UAAU;IAGrC,IAAI,EAAG,WAAW,CAAsB;IAIxC,IAAI,EAAG,WAAW,CAAsB;IAIxC,OAAO,EAAG,cAAc,CAA0B;IAGlD,QAAQ,EAAG,OAAO,CAAS;IAE3B,MAAM;IA2BN,MAAM,CAAC,MAAM,0BAAqB;CACrC;AAED,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,qBAAqB;QAC3B,YAAY,EAAE,SAAS,CAAC;KAC3B;CACJ"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,KAAK,CAAC;AAMlD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAGlE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,CAAC;AAEpD,qBACa,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;IAwBN,MAAM,CAAC,MAAM,0BAAqB;CACrC;AAED,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,qBAAqB;QAC3B,YAAY,EAAE,SAAS,CAAC;KAC3B;CACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-button",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "PIE design system button built using web components",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -31,19 +31,24 @@
31
31
  body {
32
32
  font-feature-settings: "tnum"; /* Enable tabular numbers */
33
33
  }
34
+ /* basic styles to center align components and give them some spacing */
34
35
  #root {
35
- padding: 1.5em;
36
- display: flex;
37
- gap: 1em;
38
- justify-content: center;
39
- align-items: center;
40
- flex-direction: column;
36
+ padding: 1em;
37
+ }
38
+
39
+ #root > * {
40
+ display: block;
41
+ margin-inline: auto;
42
+ }
43
+
44
+ #root > * + * {
45
+ margin-top: 1em;
41
46
  }
42
47
  </style>
43
48
  <title>Testing Page</title>
44
- </head>
45
- <body>
49
+ </head>
50
+ <body>
46
51
  <div id="root"></div>
47
52
  <script type="module" src="./index.ts"></script>
48
- </body>
53
+ </body>
49
54
  </html>
package/src/button.scss CHANGED
@@ -41,16 +41,16 @@ $button-outline-color-disabled: dt.$color-disabled-01;
41
41
  background-color: $bg-color;
42
42
  color: $text-color;
43
43
 
44
- &:hover {
44
+ &:hover:not(:disabled) {
45
45
  background-color: darken($bg-color, dt.$color-hover-01);
46
46
  }
47
47
 
48
- &:active {
48
+ &:active:not(:disabled) {
49
49
  background-color: darken($bg-color, dt.$color-active-01);
50
50
  }
51
51
 
52
52
  @if $outline-color != null {
53
- outline: 1px solid $outline-color;
53
+ border: 1px solid $outline-color;
54
54
  }
55
55
  }
56
56
 
@@ -146,10 +146,15 @@ $button-sizes: (
146
146
  .o-btn.o-btn--is-disabled {
147
147
  @include button-variant($button-bg-color-disabled, $button-text-color-disabled, $button-outline-color-disabled);
148
148
 
149
- cursor: default;
149
+ cursor: not-allowed;
150
150
 
151
151
  &.o-btn--ghost {
152
152
  background-color: $button-disabled-bg-color-ghost;
153
153
  outline: none;
154
154
  }
155
155
  }
156
+
157
+ // Additional modifiers
158
+ .o-btn--fullWidth {
159
+ inline-size: 100%;
160
+ }
package/src/index.ts CHANGED
@@ -13,41 +13,41 @@ export { BUTTON_SIZE, BUTTON_TYPE, BUTTON_VARIANT };
13
13
  export class PieButton extends LitElement {
14
14
  @property()
15
15
  @validPropertyValues(Object.values(BUTTON_SIZE), BUTTON_SIZE.MEDIUM)
16
- size : BUTTON_SIZE = BUTTON_SIZE.MEDIUM;
16
+ size : BUTTON_SIZE = BUTTON_SIZE.MEDIUM;
17
17
 
18
18
  @property()
19
19
  @validPropertyValues(Object.values(BUTTON_TYPE), BUTTON_TYPE.SUBMIT)
20
- type : BUTTON_TYPE = BUTTON_TYPE.SUBMIT;
20
+ type : BUTTON_TYPE = BUTTON_TYPE.SUBMIT;
21
21
 
22
22
  @property()
23
23
  @validPropertyValues(Object.values(BUTTON_VARIANT), BUTTON_VARIANT.PRIMARY)
24
- variant : BUTTON_VARIANT = BUTTON_VARIANT.PRIMARY;
24
+ variant : BUTTON_VARIANT = BUTTON_VARIANT.PRIMARY;
25
25
 
26
- @property({type: Boolean, reflect: true})
27
- disabled : boolean = false;
26
+ @property({ type: Boolean, reflect: true })
27
+ disabled = false;
28
+
29
+ @property({ type: Boolean, reflect: true })
30
+ isFullWidth = false;
28
31
 
29
32
  render () {
30
- const { size, type, variant, disabled } = this;
33
+ const {
34
+ size, type, variant, disabled, isFullWidth,
35
+ } = this;
31
36
 
32
37
  const classes = {
33
38
  'o-btn': true,
34
39
  [`o-btn--${size}`]: size,
35
40
  [`o-btn--${variant}`]: variant,
36
41
  'o-btn--is-disabled': disabled,
42
+ 'o-btn--fullWidth': isFullWidth,
37
43
  };
38
44
 
39
- const raiseWCEvent = () => {
40
- const event = new CustomEvent('CustomEvent', { detail: 'WC event dispatched' })
41
- console.info('WC event dispatched')
42
- this.dispatchEvent(event)
43
- }
44
-
45
45
  return html`
46
46
  <button
47
47
  class=${classMap(classes)}
48
48
  type=${type}
49
49
  ?disabled=${disabled}
50
- @click="${raiseWCEvent}">
50
+ ?isFullWidth=${isFullWidth}>
51
51
  <slot></slot>
52
52
  </button>`;
53
53
  }
@@ -6,46 +6,52 @@ const sizes = Object.values(BUTTON_SIZE);
6
6
  const variants = Object.values(BUTTON_VARIANT);
7
7
  const disabledStates = [true, false];
8
8
 
9
- variants.forEach(variant => {
10
- test(`should render - ${variant}`, async ({ mount }) => {
9
+ variants.forEach((variant) => {
10
+ test(`should render - ${variant}`, async ({ mount }) => {
11
+ for (const size of sizes) {
12
+ for (const isDisabled of disabledStates) {
13
+ const component = await mount(
14
+ PieButton,
15
+ {
16
+ props: {
17
+ size,
18
+ variant,
19
+ disabled: isDisabled,
20
+ },
21
+ slots: {
22
+ default: `Hello, ${size} ${variant} Button!`,
23
+ },
24
+ },
25
+ );
11
26
 
12
- for (const size of sizes) {
13
- for (const isDisabled of disabledStates) {
14
- const component = await mount(PieButton,
15
- {
27
+ await expect(component).toContainText(`Hello, ${size} ${variant} Button!`);
28
+ }
29
+ }
30
+ });
31
+ });
32
+
33
+ test('should correctly work with native click events', async ({ mount }) => {
34
+ const messages: string[] = [];
35
+ const expectedEventMessage = 'Native event dispatched';
36
+ const component = await mount(
37
+ PieButton,
38
+ {
16
39
  props: {
17
- size,
18
- variant,
19
- disabled: isDisabled
40
+ size: BUTTON_SIZE.LARGE,
41
+ variant: BUTTON_VARIANT.PRIMARY,
20
42
  },
21
43
  slots: {
22
- default: `Hello, ${size} ${variant} Button!`
44
+ default: 'Click me!',
23
45
  },
24
- });
25
-
26
- await expect(component).toContainText(`Hello, ${size} ${variant} Button!`);
27
- }
28
- }
29
- });
30
- })
31
-
32
- test('should emit an event when clicked', async ({ mount }) => {
33
- const messages: string[] = [];
34
- const component = await mount(PieButton,
35
- {
36
- props: {
37
- size: BUTTON_SIZE.LARGE,
38
- variant: BUTTON_VARIANT.PRIMARY
39
- },
40
- slots: {
41
- default: 'Click me!'
42
- },
43
- on: {
44
- CustomEvent: (data: string) => messages.push(data),
45
- },
46
- });
46
+ on: {
47
+ click: () => {
48
+ messages.push(expectedEventMessage);
49
+ },
50
+ },
51
+ },
52
+ );
47
53
 
48
- await component.click();
54
+ await component.click();
49
55
 
50
- expect(messages).toEqual(['WC event dispatched'])
51
- });
56
+ expect(messages).toEqual([expectedEventMessage]);
57
+ });
@@ -1,31 +1,52 @@
1
1
  import { test } from '@sand4rt/experimental-ct-web';
2
+ import percySnapshot from '@percy/playwright';
2
3
  import { PieButton } from '@/index';
3
- import percySnapshot from '@percy/playwright'
4
4
  import { BUTTON_SIZE, BUTTON_TYPE, BUTTON_VARIANT } from '@/defs';
5
5
 
6
6
  const sizes = Object.values(BUTTON_SIZE);
7
7
  const variants = Object.values(BUTTON_VARIANT);
8
8
  const disabledStates = [true, false];
9
9
 
10
- variants.forEach(variant => {
11
- test(`should render - ${variant}`, async ({ page, mount }) => {
10
+ variants.forEach((variant) => {
11
+ test(`should render - ${variant}`, async ({ page, mount }) => {
12
+ for (const size of sizes) {
13
+ for (const disabledState of disabledStates) {
14
+ await mount(
15
+ PieButton,
16
+ {
17
+ props: {
18
+ type: BUTTON_TYPE.BUTTON,
19
+ size,
20
+ variant,
21
+ disabled: disabledState,
22
+ isFullWidth: false,
23
+ },
24
+ slots: {
25
+ default: `Hello, ${size} ${variant} Button!`,
26
+ },
27
+ },
28
+ );
29
+ }
12
30
 
13
- for (const size of sizes) {
14
- for (const isDisabled of disabledStates) {
15
- await mount(PieButton,
16
- {
17
- props: {
18
- type: BUTTON_TYPE.BUTTON,
19
- size,
20
- variant,
21
- disabled: isDisabled
22
- },
23
- slots: {
24
- default: `Hello, ${size} ${variant} Button!`
25
- },
26
- });
27
- }
28
- }
29
- await percySnapshot(page, `PIE Button - ${variant}`);
30
- });
31
- })
31
+ for (const disabledState of disabledStates) {
32
+ await mount(
33
+ PieButton,
34
+ {
35
+ props: {
36
+ type: BUTTON_TYPE.BUTTON,
37
+ size,
38
+ variant,
39
+ disabled: disabledState,
40
+ isFullWidth: true,
41
+ },
42
+ slots: {
43
+ default: `Hello, ${size} ${variant} Button!`,
44
+ },
45
+ },
46
+ );
47
+ }
48
+ }
49
+
50
+ await percySnapshot(page, `PIE Button - ${variant}`);
51
+ });
52
+ });