@justeattakeaway/pie-tag 0.1.0 → 0.2.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/README.md CHANGED
@@ -19,7 +19,7 @@
19
19
 
20
20
  ## pie-tag
21
21
 
22
- `pie-tag` is a Web Component built using the Lit library.
22
+ `pie-tag` is a Web Component built using the Lit library. A tag is a small visual element used to represent and categorize information within a user interface. 
23
23
 
24
24
  This component can be easily integrated into various frontend frameworks and customized through a set of properties.
25
25
 
@@ -74,16 +74,40 @@ import { PieTag } from '@justeattakeaway/pie-tag/dist/react';
74
74
 
75
75
  | Property | Type | Default | Description |
76
76
  |---|---|---|---|
77
- | - | - | - | - |
77
+ | size | `String` | `large` | Size of the tag. Can be either `large` or `small` |
78
+ | variant | `String` | `neutral` | Variant of the tag, one of `variants` - `neutral-alternative`, `neutral`, `outline`, `ghost`, `blue`, `green`, `yellow`, `red`, `brand` |
79
+ | isStrong | `Boolean` | `false` | If `true`, displays strong tag styles for `green`, `yellow`, `red`, `blue` and `neutral` variants'|
80
+
81
+ Since the component is not interactive it doesn't have a disabled property. To give the Tag a disabled look please use `--tag-opacity` css variable. Recommended opacity level for disabled tag is 0.5.
78
82
 
79
83
  In your markup or JSX, you can then use these to set the properties for the `pie-tag` component:
80
84
 
81
85
  ```html
82
86
  <!-- Native HTML -->
83
- <pie-tag></pie-tag>
87
+ <pie-tag>Label</pie-tag>
84
88
 
85
89
  <!-- JSX -->
86
- <PieTag></PieTag>
90
+ <PieTag>Label</PieTag>
91
+ ```
92
+ ## Slots
93
+
94
+ | Slot | Description |
95
+ | Default slot | Used to pass text into the tag component. |
96
+ | icon | Used to pass in an icon to the tag component. We recommend using `pie-icons-webc` for defining this icon, but this can also accept an SVG icon. |
97
+
98
+ ### Using `pie-icons-webc` with `pie-tag` icon slot
99
+
100
+ We recommend using `pie-icons-webc` when using the `icon` slot. Here is an example of how you would do this:
101
+
102
+ ```html
103
+ <!--
104
+ Note that pie-tag and the icon that you want to use will need to be imported as components into your application.
105
+ See the `pie-icons-webc` README for more info on importing these icons.
106
+ -->
107
+ <pie-tag>
108
+ <icon-vegan slot="icon"></icon-vegan>
109
+ Vegan
110
+ </pie-tag>
87
111
  ```
88
112
 
89
113
  ## Contributing
package/dist/index.d.ts CHANGED
@@ -4,13 +4,34 @@ import type { TemplateResult } from 'lit-html';
4
4
 
5
5
  /**
6
6
  * @tagname pie-tag
7
+ * @slot icon - The icon slot
8
+ * @slot - Default slot
7
9
  */
8
10
  export declare class PieTag extends LitElement implements TagProps {
11
+ variant: TagProps['variant'];
12
+ size: TagProps['size'];
13
+ isStrong: boolean;
9
14
  render(): TemplateResult<1>;
10
15
  static styles: CSSResult;
11
16
  }
12
17
 
18
+ export declare const sizes: readonly ["small", "large"];
19
+
13
20
  export declare interface TagProps {
21
+ /**
22
+ * What style variant the tag should be such as neutral/ghost etc.
23
+ */
24
+ variant: typeof variants[number];
25
+ /**
26
+ * When true, the 'green', "yellow", "red", "blue" and "neutral" variants change their styles and become bolder
27
+ */
28
+ isStrong: boolean;
29
+ /**
30
+ * What size the tag should be.
31
+ */
32
+ size: typeof sizes[number];
14
33
  }
15
34
 
35
+ export declare const variants: readonly ["neutral-alternative", "neutral", "outline", "ghost", "blue", "green", "yellow", "red", "brand"];
36
+
16
37
  export { }
package/dist/index.js CHANGED
@@ -1,13 +1,52 @@
1
- import { unsafeCSS as t, LitElement as o, html as s } from "lit";
2
- import { defineCustomElement as n } from "@justeattakeaway/pie-webc-core";
3
- const r = "", l = "pie-tag";
4
- class e extends o {
1
+ import { unsafeCSS as p, LitElement as u, html as s, nothing as h } from "lit";
2
+ import { property as l } from "lit/decorators.js";
3
+ import { validPropertyValues as v, defineCustomElement as b } from "@justeattakeaway/pie-webc-core";
4
+ const f = `.c-tag{--tag-bg-color: var(--dt-color-container-inverse);--tag-color: var(--dt-color-content-inverse);--tag-padding: 2px var(--dt-spacing-b);--tag-height: 24px;--tag-border-radius: var(--dt-radius-rounded-b);--tag-font-family: var(--dt-font-body-s-family);--tag-font-weight: var(--dt-font-body-s-weight);--tag-font-size: calc(var(--dt-font-body-s-size) * 1px);--tag-line-height: calc(var(--dt-font-body-s-line-height) * 1px);--tag-transparent-bg-color: transparent;--tag-height-large: 24px;--tag-height-small: 16px;--icon-display-override: block;--icon-size-override: 16px;display:inline-flex;vertical-align:middle;align-items:center;justify-content:center;gap:var(--dt-spacing-a);height:var(--tag-height);padding:var(--tag-padding);border:none;border-radius:var(--tag-border-radius);background-color:var(--tag-bg-color);color:var(--tag-color);font-family:var(--tag-font-family);font-weight:var(--tag-font-weight);font-size:var(--tag-font-size);line-height:var(--tag-line-height);opacity:var(--tag-opacity, 1)}.c-tag[size=small]{--tag-height: var(--tag-height-small);--tag-padding: 0 var(--dt-spacing-a);--tag-border-radius: var(--dt-radius-rounded-a);--tag-font-size: calc(var(--dt-font-caption-size) * 1px);--tag-line-height: calc(var(--dt-font-caption-line-height) * 1px)}.c-tag[size=large]{--tag-height: var(--tag-height-large);--tag-padding: 2px var(--dt-spacing-b);--tag-border-radius: var(--dt-radius-rounded-b);--tag-font-size: calc(var(--dt-font-body-s-size) * 1px);--tag-line-height: calc(var(--dt-font-body-s-line-height) * 1px)}.c-tag[variant=neutral]{--tag-bg-color: var(--dt-color-container-strong);--tag-color: var(--dt-color-content-default)}.c-tag[variant=neutral][isStrong]{--tag-bg-color: var(--dt-color-container-inverse);--tag-color: var(--dt-color-content-inverse)}.c-tag[variant=blue]{--tag-bg-color: var(--dt-color-support-info-02);--tag-color: var(--dt-color-content-default)}.c-tag[variant=blue][isStrong]{--tag-bg-color: var(--dt-color-support-info);--tag-color: var(--dt-color-content-light)}.c-tag[variant=green]{--tag-bg-color: var(--dt-color-support-positive-02);--tag-color: var(--dt-color-content-default)}.c-tag[variant=green][isStrong]{--tag-bg-color: var(--dt-color-support-positive);--tag-color: var(--dt-color-content-light)}.c-tag[variant=yellow]{--tag-bg-color: var(--dt-color-support-warning-02);--tag-color: var(--dt-color-content-dark)}.c-tag[variant=yellow][isStrong]{--tag-bg-color: var(--dt-color-support-warning);--tag-color: var(--dt-color-content-dark)}.c-tag[variant=red]{--tag-bg-color: var(--dt-color-support-error-02);--tag-color: var(--dt-color-content-default)}.c-tag[variant=red][isStrong]{--tag-bg-color: var(--dt-color-support-error);--tag-color: var(--dt-color-content-light)}.c-tag[variant=brand]{--tag-bg-color: var(--dt-color-support-brand-02);--tag-color: var(--dt-color-content-default)}.c-tag[variant=neutral-alternative]{--tag-bg-color: var(--dt-color-container-default);--tag-color: var(--dt-color-content-default)}.c-tag[variant=outline]{--tag-bg-color: var(--tag-transparent-bg-color);--tag-color: var(--dt-color-content-default);border:1px solid var(--dt-color-border-strong)}.c-tag[variant=outline][size=small]{--tag-padding: 0 3px}.c-tag[variant=outline][size=large]{--tag-padding: 1px 7px}.c-tag[variant=ghost]{--tag-bg-color: var(--tag-transparent-bg-color);--tag-color: var(--dt-color-content-default)}::slotted(svg){display:block;height:var(--icon-size-override);width:var(--icon-size-override)}
5
+ `, y = ["neutral-alternative", "neutral", "outline", "ghost", "blue", "green", "yellow", "red", "brand"], m = ["small", "large"];
6
+ var z = Object.defineProperty, x = Object.getOwnPropertyDescriptor, c = (n, a, r, o) => {
7
+ for (var t = o > 1 ? void 0 : o ? x(a, r) : a, g = n.length - 1, i; g >= 0; g--)
8
+ (i = n[g]) && (t = (o ? i(a, r, t) : i(t)) || t);
9
+ return o && t && z(a, r, t), t;
10
+ };
11
+ const d = "pie-tag";
12
+ class e extends u {
13
+ constructor() {
14
+ super(...arguments), this.variant = "neutral", this.size = "large", this.isStrong = !1;
15
+ }
5
16
  render() {
6
- return s`<h1 data-test-id="pie-tag">Hello world!</h1>`;
17
+ const {
18
+ variant: a,
19
+ size: r,
20
+ isStrong: o
21
+ } = this;
22
+ return s`
23
+ <div
24
+ class="c-tag"
25
+ variant=${a}
26
+ size=${r}
27
+ ?isStrong=${o}
28
+ data-test-id="pie-tag"
29
+ >
30
+ ${r === "large" ? s`<slot name="icon"></slot>` : h}
31
+ <slot></slot>
32
+ </div>`;
7
33
  }
8
34
  }
9
- e.styles = t(r);
10
- n(l, e);
35
+ e.styles = p(f);
36
+ c([
37
+ l({ type: String }),
38
+ v(d, y, "neutral")
39
+ ], e.prototype, "variant", 2);
40
+ c([
41
+ l({ type: String }),
42
+ v(d, m, "large")
43
+ ], e.prototype, "size", 2);
44
+ c([
45
+ l({ type: Boolean })
46
+ ], e.prototype, "isStrong", 2);
47
+ b(d, e);
11
48
  export {
12
- e as PieTag
49
+ e as PieTag,
50
+ m as sizes,
51
+ y as variants
13
52
  };
package/dist/react.d.ts CHANGED
@@ -7,13 +7,34 @@ export declare const PieTag: ReactWebComponent<PieTag_2, {}>;
7
7
 
8
8
  /**
9
9
  * @tagname pie-tag
10
+ * @slot icon - The icon slot
11
+ * @slot - Default slot
10
12
  */
11
13
  declare class PieTag_2 extends LitElement implements TagProps {
14
+ variant: TagProps['variant'];
15
+ size: TagProps['size'];
16
+ isStrong: boolean;
12
17
  render(): TemplateResult<1>;
13
18
  static styles: CSSResult;
14
19
  }
15
20
 
21
+ export declare const sizes: readonly ["small", "large"];
22
+
16
23
  export declare interface TagProps {
24
+ /**
25
+ * What style variant the tag should be such as neutral/ghost etc.
26
+ */
27
+ variant: typeof variants[number];
28
+ /**
29
+ * When true, the 'green', "yellow", "red", "blue" and "neutral" variants change their styles and become bolder
30
+ */
31
+ isStrong: boolean;
32
+ /**
33
+ * What size the tag should be.
34
+ */
35
+ size: typeof sizes[number];
17
36
  }
18
37
 
38
+ export declare const variants: readonly ["neutral-alternative", "neutral", "outline", "ghost", "blue", "green", "yellow", "red", "brand"];
39
+
19
40
  export { }
package/dist/react.js CHANGED
@@ -1,15 +1,19 @@
1
1
  import * as e from "react";
2
- import { createComponent as a } from "@lit/react";
3
- import { PieTag as t } from "./index.js";
2
+ import { createComponent as t } from "@lit/react";
3
+ import { PieTag as a } from "./index.js";
4
+ import { sizes as c, variants as f } from "./index.js";
4
5
  import "lit";
6
+ import "lit/decorators.js";
5
7
  import "@justeattakeaway/pie-webc-core";
6
- const p = a({
8
+ const s = t({
7
9
  displayName: "PieTag",
8
- elementClass: t,
10
+ elementClass: a,
9
11
  react: e,
10
12
  tagName: "pie-tag",
11
13
  events: {}
12
14
  });
13
15
  export {
14
- p as PieTag
16
+ s as PieTag,
17
+ c as sizes,
18
+ f as variants
15
19
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-tag",
3
3
  "description": "PIE Design System Tag built using Web Components",
4
- "version": "0.1.0",
4
+ "version": "0.2.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -28,10 +28,10 @@
28
28
  "author": "Just Eat Takeaway.com - Design System Team",
29
29
  "license": "Apache-2.0",
30
30
  "devDependencies": {
31
- "@justeattakeaway/pie-components-config": "0.6.1"
31
+ "@justeattakeaway/pie-components-config": "0.7.0"
32
32
  },
33
33
  "dependencies": {
34
- "@justeattakeaway/pie-webc-core": "0.13.0"
34
+ "@justeattakeaway/pie-webc-core": "0.15.0"
35
35
  },
36
36
  "volta": {
37
37
  "extends": "../../../package.json"
package/src/defs.ts CHANGED
@@ -1,3 +1,19 @@
1
- // TODO - please remove the eslint disable comment below when you add props to this interface
2
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
3
- export interface TagProps {}
1
+ export const variants = ['neutral-alternative', 'neutral', 'outline', 'ghost', 'blue', 'green', 'yellow', 'red', 'brand'] as const;
2
+ export const sizes = ['small', 'large'] as const;
3
+
4
+ export interface TagProps {
5
+ /**
6
+ * What style variant the tag should be such as neutral/ghost etc.
7
+ */
8
+ variant: typeof variants[number];
9
+
10
+ /**
11
+ * When true, the 'green', "yellow", "red", "blue" and "neutral" variants change their styles and become bolder
12
+ */
13
+ isStrong: boolean;
14
+
15
+ /**
16
+ * What size the tag should be.
17
+ */
18
+ size: typeof sizes[number];
19
+ }
package/src/index.ts CHANGED
@@ -1,8 +1,10 @@
1
- import { LitElement, html, unsafeCSS } from 'lit';
2
-
3
- import { defineCustomElement } from '@justeattakeaway/pie-webc-core';
1
+ import {
2
+ LitElement, html, unsafeCSS, nothing,
3
+ } from 'lit';
4
+ import { property } from 'lit/decorators.js';
5
+ import { validPropertyValues, defineCustomElement } from '@justeattakeaway/pie-webc-core';
4
6
  import styles from './tag.scss?inline';
5
- import { TagProps } from './defs';
7
+ import { TagProps, variants, sizes } from './defs';
6
8
 
7
9
  // Valid values available to consumers
8
10
  export * from './defs';
@@ -11,10 +13,38 @@ const componentSelector = 'pie-tag';
11
13
 
12
14
  /**
13
15
  * @tagname pie-tag
16
+ * @slot icon - The icon slot
17
+ * @slot - Default slot
14
18
  */
15
19
  export class PieTag extends LitElement implements TagProps {
20
+ @property({ type: String })
21
+ @validPropertyValues(componentSelector, variants, 'neutral')
22
+ public variant: TagProps['variant'] = 'neutral';
23
+
24
+ @property({ type: String })
25
+ @validPropertyValues(componentSelector, sizes, 'large')
26
+ public size : TagProps['size'] = 'large';
27
+
28
+ @property({ type: Boolean })
29
+ public isStrong = false;
30
+
16
31
  render () {
17
- return html`<h1 data-test-id="pie-tag">Hello world!</h1>`;
32
+ const {
33
+ variant,
34
+ size,
35
+ isStrong,
36
+ } = this;
37
+ return html`
38
+ <div
39
+ class="c-tag"
40
+ variant=${variant}
41
+ size=${size}
42
+ ?isStrong=${isStrong}
43
+ data-test-id="pie-tag"
44
+ >
45
+ ${size === 'large' ? html`<slot name="icon"></slot>` : nothing}
46
+ <slot></slot>
47
+ </div>`;
18
48
  }
19
49
 
20
50
  // Renders a `CSSResult` generated from SCSS by Vite
package/src/tag.scss CHANGED
@@ -1 +1,147 @@
1
1
  @use '@justeattakeaway/pie-css/scss' as p;
2
+
3
+ // Base tag styles
4
+ .c-tag {
5
+ // The following values set to a default tag (neutral large)
6
+ --tag-bg-color: var(--dt-color-container-inverse);
7
+ --tag-color: var(--dt-color-content-inverse);
8
+ --tag-padding: 2px var(--dt-spacing-b);
9
+ --tag-height: 24px;
10
+ --tag-border-radius: var(--dt-radius-rounded-b);
11
+ --tag-font-family: var(--dt-font-body-s-family);
12
+ --tag-font-weight: var(--dt-font-body-s-weight);
13
+ --tag-font-size: #{p.font-size(--dt-font-body-s-size)};
14
+ --tag-line-height: #{p.line-height(--dt-font-body-s-line-height)};
15
+
16
+ // transparent to variable to function properly in component tests
17
+ --tag-transparent-bg-color: transparent;
18
+
19
+ // Heights for the different tag sizes
20
+ --tag-height-large: 24px;
21
+ --tag-height-small: 16px;
22
+
23
+ // Pie Webc Icon var that is used to ensure the correctly sized icon passed in a slot
24
+ --icon-display-override: block;
25
+ --icon-size-override: 16px;
26
+
27
+ display: inline-flex;
28
+ vertical-align: middle;
29
+ align-items: center;
30
+ justify-content: center;
31
+ gap: var(--dt-spacing-a);
32
+ height: var(--tag-height);
33
+ padding: var(--tag-padding);
34
+ border: none;
35
+ border-radius: var(--tag-border-radius);
36
+ background-color: var(--tag-bg-color);
37
+ color: var(--tag-color);
38
+ font-family: var(--tag-font-family);
39
+ font-weight: var(--tag-font-weight);
40
+ font-size: var(--tag-font-size);
41
+ line-height: var(--tag-line-height);
42
+ opacity: var(--tag-opacity, 1); // we don't specify --tag-opacity variable here to let consumers override a default value that we set
43
+
44
+ // Size
45
+ &[size='small'] {
46
+ --tag-height: var(--tag-height-small);
47
+ --tag-padding: 0 var(--dt-spacing-a);
48
+ --tag-border-radius: var(--dt-radius-rounded-a);
49
+ --tag-font-size: #{p.font-size(--dt-font-caption-size)};
50
+ --tag-line-height: #{p.line-height(--dt-font-caption-line-height)};
51
+ }
52
+
53
+ &[size='large'] {
54
+ --tag-height: var(--tag-height-large);
55
+ --tag-padding: 2px var(--dt-spacing-b);
56
+ --tag-border-radius: var(--dt-radius-rounded-b);
57
+ --tag-font-size: #{p.font-size(--dt-font-body-s-size)};
58
+ --tag-line-height: #{p.line-height(--dt-font-body-s-line-height)};
59
+ }
60
+
61
+ // Variant
62
+ &[variant='neutral'] {
63
+ --tag-bg-color: var(--dt-color-container-strong);
64
+ --tag-color: var(--dt-color-content-default);
65
+
66
+ &[isStrong] {
67
+ --tag-bg-color: var(--dt-color-container-inverse);
68
+ --tag-color: var(--dt-color-content-inverse);
69
+ }
70
+ }
71
+
72
+ &[variant='blue'] {
73
+ --tag-bg-color: var(--dt-color-support-info-02);
74
+ --tag-color: var(--dt-color-content-default);
75
+
76
+ &[isStrong] {
77
+ --tag-bg-color: var(--dt-color-support-info);
78
+ --tag-color: var(--dt-color-content-light);
79
+ }
80
+ }
81
+
82
+ &[variant='green'] {
83
+ --tag-bg-color: var(--dt-color-support-positive-02);
84
+ --tag-color: var(--dt-color-content-default);
85
+
86
+ &[isStrong] {
87
+ --tag-bg-color: var(--dt-color-support-positive);
88
+ --tag-color: var(--dt-color-content-light);
89
+ }
90
+ }
91
+
92
+ &[variant='yellow'] {
93
+ --tag-bg-color: var(--dt-color-support-warning-02);
94
+ --tag-color: var(--dt-color-content-dark);
95
+
96
+ &[isStrong] {
97
+ --tag-bg-color: var(--dt-color-support-warning);
98
+ --tag-color: var(--dt-color-content-dark);
99
+ }
100
+ }
101
+
102
+ &[variant='red'] {
103
+ --tag-bg-color: var(--dt-color-support-error-02);
104
+ --tag-color: var(--dt-color-content-default);
105
+
106
+ &[isStrong] {
107
+ --tag-bg-color: var(--dt-color-support-error);
108
+ --tag-color: var(--dt-color-content-light);
109
+ }
110
+ }
111
+
112
+ &[variant='brand'] {
113
+ --tag-bg-color: var(--dt-color-support-brand-02);
114
+ --tag-color: var(--dt-color-content-default);
115
+ }
116
+
117
+ &[variant='neutral-alternative'] {
118
+ --tag-bg-color: var(--dt-color-container-default);
119
+ --tag-color: var(--dt-color-content-default);
120
+ }
121
+
122
+ &[variant='outline'] {
123
+ --tag-bg-color: var(--tag-transparent-bg-color);
124
+ --tag-color: var(--dt-color-content-default);
125
+ border: 1px solid var(--dt-color-border-strong);
126
+
127
+ &[size='small'] {
128
+ --tag-padding: 0 3px; // small tag padding minus 1px of the border
129
+ }
130
+
131
+ &[size='large'] {
132
+ --tag-padding: 1px 7px; // large tag padding minus 1px of the border
133
+ }
134
+ }
135
+
136
+ &[variant='ghost'] {
137
+ --tag-bg-color: var(--tag-transparent-bg-color);
138
+ --tag-color: var(--dt-color-content-default);
139
+ }
140
+ }
141
+
142
+ // Used to size an SVG if one is passed in (when not using the component icons)
143
+ ::slotted(svg) {
144
+ display: block;
145
+ height: var(--icon-size-override);
146
+ width: var(--icon-size-override);
147
+ }