@justeattakeaway/pie-button 0.16.1 → 0.18.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.
@@ -1,14 +1,14 @@
1
- [2:38:37 PM] @custom-elements-manifest/analyzer: Created new manifest.
1
+ [13:50:20] @custom-elements-manifest/analyzer: Created new manifest.
2
2
  react wrapper has been added!
3
3
  vite v4.3.9 building for production...
4
4
  transforming...
5
- ✓ 28 modules transformed.
5
+ ✓ 22 modules transformed.
6
6
  rendering chunks...
7
7
  computing gzip size...
8
- dist/index.js  7.96 kB │ gzip: 2.10 kB
8
+ dist/index.js  8.26 kB │ gzip: 1.86 kB
9
9
  dist/react.js 59.01 kB │ gzip: 15.91 kB
10
- 
11
- [vite:dts] Start generate declaration files...
12
- ✓ built in 22.93s
13
- [vite:dts] Declaration files built in 21054ms.
14
- 
10
+
11
+ [vite:dts] Start generate declaration files...
12
+ ✓ built in 4.60s
13
+ [vite:dts] Declaration files built in 4021ms.
14
+
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.18.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [Added] - inverse and ghost-inverse variants to pie-button ([#596](https://github.com/justeattakeaway/pie/pull/596)) by [@jamieomaguire](https://github.com/jamieomaguire)
8
+
9
+ - [Changed] - Set all component props to public ([#597](https://github.com/justeattakeaway/pie/pull/597)) by [@jamieomaguire](https://github.com/jamieomaguire)
10
+
11
+ ## 0.17.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [Changed] - Styles updated to fully match design updates ([#581](https://github.com/justeattakeaway/pie/pull/581)) by [@ashleynolan](https://github.com/ashleynolan)
16
+
17
+ - Focus styles have been updated to the new style
18
+ - Padding, font-size and line-heights adjusted inline with designs
19
+ - Outline button text colour updated from `color-content-interactive-tertiary` to `color-content-interactive-secondary`
20
+ - Primary buttons at `xsmall` and `small-productive` now have darker background
21
+ - `ghost` variant background colour changed to `transparent` (rather than #fff)
22
+
3
23
  ## 0.16.1
4
24
 
5
25
  ### Patch Changes
package/README.md CHANGED
@@ -65,13 +65,13 @@ import { PieButton } from '@justeattakeaway/pie-button/dist/react';
65
65
 
66
66
  ## Props
67
67
 
68
- | Property | Type | Default | Description |
69
- |-------------|-----------|-----------------|----------------------------------------------------------------------------------------------------------------|
70
- | size | `String` | `medium` | Size of the button, one of `buttonSizes` – `xsmall`, `small-expressive`, `small-productive`, `medium`, `large` |
71
- | type | `String` | `submit` | Type of the button, one of `buttonTypes` – `submit`, `button`, `reset`, `menu` |
72
- | variant | `String` | `primary` | Variant of the button, one of `buttonVariants`– `primary`, `secondary`, `outline`, `ghost` |
73
- | disabled | `Boolean` | `false` | If `true`, disables the button. |
74
- | isFullWidth | `Boolean` | `false` | If `true`, sets the button width to 100% of it's container. |
68
+ | Property | Type | Default | Description |
69
+ |-------------|-----------|-----------------|----------------------------------------------------------------------|
70
+ | size | `String` | `medium` | Size of the button, one of `sizes` – `xsmall`, `small-expressive`, `small-productive`, `medium`, `large` |
71
+ | type | `String` | `submit` | Type of the button, one of `types` – `submit`, `button`, `reset`, `menu` |
72
+ | variant | `String` | `primary` | Variant of the button, one of `variants` – `primary`, `secondary`, `outline`, `ghost`, `inverse`, `ghost-inverse` |
73
+ | disabled | `Boolean` | `false` | If `true`, disables the button. |
74
+ | isFullWidth | `Boolean` | `false` | If `true`, sets the button width to 100% of it's container. |
75
75
 
76
76
  In your markup or JSX, you can then use these to set the properties for the `pie-button` component:
77
77
 
@@ -111,7 +111,6 @@ For example, to add a click handler in various templates:
111
111
 
112
112
  ```
113
113
 
114
-
115
114
  ## Testing
116
115
 
117
116
  ### Browser tests
package/dist/index.js CHANGED
@@ -1,84 +1,30 @@
1
- import { unsafeCSS as h, LitElement as f, html as v } from "lit";
2
- import { property as c } from "lit/decorators.js";
1
+ import { unsafeCSS as h, LitElement as u, html as g } from "lit";
2
+ import { property as l } from "lit/decorators.js";
3
3
  import "lit/decorators/property.js";
4
- const b = (i, o, e) => function(r, t) {
5
- const n = `#${t}`;
6
- Object.defineProperty(r, t, {
4
+ const b = (c, o, e) => function(t, r) {
5
+ const a = `#${r}`;
6
+ Object.defineProperty(t, r, {
7
7
  get() {
8
- return this[n];
8
+ return this[a];
9
9
  },
10
- set(a) {
11
- const g = this[n];
12
- o.includes(a) ? this[n] = a : (console.error(
13
- `<${i}> Invalid value "${a}" provided for property "${t}".`,
10
+ set(v) {
11
+ const p = this[a];
12
+ o.includes(v) ? this[a] = v : (console.error(
13
+ `<${c}> Invalid value "${v}" provided for property "${r}".`,
14
14
  `Must be one of: ${o.join(" | ")}.`,
15
15
  `Falling back to default value: "${e}"`
16
- ), this[n] = e), this.requestUpdate(t, g);
16
+ ), this[a] = e), this.requestUpdate(r, p);
17
17
  }
18
18
  });
19
- }, m = `.c-webComponentTestWrapper{padding-block:var(--dt-spacing-c);padding-inline:var(--dt-spacing-e);font-family:var(--dt-font-interactive-m-family);font-size:calc(var(--dt-font-size-20) * 1px);border:1px solid var(--dt-color-background-dark);display:grid;grid-template-columns:1fr 1fr}.c-webComponentTestWrapper-label{margin-block:var(--dt-spacing-c)}.c-webComponentTestWrapper-slot{padding:var(--dt-spacing-c);border:1px dashed var(--dt-color-background-dark);grid-column:1/3;margin-block-start:var(--dt-spacing-c)}
20
- `;
21
- var y = Object.defineProperty, x = Object.getOwnPropertyDescriptor, z = (i, o, e, r) => {
22
- for (var t = r > 1 ? void 0 : r ? x(o, e) : o, n = i.length - 1, a; n >= 0; n--)
23
- (a = i[n]) && (t = (r ? a(o, e, t) : a(t)) || t);
24
- return r && t && y(o, e, t), t;
19
+ }, m = `.o-btn{--btn-border-radius: var(--dt-radius-rounded-e);--btn-font-family: var(--dt-font-interactive-m-family);--btn-font-weight: var(--dt-font-interactive-m-weight);--btn-padding: 10px var(--dt-spacing-e);--btn-min-height: 48px;--btn-font-size: calc(var(--dt-font-size-20) * 1px);--btn-line-height: calc(var(--dt-font-size-20-line-height) * 1px);--btn-bg-color: var(--dt-color-interactive-brand);--btn-text-color: var(--dt-color-content-interactive-primary);min-block-size:var(--btn-min-block-size);padding:var(--btn-padding);border:none;border-radius:var(--btn-border-radius);outline:none;background-color:var(--btn-bg-color);font-family:var(--btn-font-family);font-size:var(--btn-font-size);font-weight:var(--btn-font-weight);color:var(--btn-text-color);line-height:var(--btn-line-height);cursor:pointer;user-select:none}.o-btn:focus-visible{box-shadow:0 0 0 2px var(--dt-color-focus-inner);outline:none;position:relative}.o-btn:focus-visible:after{content:"";display:block;position:absolute;top:-3px;left:-3px;right:-3px;bottom:-3px;border-radius:var(--btn-border-radius);box-shadow:0 0 0 2px var(--dt-color-focus-outer)}.o-btn[variant=primary]:hover:not(:disabled){background-color:hsl(var(--dt-color-interactive-brand-h),var(--dt-color-interactive-brand-s),calc(var(--dt-color-interactive-brand-l) - var(--dt-color-hover-01)))}.o-btn[variant=primary]:active:not(:disabled){background-color:hsl(var(--dt-color-interactive-brand-h),var(--dt-color-interactive-brand-s),calc(var(--dt-color-interactive-brand-l) - var(--dt-color-active-01)))}.o-btn[variant=primary][size=xsmall],.o-btn[variant=primary][size=small-productive]{--btn-bg-color: var(--dt-color-interactive-primary)}.o-btn[variant=primary][size=xsmall]:hover:not(:disabled),.o-btn[variant=primary][size=small-productive]:hover:not(:disabled){background-color:hsl(var(--dt-color-interactive-primary-h),var(--dt-color-interactive-primary-s),calc(var(--dt-color-interactive-primary-l) - var(--dt-color-hover-01)))}.o-btn[variant=primary][size=xsmall]:active:not(:disabled),.o-btn[variant=primary][size=small-productive]:active:not(:disabled){background-color:hsl(var(--dt-color-interactive-primary-h),var(--dt-color-interactive-primary-s),calc(var(--dt-color-interactive-primary-l) - var(--dt-color-active-01)))}.o-btn[variant=secondary]{--btn-bg-color: var(--dt-color-interactive-secondary);--btn-text-color: var(--dt-color-content-interactive-secondary)}.o-btn[variant=secondary]:hover:not(:disabled){background-color:hsl(var(--dt-color-interactive-secondary-h),var(--dt-color-interactive-secondary-s),calc(var(--dt-color-interactive-secondary-l) - var(--dt-color-hover-01)))}.o-btn[variant=secondary]:active:not(:disabled){background-color:hsl(var(--dt-color-interactive-secondary-h),var(--dt-color-interactive-secondary-s),calc(var(--dt-color-interactive-secondary-l) - var(--dt-color-active-01)))}.o-btn[variant=outline]{--btn-bg-color: var(--dt-color-container-default);--btn-text-color: var(--dt-color-content-interactive-secondary);border:1px solid var(--dt-color-border-strong)}.o-btn[variant=outline]:hover:not(:disabled){background-color:hsl(var(--dt-color-container-default-h),var(--dt-color-container-default-s),calc(var(--dt-color-container-default-l) - var(--dt-color-hover-01)))}.o-btn[variant=outline]:active:not(:disabled){background-color:hsl(var(--dt-color-container-default-h),var(--dt-color-container-default-s),calc(var(--dt-color-container-default-l) - var(--dt-color-active-01)))}.o-btn[variant=ghost]{--btn-bg-color: transparent;--btn-text-color: var(--dt-color-content-link)}.o-btn[variant=ghost]:hover:not(:disabled){background-color:hsl(var(--dt-color-container-default-h),var(--dt-color-container-default-s),calc(var(--dt-color-container-default-l) - var(--dt-color-hover-01)))}.o-btn[variant=ghost]:active:not(:disabled){background-color:hsl(var(--dt-color-container-default-h),var(--dt-color-container-default-s),calc(var(--dt-color-container-default-l) - var(--dt-color-active-01)))}.o-btn[variant=inverse]{--btn-bg-color: var(--dt-color-interactive-inverse);--btn-text-color: var(--dt-color-content-interactive-secondary)}.o-btn[variant=inverse]:hover:not(:disabled){background-color:hsl(var(--dt-color-interactive-inverse-h),var(--dt-color-interactive-inverse-s),calc(var(--dt-color-interactive-inverse-l) - var(--dt-color-hover-01)))}.o-btn[variant=inverse]:active:not(:disabled){background-color:hsl(var(--dt-color-interactive-inverse-h),var(--dt-color-interactive-inverse-s),calc(var(--dt-color-interactive-inverse-l) - var(--dt-color-active-01)))}.o-btn[variant=ghost-inverse]{--btn-bg-color: transparent;--btn-text-color: var(--dt-color-content-interactive-primary)}.o-btn[variant=ghost-inverse]:hover:not(:disabled){background-color:hsl(var(--dt-color-container-inverse-h),var(--dt-color-container-inverse-s),calc(var(--dt-color-container-inverse-l) - var(--dt-color-hover-01)))}.o-btn[variant=ghost-inverse]:active:not(:disabled){background-color:hsl(var(--dt-color-container-inverse-h),var(--dt-color-container-inverse-s),calc(var(--dt-color-container-inverse-l) - var(--dt-color-active-01)))}.o-btn[isFullWidth]{inline-size:100%}.o-btn[disabled]{--btn-text-color: var(--dt-color-content-disabled) !important;cursor:not-allowed}.o-btn[disabled]:not([variant=ghost],[variant=ghost-inverse]){--btn-bg-color: var(--dt-color-disabled-01) !important}.o-btn[disabled][variant=outline]{border-color:var(--dt-color-disabled-01)!important}.o-btn[size=xsmall]{--btn-padding: 6px var(--dt-spacing-b);--btn-font-size: calc(var(--dt-font-size-14) * 1px);--btn-line-height: calc(var(--dt-font-size-14-line-height) * 1px)}.o-btn[size=small-expressive]{--btn-padding: 6px var(--dt-spacing-d);--btn-font-size: calc(var(--dt-font-size-20) * 1px);--btn-line-height: calc(var(--dt-font-size-20-line-height) * 1px)}.o-btn[size=small-productive]{--btn-padding: 8px var(--dt-spacing-d);--btn-font-size: calc(var(--dt-font-size-16) * 1px);--btn-line-height: calc(var(--dt-font-size-16-line-height) * 1px)}.o-btn[size=large]{--btn-padding: 14px var(--dt-spacing-e);--btn-font-size: calc(var(--dt-font-size-20) * 1px);--btn-line-height: calc(var(--dt-font-size-20-line-height) * 1px)}
20
+ `, f = ["xsmall", "small-productive", "small-expressive", "medium", "large"], y = ["submit", "button", "reset", "menu"], x = ["primary", "secondary", "outline", "ghost", "inverse", "ghost-inverse"];
21
+ var z = Object.defineProperty, k = Object.getOwnPropertyDescriptor, d = (c, o, e, n) => {
22
+ for (var t = n > 1 ? void 0 : n ? k(o, e) : o, r = c.length - 1, a; r >= 0; r--)
23
+ (a = c[r]) && (t = (n ? a(o, e, t) : a(t)) || t);
24
+ return n && t && z(o, e, t), t;
25
25
  };
26
- class p extends f {
27
- constructor() {
28
- super(...arguments), this.propKeyValues = "";
29
- }
30
- // Renders a string such as 'size: small, isFullWidth: true'
31
- // as HTML such as:
32
- // <p class="c-webComponentTestWrapper-label"><b>size</b>: <code>small</code></p>
33
- // <p class="c-webComponentTestWrapper-label"><b>isFullWidth</b>: <code>true</code></p>
34
- _renderPropKeyValues() {
35
- return this.propKeyValues.split(",").map((o) => {
36
- const [e, r] = o.split(":");
37
- return v`<p class="c-webComponentTestWrapper-label"><b>${e}</b>: <code>${r}</code></p>`;
38
- });
39
- }
40
- // eslint-disable-next-line class-methods-use-this
41
- render() {
42
- return v`
43
- <div class="c-webComponentTestWrapper">
44
- ${this._renderPropKeyValues()}
45
- <div class="c-webComponentTestWrapper-slot">
46
- <slot></slot>
47
- </div>
48
- </div>`;
49
- }
50
- }
51
- p.styles = h(m);
52
- z([
53
- c({ type: String })
54
- ], p.prototype, "propKeyValues", 2);
55
- const u = "web-component-test-wrapper";
56
- customElements.get(u) || customElements.define(u, p);
57
- const $ = `.o-btn{--btn-border-radius: var(--dt-radius-rounded-e);--btn-font-family: var(--dt-font-interactive-m-family);--btn-font-weight: var(--dt-font-interactive-m-weight);--btn-padding: 10px var(--dt-spacing-e);--btn-min-height: 48px;--btn-font-size: calc(var(--dt-font-size-20) * 1px);--btn-line-height: calc(var(--dt-font-size-20-line-height) * 1px);--btn-bg-color: var(--dt-color-interactive-brand);--btn-text-color: var(--dt-color-content-interactive-primary);--btn-focus: var(--dt-color-focus-outer);min-block-size:var(--btn-min-block-size);padding:var(--btn-padding);border:none;border-radius:var(--btn-border-radius);outline:none;background-color:var(--btn-bg-color);font-family:var(--btn-font-family);font-size:var(--btn-font-size);font-weight:var(--btn-font-weight);color:var(--btn-text-color);line-height:var(--btn-line-height);cursor:pointer;user-select:none}.o-btn:focus-visible{outline:2px solid var(--btn-focus)}.o-btn[variant=primary]:hover:not(:disabled){background-color:hsl(var(--dt-color-interactive-brand-h),var(--dt-color-interactive-brand-s),calc(var(--dt-color-interactive-brand-l) - var(--dt-color-hover-01)))}.o-btn[variant=primary]:active:not(:disabled){background-color:hsl(var(--dt-color-interactive-brand-h),var(--dt-color-interactive-brand-s),calc(var(--dt-color-interactive-brand-l) - var(--dt-color-active-01)))}.o-btn[variant=secondary]{--btn-bg-color: var(--dt-color-interactive-secondary);--btn-text-color: var(--dt-color-content-interactive-secondary)}.o-btn[variant=secondary]:hover:not(:disabled){background-color:hsl(var(--dt-color-interactive-secondary-h),var(--dt-color-interactive-secondary-s),calc(var(--dt-color-interactive-secondary-l) - var(--dt-color-hover-01)))}.o-btn[variant=secondary]:active:not(:disabled){background-color:hsl(var(--dt-color-interactive-secondary-h),var(--dt-color-interactive-secondary-s),calc(var(--dt-color-interactive-secondary-l) - var(--dt-color-active-01)))}.o-btn[variant=outline]{--btn-bg-color: var(--dt-color-container-default);--btn-text-color: var(--dt-color-content-interactive-tertiary);border:1px solid var(--dt-color-border-strong)}.o-btn[variant=outline]:hover:not(:disabled){background-color:hsl(var(--dt-color-container-default-h),var(--dt-color-container-default-s),calc(var(--dt-color-container-default-l) - var(--dt-color-hover-01)))}.o-btn[variant=outline]:active:not(:disabled){background-color:hsl(var(--dt-color-container-default-h),var(--dt-color-container-default-s),calc(var(--dt-color-container-default-l) - var(--dt-color-active-01)))}.o-btn[variant=ghost]{--btn-bg-color: var(--dt-color-container-default);--btn-text-color: var(--dt-color-content-link)}.o-btn[variant=ghost]:hover:not(:disabled){background-color:hsl(var(--dt-color-container-default-h),var(--dt-color-container-default-s),calc(var(--dt-color-container-default-l) - var(--dt-color-hover-01)))}.o-btn[variant=ghost]:active:not(:disabled){background-color:hsl(var(--dt-color-container-default-h),var(--dt-color-container-default-s),calc(var(--dt-color-container-default-l) - var(--dt-color-active-01)))}.o-btn[isFullWidth]{inline-size:100%}.o-btn[disabled]{--btn-bg-color: var(--dt-color-disabled-01);--btn-text-color: var(--dt-color-content-disabled);border:1px solid var(--dt-color-disabled-01);cursor:not-allowed}.o-btn[disabled][variant=ghost]{--btn-bg-color: var(--dt-color-container-default);outline:none}.o-btn[size=xsmall]{--btn-padding: 6px var(--dt-spacing-b);--btn-min-block-size: 32px;--btn-font-size: calc(var(--dt-font-size-14) * 1px);--btn-line-height: calc(var(--dt-font-size-14-line-height) * 1px)}.o-btn[size=small]{--btn-padding: 8px var(--dt-spacing-d);--btn-min-block-size: 40px;--btn-font-size: calc(var(--dt-font-size-19) * 1px);--btn-line-height: calc(var(--dt-font-size-19-line-height) * 1px)}.o-btn[size=large]{--btn-padding: 14px var(--dt-spacing-e);--btn-min-block-size: 56px;--btn-font-size: calc(var(--dt-font-size-20) * 1px);--btn-line-height: calc(var(--dt-font-size-20-line-height) * 1px)}
58
- `, w = [
59
- "xsmall",
60
- "small-expressive",
61
- "small-productive",
62
- "medium",
63
- "large"
64
- ], k = [
65
- "primary",
66
- "secondary",
67
- "outline",
68
- "ghost"
69
- ], P = [
70
- "submit",
71
- "button",
72
- "reset",
73
- "menu"
74
- ];
75
- var _ = Object.defineProperty, W = Object.getOwnPropertyDescriptor, s = (i, o, e, r) => {
76
- for (var t = r > 1 ? void 0 : r ? W(o, e) : o, n = i.length - 1, a; n >= 0; n--)
77
- (a = i[n]) && (t = (r ? a(o, e, t) : a(t)) || t);
78
- return r && t && _(o, e, t), t;
79
- };
80
- const d = "pie-button";
81
- class l extends f {
26
+ const s = "pie-button";
27
+ class i extends u {
82
28
  constructor() {
83
29
  super(...arguments), this.size = "medium", this.type = "submit", this.variant = "primary", this.disabled = !1, this.isFullWidth = !1;
84
30
  }
@@ -86,45 +32,45 @@ class l extends f {
86
32
  const {
87
33
  type: o,
88
34
  disabled: e,
89
- isFullWidth: r,
35
+ isFullWidth: n,
90
36
  variant: t,
91
- size: n
37
+ size: r
92
38
  } = this;
93
- return v`
39
+ return g`
94
40
  <button
95
41
  class="o-btn"
96
42
  type=${o}
97
43
  variant=${t}
98
- size=${n}
44
+ size=${r}
99
45
  ?disabled=${e}
100
- ?isFullWidth=${r}>
46
+ ?isFullWidth=${n}>
101
47
  <slot></slot>
102
48
  </button>`;
103
49
  }
104
50
  }
105
- l.styles = h($);
106
- s([
107
- c(),
108
- b(d, w, "medium")
109
- ], l.prototype, "size", 2);
110
- s([
111
- c(),
112
- b(d, P, "submit")
113
- ], l.prototype, "type", 2);
114
- s([
115
- c(),
116
- b(d, k, "primary")
117
- ], l.prototype, "variant", 2);
118
- s([
119
- c({ type: Boolean })
120
- ], l.prototype, "disabled", 2);
121
- s([
122
- c({ type: Boolean })
123
- ], l.prototype, "isFullWidth", 2);
124
- customElements.define(d, l);
51
+ i.styles = h(m);
52
+ d([
53
+ l(),
54
+ b(s, f, "medium")
55
+ ], i.prototype, "size", 2);
56
+ d([
57
+ l(),
58
+ b(s, y, "submit")
59
+ ], i.prototype, "type", 2);
60
+ d([
61
+ l(),
62
+ b(s, x, "primary")
63
+ ], i.prototype, "variant", 2);
64
+ d([
65
+ l({ type: Boolean })
66
+ ], i.prototype, "disabled", 2);
67
+ d([
68
+ l({ type: Boolean })
69
+ ], i.prototype, "isFullWidth", 2);
70
+ customElements.define(s, i);
125
71
  export {
126
- l as PieButton,
127
- w as buttonSizes,
128
- P as buttonTypes,
129
- k as buttonVariants
72
+ i as PieButton,
73
+ f as sizes,
74
+ y as types,
75
+ x as variants
130
76
  };
package/dist/react.js CHANGED
File without changes
File without changes
@@ -1,40 +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", "inverse", "ghost-inverse"];
1
4
  export interface ButtonProps {
2
5
  /**
3
- * the size of the button.
4
- * @default medium
6
+ * (Optional) What size the button should be.
7
+ * @default "medium"
5
8
  */
6
- size: 'xsmall' | 'small-expressive' | 'small-productive' | 'medium' | 'large';
9
+ size: typeof sizes[number];
7
10
  /**
8
- * The html button type to use.
9
- * @default submit
11
+ * (Optional) What type attribute should be applied to the button. For example submit, button or menu.
12
+ * @default "submit"
10
13
  */
11
- type: 'submit' | 'button' | 'reset' | 'menu';
14
+ type: typeof types[number];
12
15
  /**
13
- * the variant of the button.
14
- * @default primary
16
+ * (Optional) What style variant the button should be such as primary, outline or ghost.
17
+ * @default "primary"
15
18
  */
16
- variant: 'primary' | 'secondary' | 'outline' | 'ghost';
19
+ variant: typeof variants[number];
17
20
  /**
18
- * If `true`, the button will be disabled.
21
+ * (Optional) When true, the button element is disabled.
19
22
  * @default false
20
23
  */
21
24
  disabled: boolean;
22
25
  /**
23
- * If `true`, the button will span the full width.
26
+ * (Optional) When true, the button element will occupy the full width of its container.
24
27
  * @default false
25
28
  */
26
29
  isFullWidth: boolean;
27
30
  }
28
- /**
29
- * Button size variants
30
- */
31
- export declare const buttonSizes: Array<ButtonProps['size']>;
32
- /**
33
- * Button style variants
34
- */
35
- export declare const buttonVariants: Array<ButtonProps['variant']>;
36
- /**
37
- * Button type variants
38
- */
39
- export declare const buttonTypes: Array<ButtonProps['type']>;
40
31
  //# sourceMappingURL=defs.d.ts.map
@@ -1 +1 @@
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
+ {"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,mFAAoF,CAAC;AAE1G,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, buttonSizes, buttonTypes, buttonVariants } from './defs';
3
- export { type ButtonProps, buttonSizes, buttonTypes, buttonVariants, };
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;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"}
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;IAG9B,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;IAE3B,MAAM;IAkBN,MAAM,CAAC,MAAM,0BAAqB;CACrC;AAID,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,qBAAqB;QAC3B,CAAC,iBAAiB,CAAC,EAAE,SAAS,CAAC;KAClC;CACJ"}
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-button",
3
- "version": "0.16.1",
3
+ "version": "0.18.0",
4
4
  "description": "PIE design system button built using web components",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
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
- // TODO - Need to update to use the latest focus styling
49
- outline: 2px solid var(--btn-focus);
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-tertiary);
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,43 +116,63 @@
71
116
  }
72
117
 
73
118
  &[variant='ghost'] {
74
- --btn-bg-color: var(--dt-color-container-default);
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');
78
123
  }
79
124
 
125
+ &[variant='inverse'] {
126
+ --btn-bg-color: var(--dt-color-interactive-inverse);
127
+ --btn-text-color: var(--dt-color-content-interactive-secondary);
128
+
129
+ @include button-interactive-states('--dt-color-interactive-inverse');
130
+ }
131
+
132
+ &[variant='ghost-inverse'] {
133
+ --btn-bg-color: transparent;
134
+ --btn-text-color: var(--dt-color-content-interactive-primary);
135
+
136
+ @include button-interactive-states('--dt-color-container-inverse');
137
+ }
138
+
80
139
  // Additional modifiers
81
140
  &[isFullWidth] {
82
141
  inline-size: 100%;
83
142
  }
84
143
 
85
144
  &[disabled] {
86
- --btn-bg-color: var(--dt-color-disabled-01);
87
- --btn-text-color: var(--dt-color-content-disabled);
145
+ --btn-text-color: var(--dt-color-content-disabled) !important;
88
146
 
89
- border: 1px solid var(--dt-color-disabled-01);
90
147
  cursor: not-allowed;
91
- }
92
148
 
93
- &[disabled][variant='ghost'] {
94
- --btn-bg-color: var(--dt-color-container-default);
149
+ // For every variant except ghost and ghost-inverse, set the disabled background color
150
+ &:not([variant='ghost'], [variant='ghost-inverse']) {
151
+ --btn-bg-color: var(--dt-color-disabled-01) !important;
152
+ }
95
153
 
96
- outline: none;
154
+ // For outline variants, set the border to the disabled color
155
+ &[variant='outline'] {
156
+ border-color: var(--dt-color-disabled-01) !important;
157
+ }
97
158
  }
98
159
 
99
160
  &[size='xsmall'] {
100
161
  --btn-padding: 6px var(--dt-spacing-b);
101
- --btn-min-block-size: 32px;
102
162
  --btn-font-size: calc(var(--dt-font-size-14) * 1px);
103
163
  --btn-line-height: calc(var(--dt-font-size-14-line-height) * 1px);
104
164
  }
105
165
 
106
- &[size='small'] {
166
+ &[size='small-expressive'] {
167
+ --btn-padding: 6px var(--dt-spacing-d);
168
+ --btn-font-size: calc(var(--dt-font-size-20) * 1px);
169
+ --btn-line-height: calc(var(--dt-font-size-20-line-height) * 1px);
170
+ }
171
+
172
+ &[size='small-productive'] {
107
173
  --btn-padding: 8px var(--dt-spacing-d);
108
- --btn-min-block-size: 40px;
109
- --btn-font-size: calc(var(--dt-font-size-19) * 1px);
110
- --btn-line-height: calc(var(--dt-font-size-19-line-height) * 1px);
174
+ --btn-font-size: calc(var(--dt-font-size-16) * 1px);
175
+ --btn-line-height: calc(var(--dt-font-size-16-line-height) * 1px);
111
176
  }
112
177
 
113
178
  &[size='medium'] {
@@ -116,7 +181,6 @@
116
181
 
117
182
  &[size='large'] {
118
183
  --btn-padding: 14px var(--dt-spacing-e);
119
- --btn-min-block-size: 56px;
120
184
  --btn-font-size: calc(var(--dt-font-size-20) * 1px);
121
185
  --btn-line-height: calc(var(--dt-font-size-20-line-height) * 1px);
122
186
  }
package/src/defs.ts CHANGED
@@ -1,58 +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', 'inverse', 'ghost-inverse'] as const;
4
+
1
5
  export interface ButtonProps {
2
6
  /**
3
- * the size of the button.
4
- * @default medium
7
+ * (Optional) What size the button should be.
8
+ * @default "medium"
5
9
  */
6
- size: 'xsmall' | 'small-expressive' | 'small-productive' | 'medium' | 'large';
10
+ size: typeof sizes[number];
7
11
  /**
8
- * The html button type to use.
9
- * @default submit
12
+ * (Optional) What type attribute should be applied to the button. For example submit, button or menu.
13
+ * @default "submit"
10
14
  */
11
- type: 'submit' | 'button' | 'reset' | 'menu';
15
+ type: typeof types[number];
12
16
  /**
13
- * the variant of the button.
14
- * @default primary
17
+ * (Optional) What style variant the button should be such as primary, outline or ghost.
18
+ * @default "primary"
15
19
  */
16
- variant: 'primary' | 'secondary' | 'outline' | 'ghost';
20
+ variant: typeof variants[number];
17
21
  /**
18
- * If `true`, the button will be disabled.
22
+ * (Optional) When true, the button element is disabled.
19
23
  * @default false
20
24
  */
21
25
  disabled: boolean;
22
26
  /**
23
- * If `true`, the button will span the full width.
27
+ * (Optional) When true, the button element will occupy the full width of its container.
24
28
  * @default false
25
29
  */
26
30
  isFullWidth: boolean;
27
31
  }
28
-
29
- /**
30
- * Button size variants
31
- */
32
- export const buttonSizes: Array<ButtonProps['size']> = [
33
- 'xsmall',
34
- 'small-expressive',
35
- 'small-productive',
36
- 'medium',
37
- 'large'
38
- ];
39
-
40
- /**
41
- * Button style variants
42
- */
43
- export const buttonVariants: Array<ButtonProps['variant']> = [
44
- 'primary',
45
- 'secondary',
46
- 'outline',
47
- 'ghost',
48
- ];
49
-
50
- /**
51
- * Button type variants
52
- */
53
- export const buttonTypes: Array<ButtonProps['type']> = [
54
- 'submit',
55
- 'button',
56
- 'reset',
57
- 'menu',
58
- ];
package/src/index.ts CHANGED
@@ -3,37 +3,37 @@ import { property } from 'lit/decorators.js';
3
3
  import { validPropertyValues } from '@justeattakeaway/pie-webc-core';
4
4
  import styles from './button.scss?inline';
5
5
  import {
6
- ButtonProps, buttonSizes, buttonTypes, buttonVariants,
6
+ ButtonProps, sizes, types, variants,
7
7
  } from './defs';
8
8
 
9
9
  // Valid values available to consumers
10
10
  export {
11
11
  type ButtonProps,
12
- buttonSizes,
13
- buttonTypes,
14
- buttonVariants,
12
+ sizes,
13
+ types,
14
+ variants,
15
15
  };
16
16
 
17
17
  const componentSelector = 'pie-button';
18
18
 
19
19
  export class PieButton extends LitElement {
20
20
  @property()
21
- @validPropertyValues(componentSelector, buttonSizes, 'medium')
22
- size: ButtonProps['size'] = 'medium';
21
+ @validPropertyValues(componentSelector, sizes, 'medium')
22
+ public size: ButtonProps['size'] = 'medium';
23
23
 
24
24
  @property()
25
- @validPropertyValues(componentSelector, buttonTypes, 'submit')
26
- type: ButtonProps['type'] = 'submit';
25
+ @validPropertyValues(componentSelector, types, 'submit')
26
+ public type: ButtonProps['type'] = 'submit';
27
27
 
28
28
  @property()
29
- @validPropertyValues(componentSelector, buttonVariants, 'primary')
30
- variant: ButtonProps['variant'] = 'primary';
29
+ @validPropertyValues(componentSelector, variants, 'primary')
30
+ public variant: ButtonProps['variant'] = 'primary';
31
31
 
32
32
  @property({ type: Boolean })
33
- disabled = false;
33
+ public disabled = false;
34
34
 
35
35
  @property({ type: Boolean })
36
- isFullWidth = false;
36
+ public isFullWidth = false;
37
37
 
38
38
  render () {
39
39
  const {
@@ -1,13 +1,13 @@
1
1
  import { test, expect } from '@sand4rt/experimental-ct-web';
2
2
  import AxeBuilder from '@axe-core/playwright';
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';
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
5
  import { PieButton } from '@/index';
6
- import { buttonSizes, buttonVariants } from '@/defs';
6
+ import { sizes, variants } from '@/defs';
7
7
 
8
8
  const props: PropObject = {
9
- variant: buttonVariants,
10
- size: buttonSizes,
9
+ variant: variants,
10
+ size: sizes,
11
11
  type: 'button', // Changing the type does not affect the appearance of the button
12
12
  isFullWidth: [true, false],
13
13
  disabled: [true, false],
@@ -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-core/src/test-helpers/defs.ts';
5
+ } from '@justeattakeaway/pie-webc-testing/src/helpers/defs.ts';
7
6
  import {
8
7
  getAllPropCombinations, splitCombinationsByPropertyValue,
9
- } from '@justeattakeaway/pie-webc-core/src/test-helpers/get-all-prop-combos.ts';
8
+ } from '@justeattakeaway/pie-webc-testing/src/helpers/get-all-prop-combos.ts';
10
9
  import {
11
10
  createTestWebComponent,
12
- } from '@justeattakeaway/pie-webc-core/src/test-helpers/rendering.ts';
11
+ } from '@justeattakeaway/pie-webc-testing/src/helpers/rendering.ts';
13
12
  import {
14
13
  WebComponentTestWrapper,
15
- } from '@justeattakeaway/pie-webc-core/src/test-helpers/components/web-component-test-wrapper/WebComponentTestWrapper.ts';
14
+ } from '@justeattakeaway/pie-webc-testing/src/helpers/components/web-component-test-wrapper/WebComponentTestWrapper.ts';
16
15
  import { PieButton } from '@/index';
17
- import { buttonSizes, buttonVariants } from '@/defs';
16
+ import { sizes, variants } from '@/defs';
18
17
 
19
18
  const props: PropObject = {
20
- variant: buttonVariants,
21
- size: buttonSizes,
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,31 +32,35 @@ 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('Component registered in the DOM', async ({ mount }) => {
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 }) => {
47
49
  await Promise.all(componentPropsMatrixByVariant[variant].map(async (combo: WebComponentPropValues) => {
48
50
  const testComponent: WebComponentTestInput = createTestWebComponent(combo, renderTestPieButton);
49
51
  const propKeyValues = `size: ${testComponent.propValues.size}, isFullWidth: ${testComponent.propValues.isFullWidth}, disabled: ${testComponent.propValues.disabled}`;
52
+ const darkMode = variant === 'inverse' || variant === 'ghost-inverse';
50
53
 
51
54
  await mount(
52
55
  WebComponentTestWrapper,
53
56
  {
54
- props: { propKeyValues },
57
+ props: { propKeyValues, darkMode },
55
58
  slots: {
56
- default: testComponent.renderedString.trim(),
59
+ component: testComponent.renderedString.trim(),
57
60
  },
58
61
  },
59
62
  );
60
63
  }));
61
64
 
62
- await percySnapshot(page, `PIE Button - Variant: ${variant}`, getLitPercyOptions());
65
+ await percySnapshot(page, `PIE Button - Variant: ${variant}`);
63
66
  }));