@justeattakeaway/pie-link 0.5.0 → 0.6.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
@@ -62,7 +62,7 @@ import { PieLink } from '@justeattakeaway/pie-link/dist/react';
62
62
  | tag | `String` | `a` | The rendered HTML element of the link, one of `tags` – `a`, `button` |
63
63
  | variant | `String` | `default` | Variant of the link, one of `variants` – `default`, `high-visibility`, `inverse` |
64
64
  | size | `String` | `medium` | Size of the link, one of `sizes` – `medium`, `small` |
65
- | underline | `String` | `default` | The underline behavior of the link, one of `underlineTypes` – `default`, `reversed` |
65
+ | underline | `String` | `default` | The underline behavior of the link, one of `underlineTypes` – `default`, `reversed`. The `reverse` type can only be used if `isStandalone` is set to `true` |
66
66
  | href | `String` | `undefined` | Native html `href` attribute |
67
67
  | rel | `String` | `undefined` | Native html `rel` attribute |
68
68
  | target | `String` | `undefined` | Native html `target` attribute |
@@ -70,7 +70,7 @@ import { PieLink } from '@justeattakeaway/pie-link/dist/react';
70
70
  | isBold | `Boolean` | `false` | If `true`, sets the link text bold |
71
71
  | isStandalone | `Boolean` | `false` | If `true`, sets the link as a block element |
72
72
  | hasVisited | `Boolean` | `false` | If `true`, the link will apply the styles for the visited state |
73
- | iconPlacement | `String` | `leading` | Icon placements of the icon slot, if provided, one of `iconPlacements` - `leading`, `trailing` |
73
+ | iconPlacement | `String` | `leading` | Icon placements of the icon slot, if provided, one of `iconPlacements` - `leading`, `trailing`. Can only be used if `isStandalone` is `true` |
74
74
  | aria | `object` | `undefined` | The ARIA labels used for the link. |
75
75
 
76
76
  In your markup or JSX, you can then use these to set the properties for the `pie-link` component:
package/dist/index.d.ts CHANGED
@@ -28,7 +28,8 @@ export declare interface LinkProps {
28
28
  */
29
29
  size: typeof sizes[number];
30
30
  /**
31
- * What underline behavior the link should have such as default or reversed
31
+ * Defines what underline behavior the link should have, such as default or reversed.
32
+ * The `reversed` type can only be used if the link is a block element (isStandalone = true)
32
33
  */
33
34
  underline: typeof underlineTypes[number];
34
35
  /**
@@ -56,7 +57,8 @@ export declare interface LinkProps {
56
57
  */
57
58
  hasVisited: boolean;
58
59
  /**
59
- * The placement of the icon slot, if provided, such as leading or trailing
60
+ * The placement of the icon slot, if provided, such as leading or trailing.
61
+ * Will only apply if the link is a block element (isStandalone = true)
60
62
  */
61
63
  iconPlacement?: typeof iconPlacements[number];
62
64
  /**
@@ -85,7 +87,7 @@ export declare class PieLink extends LitElement implements LinkProps {
85
87
  aria: AriaProps;
86
88
  /**
87
89
  * Renders the link content.
88
- *
90
+ * Icons are only shown in block elements
89
91
  * @private
90
92
  */
91
93
  private renderContent;
package/dist/index.js CHANGED
@@ -1,44 +1,44 @@
1
- import { unsafeCSS as g, LitElement as k, html as u, nothing as s } from "lit";
1
+ import { unsafeCSS as k, LitElement as g, html as v, nothing as a } from "lit";
2
2
  import { property as i } from "lit/decorators.js";
3
- const d = (h, t, c) => function(o, r) {
4
- const l = `#${r}`;
5
- Object.defineProperty(o, r, {
3
+ const d = (p, t, o) => function(r, s) {
4
+ const l = `#${s}`;
5
+ Object.defineProperty(r, s, {
6
6
  get() {
7
7
  return this[l];
8
8
  },
9
- set(v) {
9
+ set(u) {
10
10
  const f = this[l];
11
- t.includes(v) ? this[l] = v : (console.error(
12
- `<${h}> Invalid value "${v}" provided for property "${r}".`,
11
+ t.includes(u) ? this[l] = u : (console.error(
12
+ `<${p}> Invalid value "${u}" provided for property "${s}".`,
13
13
  `Must be one of: ${t.join(" | ")}.`,
14
- `Falling back to default value: "${c}"`
15
- ), this[l] = c), this.requestUpdate(r, f);
14
+ `Falling back to default value: "${o}"`
15
+ ), this[l] = o), this.requestUpdate(s, f);
16
16
  }
17
17
  });
18
- }, y = `.c-link{--link-font-family: var(--dt-font-interactive-m-family);--link-font-size: calc(var(--dt-font-size-16) * 1px);--link-line-height: calc(var(--dt-font-size-16-line-height) * 1px);--link-font-weight: var(--dt-font-weight-regular);--link-text-color: var(--dt-color-content-link);--link-text-decoration: var(--dt-font-style-underline);--link-icon-size: 16px;display:inline-block;font-family:var(--link-font-family);font-size:var(--link-font-size);line-height:var(--link-line-height);font-weight:var(--link-font-weight);color:var(--link-text-color);text-decoration:var(--link-text-decoration);cursor:pointer}.c-link[tag=button]{outline:none;border:none;user-select:none;background:transparent;padding:0}.c-link[variant=high-visibility]{--link-text-color: var(--dt-color-content-link-distinct)}.c-link[variant=inverse]{--link-text-color: var(--dt-color-content-link-inverse)}.c-link[size=small]{--link-font-size: calc(var(--dt-font-size-14) * 1px);--link-line-height: calc(var(--dt-font-size-14-line-height) * 1px)}.c-link[underline=default]:hover,.c-link[underline=default]:active,.c-link[underline=reversed]{--link-text-decoration: none}.c-link[underline=reversed]:hover,.c-link[underline=reversed]:active{--link-text-decoration: var(--dt-font-style-underline)}.c-link[isBold]{--link-font-weight: var(--dt-font-weight-bold)}.c-link[isStandalone]{display:block}.c-link[hasVisited]:visited{color:var(--dt-color-content-link-visited)}.c-link[hasVisited]:visited[variant=inverse]{color:var(--dt-color-content-link-visited-inverse)}.c-link:focus-visible{box-shadow:0 0 0 2px var(--dt-color-focus-outer)}.c-link-content{display:flex;gap:var(--dt-spacing-a)}::slotted(.c-pieIcon),::slotted(svg){display:inline-flex;margin-block-start:var(--dt-spacing-a);height:var(--link-icon-size);width:var(--link-icon-size)}
19
- `, m = ["default", "high-visibility", "inverse"], b = ["small", "medium"], $ = ["leading", "trailing"], x = ["a", "button"], z = ["submit", "button", "reset", "menu"], S = ["default", "reversed"];
20
- var B = Object.defineProperty, P = Object.getOwnPropertyDescriptor, n = (h, t, c, p) => {
21
- for (var o = p > 1 ? void 0 : p ? P(t, c) : t, r = h.length - 1, l; r >= 0; r--)
22
- (l = h[r]) && (o = (p ? l(t, c, o) : l(o)) || o);
23
- return p && o && B(t, c, o), o;
18
+ }, y = `.c-link{--link-font-family: var(--dt-font-interactive-m-family);--link-font-size: calc(var(--dt-font-size-16) * 1px);--link-line-height: calc(var(--dt-font-size-16-line-height) * 1px);--link-font-weight: var(--dt-font-weight-regular);--link-text-color: var(--dt-color-content-link);--link-text-decoration: var(--dt-font-style-underline);--link-icon-size: 16px;--link-icon-offset-top: var(--dt-spacing-a);display:inline-block;font-family:var(--link-font-family);font-size:var(--link-font-size);line-height:var(--link-line-height);font-weight:var(--link-font-weight);color:var(--link-text-color);text-decoration:var(--link-text-decoration);cursor:pointer}.c-link:hover,.c-link:active{--link-text-decoration: none}.c-link[tag=button]{outline:none;border:none;user-select:none;background:transparent;padding:0}.c-link[variant=high-visibility]{--link-text-color: var(--dt-color-content-link-distinct)}.c-link[variant=inverse]{--link-text-color: var(--dt-color-content-link-inverse)}.c-link[size=small]{--link-font-size: calc(var(--dt-font-size-14) * 1px);--link-line-height: calc(var(--dt-font-size-14-line-height) * 1px);--link-icon-offset-top: 2px}.c-link[underline=reversed][isStandalone]{--link-text-decoration: none}.c-link[underline=reversed][isStandalone]:hover,.c-link[underline=reversed][isStandalone]:active{--link-text-decoration: var(--dt-font-style-underline)}.c-link[isBold]{--link-font-weight: var(--dt-font-weight-bold)}.c-link[isStandalone]{display:block}.c-link[hasVisited]:visited{color:var(--dt-color-content-link-visited)}.c-link[hasVisited]:visited[variant=inverse]{color:var(--dt-color-content-link-visited-inverse)}.c-link:focus-visible{outline:none;border-radius:2px;box-shadow:0 0 0 2px var(--dt-color-focus-inner),0 0 0 4px var(--dt-color-focus-outer)}.c-link-content{display:flex;gap:var(--dt-spacing-a)}::slotted(.c-pieIcon),::slotted(svg){display:inline-flex;margin-block-start:var(--link-icon-offset-top);height:var(--link-icon-size);width:var(--link-icon-size)}
19
+ `, m = ["default", "high-visibility", "inverse"], b = ["small", "medium"], $ = ["leading", "trailing"], x = ["a", "button"], S = ["submit", "button", "reset", "menu"], z = ["default", "reversed"];
20
+ var B = Object.defineProperty, P = Object.getOwnPropertyDescriptor, n = (p, t, o, h) => {
21
+ for (var r = h > 1 ? void 0 : h ? P(t, o) : t, s = p.length - 1, l; s >= 0; s--)
22
+ (l = p[s]) && (r = (h ? l(t, o, r) : l(r)) || r);
23
+ return h && r && B(t, o, r), r;
24
24
  };
25
- const a = "pie-link";
26
- class e extends k {
25
+ const c = "pie-link";
26
+ class e extends g {
27
27
  constructor() {
28
28
  super(...arguments), this.tag = "a", this.variant = "default", this.size = "medium", this.underline = "default", this.iconPlacement = "leading", this.isBold = !1, this.isStandalone = !1, this.hasVisited = !1, this.type = "submit";
29
29
  }
30
30
  /**
31
31
  * Renders the link content.
32
- *
32
+ * Icons are only shown in block elements
33
33
  * @private
34
34
  */
35
35
  renderContent() {
36
- const { iconPlacement: t } = this;
37
- return u`
36
+ const { iconPlacement: t, isStandalone: o } = this;
37
+ return v`
38
38
  <span class="c-link-content">
39
- ${t === "leading" ? u`<slot name="icon"></slot>` : s}
39
+ ${o && t === "leading" ? v`<slot name="icon"></slot>` : a}
40
40
  <slot></slot>
41
- ${t === "trailing" ? u`<slot name="icon"></slot>` : s}
41
+ ${o && t === "trailing" ? v`<slot name="icon"></slot>` : a}
42
42
  </span>`;
43
43
  }
44
44
  /**
@@ -48,7 +48,7 @@ class e extends k {
48
48
  */
49
49
  renderButton() {
50
50
  var t;
51
- return u`
51
+ return v`
52
52
  <button
53
53
  data-test-id="pie-link"
54
54
  class="c-link"
@@ -59,8 +59,8 @@ class e extends k {
59
59
  ?isBold=${this.isBold}
60
60
  ?isStandalone=${this.isStandalone}
61
61
  ?hasVisited=${this.hasVisited}
62
- type=${this.type || s}
63
- aria-label=${((t = this.aria) == null ? void 0 : t.label) || s}>
62
+ type=${this.type || a}
63
+ aria-label=${((t = this.aria) == null ? void 0 : t.label) || a}>
64
64
  ${this.renderContent()}
65
65
  </button>`;
66
66
  }
@@ -71,7 +71,7 @@ class e extends k {
71
71
  */
72
72
  renderAnchor() {
73
73
  var t;
74
- return u`
74
+ return v`
75
75
  <a
76
76
  data-test-id="pie-link"
77
77
  class="c-link"
@@ -82,10 +82,10 @@ class e extends k {
82
82
  ?isBold=${this.isBold}
83
83
  ?isStandalone=${this.isStandalone}
84
84
  ?hasVisited=${this.hasVisited}
85
- href=${this.href || s}
86
- target=${this.target || s}
87
- rel=${this.rel || s}
88
- aria-label=${((t = this.aria) == null ? void 0 : t.label) || s}>
85
+ href=${this.href || a}
86
+ target=${this.target || a}
87
+ rel=${this.rel || a}
88
+ aria-label=${((t = this.aria) == null ? void 0 : t.label) || a}>
89
89
  ${this.renderContent()}
90
90
  </a>`;
91
91
  }
@@ -93,26 +93,26 @@ class e extends k {
93
93
  return this.tag === "button" ? this.renderButton() : this.renderAnchor();
94
94
  }
95
95
  }
96
- e.styles = g(y);
96
+ e.styles = k(y);
97
97
  n([
98
98
  i(),
99
- d(a, x, "a")
99
+ d(c, x, "a")
100
100
  ], e.prototype, "tag", 2);
101
101
  n([
102
102
  i({ type: String }),
103
- d(a, m, "default")
103
+ d(c, m, "default")
104
104
  ], e.prototype, "variant", 2);
105
105
  n([
106
106
  i({ type: String }),
107
- d(a, b, "medium")
107
+ d(c, b, "medium")
108
108
  ], e.prototype, "size", 2);
109
109
  n([
110
110
  i({ type: String }),
111
- d(a, S, "default")
111
+ d(c, z, "default")
112
112
  ], e.prototype, "underline", 2);
113
113
  n([
114
114
  i({ type: String }),
115
- d(a, $, "leading")
115
+ d(c, $, "leading")
116
116
  ], e.prototype, "iconPlacement", 2);
117
117
  n([
118
118
  i({ type: String, reflect: !0 })
@@ -134,18 +134,18 @@ n([
134
134
  ], e.prototype, "hasVisited", 2);
135
135
  n([
136
136
  i(),
137
- d(a, z, "submit")
137
+ d(c, S, "submit")
138
138
  ], e.prototype, "type", 2);
139
139
  n([
140
140
  i({ type: Object })
141
141
  ], e.prototype, "aria", 2);
142
- customElements.define(a, e);
142
+ customElements.define(c, e);
143
143
  export {
144
144
  e as PieLink,
145
- z as buttonTypes,
145
+ S as buttonTypes,
146
146
  $ as iconPlacements,
147
147
  b as sizes,
148
148
  x as tags,
149
- S as underlineTypes,
149
+ z as underlineTypes,
150
150
  m as variants
151
151
  };
package/dist/react.d.ts CHANGED
@@ -29,7 +29,8 @@ export declare interface LinkProps {
29
29
  */
30
30
  size: typeof sizes[number];
31
31
  /**
32
- * What underline behavior the link should have such as default or reversed
32
+ * Defines what underline behavior the link should have, such as default or reversed.
33
+ * The `reversed` type can only be used if the link is a block element (isStandalone = true)
33
34
  */
34
35
  underline: typeof underlineTypes[number];
35
36
  /**
@@ -57,7 +58,8 @@ export declare interface LinkProps {
57
58
  */
58
59
  hasVisited: boolean;
59
60
  /**
60
- * The placement of the icon slot, if provided, such as leading or trailing
61
+ * The placement of the icon slot, if provided, such as leading or trailing.
62
+ * Will only apply if the link is a block element (isStandalone = true)
61
63
  */
62
64
  iconPlacement?: typeof iconPlacements[number];
63
65
  /**
@@ -88,7 +90,7 @@ declare class PieLink_2 extends LitElement implements LinkProps {
88
90
  aria: AriaProps;
89
91
  /**
90
92
  * Renders the link content.
91
- *
93
+ * Icons are only shown in block elements
92
94
  * @private
93
95
  */
94
96
  private renderContent;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-link",
3
3
  "description": "PIE Design System Link built using Web Components",
4
- "version": "0.5.0",
4
+ "version": "0.6.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -28,10 +28,10 @@
28
28
  "author": "JustEatTakeaway.com - Design System Web Team",
29
29
  "license": "Apache-2.0",
30
30
  "devDependencies": {
31
- "@justeattakeaway/pie-components-config": "workspace:*"
31
+ "@justeattakeaway/pie-components-config": "0.4.0"
32
32
  },
33
33
  "dependencies": {
34
- "@justeattakeaway/pie-webc-core": "workspace:*"
34
+ "@justeattakeaway/pie-webc-core": "0.9.0"
35
35
  },
36
36
  "volta": {
37
37
  "extends": "../../../package.json"
package/src/defs.ts CHANGED
@@ -27,7 +27,8 @@ export interface LinkProps {
27
27
  */
28
28
  size: typeof sizes[number];
29
29
  /**
30
- * What underline behavior the link should have such as default or reversed
30
+ * Defines what underline behavior the link should have, such as default or reversed.
31
+ * The `reversed` type can only be used if the link is a block element (isStandalone = true)
31
32
  */
32
33
  underline: typeof underlineTypes[number];
33
34
  /**
@@ -55,7 +56,8 @@ export interface LinkProps {
55
56
  */
56
57
  hasVisited: boolean;
57
58
  /**
58
- * The placement of the icon slot, if provided, such as leading or trailing
59
+ * The placement of the icon slot, if provided, such as leading or trailing.
60
+ * Will only apply if the link is a block element (isStandalone = true)
59
61
  */
60
62
  iconPlacement?: typeof iconPlacements[number];
61
63
  /**
package/src/index.ts CHANGED
@@ -73,16 +73,16 @@ export class PieLink extends LitElement implements LinkProps {
73
73
 
74
74
  /**
75
75
  * Renders the link content.
76
- *
76
+ * Icons are only shown in block elements
77
77
  * @private
78
78
  */
79
79
  private renderContent (): TemplateResult {
80
- const { iconPlacement } = this;
80
+ const { iconPlacement, isStandalone } = this;
81
81
  return html`
82
82
  <span class="c-link-content">
83
- ${iconPlacement === 'leading' ? html`<slot name="icon"></slot>` : nothing}
83
+ ${isStandalone && iconPlacement === 'leading' ? html`<slot name="icon"></slot>` : nothing}
84
84
  <slot></slot>
85
- ${iconPlacement === 'trailing' ? html`<slot name="icon"></slot>` : nothing}
85
+ ${isStandalone && iconPlacement === 'trailing' ? html`<slot name="icon"></slot>` : nothing}
86
86
  </span>`;
87
87
  }
88
88
 
package/src/link.scss CHANGED
@@ -20,6 +20,7 @@
20
20
  --link-text-color: var(--dt-color-content-link);
21
21
  --link-text-decoration: var(--dt-font-style-underline);
22
22
  --link-icon-size: 16px;
23
+ --link-icon-offset-top: var(--dt-spacing-a);
23
24
 
24
25
  display: inline-block;
25
26
  font-family: var(--link-font-family);
@@ -30,6 +31,9 @@
30
31
  text-decoration: var(--link-text-decoration);
31
32
  cursor: pointer;
32
33
 
34
+ @include link-interactive-states('default');
35
+
36
+
33
37
  &[tag='a'] {
34
38
  /* Same as default styles */
35
39
  }
@@ -57,6 +61,7 @@
57
61
  &[size='small'] {
58
62
  --link-font-size: #{p.font-size(--dt-font-size-14)};
59
63
  --link-line-height: calc(var(--dt-font-size-14-line-height) * 1px);
64
+ --link-icon-offset-top: 2px;
60
65
  }
61
66
 
62
67
  &[size='medium'] {
@@ -65,11 +70,9 @@
65
70
 
66
71
  &[underline='default'] {
67
72
  /* Same as default styles */
68
-
69
- @include link-interactive-states('default');
70
73
  }
71
74
 
72
- &[underline='reversed'] {
75
+ &[underline='reversed'][isStandalone] {
73
76
  --link-text-decoration: none;
74
77
 
75
78
  @include link-interactive-states('reversed');
@@ -92,7 +95,9 @@
92
95
  }
93
96
 
94
97
  &:focus-visible {
95
- box-shadow: 0 0 0 2px var(--dt-color-focus-outer);
98
+ outline: none;
99
+ border-radius: 2px;
100
+ box-shadow: 0 0 0 2px var(--dt-color-focus-inner), 0 0 0 4px var(--dt-color-focus-outer);
96
101
  }
97
102
  }
98
103
 
@@ -104,7 +109,7 @@
104
109
  ::slotted(.c-pieIcon),
105
110
  ::slotted(svg) {
106
111
  display: inline-flex;
107
- margin-block-start: var(--dt-spacing-a);
112
+ margin-block-start: var(--link-icon-offset-top);
108
113
  height: var(--link-icon-size);
109
114
  width: var(--link-icon-size);
110
115
  }