@justeattakeaway/pie-divider 0.13.8 → 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": [
@@ -76,36 +76,34 @@
76
76
  {
77
77
  "kind": "field",
78
78
  "name": "variant",
79
- "type": {
80
- "text": "DividerProps['variant']"
81
- },
82
79
  "privacy": "public",
83
80
  "attribute": "variant"
84
81
  },
85
82
  {
86
83
  "kind": "field",
87
84
  "name": "orientation",
88
- "type": {
89
- "text": "DividerProps['orientation']"
90
- },
91
85
  "privacy": "public",
92
86
  "attribute": "orientation"
87
+ },
88
+ {
89
+ "kind": "field",
90
+ "name": "label",
91
+ "privacy": "public",
92
+ "attribute": "label"
93
93
  }
94
94
  ],
95
95
  "attributes": [
96
96
  {
97
97
  "name": "variant",
98
- "type": {
99
- "text": "DividerProps['variant']"
100
- },
101
98
  "fieldName": "variant"
102
99
  },
103
100
  {
104
101
  "name": "orientation",
105
- "type": {
106
- "text": "DividerProps['orientation']"
107
- },
108
102
  "fieldName": "orientation"
103
+ },
104
+ {
105
+ "name": "label",
106
+ "fieldName": "label"
109
107
  }
110
108
  ],
111
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"];
@@ -24,8 +28,9 @@ export declare const orientations: readonly ["horizontal", "vertical"];
24
28
  * @tagname pie-divider
25
29
  */
26
30
  export declare class PieDivider extends LitElement implements DividerProps {
27
- variant: DividerProps['variant'];
28
- orientation: DividerProps['orientation'];
31
+ variant: "default" | "inverse";
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,46 +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 { validPropertyValues as l, defineCustomElement as g } from "@justeattakeaway/pie-webc-core";
4
- const m = `*,*: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[variant=inverse]{--divider-bg-color: var(--dt-color-divider-inverse)}.c-divider[orientation=vertical]{--divider-width: 1px;--divider-height: 100%}
5
- `, b = ["default", "inverse"], y = ["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 = {
6
7
  variant: "default",
7
- orientation: "horizontal"
8
+ orientation: "horizontal",
9
+ label: ""
8
10
  };
9
- var P = Object.defineProperty, w = Object.getOwnPropertyDescriptor, p = (a, r, t, e) => {
10
- for (var i = e > 1 ? void 0 : e ? w(r, t) : r, d = a.length - 1, v; d >= 0; d--)
11
- (v = a[d]) && (i = (e ? v(r, t, i) : v(i)) || i);
12
- return e && i && P(r, t, 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;
13
15
  };
14
- const s = "pie-divider";
15
- class n extends f {
16
+ const e = "pie-divider";
17
+ class o extends m {
16
18
  constructor() {
17
- 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;
18
20
  }
19
21
  render() {
20
- const { variant: r, orientation: t } = this;
21
- return u`
22
- <hr
23
- data-test-id="pie-divider"
24
- aria-hidden="true"
25
- class="c-divider"
26
- variant=${r}
27
- orientation=${t}
28
- />`;
22
+ const { variant: d, orientation: t, label: r } = this, i = r.length > 0 && t === "horizontal", a = {
23
+ "c-divider": !0,
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
+ />`}`;
29
44
  }
30
45
  }
31
- n.styles = h(m);
32
- p([
33
- c({ type: String }),
34
- l(s, b, o.variant)
35
- ], n.prototype, "variant", 2);
36
- p([
37
- c({ type: String }),
38
- l(s, y, o.orientation)
39
- ], n.prototype, "orientation", 2);
40
- g(s, n);
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);
41
59
  export {
42
- n as PieDivider,
43
- o as defaultProps,
44
- y as orientations,
45
- b as variants
60
+ o as PieDivider,
61
+ l as defaultProps,
62
+ x as orientations,
63
+ w as variants
46
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"];
@@ -27,8 +31,9 @@ export declare const PieDivider: React_2.ForwardRefExoticComponent<DividerProps
27
31
  * @tagname pie-divider
28
32
  */
29
33
  declare class PieDivider_2 extends LitElement implements DividerProps {
30
- variant: DividerProps['variant'];
31
- orientation: DividerProps['orientation'];
34
+ variant: "default" | "inverse";
35
+ orientation: "horizontal" | "vertical";
36
+ label: string;
32
37
  render(): TemplateResult<1>;
33
38
  static styles: CSSResult;
34
39
  }
package/dist/react.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import * as e from "react";
2
2
  import { createComponent as i } from "@lit/react";
3
3
  import { PieDivider as r } from "./index.js";
4
- import { defaultProps as c, orientations as P, variants as f } from "./index.js";
4
+ import { defaultProps as P, orientations as f, variants as D } from "./index.js";
5
5
  import "lit";
6
6
  import "lit/decorators.js";
7
+ import "lit/directives/class-map.js";
7
8
  import "@justeattakeaway/pie-webc-core";
8
9
  const t = i({
9
10
  displayName: "PieDivider",
@@ -11,10 +12,10 @@ const t = i({
11
12
  react: e,
12
13
  tagName: "pie-divider",
13
14
  events: {}
14
- }), d = t;
15
+ }), n = t;
15
16
  export {
16
- d as PieDivider,
17
- c as defaultProps,
18
- P as orientations,
19
- f as variants
17
+ n as PieDivider,
18
+ P as defaultProps,
19
+ f as orientations,
20
+ D as variants
20
21
  };
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.8",
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-react.ts CHANGED
@@ -1,3 +1,3 @@
1
- import React from 'react';
1
+ import type React from 'react';
2
2
 
3
3
  export type ReactBaseType = React.HTMLAttributes<HTMLHRElement>
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,30 +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
- &[variant='default'] {
15
- /* Same as default styles */
16
- }
19
+ &:not(.c-divider--labelled) {
20
+ height: var(--divider-height);
21
+ }
17
22
 
18
- &[variant='inverse'] {
19
- --divider-bg-color: var(--dt-color-divider-inverse);
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;
20
33
  }
21
34
 
22
- &[orientation='horizontal'] {
23
- /* Same as default styles */
35
+ hr {
36
+ flex-grow: 1;
37
+ height: var(--divider-height);
38
+ min-width: var(--divider-min-width);
24
39
  }
25
40
 
26
- &[orientation='vertical'] {
27
- --divider-width: 1px;
28
- --divider-height: 100%;
41
+ &.c-divider--inverse {
42
+ color: var(--dt-color-content-inverse);
29
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
+ }
30
54
  }
package/src/index.ts CHANGED
@@ -1,9 +1,12 @@
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
- import { validPropertyValues, defineCustomElement } from '@justeattakeaway/pie-webc-core';
5
+ import { classMap } from 'lit/directives/class-map.js';
6
+ import { defineCustomElement, validPropertyValues } from '@justeattakeaway/pie-webc-core';
4
7
  import styles from './divider.scss?inline';
5
8
  import {
6
- DividerProps, variants, orientations, defaultProps,
9
+ type DividerProps, defaultProps, orientations, variants,
7
10
  } from './defs';
8
11
 
9
12
  // Valid values available to consumers
@@ -17,23 +20,44 @@ const componentSelector = 'pie-divider';
17
20
  export class PieDivider extends LitElement implements DividerProps {
18
21
  @property({ type: String })
19
22
  @validPropertyValues(componentSelector, variants, defaultProps.variant)
20
- public variant: DividerProps['variant'] = defaultProps.variant;
23
+ public variant = defaultProps.variant;
21
24
 
22
25
  @property({ type: String })
23
26
  @validPropertyValues(componentSelector, orientations, defaultProps.orientation)
24
- public orientation : DividerProps['orientation'] = defaultProps.orientation;
27
+ public orientation = defaultProps.orientation;
28
+
29
+ @property({ type: String })
30
+ public label = defaultProps.label;
25
31
 
26
32
  render () {
27
- const { variant, orientation } = this;
33
+ const { variant, orientation, label } = this;
34
+
35
+ const showLabel = label.length > 0 && orientation === 'horizontal';
36
+ const classes = {
37
+ 'c-divider': true,
38
+ 'c-divider--inverse': variant === 'inverse',
39
+ 'c-divider--vertical': orientation === 'vertical',
40
+ 'c-divider--labelled': showLabel,
41
+ };
28
42
 
29
43
  return html`
30
- <hr
31
- data-test-id="pie-divider"
32
- aria-hidden="true"
33
- class="c-divider"
34
- variant=${variant}
35
- orientation=${orientation}
36
- />`;
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
+ }`;
37
61
  }
38
62
 
39
63
  // Renders a `CSSResult` generated from SCSS by Vite