@justeattakeaway/pie-button 0.3.0 → 0.5.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/.turbo/turbo-build.log +7 -0
- package/CHANGELOG.md +36 -9
- package/declaration.d.ts +9 -0
- package/dist/pie-button.js +65 -0
- package/package.json +1 -1
- package/src/button.scss +60 -0
- package/src/decorators.ts +34 -0
- package/src/defs.ts +29 -0
- package/src/index.ts +36 -20
- package/tsconfig.json +3 -2
- package/index.html +0 -49
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
@justeattakeaway/pie-button:build: cache hit, replaying output 21df156a0b013060
|
|
2
|
+
@justeattakeaway/pie-button:build: [36mvite v4.0.4 [32mbuilding for production...[36m[39m
|
|
3
|
+
@justeattakeaway/pie-button:build: transforming...
|
|
4
|
+
@justeattakeaway/pie-button:build: [32m✓[39m 4 modules transformed.
|
|
5
|
+
@justeattakeaway/pie-button:build: rendering chunks...
|
|
6
|
+
@justeattakeaway/pie-button:build: computing gzip size...
|
|
7
|
+
@justeattakeaway/pie-button:build: [2mdist/[22m[36mpie-button.js [39m[1m[2m2.73 kB[22m[1m[22m[2m │ gzip: 1.29 kB[22m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,29 +1,56 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [Changed] - Bring button styles into the component ([#178](https://github.com/justeattakeaway/pie/pull/178)) by [@xander-marjoram](https://github.com/xander-marjoram)
|
|
8
|
+
|
|
9
|
+
- [Added] - Size property to pie-button component ([#178](https://github.com/justeattakeaway/pie/pull/178)) by [@xander-marjoram](https://github.com/xander-marjoram)
|
|
10
|
+
|
|
11
|
+
- [Removed] - index.html file in favour of Storybook ([#178](https://github.com/justeattakeaway/pie/pull/178)) by [@xander-marjoram](https://github.com/xander-marjoram)
|
|
12
|
+
|
|
13
|
+
## 0.4.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- [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)
|
|
18
|
+
|
|
19
|
+
- [Added] Create decorator for validating property values ([#171](https://github.com/justeattakeaway/pie/pull/171)) by [@jamieomaguire](https://github.com/jamieomaguire)
|
|
20
|
+
|
|
21
|
+
- [Added] - `variant` property to decide how we style the button ([#171](https://github.com/justeattakeaway/pie/pull/171)) by [@jamieomaguire](https://github.com/jamieomaguire)
|
|
22
|
+
|
|
23
|
+
- [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)
|
|
24
|
+
|
|
25
|
+
- [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)
|
|
26
|
+
|
|
27
|
+
- [Changed] - Renamed `actionType` property to `type` ([#171](https://github.com/justeattakeaway/pie/pull/171)) by [@jamieomaguire](https://github.com/jamieomaguire)
|
|
28
|
+
|
|
3
29
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|
4
30
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
5
31
|
|
|
6
|
-
v0.3.0
|
|
7
|
-
|
|
8
|
-
|
|
32
|
+
## v0.3.0
|
|
33
|
+
|
|
34
|
+
_January 24, 2023_
|
|
9
35
|
|
|
10
36
|
### Added
|
|
37
|
+
|
|
11
38
|
- Button default styling (medium).
|
|
12
39
|
- JET font family to html file.
|
|
13
40
|
|
|
41
|
+
## v0.2.0
|
|
14
42
|
|
|
15
|
-
|
|
16
|
-
---------------------
|
|
17
|
-
*January 23, 2023*
|
|
43
|
+
_January 23, 2023_
|
|
18
44
|
|
|
19
45
|
### Added
|
|
46
|
+
|
|
20
47
|
- `actionType` property mapped to `type` attribute.
|
|
21
48
|
|
|
49
|
+
## v0.1.0
|
|
22
50
|
|
|
23
|
-
|
|
24
|
-
---------------------
|
|
25
|
-
*January 19, 2023*
|
|
51
|
+
_January 19, 2023_
|
|
26
52
|
|
|
27
53
|
### Added
|
|
54
|
+
|
|
28
55
|
- Basic button using Lit
|
|
29
56
|
- Initial TypeScript and Vite config
|
package/declaration.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { unsafeCSS as d, LitElement as m, html as h } from "lit";
|
|
2
|
+
import { classMap as x } from "lit/directives/class-map.js";
|
|
3
|
+
import { property as b, customElement as g } from "lit/decorators.js";
|
|
4
|
+
const v = `.o-btn{border-radius:50rem;border:none;font-family:JetSansDigital;font-weight:700}.o-btn--xsmall{padding:6px 8px;min-height:32px;font-size:14px;line-height:20px}.o-btn--small{padding:8px 16px;min-height:40px;font-size:19px;line-height:28px}.o-btn--medium{padding:10px 24px;min-height:48px;font-size:20px;line-height:28px}.o-btn--large{padding:14px 24px;min-height:56px;font-size:20px;line-height:28px}.o-btn--primary{background-color:#f36805;color:#fff}.o-btn--secondary{background-color:#f5f3f1;color:#242e30}.o-btn--outline{border:1px solid #dbd9d7;background-color:#fff;color:#303d3f}.o-btn--ghost{background-color:#fff;color:#242e30}
|
|
5
|
+
`, f = (t, r) => function(e, n) {
|
|
6
|
+
const o = `_${n}`;
|
|
7
|
+
Object.defineProperty(e, n, {
|
|
8
|
+
get() {
|
|
9
|
+
return e[o];
|
|
10
|
+
},
|
|
11
|
+
set(i) {
|
|
12
|
+
const p = e[o];
|
|
13
|
+
t.includes(i) ? e[o] = i : (console.error(
|
|
14
|
+
`[pie-button] Invalid value "${i}" provided for property "${n}".`,
|
|
15
|
+
`Must be one of: ${t.join(" | ")}.`,
|
|
16
|
+
`Falling back to default value: "${r}"`
|
|
17
|
+
), e[o] = r), this.requestUpdate(n, p);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var l = /* @__PURE__ */ ((t) => (t.XSMALL = "xsmall", t.SMALL = "small", t.MEDIUM = "medium", t.LARGE = "large", t))(l || {}), a = /* @__PURE__ */ ((t) => (t.SUBMIT = "submit", t.BUTTON = "button", t.RESET = "reset", t.MENU = "menu", t))(a || {}), u = /* @__PURE__ */ ((t) => (t.PRIMARY = "primary", t.SECONDARY = "secondary", t.OUTLINE = "outline", t.GHOST = "ghost", t))(u || {}), M = Object.defineProperty, y = Object.getOwnPropertyDescriptor, c = (t, r, e, n) => {
|
|
22
|
+
for (var o = n > 1 ? void 0 : n ? y(r, e) : r, i = t.length - 1, p; i >= 0; i--)
|
|
23
|
+
(p = t[i]) && (o = (n ? p(r, e, o) : p(o)) || o);
|
|
24
|
+
return n && o && M(r, e, o), o;
|
|
25
|
+
};
|
|
26
|
+
let s = class extends m {
|
|
27
|
+
constructor() {
|
|
28
|
+
super(...arguments), this.size = l.MEDIUM, this.type = a.SUBMIT, this.variant = u.PRIMARY;
|
|
29
|
+
}
|
|
30
|
+
render() {
|
|
31
|
+
const { size: t, type: r, variant: e } = this, n = {
|
|
32
|
+
"o-btn": !0,
|
|
33
|
+
[`o-btn--${t}`]: t,
|
|
34
|
+
[`o-btn--${e}`]: e
|
|
35
|
+
};
|
|
36
|
+
return h`
|
|
37
|
+
<button
|
|
38
|
+
class=${x(n)}
|
|
39
|
+
type=${r}>
|
|
40
|
+
I'm a PIE button
|
|
41
|
+
</button>`;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
s.styles = d(v);
|
|
45
|
+
c([
|
|
46
|
+
b(),
|
|
47
|
+
f(Object.values(l), l.MEDIUM)
|
|
48
|
+
], s.prototype, "size", 2);
|
|
49
|
+
c([
|
|
50
|
+
b(),
|
|
51
|
+
f(Object.values(a), a.SUBMIT)
|
|
52
|
+
], s.prototype, "type", 2);
|
|
53
|
+
c([
|
|
54
|
+
b(),
|
|
55
|
+
f(Object.values(u), u.PRIMARY)
|
|
56
|
+
], s.prototype, "variant", 2);
|
|
57
|
+
s = c([
|
|
58
|
+
g("pie-button")
|
|
59
|
+
], s);
|
|
60
|
+
export {
|
|
61
|
+
l as BUTTON_SIZE,
|
|
62
|
+
a as BUTTON_TYPE,
|
|
63
|
+
u as BUTTON_VARIANT,
|
|
64
|
+
s as PieButton
|
|
65
|
+
};
|
package/package.json
CHANGED
package/src/button.scss
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
@use '@justeat/pie-design-tokens/dist/jet.scss' as dt;
|
|
2
|
+
|
|
3
|
+
.o-btn {
|
|
4
|
+
border-radius: dt.$radius-rounded-e;
|
|
5
|
+
border: none;
|
|
6
|
+
font-family: dt.$font-interactive-m-family;
|
|
7
|
+
font-weight: dt.$font-interactive-m-weight;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// TODO - Use latest design tokens for font size and line height
|
|
11
|
+
// once fozzie has been updated to handle them.
|
|
12
|
+
|
|
13
|
+
.o-btn--xsmall {
|
|
14
|
+
padding: 6px dt.$spacing-b;
|
|
15
|
+
min-height: 32px;
|
|
16
|
+
font-size: 14px;
|
|
17
|
+
line-height: 20px;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.o-btn--small {
|
|
21
|
+
padding: 8px dt.$spacing-d;
|
|
22
|
+
min-height: 40px;
|
|
23
|
+
font-size: 19px;
|
|
24
|
+
line-height: 28px;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.o-btn--medium {
|
|
28
|
+
padding: 10px dt.$spacing-e;
|
|
29
|
+
min-height: 48px;
|
|
30
|
+
font-size: 20px;
|
|
31
|
+
line-height: 28px;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.o-btn--large {
|
|
35
|
+
padding: 14px dt.$spacing-e;
|
|
36
|
+
min-height: 56px;
|
|
37
|
+
font-size: 20px;
|
|
38
|
+
line-height: 28px;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.o-btn--primary {
|
|
42
|
+
background-color: dt.$color-interactive-brand;
|
|
43
|
+
color: dt.$color-content-interactive-primary;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.o-btn--secondary {
|
|
47
|
+
background-color: dt.$color-interactive-secondary;
|
|
48
|
+
color: dt.$color-content-interactive-secondary;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.o-btn--outline {
|
|
52
|
+
border: 1px solid dt.$color-border-strong;
|
|
53
|
+
background-color: dt.$color-container-default;
|
|
54
|
+
color: dt.$color-content-interactive-tertiary;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.o-btn--ghost {
|
|
58
|
+
background-color: dt.$color-container-default;
|
|
59
|
+
color: dt.$color-content-link;
|
|
60
|
+
}
|
|
@@ -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,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Button size variants
|
|
3
|
+
*/
|
|
4
|
+
export enum BUTTON_SIZE {
|
|
5
|
+
XSMALL = 'xsmall',
|
|
6
|
+
SMALL = 'small',
|
|
7
|
+
MEDIUM = 'medium',
|
|
8
|
+
LARGE = 'large'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Button style variants
|
|
13
|
+
*/
|
|
14
|
+
export enum BUTTON_TYPE {
|
|
15
|
+
SUBMIT = 'submit',
|
|
16
|
+
BUTTON = 'button',
|
|
17
|
+
RESET = 'reset',
|
|
18
|
+
MENU = 'menu'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Button style variants
|
|
23
|
+
*/
|
|
24
|
+
export enum BUTTON_VARIANT {
|
|
25
|
+
PRIMARY = 'primary',
|
|
26
|
+
SECONDARY = 'secondary',
|
|
27
|
+
OUTLINE = 'outline',
|
|
28
|
+
GHOST = 'ghost'
|
|
29
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,29 +1,45 @@
|
|
|
1
|
-
import { LitElement, html,
|
|
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_SIZE, BUTTON_TYPE, BUTTON_VARIANT } from './defs';
|
|
8
|
+
|
|
9
|
+
// Valid values available to consumers
|
|
10
|
+
export { BUTTON_SIZE, BUTTON_TYPE, BUTTON_VARIANT };
|
|
11
|
+
|
|
4
12
|
@customElement('pie-button')
|
|
5
13
|
export class PieButton extends LitElement {
|
|
6
|
-
@property()
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
font-weight: var(--dt-font-interactive-m-weight);
|
|
18
|
-
padding: 10px var(--dt-spacing-e);
|
|
19
|
-
min-height: 48px;
|
|
20
|
-
}
|
|
21
|
-
`];
|
|
14
|
+
@property()
|
|
15
|
+
@validPropertyValues(Object.values(BUTTON_SIZE), BUTTON_SIZE.MEDIUM)
|
|
16
|
+
size : BUTTON_SIZE = BUTTON_SIZE.MEDIUM;
|
|
17
|
+
|
|
18
|
+
@property()
|
|
19
|
+
@validPropertyValues(Object.values(BUTTON_TYPE), BUTTON_TYPE.SUBMIT)
|
|
20
|
+
type : BUTTON_TYPE = BUTTON_TYPE.SUBMIT;
|
|
21
|
+
|
|
22
|
+
@property()
|
|
23
|
+
@validPropertyValues(Object.values(BUTTON_VARIANT), BUTTON_VARIANT.PRIMARY)
|
|
24
|
+
variant : BUTTON_VARIANT = BUTTON_VARIANT.PRIMARY;
|
|
22
25
|
|
|
23
26
|
render () {
|
|
27
|
+
const { size, type, variant } = this;
|
|
28
|
+
|
|
29
|
+
const classes = {
|
|
30
|
+
'o-btn': true,
|
|
31
|
+
[`o-btn--${size}`]: size,
|
|
32
|
+
[`o-btn--${variant}`]: variant
|
|
33
|
+
};
|
|
34
|
+
|
|
24
35
|
return html`
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
36
|
+
<button
|
|
37
|
+
class=${classMap(classes)}
|
|
38
|
+
type=${type}>
|
|
39
|
+
I'm a PIE button
|
|
40
|
+
</button>`;
|
|
28
41
|
}
|
|
42
|
+
|
|
43
|
+
// Renders a `CSSResult` generated from SCSS by Vite
|
|
44
|
+
static styles = unsafeCSS(styles);
|
|
29
45
|
}
|
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
|
+
}
|
package/index.html
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<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>
|
|
20
|
-
<script type="module" src="/src/index.ts"></script>
|
|
21
|
-
</head>
|
|
22
|
-
<body>
|
|
23
|
-
<!-- This is a temporary file for testing until Storybook is in place -->
|
|
24
|
-
<!-- Run `yarn dev` to serve this file -->
|
|
25
|
-
<pie-button />
|
|
26
|
-
|
|
27
|
-
<script>
|
|
28
|
-
(function () {
|
|
29
|
-
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
|
-
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
|
-
|
|
32
|
-
if('fonts' in document ) {
|
|
33
|
-
var bold = new FontFace('JETSansDigital', boldFontUrls, { weight: '700' });
|
|
34
|
-
var extrabold = new FontFace('JETSansDigital', extraboldFontUrls, { weight: '800' });
|
|
35
|
-
|
|
36
|
-
Promise.all([bold.load(), extrabold.load()])
|
|
37
|
-
.then(function (fonts) {
|
|
38
|
-
fonts.forEach(function (font) {
|
|
39
|
-
document.fonts.add(font);
|
|
40
|
-
});
|
|
41
|
-
})
|
|
42
|
-
.then(function () {
|
|
43
|
-
document.documentElement.classList.add ('webfonts-loaded');
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
})();
|
|
47
|
-
</script>
|
|
48
|
-
</body>
|
|
49
|
-
</html>
|