@justeattakeaway/pie-button 0.47.7 → 0.48.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
@@ -1,4 +1,4 @@
1
- import { ComponentDefaultPropsGeneric } from '@justeattakeaway/pie-webc-core';
1
+ import { ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
2
2
  import type { CSSResult } from 'lit';
3
3
  import type { FormControlInterface } from '@justeattakeaway/pie-webc-core';
4
4
  import type { GenericConstructor } from '@justeattakeaway/pie-webc-core';
@@ -84,7 +84,7 @@ export declare interface ButtonProps {
84
84
  responsiveSize?: typeof responsiveSizes[number];
85
85
  }
86
86
 
87
- export declare type DefaultProps = ComponentDefaultPropsGeneric<ButtonProps, 'size' | 'type' | 'variant' | 'iconPlacement' | 'disabled' | 'isLoading' | 'isFullWidth' | 'isResponsive'>;
87
+ export declare type DefaultProps = ComponentDefaultProps<ButtonProps, 'size' | 'type' | 'variant' | 'iconPlacement' | 'disabled' | 'isFullWidth' | 'isLoading' | 'isResponsive'>;
88
88
 
89
89
  export declare const defaultProps: DefaultProps;
90
90
 
package/dist/react.js CHANGED
@@ -3,8 +3,8 @@ import { createComponent as e } from "@lit/react";
3
3
  import { PieButton as o } from "./index.js";
4
4
  import { defaultProps as l, formEncodingtypes as y, formMethodTypes as B, formTargetTypes as d, iconPlacements as g, responsiveSizes as v, sizes as T, types as x, variants as z } from "./index.js";
5
5
  import "lit";
6
+ import "lit/directives/class-map.js";
6
7
  import "lit/decorators.js";
7
- import "lit/directives/if-defined.js";
8
8
  import "@justeattakeaway/pie-webc-core";
9
9
  import "@justeattakeaway/pie-spinner";
10
10
  const r = e({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-button",
3
- "version": "0.47.7",
3
+ "version": "0.48.0",
4
4
  "description": "PIE design system button built using web components",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -48,8 +48,8 @@
48
48
  "dist/*.js"
49
49
  ],
50
50
  "dependencies": {
51
- "@justeattakeaway/pie-spinner": "0.6.5",
52
- "@justeattakeaway/pie-webc-core": "0.23.0",
51
+ "@justeattakeaway/pie-spinner": "0.6.6",
52
+ "@justeattakeaway/pie-webc-core": "0.24.0",
53
53
  "element-internals-polyfill": "1.3.11"
54
54
  }
55
55
  }
package/src/button.scss CHANGED
@@ -1,14 +1,13 @@
1
1
  @use '@justeattakeaway/pie-css/scss' as p;
2
-
3
- $breakpoint-wide: 768px;
2
+ @use '@justeattakeaway/pie-css/scss/settings' as *;
4
3
 
5
4
  /**
6
5
  * Mixin for adding the responsive behaviour.
7
6
  * Takes in the the particular settings for the wide breakpoint.
8
7
  */
9
8
  @mixin responsive-wide {
10
- &[isResponsive] {
11
- @media (min-width: $breakpoint-wide) {
9
+ &.o-btn--responsive {
10
+ @include media('>md') {
12
11
  @content;
13
12
  }
14
13
  }
@@ -94,12 +93,14 @@ $breakpoint-wide: 768px;
94
93
  // used to specify whether the button should be full width or not
95
94
  inline-size: var(--btn-inline-size);
96
95
 
97
- // Variant
98
- &[variant='primary'] {
96
+ // ************************
97
+ // Button Variant Modifiers
98
+ // ************************
99
+ &.o-btn--primary {
99
100
  @include p.button-interactive-states('--dt-color-interactive-brand');
100
101
 
101
- &[size='xsmall'],
102
- &[size='small-productive'] {
102
+ &.o-btn--xsmall,
103
+ &.o-btn--small-productive {
103
104
  /**
104
105
  * Where the font-size is smaller,
105
106
  * update the button backgrounds so that the text is accessible
@@ -108,16 +109,27 @@ $breakpoint-wide: 768px;
108
109
 
109
110
  @include p.button-interactive-states('--dt-color-interactive-primary', 'inverse');
110
111
  }
112
+
113
+ // This is to handle the background colour change getting overridden above, but then being put in responsive mode
114
+ // can't use :not for this unfortunately, as then the smaller narrow state would lose its background colour too
115
+ &.o-btn--xsmall.o-btn--expressive,
116
+ &.o-btn--small-productive {
117
+ @include responsive-wide {
118
+ --btn-bg-color: var(--dt-color-interactive-brand);
119
+
120
+ @include p.button-interactive-states('--dt-color-interactive-brand');
121
+ }
122
+ }
111
123
  }
112
124
 
113
- &[variant='secondary'] {
125
+ &.o-btn--secondary {
114
126
  --btn-bg-color: var(--dt-color-interactive-secondary);
115
127
  --btn-text-color: var(--dt-color-content-interactive-secondary);
116
128
 
117
129
  @include p.button-interactive-states('--dt-color-interactive-secondary');
118
130
  }
119
131
 
120
- &[variant='outline'] {
132
+ &.o-btn--outline {
121
133
  --btn-bg-color: transparent;
122
134
  --btn-text-color: var(--dt-color-content-interactive-secondary);
123
135
 
@@ -128,7 +140,7 @@ $breakpoint-wide: 768px;
128
140
  @include p.button-interactive-states('--dt-color-black', 'transparent');
129
141
  }
130
142
 
131
- &[variant='ghost'] {
143
+ &.o-btn--ghost {
132
144
  --btn-bg-color: transparent;
133
145
  --btn-text-color: var(--dt-color-content-link);
134
146
 
@@ -137,15 +149,15 @@ $breakpoint-wide: 768px;
137
149
  @include p.button-interactive-states('--dt-color-black', 'transparent');
138
150
  }
139
151
 
140
- &[variant='inverse'] {
152
+ &.o-btn--inverse {
141
153
  --btn-bg-color: var(--dt-color-interactive-inverse);
142
154
  --btn-text-color: var(--dt-color-content-interactive-secondary);
143
155
 
144
156
  @include p.button-interactive-states('--dt-color-interactive-inverse');
145
157
  }
146
158
 
147
- &[variant='ghost-inverse'],
148
- &[variant='outline-inverse'] {
159
+ &.o-btn--ghost-inverse,
160
+ &.o-btn--outline-inverse {
149
161
  --btn-bg-color: transparent;
150
162
  --btn-text-color: var(--dt-color-content-interactive-primary);
151
163
 
@@ -154,17 +166,17 @@ $breakpoint-wide: 768px;
154
166
  @include p.button-interactive-states('--dt-color-container-default', 'transparent');
155
167
  }
156
168
 
157
- &[variant='outline-inverse']:not([disabled]) {
169
+ &.o-btn--outline-inverse:not([disabled]) {
158
170
  border: 1px solid var(--dt-color-border-strong);
159
171
  }
160
172
 
161
- &[variant='destructive'] {
173
+ &.o-btn--destructive {
162
174
  --btn-bg-color: var(--dt-color-support-error);
163
175
 
164
176
  @include p.button-interactive-states('--dt-color-support-error');
165
177
  }
166
178
 
167
- &[variant='destructive-ghost'] {
179
+ &.o-btn--destructive-ghost {
168
180
  --btn-bg-color: transparent;
169
181
  --btn-text-color: var(--dt-color-content-interactive-error);
170
182
 
@@ -173,65 +185,80 @@ $breakpoint-wide: 768px;
173
185
  @include p.button-interactive-states('--dt-color-black', 'transparent');
174
186
  }
175
187
 
176
- // Additional modifiers
177
- &[isFullWidth] {
178
- --btn-inline-size: 100%;
179
- }
180
-
181
- &[disabled] {
182
- --btn-text-color: var(--dt-color-content-disabled) !important;
183
-
184
- cursor: not-allowed;
185
-
186
- // For every variant (except ghost variants) set the disabled background color
187
- &:not([variant='ghost'], [variant='ghost-inverse'], [variant='destructive-ghost']) {
188
- --btn-bg-color: var(--dt-color-disabled-01) !important;
189
- }
190
-
191
- // For outline variants, set the border to the disabled color
192
- &[variant='outline'] {
193
- border-color: var(--dt-color-disabled-01) !important;
194
- }
195
- }
196
-
197
- &[size='xsmall'] {
188
+ // *********************
189
+ // Button Size Modifiers
190
+ // *********************
191
+ &.o-btn--xsmall {
198
192
  @include button-size(xsmall);
193
+
199
194
  @include responsive-wide {
200
195
  // productive is the default size when responsive is enabled
201
196
  @include button-size(small-productive);
202
197
 
203
- &[responsiveSize='expressive'] {
198
+ &.o-btn--expressive {
204
199
  @include button-size(small-expressive);
205
200
  }
206
201
  }
207
202
  }
208
203
 
209
- &[size='small-expressive'] {
204
+ &.o-btn--small-expressive {
210
205
  @include button-size(small-expressive);
206
+
211
207
  @include responsive-wide {
212
208
  @include button-size(medium);
213
209
  }
214
210
  }
215
211
 
216
- &[size='small-productive'] {
212
+ &.o-btn--small-productive {
217
213
  @include button-size(small-productive);
214
+
218
215
  @include responsive-wide {
219
216
  @include button-size(medium);
220
217
  }
221
218
  }
222
219
 
223
- &[size='medium'] {
220
+ &.o-btn--medium {
224
221
  @include button-size(medium);
222
+
225
223
  @include responsive-wide {
226
224
  @include button-size(large);
227
225
  }
228
226
  }
229
227
 
230
- &[size='large'] {
228
+ &.o-btn--large {
231
229
  @include button-size(large);
232
230
  }
233
231
 
234
- &[isLoading] {
232
+ // ******************************
233
+ // Additional component modifiers
234
+ // ******************************
235
+ &.o-btn--fullWidth {
236
+ --btn-inline-size: 100%;
237
+ }
238
+
239
+ // **************
240
+ // Disabled state
241
+ // **************
242
+ &[disabled] {
243
+ --btn-text-color: var(--dt-color-content-disabled) !important;
244
+
245
+ cursor: not-allowed;
246
+
247
+ // For every variant (except ghost variants) set the disabled background color
248
+ &:not(.o-btn--ghost, .o-btn--ghost-inverse, .o-btn--destructive-ghost) {
249
+ --btn-bg-color: var(--dt-color-disabled-01) !important;
250
+ }
251
+
252
+ // For outline variants, set the border to the disabled color
253
+ &.o-btn--outline {
254
+ border-color: var(--dt-color-disabled-01) !important;
255
+ }
256
+ }
257
+
258
+ // *************
259
+ // Loading state
260
+ // *************
261
+ &.is-loading {
235
262
  & > *:not(pie-spinner) {
236
263
  visibility: hidden;
237
264
  }
@@ -241,6 +268,9 @@ $breakpoint-wide: 768px;
241
268
  }
242
269
  }
243
270
 
271
+ // ************
272
+ // Focus styles
273
+ // ************
244
274
  &:focus-visible {
245
275
  @include p.focus;
246
276
  }
package/src/defs.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type ComponentDefaultPropsGeneric } from '@justeattakeaway/pie-webc-core';
1
+ import { type ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
2
2
 
3
3
  export const sizes = ['xsmall', 'small-productive', 'small-expressive', 'medium', 'large'] as const;
4
4
  export const responsiveSizes = ['productive', 'expressive'] as const;
@@ -101,7 +101,7 @@ export interface ButtonProps {
101
101
  responsiveSize?: typeof responsiveSizes[number];
102
102
  }
103
103
 
104
- export type DefaultProps = ComponentDefaultPropsGeneric<ButtonProps, 'size' | 'type' | 'variant' | 'iconPlacement' | 'disabled' | 'isLoading' | 'isFullWidth' | 'isResponsive'>;
104
+ export type DefaultProps = ComponentDefaultProps<ButtonProps, 'size' | 'type' | 'variant' | 'iconPlacement' | 'disabled' | 'isFullWidth' | 'isLoading' | 'isResponsive'>;
105
105
 
106
106
  export const defaultProps: DefaultProps = {
107
107
  size: 'medium',
package/src/index.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  LitElement, html, unsafeCSS, nothing, PropertyValues, TemplateResult,
3
3
  } from 'lit';
4
+ import { classMap } from 'lit/directives/class-map.js';
4
5
  import { property } from 'lit/decorators.js';
5
- import { ifDefined } from 'lit/directives/if-defined.js';
6
6
  import { validPropertyValues, defineCustomElement, FormControlMixin } from '@justeattakeaway/pie-webc-core';
7
7
  import {
8
8
  ButtonProps, sizes, types, variants, iconPlacements, defaultProps,
@@ -226,18 +226,22 @@ export class PieButton extends FormControlMixin(LitElement) implements ButtonPro
226
226
  responsiveSize,
227
227
  } = this;
228
228
 
229
+ const classes = {
230
+ 'o-btn': true,
231
+ 'o-btn--fullWidth': isFullWidth,
232
+ 'o-btn--responsive': isResponsive,
233
+ [`o-btn--${responsiveSize}`]: Boolean(isResponsive && responsiveSize),
234
+ [`o-btn--${variant}`]: true,
235
+ [`o-btn--${size}`]: true,
236
+ 'is-loading': isLoading,
237
+ };
238
+
229
239
  return html`
230
240
  <button
231
241
  @click=${this._handleClick}
232
- class="o-btn"
242
+ class=${classMap(classes)}
233
243
  type=${type || 'submit'}
234
- variant=${variant || 'primary'}
235
- size=${size || 'medium'}
236
- responsiveSize=${ifDefined(responsiveSize)}
237
- ?disabled=${disabled}
238
- ?isFullWidth=${isFullWidth}
239
- ?isResponsive=${isResponsive}
240
- ?isLoading=${isLoading}>
244
+ ?disabled=${disabled}>
241
245
  ${isLoading ? this.renderSpinner() : nothing}
242
246
  ${iconPlacement === 'leading' ? html`<slot name="icon"></slot>` : nothing}
243
247
  <slot></slot>