@justeattakeaway/pie-button 0.3.0 → 0.4.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.
@@ -0,0 +1,7 @@
1
+ @justeattakeaway/pie-button:build: cache hit, replaying output 4b675d127813f9f5
2
+ @justeattakeaway/pie-button:build: vite v4.0.4 building for production...
3
+ @justeattakeaway/pie-button:build: transforming...
4
+ @justeattakeaway/pie-button:build: ✓ 4 modules transformed.
5
+ @justeattakeaway/pie-button:build: rendering chunks...
6
+ @justeattakeaway/pie-button:build: computing gzip size...
7
+ @justeattakeaway/pie-button:build: dist/pie-button.js 6.70 kB │ gzip: 2.18 kB
package/CHANGELOG.md CHANGED
@@ -1,29 +1,46 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [Changed] - Set TSconfig target to ES6 to allow modern syntax such as property accessors ([#171](https://github.com/justeattakeaway/pie/pull/171)) by [@jamieomaguire](https://github.com/jamieomaguire)
8
+
9
+ - [Added] Create decorator for validating property values ([#171](https://github.com/justeattakeaway/pie/pull/171)) by [@jamieomaguire](https://github.com/jamieomaguire)
10
+
11
+ - [Added] - `variant` property to decide how we style the button ([#171](https://github.com/justeattakeaway/pie/pull/171)) by [@jamieomaguire](https://github.com/jamieomaguire)
12
+
13
+ - [Added] - Lit `classmap` directive to handle conditional css class logic and rendering ([#171](https://github.com/justeattakeaway/pie/pull/171)) by [@jamieomaguire](https://github.com/jamieomaguire)
14
+
15
+ - [Changed] - Refactored props to include validation based on enums and add console errors for invalid values ([#171](https://github.com/justeattakeaway/pie/pull/171)) by [@jamieomaguire](https://github.com/jamieomaguire)
16
+
17
+ - [Changed] - Renamed `actionType` property to `type` ([#171](https://github.com/justeattakeaway/pie/pull/171)) by [@jamieomaguire](https://github.com/jamieomaguire)
18
+
3
19
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
4
20
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
5
21
 
6
- v0.3.0
7
- ---------------------
8
- *January 24, 2023*
22
+ ## v0.3.0
23
+
24
+ _January 24, 2023_
9
25
 
10
26
  ### Added
27
+
11
28
  - Button default styling (medium).
12
29
  - JET font family to html file.
13
30
 
31
+ ## v0.2.0
14
32
 
15
- v0.2.0
16
- ---------------------
17
- *January 23, 2023*
33
+ _January 23, 2023_
18
34
 
19
35
  ### Added
36
+
20
37
  - `actionType` property mapped to `type` attribute.
21
38
 
39
+ ## v0.1.0
22
40
 
23
- v0.1.0
24
- ---------------------
25
- *January 19, 2023*
41
+ _January 19, 2023_
26
42
 
27
43
  ### Added
44
+
28
45
  - Basic button using Lit
29
46
  - Initial TypeScript and Vite config
@@ -0,0 +1,10 @@
1
+ declare module '*.scss' {
2
+ const content: Record<string, string>;
3
+ export default content;
4
+ }
5
+
6
+
7
+ declare module '*.scss?inline' {
8
+ const content: Record<string, string>;
9
+ export default content;
10
+ }
@@ -0,0 +1,59 @@
1
+ import { unsafeCSS as u, LitElement as g, html as f } from "lit";
2
+ import { classMap as m } from "lit/directives/class-map.js";
3
+ import { property as c, customElement as h } from "lit/decorators.js";
4
+ const v = `@charset "UTF-8";.o-btn--icon{background-color:transparent;background-repeat:no-repeat;border:0;direction:ltr;display:block;overflow:hidden;text-align:left;text-indent:-999em}.o-btn--icon br{display:none}@keyframes skeleton-gradient{0%{background-position:100% 50%}to{background-position:0% 50%}}@keyframes spin{0%{transform:rotate(0)}to{transform:rotate(359deg)}}.c-spinner-wrapper{position:absolute;right:0}.c-spinner{border:3px solid #f36805;border-top:3px solid rgba(243,109,0,.2);border-right:3px solid rgba(243,109,0,.2)}.c-spinner{margin-right:20px;border-radius:50%;animation:spin 1s linear 0s infinite;width:20px;height:20px}.c-spinner{margin:0 auto;position:absolute;left:calc(50% - 10px);top:calc(50% - 10px)}.o-btn{display:inline-block;vertical-align:middle;font-size:20px;font-size:1.25rem;line-height:1.4;cursor:pointer;margin:0;padding:10px 24px;text-align:center;font-weight:700;background-color:#f36805;border-radius:50rem;border:1px solid transparent;user-select:none;color:#fff;text-decoration:none}.o-btn:focus{box-shadow:0 0 0 2px #4996fd}.o-btn:hover{background-color:#df5f05}.o-btn:active{background-color:#b74e04}.o-btn:hover:not(.o-btn--link),.o-btn:active:not(.o-btn--link){outline:0}.o-btn,.o-btn:hover,.o-btn:active,.o-btn:focus,.o-btn:visited{text-decoration:none}p+.o-btn{margin-top:16px}.o-btn .note{display:none}@media (min-width: 48em){.o-btn .note{display:block}}.o-btn[type=submit]{margin-top:16px}.o-btn--primary{background-color:#f36805}.o-btn--primary,.o-btn--primary:link,.o-btn--primary:visited{color:#fff}.o-btn--primary:hover,.o-btn--primary:active,.o-btn--primary:focus{color:#fff}.o-btn--primary:hover{background-color:#df5f05}.o-btn--primary:active,.o-btn--primary.o-btn--loading{background-color:#b74e04}.o-btn--primary .c-spinner{border:3px solid #fff;border-top:3px solid rgba(255,255,255,.35);border-right:3px solid rgba(255,255,255,.35)}.o-btn--primary.o-btn--sizeSmall,.o-btn--primary.o-btn--sizeXSmall{background-color:#262626}.o-btn--primary.o-btn--sizeSmall:hover,.o-btn--primary.o-btn--sizeXSmall:hover{background-color:#3a3a3a}.o-btn--primary.o-btn--sizeSmall:active,.o-btn--primary.o-btn--sizeSmall.o-btn--loading,.o-btn--primary.o-btn--sizeXSmall:active,.o-btn--primary.o-btn--sizeXSmall.o-btn--loading{background-color:#595959}.o-btn--secondary{background-color:#f5f3f1;color:#242e30}.o-btn--secondary:hover,.o-btn--secondary:active,.o-btn--secondary:focus{color:#242e30}.o-btn--secondary:hover{background-color:#ede9e5}.o-btn--secondary:active,.o-btn--secondary.o-btn--loading{background-color:#dcd4cd}.o-btn--secondary .c-spinner{border:3px solid #242e30;border-top:3px solid rgba(36,46,48,.35);border-right:3px solid rgba(36,46,48,.35)}.o-btn--outline{background-color:transparent;color:#303d3f;border-color:#efedea}.o-btn--outline:hover,.o-btn--outline:active,.o-btn--outline:focus{color:#303d3f}.o-btn--outline:hover{background-color:#f5f5f5}.o-btn--outline:active,.o-btn--outline.o-btn--loading{background-color:#e0e0e0}.o-btn--outline .c-spinner{border:3px solid #303d3f;border-top:3px solid rgba(48,61,63,.35);border-right:3px solid rgba(48,61,63,.35)}.o-btn--ghost{background-color:transparent;color:#242e30}.o-btn--ghost:hover,.o-btn--ghost:active,.o-btn--ghost:focus{color:#242e30}.o-btn--ghost:hover{background-color:#f5f5f5}.o-btn--ghost:active,.o-btn--ghost.o-btn--loading{background-color:#e0e0e0}.o-btn--ghost .c-spinner{border:3px solid #242e30;border-top:3px solid rgba(36,46,48,.35);border-right:3px solid rgba(36,46,48,.35)}.o-btn--sizeLarge{padding:14px 24px}.o-btn--sizeSmall{font-size:16px;font-size:1rem;line-height:1.5;padding:8px 16px}.o-btn--sizeXSmall{font-size:14px;font-size:.875rem;line-height:1.43;padding:6px 8px}.o-btn--icon{background-color:transparent;padding:0}.o-btn--icon:hover{background-color:transparent}input[type=submit].o-btn--block,input[type=reset].o-btn--block,input[type=button].o-btn--block{width:100%}.o-btn--fullWidth{display:block;width:100%}.o-btn--fullWidth+.o-btn--fullWidth{margin-top:8px}.o-btn--disabled,.o-btn.disabled,.o-btn.is-disabled,.o-btn[disabled]{cursor:not-allowed;color:#8c999b}.o-btn--disabled,.o-btn--disabled:hover,.o-btn.disabled,.o-btn.disabled:hover,.o-btn.is-disabled,.o-btn.is-disabled:hover,.o-btn[disabled],.o-btn[disabled]:hover{background-color:#efedea;color:#8c999b}.o-btn--disabled.o-btn--link,.o-btn.disabled.o-btn--link,.o-btn.is-disabled.o-btn--link,.o-btn[disabled].o-btn--link{background-color:transparent}.o-btn--link{border:0;background-color:transparent;padding:0;margin:0;color:#242e30;font-weight:700;text-decoration:underline}.o-btn--link:hover{cursor:pointer;color:#1b2324;background-color:transparent}.o-btn--link:active,.o-btn--link:focus{color:#0a0c0d;background-color:transparent}.o-btn--link .c-spinner{border:3px solid #242e30;border-top:3px solid rgba(36,46,48,.35);border-right:3px solid rgba(36,46,48,.35)}
5
+ `, p = (o, r) => function(t, e) {
6
+ const n = `_${e}`;
7
+ Object.defineProperty(t, e, {
8
+ get() {
9
+ return t[n];
10
+ },
11
+ set(i) {
12
+ const b = t[n];
13
+ o.includes(i) ? t[n] = i : (console.error(
14
+ `[pie-button] Invalid value "${i}" provided for property "${e}".`,
15
+ `Must be one of: ${o.join(" | ")}.`,
16
+ `Falling back to default value: "${r}"`
17
+ ), t[n] = r), this.requestUpdate(e, b);
18
+ }
19
+ });
20
+ };
21
+ var l = /* @__PURE__ */ ((o) => (o.PRIMARY = "primary", o.SECONDARY = "secondary", o.OUTLINE = "outline", o.GHOST = "ghost", o))(l || {}), d = /* @__PURE__ */ ((o) => (o.SUBMIT = "submit", o.BUTTON = "button", o.RESET = "reset", o.MENU = "menu", o))(d || {}), y = Object.defineProperty, x = Object.getOwnPropertyDescriptor, s = (o, r, t, e) => {
22
+ for (var n = e > 1 ? void 0 : e ? x(r, t) : r, i = o.length - 1, b; i >= 0; i--)
23
+ (b = o[i]) && (n = (e ? b(r, t, n) : b(n)) || n);
24
+ return e && n && y(r, t, n), n;
25
+ };
26
+ let a = class extends g {
27
+ constructor() {
28
+ super(...arguments), this.type = d.SUBMIT, this.variant = l.PRIMARY;
29
+ }
30
+ render() {
31
+ const { type: o, variant: r } = this, t = m({
32
+ ["o-btn"]: !0,
33
+ [`o-btn--${r}`]: r
34
+ });
35
+ return f`
36
+ <button
37
+ class="${t}"
38
+ type=${o}>
39
+ I'm a PIE button
40
+ </button>`;
41
+ }
42
+ };
43
+ a.styles = u(v);
44
+ s([
45
+ c(),
46
+ p(Object.values(d), d.SUBMIT)
47
+ ], a.prototype, "type", 2);
48
+ s([
49
+ c(),
50
+ p(Object.values(l), l.PRIMARY)
51
+ ], a.prototype, "variant", 2);
52
+ a = s([
53
+ h("pie-button")
54
+ ], a);
55
+ export {
56
+ d as BUTTON_TYPE,
57
+ l as BUTTON_VARIANT,
58
+ a as PieButton
59
+ };
package/index.html CHANGED
@@ -1,37 +1,42 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
- <head>
3
+
4
+ <head>
4
5
  <meta charset="UTF-8" />
5
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <link rel="stylesheet" href="https://unpkg.com/@justeat/pie-design-tokens@latest/dist/jet.css">
7
- <link rel="preload" href="https://d30v2pzvrfyzpo.cloudfront.net/fonts/JETSansDigital-Regular-optimised.woff2" as="font" type="font/woff2" crossorigin>
8
- <style>
9
- @font-face {
10
- font-family: JETSansDigital;
11
- src: url('https://d30v2pzvrfyzpo.cloudfront.net/fonts/JETSansDigital-Regular-optimised.woff2') format("woff2"),
12
- url('https://d30v2pzvrfyzpo.cloudfront.net/fonts/JETSansDigital-Regular-optimised.woff') format("woff");
13
- font-weight: 400;
14
- font-display: swap;
15
- }
16
- body {
17
- font-feature-settings: "tnum"; /* Enable tabular numbers */
18
- }
19
- </style>
7
+ <link rel="stylesheet" href="https://unpkg.com/@justeat/pie-design-tokens@latest/dist/jet.css">
8
+ <link rel="preload" href="https://d30v2pzvrfyzpo.cloudfront.net/fonts/JETSansDigital-Regular-optimised.woff2"
9
+ as="font" type="font/woff2" crossorigin>
10
+ <style>
11
+ @font-face {
12
+ font-family: JETSansDigital;
13
+ src: url('https://d30v2pzvrfyzpo.cloudfront.net/fonts/JETSansDigital-Regular-optimised.woff2') format("woff2"),
14
+ url('https://d30v2pzvrfyzpo.cloudfront.net/fonts/JETSansDigital-Regular-optimised.woff') format("woff");
15
+ font-weight: 400;
16
+ font-display: swap;
17
+ }
18
+
19
+ body {
20
+ font-feature-settings: "tnum";
21
+ /* Enable tabular numbers */
22
+ }
23
+ </style>
20
24
  <script type="module" src="/src/index.ts"></script>
21
- </head>
22
- <body>
25
+ </head>
26
+
27
+ <body>
23
28
  <!-- This is a temporary file for testing until Storybook is in place -->
24
29
  <!-- Run `yarn dev` to serve this file -->
25
- <pie-button />
30
+ <pie-button type="button" variant="primary" />
26
31
 
27
32
  <script>
28
33
  (function () {
29
34
  var boldFontUrls = 'url("https://d30v2pzvrfyzpo.cloudfront.net/fonts/JETSansDigital-Bold-optimised.woff2") format("woff2"), url("https://d30v2pzvrfyzpo.cloudfront.net/fonts/ JETSansDigital-Bold-optimised.woff") format("woff")';
30
35
  var extraboldFontUrls = 'url("https://d30v2pzvrfyzpo.cloudfront.net/fonts/JETSansDigital-ExtraBold-optimised.woff2") format("woff2"), url("https://d30v2pzvrfyzpo.cloudfront.net/fonts/ JETSansDigital-ExtraBold-optimised.woff") format("woff")';
31
36
 
32
- if('fonts' in document ) {
33
- var bold = new FontFace('JETSansDigital', boldFontUrls, { weight: '700' });
34
- var extrabold = new FontFace('JETSansDigital', extraboldFontUrls, { weight: '800' });
37
+ if ('fonts' in document) {
38
+ var bold = new FontFace('JETSansDigital', boldFontUrls, { weight: '700' });
39
+ var extrabold = new FontFace('JETSansDigital', extraboldFontUrls, { weight: '800' });
35
40
 
36
41
  Promise.all([bold.load(), extrabold.load()])
37
42
  .then(function (fonts) {
@@ -40,10 +45,11 @@
40
45
  });
41
46
  })
42
47
  .then(function () {
43
- document.documentElement.classList.add ('webfonts-loaded');
48
+ document.documentElement.classList.add('webfonts-loaded');
44
49
  });
45
50
  }
46
51
  })();
47
52
  </script>
48
- </body>
53
+ </body>
54
+
49
55
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-button",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "PIE design system button built using web components",
5
5
  "type": "module",
6
6
  "main": "dist/pie-button.js",
@@ -0,0 +1,3 @@
1
+ @use '@justeat/fozzie/src/scss/fozzie' as f;
2
+
3
+ @include f.buttons();
@@ -0,0 +1,34 @@
1
+ /**
2
+ * A decorator for specifying a list of valid values for a property.
3
+ * If this property's setter is called with an invalid value, an error is logged and the default value will be assigned instead.
4
+ * @param validValues - The array of valid values
5
+ * @param defaultValue - The value to fall back on
6
+ * @returns
7
+ */
8
+ export const validPropertyValues = (validValues: any[], defaultValue: any) => {
9
+ return function (target: any, propertyKey: string) : void {
10
+ const privatePropertyKey = `_${propertyKey}`;
11
+
12
+ Object.defineProperty(target, propertyKey, {
13
+ get () : any {
14
+ return target[privatePropertyKey];
15
+ },
16
+ set (value: any) : void {
17
+ const oldValue = target[privatePropertyKey];
18
+
19
+ if (!validValues.includes(value)) {
20
+ console.error(
21
+ `[pie-button] Invalid value "${value}" provided for property "${propertyKey}".`,
22
+ `Must be one of: ${validValues.join(' | ')}.`,
23
+ `Falling back to default value: "${defaultValue}"`
24
+ );
25
+ target[privatePropertyKey] = defaultValue;
26
+ } else {
27
+ target[privatePropertyKey] = value;
28
+ }
29
+
30
+ this.requestUpdate(propertyKey, oldValue);
31
+ }
32
+ });
33
+ }
34
+ };
package/src/defs.ts ADDED
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Button style variants
3
+ */
4
+ export enum BUTTON_VARIANT {
5
+ /**
6
+ * Primary button.
7
+ */
8
+ PRIMARY = 'primary',
9
+
10
+ /**
11
+ * Secondary button.
12
+ */
13
+ SECONDARY = 'secondary',
14
+
15
+ /**
16
+ * Outline button.
17
+ */
18
+ OUTLINE = 'outline',
19
+
20
+ /**
21
+ * Ghost button.
22
+ */
23
+ GHOST = 'ghost'
24
+ }
25
+
26
+ /**
27
+ * Button style variants
28
+ */
29
+ export enum BUTTON_TYPE {
30
+ /**
31
+ * Submit button.
32
+ */
33
+ SUBMIT = 'submit',
34
+
35
+ /**
36
+ * Standard button.
37
+ */
38
+ BUTTON = 'button',
39
+
40
+ /**
41
+ * Reset button.
42
+ */
43
+ RESET = 'reset',
44
+
45
+ /**
46
+ * Menu button.
47
+ */
48
+ MENU = 'menu'
49
+ }
package/src/index.ts CHANGED
@@ -1,29 +1,46 @@
1
- import { LitElement, html, css } from 'lit';
1
+ import { LitElement, html, unsafeCSS } from 'lit';
2
+ import { classMap } from 'lit/directives/class-map.js';
2
3
  import { customElement, property } from 'lit/decorators.js';
3
4
 
5
+ import styles from './button.scss?inline';
6
+ import { validPropertyValues } from './decorators';
7
+ import { BUTTON_TYPE, BUTTON_VARIANT } from './defs';
8
+
9
+ // Valid values available to consumers
10
+ export { BUTTON_TYPE, BUTTON_VARIANT };
11
+
4
12
  @customElement('pie-button')
5
13
  export class PieButton extends LitElement {
6
- @property() actionType = 'submit';
7
-
8
- static styles = [css`
9
- button {
10
- background-color: var(--dt-color-interactive-brand);
11
- border-radius: var(--dt-radius-rounded-e);
12
- border: none;
13
- color: var(--dt-color-content-interactive-primary);
14
- font-size: 20px; // A future ticket will pull in a helper for font size & line height.
15
- line-height: 1.4;
16
- font-family: var(--dt-font-interactive-m-family);
17
- font-weight: var(--dt-font-interactive-m-weight);
18
- padding: 10px var(--dt-spacing-e);
19
- min-height: 48px;
20
- }
21
- `];
14
+ /**
15
+ * The Button type to use
16
+ */
17
+ @property()
18
+ @validPropertyValues(Object.values(BUTTON_TYPE), BUTTON_TYPE.SUBMIT)
19
+ type : BUTTON_TYPE = BUTTON_TYPE.SUBMIT;
20
+
21
+ /**
22
+ * The Button style variant to use
23
+ */
24
+ @property()
25
+ @validPropertyValues(Object.values(BUTTON_VARIANT), BUTTON_VARIANT.PRIMARY)
26
+ variant : BUTTON_VARIANT = BUTTON_VARIANT.PRIMARY;
22
27
 
23
28
  render () {
29
+ const { type, variant } = this;
30
+
31
+ const classes = classMap({
32
+ ['o-btn']: true,
33
+ [`o-btn--${variant}`]: variant
34
+ });
35
+
24
36
  return html`
25
- <button type=${this.actionType}>
26
- I'm a PIE button
27
- </button>`;
37
+ <button
38
+ class="${classes}"
39
+ type=${type}>
40
+ I'm a PIE button
41
+ </button>`;
28
42
  }
43
+
44
+ // Renders a `CSSResult` generated from SCSS by Vite
45
+ static styles = unsafeCSS(styles);
29
46
  }
package/tsconfig.json CHANGED
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
+ "target": "ES6",
3
4
  "module": "ES2022",
4
5
  "lib": ["es2020", "DOM", "DOM.Iterable"],
5
6
  "declaration": true,
@@ -20,6 +21,6 @@
20
21
  "experimentalDecorators": true,
21
22
  "forceConsistentCasingInFileNames": true
22
23
  },
23
- "include": ["src/**/*.ts"],
24
+ "include": ["src/**/*.ts","./declaration.d.ts"],
24
25
  "exclude": []
25
- }
26
+ }