@justeattakeaway/pie-divider 0.13.9 → 0.14.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.
@@ -34,7 +34,7 @@
34
34
  "type": {
35
35
  "text": "DefaultProps"
36
36
  },
37
- "default": "{\n variant: 'default',\n orientation: 'horizontal',\n}"
37
+ "default": "{\n variant: 'default',\n orientation: 'horizontal',\n label: '',\n}"
38
38
  }
39
39
  ],
40
40
  "exports": [
@@ -84,6 +84,12 @@
84
84
  "name": "orientation",
85
85
  "privacy": "public",
86
86
  "attribute": "orientation"
87
+ },
88
+ {
89
+ "kind": "field",
90
+ "name": "label",
91
+ "privacy": "public",
92
+ "attribute": "label"
87
93
  }
88
94
  ],
89
95
  "attributes": [
@@ -94,6 +100,10 @@
94
100
  {
95
101
  "name": "orientation",
96
102
  "fieldName": "orientation"
103
+ },
104
+ {
105
+ "name": "label",
106
+ "fieldName": "label"
97
107
  }
98
108
  ],
99
109
  "superclass": {
package/dist/index.d.ts CHANGED
@@ -16,6 +16,10 @@ export declare interface DividerProps {
16
16
  * What orientation the divider should be such as horizontal or vertical.
17
17
  */
18
18
  orientation?: typeof orientations[number];
19
+ /**
20
+ * The label text for the divider.
21
+ */
22
+ label?: string;
19
23
  }
20
24
 
21
25
  export declare const orientations: readonly ["horizontal", "vertical"];
@@ -26,6 +30,7 @@ export declare const orientations: readonly ["horizontal", "vertical"];
26
30
  export declare class PieDivider extends LitElement implements DividerProps {
27
31
  variant: "default" | "inverse";
28
32
  orientation: "horizontal" | "vertical";
33
+ label: string;
29
34
  render(): TemplateResult<1>;
30
35
  static styles: CSSResult;
31
36
  }
package/dist/index.js CHANGED
@@ -1,48 +1,64 @@
1
- import { unsafeCSS as h, LitElement as f, html as u } from "lit";
2
- import { property as c } from "lit/decorators.js";
3
- import { classMap as m } from "lit/directives/class-map.js";
4
- import { validPropertyValues as l, defineCustomElement as g } from "@justeattakeaway/pie-webc-core";
5
- const b = `*,*:after,*:before{box-sizing:inherit}.c-divider{--divider-bg-color: var(--dt-color-divider-default);--divider-width: 100%;--divider-height: 1px;margin:0;border:0;width:var(--divider-width);height:var(--divider-height);background-color:var(--divider-bg-color)}.c-divider.c-divider--inverse{--divider-bg-color: var(--dt-color-divider-inverse)}.c-divider.c-divider--vertical{--divider-width: 1px;--divider-height: 100%}
6
- `, y = ["default", "inverse"], P = ["horizontal", "vertical"], o = {
1
+ import { unsafeCSS as g, LitElement as m, html as c } from "lit";
2
+ import { property as s } from "lit/decorators.js";
3
+ import { classMap as p } from "lit/directives/class-map.js";
4
+ import { validPropertyValues as b, defineCustomElement as f } from "@justeattakeaway/pie-webc-core";
5
+ const u = `*,*:after,*:before{box-sizing:inherit}.c-divider{--divider-bg-color: var(--dt-color-divider-default);--divider-width: 100%;--divider-min-width: 16px;--divider-height: 1px;--divider-label-max-width: 90%;width:var(--divider-width)}.c-divider,.c-divider hr{margin:0;border:0;background-color:var(--divider-bg-color)}.c-divider:not(.c-divider--labelled){height:var(--divider-height)}.c-divider.c-divider--labelled{display:flex;align-items:center;text-align:center;gap:var(--dt-spacing-b);background-color:transparent}.c-divider.c-divider--labelled .c-divider-label{max-width:var(--divider-label-max-width);word-wrap:break-word}.c-divider.c-divider--labelled hr{flex-grow:1;height:var(--divider-height);min-width:var(--divider-min-width)}.c-divider.c-divider--labelled.c-divider--inverse{color:var(--dt-color-content-inverse)}.c-divider.c-divider--inverse{--divider-bg-color: var(--dt-color-divider-inverse)}.c-divider.c-divider--vertical{--divider-width: 1px;--divider-height: 100%}
6
+ `, w = ["default", "inverse"], x = ["horizontal", "vertical"], l = {
7
7
  variant: "default",
8
- orientation: "horizontal"
8
+ orientation: "horizontal",
9
+ label: ""
9
10
  };
10
- var w = Object.defineProperty, _ = Object.getOwnPropertyDescriptor, p = (n, r, e, t) => {
11
- for (var i = t > 1 ? void 0 : t ? _(r, e) : r, a = n.length - 1, v; a >= 0; a--)
12
- (v = n[a]) && (i = (t ? v(r, e, i) : v(i)) || i);
13
- return t && i && w(r, e, i), i;
11
+ var y = Object.defineProperty, $ = Object.getOwnPropertyDescriptor, h = (n, d, t, r) => {
12
+ for (var i = r > 1 ? void 0 : r ? $(d, t) : d, a = n.length - 1, v; a >= 0; a--)
13
+ (v = n[a]) && (i = (r ? v(d, t, i) : v(i)) || i);
14
+ return r && i && y(d, t, i), i;
14
15
  };
15
- const s = "pie-divider";
16
- class d extends f {
16
+ const e = "pie-divider";
17
+ class o extends m {
17
18
  constructor() {
18
- super(...arguments), this.variant = o.variant, this.orientation = o.orientation;
19
+ super(...arguments), this.variant = l.variant, this.orientation = l.orientation, this.label = l.label;
19
20
  }
20
21
  render() {
21
- const { variant: r, orientation: e } = this;
22
- return u`
23
- <hr
24
- data-test-id="pie-divider"
25
- aria-hidden="true"
26
- class="${m({
22
+ const { variant: d, orientation: t, label: r } = this, i = r.length > 0 && t === "horizontal", a = {
27
23
  "c-divider": !0,
28
- "c-divider--inverse": r === "inverse",
29
- "c-divider--vertical": e === "vertical"
30
- })}" />`;
24
+ "c-divider--inverse": d === "inverse",
25
+ "c-divider--vertical": t === "vertical",
26
+ "c-divider--labelled": i
27
+ };
28
+ return c`
29
+ ${i ? c`
30
+ <div
31
+ id="${e}"
32
+ data-test-id="${e}"
33
+ class="${p(a)}"
34
+ aria-labelledby="${e}-label">
35
+ <hr aria-hidden="true"/>
36
+ <span id="${e}-label" class="c-divider-label">${r}</span>
37
+ <hr aria-hidden="true"/>
38
+ </div>` : c`
39
+ <hr id="${e}"
40
+ data-test-id="${e}"
41
+ class="${p(a)}"
42
+ aria-hidden="true"
43
+ />`}`;
31
44
  }
32
45
  }
33
- d.styles = h(b);
34
- p([
35
- c({ type: String }),
36
- l(s, y, o.variant)
37
- ], d.prototype, "variant", 2);
38
- p([
39
- c({ type: String }),
40
- l(s, P, o.orientation)
41
- ], d.prototype, "orientation", 2);
42
- g(s, d);
46
+ o.styles = g(u);
47
+ h([
48
+ s({ type: String }),
49
+ b(e, w, l.variant)
50
+ ], o.prototype, "variant", 2);
51
+ h([
52
+ s({ type: String }),
53
+ b(e, x, l.orientation)
54
+ ], o.prototype, "orientation", 2);
55
+ h([
56
+ s({ type: String })
57
+ ], o.prototype, "label", 2);
58
+ f(e, o);
43
59
  export {
44
- d as PieDivider,
45
- o as defaultProps,
46
- P as orientations,
47
- y as variants
60
+ o as PieDivider,
61
+ l as defaultProps,
62
+ x as orientations,
63
+ w as variants
48
64
  };
package/dist/react.d.ts CHANGED
@@ -17,6 +17,10 @@ export declare interface DividerProps {
17
17
  * What orientation the divider should be such as horizontal or vertical.
18
18
  */
19
19
  orientation?: typeof orientations[number];
20
+ /**
21
+ * The label text for the divider.
22
+ */
23
+ label?: string;
20
24
  }
21
25
 
22
26
  export declare const orientations: readonly ["horizontal", "vertical"];
@@ -29,6 +33,7 @@ export declare const PieDivider: React_2.ForwardRefExoticComponent<DividerProps
29
33
  declare class PieDivider_2 extends LitElement implements DividerProps {
30
34
  variant: "default" | "inverse";
31
35
  orientation: "horizontal" | "vertical";
36
+ label: string;
32
37
  render(): TemplateResult<1>;
33
38
  static styles: CSSResult;
34
39
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-divider",
3
3
  "description": "PIE Design System Divider built using Web Components",
4
- "version": "0.13.9",
4
+ "version": "0.14.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -36,7 +36,7 @@
36
36
  "license": "Apache-2.0",
37
37
  "devDependencies": {
38
38
  "@custom-elements-manifest/analyzer": "0.9.0",
39
- "@justeattakeaway/pie-components-config": "0.17.0",
39
+ "@justeattakeaway/pie-components-config": "0.18.0",
40
40
  "@justeattakeaway/pie-css": "0.12.1",
41
41
  "@justeattakeaway/pie-wrapper-react": "0.14.1",
42
42
  "cem-plugin-module-file-extensions": "0.0.5"
package/src/defs.ts CHANGED
@@ -12,6 +12,10 @@ export interface DividerProps {
12
12
  * What orientation the divider should be such as horizontal or vertical.
13
13
  */
14
14
  orientation?: typeof orientations[number];
15
+ /**
16
+ * The label text for the divider.
17
+ */
18
+ label?: string;
15
19
  }
16
20
 
17
21
  export type DefaultProps = ComponentDefaultProps<DividerProps>;
@@ -19,4 +23,5 @@ export type DefaultProps = ComponentDefaultProps<DividerProps>;
19
23
  export const defaultProps: DefaultProps = {
20
24
  variant: 'default',
21
25
  orientation: 'horizontal',
26
+ label: '',
22
27
  };
package/src/divider.scss CHANGED
@@ -1,22 +1,54 @@
1
1
  @use '@justeattakeaway/pie-css/scss' as p;
2
2
 
3
3
  .c-divider {
4
- --divider-bg-color: var(--dt-color-divider-default);
5
- --divider-width: 100%;
6
- --divider-height: 1px;
4
+ --divider-bg-color: var(--dt-color-divider-default);
5
+ --divider-width: 100%;
6
+ --divider-min-width: 16px;
7
+ --divider-height: 1px;
8
+ --divider-label-max-width: 90%;
7
9
 
10
+ width: var(--divider-width);
11
+
12
+ &,
13
+ hr {
8
14
  margin: 0;
9
15
  border: 0;
10
- width: var(--divider-width);
11
- height: var(--divider-height);
12
16
  background-color: var(--divider-bg-color);
17
+ }
13
18
 
14
- &.c-divider--inverse {
15
- --divider-bg-color: var(--dt-color-divider-inverse);
19
+ &:not(.c-divider--labelled) {
20
+ height: var(--divider-height);
21
+ }
22
+
23
+ &.c-divider--labelled {
24
+ display: flex;
25
+ align-items: center;
26
+ text-align: center;
27
+ gap: var(--dt-spacing-b);
28
+ background-color: transparent;
29
+
30
+ .c-divider-label {
31
+ max-width: var(--divider-label-max-width);
32
+ word-wrap: break-word;
16
33
  }
17
34
 
18
- &.c-divider--vertical {
19
- --divider-width: 1px;
20
- --divider-height: 100%;
35
+ hr {
36
+ flex-grow: 1;
37
+ height: var(--divider-height);
38
+ min-width: var(--divider-min-width);
21
39
  }
40
+
41
+ &.c-divider--inverse {
42
+ color: var(--dt-color-content-inverse);
43
+ }
44
+ }
45
+
46
+ &.c-divider--inverse {
47
+ --divider-bg-color: var(--dt-color-divider-inverse);
48
+ }
49
+
50
+ &.c-divider--vertical {
51
+ --divider-width: 1px;
52
+ --divider-height: 100%;
53
+ }
22
54
  }
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
- import { LitElement, html, unsafeCSS } from 'lit';
1
+ import {
2
+ html, LitElement, unsafeCSS,
3
+ } from 'lit';
2
4
  import { property } from 'lit/decorators.js';
3
5
  import { classMap } from 'lit/directives/class-map.js';
4
6
  import { defineCustomElement, validPropertyValues } from '@justeattakeaway/pie-webc-core';
@@ -24,20 +26,38 @@ export class PieDivider extends LitElement implements DividerProps {
24
26
  @validPropertyValues(componentSelector, orientations, defaultProps.orientation)
25
27
  public orientation = defaultProps.orientation;
26
28
 
29
+ @property({ type: String })
30
+ public label = defaultProps.label;
31
+
27
32
  render () {
28
- const { variant, orientation } = this;
33
+ const { variant, orientation, label } = this;
29
34
 
35
+ const showLabel = label.length > 0 && orientation === 'horizontal';
30
36
  const classes = {
31
37
  'c-divider': true,
32
38
  'c-divider--inverse': variant === 'inverse',
33
39
  'c-divider--vertical': orientation === 'vertical',
40
+ 'c-divider--labelled': showLabel,
34
41
  };
35
42
 
36
43
  return html`
37
- <hr
38
- data-test-id="pie-divider"
39
- aria-hidden="true"
40
- class="${classMap(classes)}" />`;
44
+ ${showLabel ? html`
45
+ <div
46
+ id="${componentSelector}"
47
+ data-test-id="${componentSelector}"
48
+ class="${classMap(classes)}"
49
+ aria-labelledby="${componentSelector}-label">
50
+ <hr aria-hidden="true"/>
51
+ <span id="${componentSelector}-label" class="c-divider-label">${label}</span>
52
+ <hr aria-hidden="true"/>
53
+ </div>`
54
+ : html`
55
+ <hr id="${componentSelector}"
56
+ data-test-id="${componentSelector}"
57
+ class="${classMap(classes)}"
58
+ aria-hidden="true"
59
+ />`
60
+ }`;
41
61
  }
42
62
 
43
63
  // Renders a `CSSResult` generated from SCSS by Vite