@justeattakeaway/pie-link 0.1.0 → 0.3.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
@@ -57,15 +57,18 @@ import { PieLink } from '@justeattakeaway/pie-link/dist/react';
57
57
 
58
58
  ## Props
59
59
 
60
- | Property | Type | Default | Description |
61
- | ------------ | ----------- | ------------- | --------------------------------------------------------------------------- |
62
- | variant | `String` | `default` | Variant of the link, one of variants default, high-visibility or inverse |
63
- | size | `String` | `medium` | Size of the link, one of `sizes` – `medium`, `small` |
64
- | href | `String` | `undefined` | Native html `href` attribute |
65
- | rel | `String` | `undefined` | Native html `rel` attribute |
66
- | target | `String` | `undefined` | Native html `target` attribute |
67
- | isBold | `Boolean` | `false` | If `true`, sets the link text bold |
68
- | isStandalone | `Boolean` | `false` | If `true`, sets the link as a block element |
60
+ | Property | Type | Default | Description |
61
+ | ------------- | ----------- | ------------- | ---------------------------------------------------------------------------------------------------- |
62
+ | tag | `String` | `a` | The rendered HTML element of the link, one of `tags` `a`, `button` |
63
+ | variant | `String` | `default` | Variant of the link, one of `variants` – `default`, `high-visibility`, `inverse` |
64
+ | size | `String` | `medium` | Size of the link, one of `sizes` – `medium`, `small` |
65
+ | href | `String` | `undefined` | Native html `href` attribute |
66
+ | rel | `String` | `undefined` | Native html `rel` attribute |
67
+ | target | `String` | `undefined` | Native html `target` attribute |
68
+ | type | `String` | `submit` | Native html `type` attribute if the tag is set to `button` |
69
+ | isBold | `Boolean` | `false` | If `true`, sets the link text bold |
70
+ | isStandalone | `Boolean` | `false` | If `true`, sets the link as a block element |
71
+ | iconPlacement | `String` | `leading` | Icon placements of the icon slot, if provided, one of `iconPlacements` - `leading`, `trailing` |
69
72
 
70
73
  In your markup or JSX, you can then use these to set the properties for the `pie-link` component:
71
74
 
@@ -77,6 +80,28 @@ In your markup or JSX, you can then use these to set the properties for the `pie
77
80
  <PieLink></PieLink>
78
81
  ```
79
82
 
83
+ ## Slots
84
+
85
+ | Slot | Description |
86
+ | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
87
+ | Default slot | The default slot is used to pass text into the link component. |
88
+ | icon | Used to pass in an icon to the link component. The icon placement can be controlled via the `iconPlacement` prop and we recommend using `pie-icons-webc` for defining this icon, but this can also accept an SVG icon. |
89
+
90
+ ### Using `pie-icons-webc` with the `pie-link` icon slot
91
+
92
+ We recommend using `pie-icons-webc` when using the `icon` slot. Here is an example of how you would do this:
93
+
94
+ ```html
95
+ <!--
96
+ Note that pie-link and the icons that you want to use will need to be imported as components into your application.
97
+ See the `pie-icons-webc` README for more info on importing these icons.
98
+ -->
99
+ <pie-link>
100
+ <icon-plus-circle slot="icon"></icon-plus-circle>
101
+ Search
102
+ </pie-link>
103
+ ```
104
+
80
105
  ## Testing
81
106
 
82
107
  ### Browser tests
@@ -0,0 +1,77 @@
1
+ import type { CSSResult } from 'lit';
2
+ import type { LitElement } from 'lit';
3
+ import type { TemplateResult } from 'lit-html';
4
+
5
+ export declare const buttonTypes: readonly ["submit", "button", "reset", "menu"];
6
+
7
+ export declare const iconPlacements: readonly ["leading", "trailing"];
8
+
9
+ export declare interface LinkProps {
10
+ /**
11
+ * What HTML element the link should be such as a or button.
12
+ */
13
+ tag: typeof tags[number];
14
+ /**
15
+ * What style variant the link should be such as default, high-visibility or inverse.
16
+ */
17
+ variant: typeof variants[number];
18
+ /**
19
+ * What size the link should be.
20
+ */
21
+ size: typeof sizes[number];
22
+ /**
23
+ * The URL that the hyperlink should point to
24
+ */
25
+ href?: string;
26
+ /**
27
+ * Where to display the linked URL such as _self, _blank, _parent or _top
28
+ */
29
+ target?: string;
30
+ /**
31
+ * What the relationship of the linked URL is
32
+ */
33
+ rel?: string;
34
+ /**
35
+ * When true, the link text will be bold.
36
+ */
37
+ isBold: boolean;
38
+ /**
39
+ * When true, the link will be treated as a block box
40
+ */
41
+ isStandalone: boolean;
42
+ /**
43
+ * The placement of the icon slot, if provided, such as leading or trailing
44
+ */
45
+ iconPlacement?: typeof iconPlacements[number];
46
+ /**
47
+ * What type attribute should be applied if the tag is set to button. For example submit, button or menu.
48
+ */
49
+ type?: typeof buttonTypes[number];
50
+ }
51
+
52
+ /**
53
+ * @slot icon - The icon slot
54
+ * @slot - Default slot
55
+ */
56
+ export declare class PieLink extends LitElement implements LinkProps {
57
+ tag: LinkProps['tag'];
58
+ variant: LinkProps['variant'];
59
+ size: LinkProps['size'];
60
+ iconPlacement: LinkProps['iconPlacement'];
61
+ href?: string;
62
+ target?: string;
63
+ rel?: string;
64
+ isBold: boolean;
65
+ isStandalone: boolean;
66
+ type: LinkProps['type'];
67
+ render(): TemplateResult;
68
+ static styles: CSSResult;
69
+ }
70
+
71
+ export declare const sizes: readonly ["small", "medium"];
72
+
73
+ export declare const tags: readonly ["a", "button"];
74
+
75
+ export declare const variants: readonly ["default", "high-visibility", "inverse"];
76
+
77
+ export { }
package/dist/index.js CHANGED
@@ -1,86 +1,110 @@
1
- import { unsafeCSS as k, LitElement as g, html as m } from "lit";
2
- import { property as s } from "lit/decorators.js";
3
- import { ifDefined as d } from "lit/directives/if-defined.js";
1
+ import { unsafeCSS as b, LitElement as $, nothing as p } from "lit";
2
+ import { unsafeStatic as z, html as u } from "lit/static-html.js";
3
+ import { property as l } from "lit/decorators.js";
4
4
  import "lit/decorators/property.js";
5
- const v = (c, n, r) => function(t, e) {
6
- const i = `#${e}`;
7
- Object.defineProperty(t, e, {
5
+ const g = (f, n, a) => function(t, i) {
6
+ const o = `#${i}`;
7
+ Object.defineProperty(t, i, {
8
8
  get() {
9
- return this[i];
9
+ return this[o];
10
10
  },
11
- set(f) {
12
- const h = this[i];
13
- n.includes(f) ? this[i] = f : (console.error(
14
- `<${c}> Invalid value "${f}" provided for property "${e}".`,
11
+ set(c) {
12
+ const v = this[o];
13
+ n.includes(c) ? this[o] = c : (console.error(
14
+ `<${f}> Invalid value "${c}" provided for property "${i}".`,
15
15
  `Must be one of: ${n.join(" | ")}.`,
16
- `Falling back to default value: "${r}"`
17
- ), this[i] = r), this.requestUpdate(e, h);
16
+ `Falling back to default value: "${a}"`
17
+ ), this[o] = a), this.requestUpdate(i, v);
18
18
  }
19
19
  });
20
- }, u = `.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);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[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[isBold]{--link-font-weight: var(--dt-font-weight-bold)}.c-link[isStandalone]{display:block}
21
- `, y = ["default", "high-visibility", "inverse"], z = ["small", "medium"];
22
- var x = Object.defineProperty, S = Object.getOwnPropertyDescriptor, a = (c, n, r, l) => {
23
- for (var t = l > 1 ? void 0 : l ? S(n, r) : n, e = c.length - 1, i; e >= 0; e--)
24
- (i = c[e]) && (t = (l ? i(n, r, t) : i(t)) || t);
25
- return l && t && x(n, r, t), t;
20
+ }, x = `.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[isBold]{--link-font-weight: var(--dt-font-weight-bold)}.c-link[isStandalone]{display:block}.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)}
21
+ `, S = ["default", "high-visibility", "inverse"], P = ["small", "medium"], w = ["leading", "trailing"], B = ["a", "button"], _ = ["submit", "button", "reset", "menu"];
22
+ var O = Object.defineProperty, j = Object.getOwnPropertyDescriptor, r = (f, n, a, s) => {
23
+ for (var t = s > 1 ? void 0 : s ? j(n, a) : n, i = f.length - 1, o; i >= 0; i--)
24
+ (o = f[i]) && (t = (s ? o(n, a, t) : o(t)) || t);
25
+ return s && t && O(n, a, t), t;
26
26
  };
27
- const p = "pie-link";
28
- class o extends g {
27
+ const d = "pie-link";
28
+ class e extends $ {
29
29
  constructor() {
30
- super(...arguments), this.variant = "default", this.size = "medium", this.isBold = !1, this.isStandalone = !1;
30
+ super(...arguments), this.tag = "a", this.variant = "default", this.size = "medium", this.iconPlacement = "leading", this.isBold = !1, this.isStandalone = !1, this.type = "submit";
31
31
  }
32
32
  render() {
33
33
  const {
34
- variant: n,
35
- size: r,
36
- href: l,
37
- target: t,
38
- rel: e,
34
+ tag: n,
35
+ variant: a,
36
+ size: s,
37
+ iconPlacement: t,
39
38
  isBold: i,
40
- isStandalone: f
41
- } = this;
42
- return m`
43
- <a
39
+ isStandalone: o,
40
+ href: c,
41
+ target: v,
42
+ rel: m,
43
+ type: y
44
+ } = this, k = z(n), h = n === "button";
45
+ return u`
46
+ <${k}
44
47
  data-test-id="pie-link"
45
48
  class="c-link"
46
- variant=${n}
47
- size=${r}
48
- href=${d(l)}
49
- target=${d(t)}
50
- rel=${d(e)}
49
+ tag="${n}"
50
+ variant=${a}
51
+ size=${s}
51
52
  ?isBold=${i}
52
- ?isStandalone=${f}>
53
- <slot></slot>
54
- </a>`;
53
+ ?isStandalone=${o}
54
+ href=${!h && c ? c : p}
55
+ target=${!h && v ? v : p}
56
+ rel=${!h && m ? m : p}
57
+ type=${h && y ? y : p}>
58
+ <span class="c-link-content">
59
+ ${t === "leading" ? u`<slot name="icon"></slot>` : p}
60
+ <slot></slot>
61
+ ${t === "trailing" ? u`<slot name="icon"></slot>` : p}
62
+ </span>
63
+ </${k}>`;
55
64
  }
56
65
  }
57
- o.styles = k(u);
58
- a([
59
- s({ type: String }),
60
- v(p, y, "default")
61
- ], o.prototype, "variant", 2);
62
- a([
63
- s({ type: String }),
64
- v(p, z, "medium")
65
- ], o.prototype, "size", 2);
66
- a([
67
- s({ type: String, reflect: !0 })
68
- ], o.prototype, "href", 2);
69
- a([
70
- s({ type: String, reflect: !0 })
71
- ], o.prototype, "target", 2);
72
- a([
73
- s({ type: String, reflect: !0 })
74
- ], o.prototype, "rel", 2);
75
- a([
76
- s({ type: Boolean })
77
- ], o.prototype, "isBold", 2);
78
- a([
79
- s({ type: Boolean })
80
- ], o.prototype, "isStandalone", 2);
81
- customElements.define(p, o);
66
+ e.styles = b(x);
67
+ r([
68
+ l(),
69
+ g(d, B, "a")
70
+ ], e.prototype, "tag", 2);
71
+ r([
72
+ l({ type: String }),
73
+ g(d, S, "default")
74
+ ], e.prototype, "variant", 2);
75
+ r([
76
+ l({ type: String }),
77
+ g(d, P, "medium")
78
+ ], e.prototype, "size", 2);
79
+ r([
80
+ l({ type: String }),
81
+ g(d, w, "leading")
82
+ ], e.prototype, "iconPlacement", 2);
83
+ r([
84
+ l({ type: String, reflect: !0 })
85
+ ], e.prototype, "href", 2);
86
+ r([
87
+ l({ type: String, reflect: !0 })
88
+ ], e.prototype, "target", 2);
89
+ r([
90
+ l({ type: String, reflect: !0 })
91
+ ], e.prototype, "rel", 2);
92
+ r([
93
+ l({ type: Boolean })
94
+ ], e.prototype, "isBold", 2);
95
+ r([
96
+ l({ type: Boolean })
97
+ ], e.prototype, "isStandalone", 2);
98
+ r([
99
+ l(),
100
+ g(d, _, "submit")
101
+ ], e.prototype, "type", 2);
102
+ customElements.define(d, e);
82
103
  export {
83
- o as PieLink,
84
- z as sizes,
85
- y as variants
104
+ e as PieLink,
105
+ _ as buttonTypes,
106
+ w as iconPlacements,
107
+ P as sizes,
108
+ B as tags,
109
+ S as variants
86
110
  };
@@ -0,0 +1,80 @@
1
+ import type { CSSResult } from 'lit';
2
+ import type { LitElement } from 'lit';
3
+ import type { ReactWebComponent } from '@lit-labs/react';
4
+ import type { TemplateResult } from 'lit-html';
5
+
6
+ export declare const buttonTypes: readonly ["submit", "button", "reset", "menu"];
7
+
8
+ export declare const iconPlacements: readonly ["leading", "trailing"];
9
+
10
+ export declare interface LinkProps {
11
+ /**
12
+ * What HTML element the link should be such as a or button.
13
+ */
14
+ tag: typeof tags[number];
15
+ /**
16
+ * What style variant the link should be such as default, high-visibility or inverse.
17
+ */
18
+ variant: typeof variants[number];
19
+ /**
20
+ * What size the link should be.
21
+ */
22
+ size: typeof sizes[number];
23
+ /**
24
+ * The URL that the hyperlink should point to
25
+ */
26
+ href?: string;
27
+ /**
28
+ * Where to display the linked URL such as _self, _blank, _parent or _top
29
+ */
30
+ target?: string;
31
+ /**
32
+ * What the relationship of the linked URL is
33
+ */
34
+ rel?: string;
35
+ /**
36
+ * When true, the link text will be bold.
37
+ */
38
+ isBold: boolean;
39
+ /**
40
+ * When true, the link will be treated as a block box
41
+ */
42
+ isStandalone: boolean;
43
+ /**
44
+ * The placement of the icon slot, if provided, such as leading or trailing
45
+ */
46
+ iconPlacement?: typeof iconPlacements[number];
47
+ /**
48
+ * What type attribute should be applied if the tag is set to button. For example submit, button or menu.
49
+ */
50
+ type?: typeof buttonTypes[number];
51
+ }
52
+
53
+ export declare const PieLink: ReactWebComponent<PieLink_2, {}>;
54
+
55
+ /**
56
+ * @slot icon - The icon slot
57
+ * @slot - Default slot
58
+ */
59
+ declare class PieLink_2 extends LitElement implements LinkProps {
60
+ tag: LinkProps['tag'];
61
+ variant: LinkProps['variant'];
62
+ size: LinkProps['size'];
63
+ iconPlacement: LinkProps['iconPlacement'];
64
+ href?: string;
65
+ target?: string;
66
+ rel?: string;
67
+ isBold: boolean;
68
+ isStandalone: boolean;
69
+ type: LinkProps['type'];
70
+ render(): TemplateResult;
71
+ static styles: CSSResult;
72
+ }
73
+
74
+ export declare const sizes: readonly ["small", "medium"];
75
+
76
+ export declare const tags: readonly ["a", "button"];
77
+
78
+ export declare const variants: readonly ["default", "high-visibility", "inverse"];
79
+
80
+ export { }