@justeattakeaway/pie-button 0.36.0 → 0.37.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.
package/dist/react.d.ts CHANGED
@@ -2,7 +2,7 @@ import type { CSSResult } from 'lit';
2
2
  import type { LitElement } from 'lit';
3
3
  import type { PropertyValues } from 'lit';
4
4
  import type { ReactWebComponent } from '@lit-labs/react';
5
- import type { TemplateResult } from 'lit-html';
5
+ import type { TemplateResult } from 'lit';
6
6
 
7
7
  export declare interface ButtonProps {
8
8
  /**
@@ -121,6 +121,12 @@ declare class PieButton_2 extends LitElement implements ButtonProps {
121
121
  private _simulateNativeButtonClick;
122
122
  private _handleClick;
123
123
  private _handleFormKeyDown;
124
+ /**
125
+ * Template for the loading state
126
+ *
127
+ * @private
128
+ */
129
+ private renderSpinner;
124
130
  render(): TemplateResult<1>;
125
131
  focus(): void;
126
132
  static styles: CSSResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-button",
3
- "version": "0.36.0",
3
+ "version": "0.37.0",
4
4
  "description": "PIE design system button built using web components",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -28,10 +28,7 @@
28
28
  "author": "Just Eat Takeaway.com - Design System Team",
29
29
  "license": "Apache-2.0",
30
30
  "devDependencies": {
31
- "@justeat/pie-design-tokens": "5.8.2",
32
- "@justeattakeaway/pie-components-config": "0.4.0",
33
- "@justeattakeaway/pie-css": "0.7.0",
34
- "@justeattakeaway/pie-webc-core": "0.11.0"
31
+ "@justeattakeaway/pie-components-config": "0.4.0"
35
32
  },
36
33
  "volta": {
37
34
  "extends": "../../../package.json"
@@ -40,6 +37,8 @@
40
37
  "dist/*.js"
41
38
  ],
42
39
  "dependencies": {
40
+ "@justeattakeaway/pie-spinner": "0.2.1",
41
+ "@justeattakeaway/pie-webc-core": "0.11.0",
43
42
  "element-internals-polyfill": "1.3.8"
44
43
  }
45
44
  }
package/src/button.scss CHANGED
@@ -6,27 +6,6 @@
6
6
  box-sizing: border-box;
7
7
  }
8
8
 
9
- /**
10
- * Shorthand mixin for updating the HSL custom properties for the loading spinner.
11
- * Takes in the name of the color to be split into its HSL components.
12
- */
13
- @mixin spinner-base-colors($color) {
14
- --spinner-base-color-h: var(#{$color}-h);
15
- --spinner-base-color-s: var(#{$color}-s);
16
- --spinner-base-color-l: var(#{$color}-l);
17
- }
18
-
19
- // Spin animation for loading state
20
- @keyframes rotate360 {
21
- from {
22
- transform: rotate(0deg);
23
- }
24
-
25
- to {
26
- transform: rotate(360deg);
27
- }
28
- }
29
-
30
9
  // Base button styles
31
10
  .o-btn {
32
11
  // Custom Property Declarations
@@ -57,26 +36,6 @@
57
36
  // Set icon size to the medium button icon size (the default state)
58
37
  --btn-icon-size: 24px;
59
38
 
60
- // Spinner size defaults - currently set for the medium button size (the default state)
61
- --spinner-size-s: 20px;
62
- --spinner-size-m: 24px;
63
- --spinner-border-width-s: 2.5px;
64
- --spinner-border-width-m: 3px;
65
- --spinner-size: var(--spinner-size-m);
66
- --spinner-border-width: var(--spinner-border-width-m);
67
-
68
- // Spinner colors - currently set for the primary button styles
69
- @include spinner-base-colors(--dt-color-content-interactive-primary);
70
-
71
- --spinner-left-color-opacity: 0.35;
72
- --spinner-left-color: hsl(var(--spinner-base-color-h), var(--spinner-base-color-s), var(--spinner-base-color-l), var(--spinner-left-color-opacity));
73
- --spinner-right-color: hsl(var(--spinner-base-color-h), var(--spinner-base-color-s), var(--spinner-base-color-l), 1);
74
-
75
- // Spinner animations
76
- --spinner-animation-duration: 1.15s;
77
- --spinner-animation-timing-function: linear;
78
- --spinner-animation-iteration-count: infinite;
79
-
80
39
  position: relative;
81
40
  display: flex;
82
41
  gap: var(--dt-spacing-b);
@@ -121,7 +80,6 @@
121
80
  --btn-text-color: var(--dt-color-content-interactive-secondary);
122
81
 
123
82
  @include p.button-interactive-states('--dt-color-interactive-secondary');
124
- @include spinner-base-colors('--dt-color-content-interactive-secondary');
125
83
  }
126
84
 
127
85
  &[variant='outline'] {
@@ -133,7 +91,6 @@
133
91
  // use black as the background color for hover and inverse,
134
92
  // as this variant uses a shade of transparent black showing through the container background
135
93
  @include p.button-interactive-states('--dt-color-black', 'transparent');
136
- @include spinner-base-colors('--dt-color-content-interactive-secondary');
137
94
  }
138
95
 
139
96
  &[variant='ghost'] {
@@ -143,7 +100,6 @@
143
100
  // use black as the background color for hover and inverse,
144
101
  // as this variant uses a shade of transparent black showing through the container background
145
102
  @include p.button-interactive-states('--dt-color-black', 'transparent');
146
- @include spinner-base-colors('--dt-color-content-interactive-secondary');
147
103
  }
148
104
 
149
105
  &[variant='inverse'] {
@@ -151,7 +107,6 @@
151
107
  --btn-text-color: var(--dt-color-content-interactive-secondary);
152
108
 
153
109
  @include p.button-interactive-states('--dt-color-interactive-inverse');
154
- @include spinner-base-colors('--dt-color-content-interactive-secondary');
155
110
  }
156
111
 
157
112
  &[variant='ghost-inverse'],
@@ -181,7 +136,6 @@
181
136
  // use black as the background color for hover and inverse,
182
137
  // as this variant uses a shade of transparent black showing through the container background
183
138
  @include p.button-interactive-states('--dt-color-black', 'transparent');
184
- @include spinner-base-colors('--dt-color-content-interactive-secondary');
185
139
  }
186
140
 
187
141
  // Additional modifiers
@@ -211,16 +165,12 @@
211
165
  --btn-font-size: #{p.font-size(--dt-font-size-14)};
212
166
  --btn-line-height: calc(var(--dt-font-size-14-line-height) * 1px);
213
167
  --btn-icon-size: 16px;
214
- --spinner-size: var(--spinner-size-s);
215
- --spinner-border-width: var(--spinner-border-width-s);
216
168
  }
217
169
 
218
170
  &[size='small-expressive'],
219
171
  &[size='small-productive'] {
220
172
  --btn-height: var(--btn-height--small);
221
173
  --btn-icon-size: 20px;
222
- --spinner-size: var(--spinner-size-s);
223
- --spinner-border-width: var(--spinner-border-width-s);
224
174
  }
225
175
 
226
176
  &[size='small-expressive'] {
@@ -244,34 +194,15 @@
244
194
  --btn-padding: 14px var(--dt-spacing-e);
245
195
  --btn-font-size: #{p.font-size(--dt-font-size-20)};
246
196
  --btn-line-height: calc(var(--dt-font-size-20-line-height) * 1px);
247
- --spinner-size: var(--spinner-size-m);
248
- --spinner-border-width: var(--spinner-border-width-m);
249
197
  }
250
198
 
251
199
  &[isLoading] {
252
- &:before {
253
- content: '';
254
-
255
- // Centre the spinner over the top of the button text
256
- position: absolute;
257
- left: 50%;
258
- top: 50%;
259
- translate: -50% -50%;
260
-
261
- height: var(--spinner-size);
262
- width: var(--spinner-size);
263
- display: block;
264
- background-color: transparent;
265
- border-radius: 50%;
266
- border-color: var(--spinner-left-color) var(--spinner-right-color) var(--spinner-right-color) var(--spinner-left-color);
267
- border-width: var(--spinner-border-width);
268
- border-style: solid;
269
- will-change: transform;
270
- animation: rotate360 var(--spinner-animation-duration) var(--spinner-animation-timing-function) var(--spinner-animation-iteration-count);
200
+ & > *:not(pie-spinner) {
201
+ visibility: hidden;
271
202
  }
272
203
 
273
- & > * {
274
- visibility: hidden;
204
+ pie-spinner {
205
+ position: absolute;
275
206
  }
276
207
  }
277
208
 
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import {
2
- LitElement, html, unsafeCSS, nothing, PropertyValues,
2
+ LitElement, html, unsafeCSS, nothing, PropertyValues, TemplateResult,
3
3
  } from 'lit';
4
4
  import { property } from 'lit/decorators.js';
5
5
  import { validPropertyValues, defineCustomElement } from '@justeattakeaway/pie-webc-core';
@@ -8,6 +8,7 @@ import {
8
8
  } from './defs';
9
9
  import styles from './button.scss?inline';
10
10
  import 'element-internals-polyfill';
11
+ import '@justeattakeaway/pie-spinner';
11
12
 
12
13
  // Valid values available to consumers
13
14
  export * from './defs';
@@ -196,6 +197,23 @@ export class PieButton extends LitElement implements ButtonProps {
196
197
  this._handleClick();
197
198
  };
198
199
 
200
+ /**
201
+ * Template for the loading state
202
+ *
203
+ * @private
204
+ */
205
+ private renderSpinner (): TemplateResult {
206
+ const spinnerSize = this.size.includes('small') ? 's' : 'm'; // includes("small") matches for any small size value and xsmall
207
+ const inverseVariants: Array<ButtonProps['variant']> = ['primary', 'destructive', 'outline-inverse', 'ghost-inverse'];
208
+ const spinnerVariant = inverseVariants.includes(this.variant) ? 'inverse' : 'secondary';
209
+
210
+ return html`
211
+ <pie-spinner
212
+ size="${spinnerSize}"
213
+ variant="${spinnerVariant}"
214
+ </pie-spinner>`;
215
+ }
216
+
199
217
  render () {
200
218
  const {
201
219
  type,
@@ -217,6 +235,7 @@ export class PieButton extends LitElement implements ButtonProps {
217
235
  ?disabled=${disabled}
218
236
  ?isFullWidth=${isFullWidth}
219
237
  ?isLoading=${isLoading}>
238
+ ${isLoading ? this.renderSpinner() : nothing}
220
239
  ${iconPlacement === 'leading' ? html`<slot name="icon"></slot>` : nothing}
221
240
  <slot></slot>
222
241
  ${iconPlacement === 'trailing' ? html`<slot name="icon"></slot>` : nothing}