@justeattakeaway/pie-form-label 0.4.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/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { CSSResult } from 'lit';
2
2
  import type { LitElement } from 'lit';
3
- import type { TemplateResult } from 'lit-html';
3
+ import type { TemplateResult } from 'lit';
4
4
 
5
5
  export declare interface FormLabelProps {
6
6
  /**
@@ -17,12 +17,20 @@ export declare interface FormLabelProps {
17
17
  trailing?: string;
18
18
  }
19
19
 
20
- export declare class PieFormLabel extends LitElement implements FormLabelProps {
20
+ /**
21
+ * @tagname pie-form-label
22
+ */
23
+ export declare class PieFormLabel extends PieFormLabel_base implements FormLabelProps {
21
24
  for?: string;
22
25
  optional?: string;
23
26
  trailing?: string;
27
+ private _renderOptionalLabel;
24
28
  render(): TemplateResult<1>;
25
29
  static styles: CSSResult;
26
30
  }
27
31
 
32
+ declare const PieFormLabel_base: (new (...args: any[]) => {
33
+ isRTL: boolean;
34
+ }) & typeof LitElement;
35
+
28
36
  export { }
package/dist/index.js CHANGED
@@ -1,43 +1,68 @@
1
- import { unsafeCSS as m, LitElement as b, html as s, nothing as p } from "lit";
2
- import { property as f } from "lit/decorators.js";
3
- const g = `.c-formLabel{--form-label-font-size: calc(var(--dt-font-size-14) * 1px);--form-label-line-height: calc(var(--dt-font-size-14-line-height) * 1px);--form-label-font-weight: var(--dt-font-weight-bold);--form-label-color: var(--dt-color-content-default);display:flex;justify-content:space-between;gap:var(--dt-spacing-d);color:var(--form-label-color);font-size:var(--form-label-font-size);line-height:var(--form-label-line-height);font-weight:var(--form-label-font-weight);margin-block-end:var(--dt-spacing-a)}.c-formLabel-optional,.c-formLabel-trailing{color:var(--dt-color-content-subdued);font-weight:var(--dt-font-weight-regular)}.c-formLabel-optional{margin-inline-start:var(--dt-spacing-b)}.c-formLabel-trailing{flex-shrink:0;white-space:var(--dt-spacing-d)}
1
+ import { isServer as d, unsafeCSS as m, html as f, nothing as i, LitElement as b } from "lit";
2
+ import { property as c } from "lit/decorators.js";
3
+ const g = (t) => {
4
+ class e extends t {
5
+ /**
6
+ * A getter to determine whether the text direction is right-to-left (RTL).
7
+ * If the `dir` property is present on the component, it will be used to determine the text direction.
8
+ * If running on the client-side (not SSR) and the `dir` property is not present, the text direction will be inferred
9
+ * from the document's root element. This inference is not available during SSR.
10
+ * In all other cases, it will return `false`, indicating a left-to-right (LTR) text direction.
11
+ *
12
+ * @returns {boolean} - Returns `true` if the text direction is RTL, otherwise `false`.
13
+ */
14
+ get isRTL() {
15
+ return this.dir ? this.dir === "rtl" : !d && !this.dir ? document.documentElement.getAttribute("dir") === "rtl" : !1;
16
+ }
17
+ }
18
+ return e;
19
+ };
20
+ function h(t, e) {
21
+ customElements.get(t) ? console.warn(`PIE Web Component: "${t}" has already been defined. Please ensure the component is only being defined once in your application.`) : customElements.define(t, e);
22
+ }
23
+ const u = `.c-formLabel{--form-label-font-size: calc(var(--dt-font-size-14) * 1px);--form-label-line-height: calc(var(--dt-font-size-14-line-height) * 1px);--form-label-font-weight: var(--dt-font-weight-bold);--form-label-color: var(--dt-color-content-default);display:flex;justify-content:space-between;align-items:flex-end;gap:var(--dt-spacing-d);color:var(--form-label-color);font-size:var(--form-label-font-size);line-height:var(--form-label-line-height);font-weight:var(--form-label-font-weight);margin-block-end:var(--dt-spacing-a)}.c-formLabel-optional,.c-formLabel-trailing{color:var(--dt-color-content-subdued);font-weight:var(--dt-font-weight-regular)}.c-formLabel-leading{margin-inline-end:var(--dt-spacing-b)}.c-formLabel-trailing{flex-shrink:0;white-space:var(--dt-spacing-d)}
4
24
  `;
5
- var d = Object.defineProperty, v = Object.getOwnPropertyDescriptor, c = (a, e, o, l) => {
6
- for (var t = l > 1 ? void 0 : l ? v(e, o) : e, n = a.length - 1, i; n >= 0; n--)
7
- (i = a[n]) && (t = (l ? i(e, o, t) : i(t)) || t);
8
- return l && t && d(e, o, t), t;
25
+ var v = Object.defineProperty, L = Object.getOwnPropertyDescriptor, p = (t, e, n, o) => {
26
+ for (var r = o > 1 ? void 0 : o ? L(e, n) : e, a = t.length - 1, s; a >= 0; a--)
27
+ (s = t[a]) && (r = (o ? s(e, n, r) : s(r)) || r);
28
+ return o && r && v(e, n, r), r;
9
29
  };
10
- const h = "pie-form-label";
11
- class r extends b {
30
+ const y = "pie-form-label";
31
+ class l extends g(b) {
32
+ _renderOptionalLabel() {
33
+ const { optional: e } = this;
34
+ return e ? f`<span class="c-formLabel-optional">${e}</span>` : i;
35
+ }
12
36
  render() {
13
37
  const {
14
- optional: e,
15
- trailing: o
38
+ trailing: e,
39
+ isRTL: n
16
40
  } = this;
17
- return s`
41
+ return f`
18
42
  <label
19
43
  data-test-id="pie-form-label"
20
44
  class="c-formLabel"
21
45
  for=${this.for}>
22
46
  <div>
23
- <slot></slot>
24
- ${e ? s`<span class="c-formLabel-optional">${e}</span>` : p}
47
+ ${n ? this._renderOptionalLabel() : i}
48
+ <span class="c-formLabel-leading"><slot></slot></span>
49
+ ${n ? i : this._renderOptionalLabel()}
25
50
  </div>
26
- ${o ? s`<span class="c-formLabel-trailing">${o}</span>` : p}
51
+ ${e ? f`<span class="c-formLabel-trailing">${e}</span>` : i}
27
52
  </label>`;
28
53
  }
29
54
  }
30
- r.styles = m(g);
31
- c([
32
- f({ type: String, reflect: !0 })
33
- ], r.prototype, "for", 2);
34
- c([
35
- f({ type: String })
36
- ], r.prototype, "optional", 2);
37
- c([
38
- f({ type: String })
39
- ], r.prototype, "trailing", 2);
40
- customElements.define(h, r);
55
+ l.styles = m(u);
56
+ p([
57
+ c({ type: String, reflect: !0 })
58
+ ], l.prototype, "for", 2);
59
+ p([
60
+ c({ type: String })
61
+ ], l.prototype, "optional", 2);
62
+ p([
63
+ c({ type: String })
64
+ ], l.prototype, "trailing", 2);
65
+ h(y, l);
41
66
  export {
42
- r as PieFormLabel
67
+ l as PieFormLabel
43
68
  };
package/dist/react.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { CSSResult } from 'lit';
2
2
  import type { LitElement } from 'lit';
3
3
  import type { ReactWebComponent } from '@lit-labs/react';
4
- import type { TemplateResult } from 'lit-html';
4
+ import type { TemplateResult } from 'lit';
5
5
 
6
6
  export declare interface FormLabelProps {
7
7
  /**
@@ -20,12 +20,20 @@ export declare interface FormLabelProps {
20
20
 
21
21
  export declare const PieFormLabel: ReactWebComponent<PieFormLabel_2, {}>;
22
22
 
23
- declare class PieFormLabel_2 extends LitElement implements FormLabelProps {
23
+ /**
24
+ * @tagname pie-form-label
25
+ */
26
+ declare class PieFormLabel_2 extends PieFormLabel_base implements FormLabelProps {
24
27
  for?: string;
25
28
  optional?: string;
26
29
  trailing?: string;
30
+ private _renderOptionalLabel;
27
31
  render(): TemplateResult<1>;
28
32
  static styles: CSSResult;
29
33
  }
30
34
 
35
+ declare const PieFormLabel_base: (new (...args: any[]) => {
36
+ isRTL: boolean;
37
+ }) & typeof LitElement;
38
+
31
39
  export { }
package/dist/react.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-form-label",
3
3
  "description": "PIE Design System Form Label built using Web Components",
4
- "version": "0.4.0",
4
+ "version": "0.6.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -31,7 +31,7 @@
31
31
  "@justeattakeaway/pie-components-config": "0.4.0"
32
32
  },
33
33
  "dependencies": {
34
- "@justeattakeaway/pie-webc-core": "0.10.0"
34
+ "@justeattakeaway/pie-webc-core": "0.11.0"
35
35
  },
36
36
  "volta": {
37
37
  "extends": "../../../package.json"
@@ -8,6 +8,7 @@
8
8
 
9
9
  display: flex;
10
10
  justify-content: space-between;
11
+ align-items: flex-end;
11
12
  gap: var(--dt-spacing-d);
12
13
  color: var(--form-label-color);
13
14
  font-size: var(--form-label-font-size);
@@ -22,8 +23,8 @@
22
23
  font-weight: var(--dt-font-weight-regular);
23
24
  }
24
25
 
25
- .c-formLabel-optional {
26
- margin-inline-start: var(--dt-spacing-b);
26
+ .c-formLabel-leading {
27
+ margin-inline-end: var(--dt-spacing-b);
27
28
  }
28
29
 
29
30
  .c-formLabel-trailing {
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
- LitElement, html, nothing, unsafeCSS,
2
+ LitElement, TemplateResult, html, nothing, unsafeCSS,
3
3
  } from 'lit';
4
+ import { RtlMixin, defineCustomElement } from '@justeattakeaway/pie-webc-core';
4
5
  import { property } from 'lit/decorators.js';
5
6
  import styles from './form-label.scss?inline';
6
7
  import { FormLabelProps } from './defs';
@@ -10,7 +11,10 @@ export * from './defs';
10
11
 
11
12
  const componentSelector = 'pie-form-label';
12
13
 
13
- export class PieFormLabel extends LitElement implements FormLabelProps {
14
+ /**
15
+ * @tagname pie-form-label
16
+ */
17
+ export class PieFormLabel extends RtlMixin(LitElement) implements FormLabelProps {
14
18
  @property({ type: String, reflect: true })
15
19
  public for?: string;
16
20
 
@@ -20,10 +24,16 @@ export class PieFormLabel extends LitElement implements FormLabelProps {
20
24
  @property({ type: String })
21
25
  public trailing?: string;
22
26
 
27
+ private _renderOptionalLabel (): TemplateResult | typeof nothing {
28
+ const { optional } = this;
29
+
30
+ return optional ? html`<span class="c-formLabel-optional">${optional}</span>` : nothing;
31
+ }
32
+
23
33
  render () {
24
34
  const {
25
- optional,
26
35
  trailing,
36
+ isRTL,
27
37
  } = this;
28
38
 
29
39
  return html`
@@ -32,8 +42,9 @@ export class PieFormLabel extends LitElement implements FormLabelProps {
32
42
  class="c-formLabel"
33
43
  for=${this.for}>
34
44
  <div>
35
- <slot></slot>
36
- ${optional ? html`<span class="c-formLabel-optional">${optional}</span>` : nothing}
45
+ ${isRTL ? this._renderOptionalLabel() : nothing}
46
+ <span class="c-formLabel-leading"><slot></slot></span>
47
+ ${!isRTL ? this._renderOptionalLabel() : nothing}
37
48
  </div>
38
49
  ${trailing ? html`<span class="c-formLabel-trailing">${trailing}</span>` : nothing}
39
50
  </label>`;
@@ -43,7 +54,7 @@ export class PieFormLabel extends LitElement implements FormLabelProps {
43
54
  static styles = unsafeCSS(styles);
44
55
  }
45
56
 
46
- customElements.define(componentSelector, PieFormLabel);
57
+ defineCustomElement(componentSelector, PieFormLabel);
47
58
 
48
59
  declare global {
49
60
  interface HTMLElementTagNameMap {