@justeattakeaway/pie-form-label 0.5.0 → 0.7.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
@@ -16,7 +16,7 @@
16
16
  4. [Local Development](#local-development)
17
17
  5. [Peer Dependencies](#peer-dependencies)
18
18
  6. [Props](#props)
19
- 7. [Testing](#testing)
19
+ 7. [Contributing](#contributing)
20
20
 
21
21
  ## pie-form-label
22
22
 
@@ -56,31 +56,6 @@ import { PieFormLabel } from '@justeattakeaway/pie-form-label/dist/react';
56
56
  > [!IMPORTANT]
57
57
  > When using `pie-form-label`, you will also need to include a couple of dependencies to ensure the component renders as expected. See [the PIE Wiki](https://github.com/justeattakeaway/pie/wiki/Getting-started-with-PIE-Web-Components#expected-dependencies) for more information and how to include these in your application.
58
58
 
59
-
60
- ## Local development
61
-
62
- Install the dependencies. Note that this, and the following commands below, should be run from the **root of the monorepo**:
63
-
64
- ```bash
65
- yarn
66
- ```
67
-
68
- To build the `pie-form-label` package, run the following command:
69
-
70
- ```bash
71
- yarn build --filter=pie-form-label
72
- ```
73
-
74
- If you'd like to develop using the component storybook, then you should build the component in `watch` mode, and run storybook in a separate terminal tab:
75
-
76
- ```bash
77
- yarn watch --filter=pie-form-label
78
-
79
- # in a separate terminal tab, run
80
- yarn dev --filter=pie-storybook
81
- ```
82
-
83
-
84
59
  ## Props
85
60
 
86
61
  | Property | Type | Default | Description |
@@ -99,36 +74,6 @@ In your markup or JSX, you can then use these to set the properties for the `pie
99
74
  <PieFormLabel>Label</PieFormLabel>
100
75
  ```
101
76
 
102
- ## Testing
103
-
104
- ### Browser tests
105
-
106
- To run the browser tests, run the following command from the root of the monorepo:
77
+ ## Contributing
107
78
 
108
- ```bash
109
- yarn test:browsers --filter=pie-form-label
110
- ```
111
-
112
- ### Visual tests
113
-
114
- To run the visual regression tests, run the following command from the root of the monorepo:
115
-
116
- ```bash
117
- yarn test:visual --filter=pie-form-label
118
- ```
119
-
120
- Note: To run these locally, you will need to ensure that any environment variables required are set up on your machine to mirror those on CI (such as Percy tokens). How you achieve this will differ between operating systems.
121
-
122
- #### Setup via bash
123
-
124
- ```bash
125
- export PERCY_TOKEN_PIE_FORM_LABEL=abcde
126
- ```
127
-
128
- #### Setup via package.json
129
-
130
- Under scripts `test:visual` replace the environment variable with the below:
131
-
132
- ```bash
133
- PERCY_TOKEN_PIE_FORM_LABEL=abcde
134
- ```
79
+ Check out our [contributing guide](https://github.com/justeattakeaway/pie/wiki/Contributing-Guide) for more information on [local development](https://github.com/justeattakeaway/pie/wiki/Contributing-Guide#local-development) and how to run specific [component tests](https://github.com/justeattakeaway/pie/wiki/Contributing-Guide#testing).
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
  /**
@@ -20,12 +20,17 @@ export declare interface FormLabelProps {
20
20
  /**
21
21
  * @tagname pie-form-label
22
22
  */
23
- export declare class PieFormLabel extends LitElement implements FormLabelProps {
23
+ export declare class PieFormLabel extends PieFormLabel_base implements FormLabelProps {
24
24
  for?: string;
25
25
  optional?: string;
26
26
  trailing?: string;
27
+ private _renderOptionalLabel;
27
28
  render(): TemplateResult<1>;
28
29
  static styles: CSSResult;
29
30
  }
30
31
 
32
+ declare const PieFormLabel_base: (new (...args: any[]) => {
33
+ isRTL: boolean;
34
+ }) & typeof LitElement;
35
+
31
36
  export { }
package/dist/index.js CHANGED
@@ -1,46 +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
- function d(t, e) {
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) {
4
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);
5
22
  }
6
- 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)}
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)}
7
24
  `;
8
- var h = Object.defineProperty, v = Object.getOwnPropertyDescriptor, c = (t, e, n, l) => {
9
- for (var o = l > 1 ? void 0 : l ? v(e, n) : e, a = t.length - 1, i; a >= 0; a--)
10
- (i = t[a]) && (o = (l ? i(e, n, o) : i(o)) || o);
11
- return l && o && h(e, n, o), o;
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;
12
29
  };
13
- const u = "pie-form-label";
14
- 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
+ }
15
36
  render() {
16
37
  const {
17
- optional: e,
18
- trailing: n
38
+ trailing: e,
39
+ isRTL: n
19
40
  } = this;
20
- return s`
41
+ return f`
21
42
  <label
22
43
  data-test-id="pie-form-label"
23
44
  class="c-formLabel"
24
45
  for=${this.for}>
25
46
  <div>
26
- <slot></slot>
27
- ${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()}
28
50
  </div>
29
- ${n ? s`<span class="c-formLabel-trailing">${n}</span>` : p}
51
+ ${e ? f`<span class="c-formLabel-trailing">${e}</span>` : i}
30
52
  </label>`;
31
53
  }
32
54
  }
33
- r.styles = m(g);
34
- c([
35
- f({ type: String, reflect: !0 })
36
- ], r.prototype, "for", 2);
37
- c([
38
- f({ type: String })
39
- ], r.prototype, "optional", 2);
40
- c([
41
- f({ type: String })
42
- ], r.prototype, "trailing", 2);
43
- d(u, 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);
44
66
  export {
45
- r as PieFormLabel
67
+ l as PieFormLabel
46
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
  /**
@@ -23,12 +23,17 @@ export declare const PieFormLabel: ReactWebComponent<PieFormLabel_2, {}>;
23
23
  /**
24
24
  * @tagname pie-form-label
25
25
  */
26
- declare class PieFormLabel_2 extends LitElement implements FormLabelProps {
26
+ declare class PieFormLabel_2 extends PieFormLabel_base implements FormLabelProps {
27
27
  for?: string;
28
28
  optional?: string;
29
29
  trailing?: string;
30
+ private _renderOptionalLabel;
30
31
  render(): TemplateResult<1>;
31
32
  static styles: CSSResult;
32
33
  }
33
34
 
35
+ declare const PieFormLabel_base: (new (...args: any[]) => {
36
+ isRTL: boolean;
37
+ }) & typeof LitElement;
38
+
34
39
  export { }
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.5.0",
4
+ "version": "0.7.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -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,7 +1,7 @@
1
1
  import {
2
- LitElement, html, nothing, unsafeCSS,
2
+ LitElement, TemplateResult, html, nothing, unsafeCSS,
3
3
  } from 'lit';
4
- import { defineCustomElement } from '@justeattakeaway/pie-webc-core';
4
+ import { RtlMixin, defineCustomElement } from '@justeattakeaway/pie-webc-core';
5
5
  import { property } from 'lit/decorators.js';
6
6
  import styles from './form-label.scss?inline';
7
7
  import { FormLabelProps } from './defs';
@@ -14,7 +14,7 @@ const componentSelector = 'pie-form-label';
14
14
  /**
15
15
  * @tagname pie-form-label
16
16
  */
17
- export class PieFormLabel extends LitElement implements FormLabelProps {
17
+ export class PieFormLabel extends RtlMixin(LitElement) implements FormLabelProps {
18
18
  @property({ type: String, reflect: true })
19
19
  public for?: string;
20
20
 
@@ -24,10 +24,16 @@ export class PieFormLabel extends LitElement implements FormLabelProps {
24
24
  @property({ type: String })
25
25
  public trailing?: string;
26
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
+
27
33
  render () {
28
34
  const {
29
- optional,
30
35
  trailing,
36
+ isRTL,
31
37
  } = this;
32
38
 
33
39
  return html`
@@ -36,8 +42,9 @@ export class PieFormLabel extends LitElement implements FormLabelProps {
36
42
  class="c-formLabel"
37
43
  for=${this.for}>
38
44
  <div>
39
- <slot></slot>
40
- ${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}
41
48
  </div>
42
49
  ${trailing ? html`<span class="c-formLabel-trailing">${trailing}</span>` : nothing}
43
50
  </label>`;