@justeattakeaway/pie-link 0.2.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 +34 -9
- package/dist/index.d.ts +30 -5
- package/dist/index.js +91 -67
- package/dist/react.d.ts +30 -5
- package/dist/react.js +46 -1565
- package/package.json +1 -1
- package/src/defs.ts +19 -4
- package/src/index.ts +48 -11
- package/src/link.scss +27 -0
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
|
|
61
|
-
|
|
|
62
|
-
|
|
|
63
|
-
|
|
|
64
|
-
|
|
|
65
|
-
|
|
|
66
|
-
|
|
|
67
|
-
|
|
|
68
|
-
|
|
|
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
|
package/dist/index.d.ts
CHANGED
|
@@ -2,15 +2,23 @@ import type { CSSResult } from 'lit';
|
|
|
2
2
|
import type { LitElement } from 'lit';
|
|
3
3
|
import type { TemplateResult } from 'lit-html';
|
|
4
4
|
|
|
5
|
+
export declare const buttonTypes: readonly ["submit", "button", "reset", "menu"];
|
|
6
|
+
|
|
7
|
+
export declare const iconPlacements: readonly ["leading", "trailing"];
|
|
8
|
+
|
|
5
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];
|
|
6
14
|
/**
|
|
7
15
|
* What style variant the link should be such as default, high-visibility or inverse.
|
|
8
16
|
*/
|
|
9
|
-
variant
|
|
17
|
+
variant: typeof variants[number];
|
|
10
18
|
/**
|
|
11
19
|
* What size the link should be.
|
|
12
20
|
*/
|
|
13
|
-
size
|
|
21
|
+
size: typeof sizes[number];
|
|
14
22
|
/**
|
|
15
23
|
* The URL that the hyperlink should point to
|
|
16
24
|
*/
|
|
@@ -26,27 +34,44 @@ export declare interface LinkProps {
|
|
|
26
34
|
/**
|
|
27
35
|
* When true, the link text will be bold.
|
|
28
36
|
*/
|
|
29
|
-
isBold
|
|
37
|
+
isBold: boolean;
|
|
30
38
|
/**
|
|
31
39
|
* When true, the link will be treated as a block box
|
|
32
40
|
*/
|
|
33
|
-
isStandalone
|
|
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];
|
|
34
50
|
}
|
|
35
51
|
|
|
52
|
+
/**
|
|
53
|
+
* @slot icon - The icon slot
|
|
54
|
+
* @slot - Default slot
|
|
55
|
+
*/
|
|
36
56
|
export declare class PieLink extends LitElement implements LinkProps {
|
|
57
|
+
tag: LinkProps['tag'];
|
|
37
58
|
variant: LinkProps['variant'];
|
|
38
59
|
size: LinkProps['size'];
|
|
60
|
+
iconPlacement: LinkProps['iconPlacement'];
|
|
39
61
|
href?: string;
|
|
40
62
|
target?: string;
|
|
41
63
|
rel?: string;
|
|
42
64
|
isBold: boolean;
|
|
43
65
|
isStandalone: boolean;
|
|
44
|
-
|
|
66
|
+
type: LinkProps['type'];
|
|
67
|
+
render(): TemplateResult;
|
|
45
68
|
static styles: CSSResult;
|
|
46
69
|
}
|
|
47
70
|
|
|
48
71
|
export declare const sizes: readonly ["small", "medium"];
|
|
49
72
|
|
|
73
|
+
export declare const tags: readonly ["a", "button"];
|
|
74
|
+
|
|
50
75
|
export declare const variants: readonly ["default", "high-visibility", "inverse"];
|
|
51
76
|
|
|
52
77
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -1,86 +1,110 @@
|
|
|
1
|
-
import { unsafeCSS as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
|
6
|
-
const
|
|
7
|
-
Object.defineProperty(t,
|
|
5
|
+
const g = (f, n, a) => function(t, i) {
|
|
6
|
+
const o = `#${i}`;
|
|
7
|
+
Object.defineProperty(t, i, {
|
|
8
8
|
get() {
|
|
9
|
-
return this[
|
|
9
|
+
return this[o];
|
|
10
10
|
},
|
|
11
|
-
set(
|
|
12
|
-
const
|
|
13
|
-
n.includes(
|
|
14
|
-
`<${
|
|
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: "${
|
|
17
|
-
), this[
|
|
16
|
+
`Falling back to default value: "${a}"`
|
|
17
|
+
), this[o] = a), this.requestUpdate(i, v);
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
|
-
},
|
|
21
|
-
`,
|
|
22
|
-
var
|
|
23
|
-
for (var t =
|
|
24
|
-
(
|
|
25
|
-
return
|
|
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
|
|
28
|
-
class
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
rel: e,
|
|
34
|
+
tag: n,
|
|
35
|
+
variant: a,
|
|
36
|
+
size: s,
|
|
37
|
+
iconPlacement: t,
|
|
39
38
|
isBold: i,
|
|
40
|
-
isStandalone:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
target=${d(t)}
|
|
50
|
-
rel=${d(e)}
|
|
49
|
+
tag="${n}"
|
|
50
|
+
variant=${a}
|
|
51
|
+
size=${s}
|
|
51
52
|
?isBold=${i}
|
|
52
|
-
?isStandalone=${
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
],
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
],
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
};
|
package/dist/react.d.ts
CHANGED
|
@@ -3,15 +3,23 @@ import type { LitElement } from 'lit';
|
|
|
3
3
|
import type { ReactWebComponent } from '@lit-labs/react';
|
|
4
4
|
import type { TemplateResult } from 'lit-html';
|
|
5
5
|
|
|
6
|
+
export declare const buttonTypes: readonly ["submit", "button", "reset", "menu"];
|
|
7
|
+
|
|
8
|
+
export declare const iconPlacements: readonly ["leading", "trailing"];
|
|
9
|
+
|
|
6
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];
|
|
7
15
|
/**
|
|
8
16
|
* What style variant the link should be such as default, high-visibility or inverse.
|
|
9
17
|
*/
|
|
10
|
-
variant
|
|
18
|
+
variant: typeof variants[number];
|
|
11
19
|
/**
|
|
12
20
|
* What size the link should be.
|
|
13
21
|
*/
|
|
14
|
-
size
|
|
22
|
+
size: typeof sizes[number];
|
|
15
23
|
/**
|
|
16
24
|
* The URL that the hyperlink should point to
|
|
17
25
|
*/
|
|
@@ -27,29 +35,46 @@ export declare interface LinkProps {
|
|
|
27
35
|
/**
|
|
28
36
|
* When true, the link text will be bold.
|
|
29
37
|
*/
|
|
30
|
-
isBold
|
|
38
|
+
isBold: boolean;
|
|
31
39
|
/**
|
|
32
40
|
* When true, the link will be treated as a block box
|
|
33
41
|
*/
|
|
34
|
-
isStandalone
|
|
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];
|
|
35
51
|
}
|
|
36
52
|
|
|
37
53
|
export declare const PieLink: ReactWebComponent<PieLink_2, {}>;
|
|
38
54
|
|
|
55
|
+
/**
|
|
56
|
+
* @slot icon - The icon slot
|
|
57
|
+
* @slot - Default slot
|
|
58
|
+
*/
|
|
39
59
|
declare class PieLink_2 extends LitElement implements LinkProps {
|
|
60
|
+
tag: LinkProps['tag'];
|
|
40
61
|
variant: LinkProps['variant'];
|
|
41
62
|
size: LinkProps['size'];
|
|
63
|
+
iconPlacement: LinkProps['iconPlacement'];
|
|
42
64
|
href?: string;
|
|
43
65
|
target?: string;
|
|
44
66
|
rel?: string;
|
|
45
67
|
isBold: boolean;
|
|
46
68
|
isStandalone: boolean;
|
|
47
|
-
|
|
69
|
+
type: LinkProps['type'];
|
|
70
|
+
render(): TemplateResult;
|
|
48
71
|
static styles: CSSResult;
|
|
49
72
|
}
|
|
50
73
|
|
|
51
74
|
export declare const sizes: readonly ["small", "medium"];
|
|
52
75
|
|
|
76
|
+
export declare const tags: readonly ["a", "button"];
|
|
77
|
+
|
|
53
78
|
export declare const variants: readonly ["default", "high-visibility", "inverse"];
|
|
54
79
|
|
|
55
80
|
export { }
|