@justeattakeaway/pie-button 0.11.0 → 0.12.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 +3 -3
- package/CHANGELOG.md +21 -0
- package/README.md +73 -9
- package/dist/index.js +56 -49
- package/dist/types/index.d.ts +0 -0
- package/dist/types/src/decorators.d.ts +0 -0
- package/dist/types/src/decorators.d.ts.map +0 -0
- package/dist/types/src/defs.d.ts +0 -0
- package/dist/types/src/defs.d.ts.map +0 -0
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/package.json +1 -2
- package/playwright/index.html +14 -9
- package/src/button.scss +9 -4
- package/src/index.ts +13 -13
- package/test/component/pie-button.spec.ts +42 -36
- package/test/visual/pie-button.spec.ts +43 -22
- package/tsconfig.json +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -3,9 +3,9 @@ transforming...
|
|
|
3
3
|
[32m✓[39m 4 modules transformed.
|
|
4
4
|
rendering chunks...
|
|
5
5
|
computing gzip size...
|
|
6
|
-
[2mdist/[22m[36mindex.js [39m[1m[2m4.
|
|
6
|
+
[2mdist/[22m[36mindex.js [39m[1m[2m4.32 kB[22m[1m[22m[2m │ gzip: 1.65 kB[22m
|
|
7
7
|
[32m
|
|
8
8
|
[36m[vite:dts][32m Start generate declaration files...[39m
|
|
9
|
-
[32m✓[39m built in
|
|
10
|
-
[32m[36m[vite:dts][32m Declaration files built in
|
|
9
|
+
[32m✓[39m built in 23.55s
|
|
10
|
+
[32m[36m[vite:dts][32m Declaration files built in 21956ms.
|
|
11
11
|
[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.12.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [Changed] - Added missing newline at the end of tsconfig.json ([#439](https://github.com/justeattakeaway/pie/pull/439)) by [@fernandofranca](https://github.com/fernandofranca)
|
|
8
|
+
|
|
9
|
+
[Changed] - Updated README.md
|
|
10
|
+
[Removed] - Removed npm `dev` script
|
|
11
|
+
|
|
12
|
+
## 0.12.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- [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)
|
|
17
|
+
|
|
18
|
+
- [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)
|
|
19
|
+
|
|
20
|
+
- [Removed] - custom event handler and updated tests accordingly ([#434](https://github.com/justeattakeaway/pie/pull/434)) by [@jamieomaguire](https://github.com/jamieomaguire)
|
|
21
|
+
|
|
22
|
+
- [Added] - isFullWidth prop to button ([#434](https://github.com/justeattakeaway/pie/pull/434)) by [@jamieomaguire](https://github.com/jamieomaguire)
|
|
23
|
+
|
|
3
24
|
## 0.11.0
|
|
4
25
|
|
|
5
26
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -8,9 +8,24 @@
|
|
|
8
8
|
</a>
|
|
9
9
|
</p>
|
|
10
10
|
|
|
11
|
-
#
|
|
11
|
+
# Table of Contents
|
|
12
12
|
|
|
13
|
-
|
|
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
|
|
|
@@ -25,18 +40,70 @@ cd packages/components/pie-button
|
|
|
25
40
|
yarn build
|
|
26
41
|
```
|
|
27
42
|
|
|
28
|
-
|
|
43
|
+
Compile and watch for changes (auto-compiles `dist` on save)
|
|
29
44
|
```
|
|
30
45
|
yarn watch
|
|
31
46
|
```
|
|
32
47
|
|
|
33
|
-
|
|
48
|
+
## Props
|
|
49
|
+
|
|
50
|
+
| Property | Type | Default | Description |
|
|
51
|
+
|-------------|-----------|-----------------|----------------------------------------------------------------------|
|
|
52
|
+
| 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'` |
|
|
53
|
+
| 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'` |
|
|
54
|
+
| 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'` |
|
|
55
|
+
| disabled | `Boolean` | `false` | If `true`, disables the button. |
|
|
56
|
+
| isFullWidth | `Boolean` | `false` | If `true`, sets the button width to 100% of it's container. |
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
## Events
|
|
60
|
+
|
|
61
|
+
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.
|
|
62
|
+
|
|
63
|
+
For example, to add a click handler in various templates:
|
|
64
|
+
|
|
65
|
+
### HTML
|
|
66
|
+
```html
|
|
67
|
+
<!-- Other attributes omitted for clarity -->
|
|
68
|
+
<pie-button onclick="e => console.log(e)">Click me!</pie-button>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Vue templates (using Nuxt 3)
|
|
72
|
+
```html
|
|
73
|
+
<!-- Other attributes omitted for clarity -->
|
|
74
|
+
<pie-button @click="handleClick">Click me!</pie-button>
|
|
34
75
|
```
|
|
35
|
-
|
|
76
|
+
|
|
77
|
+
### React templates (using Next 13)
|
|
78
|
+
```html
|
|
79
|
+
<!-- Other attributes omitted for clarity -->
|
|
80
|
+
<PieButton onClick={handleClick}>increment</PieButton>
|
|
81
|
+
|
|
36
82
|
```
|
|
37
83
|
|
|
84
|
+
## TypeScript Enum Exports
|
|
38
85
|
|
|
39
|
-
|
|
86
|
+
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.
|
|
87
|
+
|
|
88
|
+
Here's an example of how to import and use the enums in a TypeScript project:
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { BUTTON_SIZE, BUTTON_TYPE, BUTTON_VARIANT } from '@justeattakeaway/pie-button';
|
|
92
|
+
|
|
93
|
+
// Using the enums to set property values
|
|
94
|
+
const myButtonSize = BUTTON_SIZE.LARGE;
|
|
95
|
+
const myButtonType = BUTTON_TYPE.RESET;
|
|
96
|
+
const myButtonVariant = BUTTON_VARIANT.SECONDARY;
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
In your markup or JSX, you can then use these variables to set the properties for the pie-button component:
|
|
100
|
+
|
|
101
|
+
```html
|
|
102
|
+
<PieButton size={myButtonSize} type={myButtonType} variant={myButtonVariant}>Click me!</PieButton>
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
## Testing
|
|
40
107
|
|
|
41
108
|
### Browser tests
|
|
42
109
|
|
|
@@ -51,6 +118,3 @@ Run at the root of the monorepo:
|
|
|
51
118
|
```
|
|
52
119
|
yarn test:visual --filter=pie-button
|
|
53
120
|
```
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
package/dist/index.js
CHANGED
|
@@ -1,74 +1,81 @@
|
|
|
1
|
-
import { unsafeCSS as f, LitElement as
|
|
2
|
-
import { classMap as
|
|
3
|
-
import { property as
|
|
4
|
-
const
|
|
5
|
-
`, u = (o, n) => function(
|
|
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(
|
|
7
|
+
Object.defineProperty(r, t, {
|
|
8
8
|
get() {
|
|
9
9
|
return this[e];
|
|
10
10
|
},
|
|
11
|
-
set(
|
|
12
|
-
const
|
|
13
|
-
o.includes(
|
|
14
|
-
`[pie-button] Invalid value "${
|
|
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,
|
|
17
|
+
), this[e] = n), this.requestUpdate(t, d);
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
|
-
var
|
|
22
|
-
for (var e = t > 1 ? void 0 : t ?
|
|
23
|
-
(
|
|
24
|
-
return t && e && y(n,
|
|
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
|
|
26
|
+
let s = class extends h {
|
|
27
27
|
constructor() {
|
|
28
|
-
super(...arguments), this.size =
|
|
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 {
|
|
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--${
|
|
35
|
-
"o-btn--is-disabled": t
|
|
36
|
-
|
|
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
|
|
44
|
+
return g`
|
|
41
45
|
<button
|
|
42
|
-
class=${
|
|
46
|
+
class=${m(i)}
|
|
43
47
|
type=${n}
|
|
44
48
|
?disabled=${t}
|
|
45
|
-
|
|
49
|
+
?isFullWidth=${e}>
|
|
46
50
|
<slot></slot>
|
|
47
51
|
</button>`;
|
|
48
52
|
}
|
|
49
53
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
u(Object.values(
|
|
54
|
-
],
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
u(Object.values(
|
|
58
|
-
],
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
u(Object.values(
|
|
62
|
-
],
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
],
|
|
66
|
-
l
|
|
67
|
-
|
|
68
|
-
],
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
b as BUTTON_SIZE,
|
|
78
|
+
c as BUTTON_TYPE,
|
|
79
|
+
p as BUTTON_VARIANT,
|
|
80
|
+
s as PieButton
|
|
74
81
|
};
|
package/dist/types/index.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/types/src/defs.d.ts
CHANGED
|
File without changes
|
|
File without changes
|
|
@@ -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;
|
|
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.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"description": "PIE design system button built using web components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "run -T vite build",
|
|
11
11
|
"watch": "run -T vite build --watch",
|
|
12
|
-
"dev": "run -T vite",
|
|
13
12
|
"test": "echo \"Error: no test specified\" && exit 0",
|
|
14
13
|
"test:browsers": "npx playwright test -c ./playwright-lit.config.ts",
|
|
15
14
|
"test:browsers:ci": "yarn test:browsers",
|
package/playwright/index.html
CHANGED
|
@@ -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:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
45
|
-
|
|
49
|
+
</head>
|
|
50
|
+
<body>
|
|
46
51
|
<div id="root"></div>
|
|
47
52
|
<script type="module" src="./index.ts"></script>
|
|
48
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
16
|
+
size : BUTTON_SIZE = BUTTON_SIZE.MEDIUM;
|
|
17
17
|
|
|
18
18
|
@property()
|
|
19
19
|
@validPropertyValues(Object.values(BUTTON_TYPE), BUTTON_TYPE.SUBMIT)
|
|
20
|
-
|
|
20
|
+
type : BUTTON_TYPE = BUTTON_TYPE.SUBMIT;
|
|
21
21
|
|
|
22
22
|
@property()
|
|
23
23
|
@validPropertyValues(Object.values(BUTTON_VARIANT), BUTTON_VARIANT.PRIMARY)
|
|
24
|
-
|
|
24
|
+
variant : BUTTON_VARIANT = BUTTON_VARIANT.PRIMARY;
|
|
25
25
|
|
|
26
|
-
@property({type: Boolean, reflect: true})
|
|
27
|
-
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
disabled: isDisabled
|
|
40
|
+
size: BUTTON_SIZE.LARGE,
|
|
41
|
+
variant: BUTTON_VARIANT.PRIMARY,
|
|
20
42
|
},
|
|
21
43
|
slots: {
|
|
22
|
-
|
|
44
|
+
default: 'Click me!',
|
|
23
45
|
},
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
54
|
+
await component.click();
|
|
49
55
|
|
|
50
|
-
|
|
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
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
+
});
|
package/tsconfig.json
CHANGED