@justeattakeaway/pie-form-label 0.5.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 +7 -2
- package/dist/index.js +50 -28
- package/dist/react.d.ts +7 -2
- package/dist/react.js +0 -0
- package/package.json +1 -1
- package/src/form-label.scss +3 -2
- package/src/index.ts +13 -6
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
|
|
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
|
|
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 {
|
|
2
|
-
import { property as
|
|
3
|
-
|
|
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
|
|
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
|
|
9
|
-
for (var
|
|
10
|
-
(
|
|
11
|
-
return
|
|
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
|
|
14
|
-
class
|
|
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
|
-
|
|
18
|
-
|
|
38
|
+
trailing: e,
|
|
39
|
+
isRTL: n
|
|
19
40
|
} = this;
|
|
20
|
-
return
|
|
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
|
-
|
|
27
|
-
|
|
47
|
+
${n ? this._renderOptionalLabel() : i}
|
|
48
|
+
<span class="c-formLabel-leading"><slot></slot></span>
|
|
49
|
+
${n ? i : this._renderOptionalLabel()}
|
|
28
50
|
</div>
|
|
29
|
-
${
|
|
51
|
+
${e ? f`<span class="c-formLabel-trailing">${e}</span>` : i}
|
|
30
52
|
</label>`;
|
|
31
53
|
}
|
|
32
54
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
],
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
],
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
],
|
|
43
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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/dist/react.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
package/src/form-label.scss
CHANGED
|
@@ -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-
|
|
26
|
-
margin-inline-
|
|
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
|
-
|
|
40
|
-
|
|
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>`;
|