@justeattakeaway/pie-form-label 0.0.0 → 0.1.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 +5 -3
- package/dist/index.d.ts +15 -0
- package/dist/index.js +38 -7
- package/dist/react.d.ts +15 -0
- package/dist/react.js +16 -15
- package/package.json +1 -1
- package/src/defs.ts +14 -3
- package/src/form-label.scss +31 -0
- package/src/index.ts +29 -3
package/README.md
CHANGED
|
@@ -59,16 +59,18 @@ import { PieFormLabel } from '@justeattakeaway/pie-form-label/dist/react';
|
|
|
59
59
|
|
|
60
60
|
| Property | Type | Default | Description |
|
|
61
61
|
|---|---|---|---|
|
|
62
|
-
|
|
|
62
|
+
| for | `String` | `undefined` | Native html `for` attribute |
|
|
63
|
+
| optional | `String` | `undefined` | Sets an optional text to be placed next to the main label |
|
|
64
|
+
| trailing | `String` | `undefined` | Sets a trailing text at the end of the label component |
|
|
63
65
|
|
|
64
66
|
In your markup or JSX, you can then use these to set the properties for the `pie-form-label` component:
|
|
65
67
|
|
|
66
68
|
```html
|
|
67
69
|
<!-- Native HTML -->
|
|
68
|
-
<pie-form-label
|
|
70
|
+
<pie-form-label>Label</pie-form-label>
|
|
69
71
|
|
|
70
72
|
<!-- JSX -->
|
|
71
|
-
<PieFormLabel
|
|
73
|
+
<PieFormLabel>Label</PieFormLabel>
|
|
72
74
|
```
|
|
73
75
|
|
|
74
76
|
## Testing
|
package/dist/index.d.ts
CHANGED
|
@@ -3,9 +3,24 @@ import type { LitElement } from 'lit';
|
|
|
3
3
|
import type { TemplateResult } from 'lit-html';
|
|
4
4
|
|
|
5
5
|
export declare interface FormLabelProps {
|
|
6
|
+
/**
|
|
7
|
+
* The native for HTML attribute.
|
|
8
|
+
*/
|
|
9
|
+
for?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Optional text to be placed next to the main label.
|
|
12
|
+
*/
|
|
13
|
+
optional?: string;
|
|
14
|
+
/**
|
|
15
|
+
* What the trailing text of the label component should be.
|
|
16
|
+
*/
|
|
17
|
+
trailing?: string;
|
|
6
18
|
}
|
|
7
19
|
|
|
8
20
|
export declare class PieFormLabel extends LitElement implements FormLabelProps {
|
|
21
|
+
for?: string;
|
|
22
|
+
optional?: string;
|
|
23
|
+
trailing?: string;
|
|
9
24
|
render(): TemplateResult<1>;
|
|
10
25
|
static styles: CSSResult;
|
|
11
26
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,43 @@
|
|
|
1
|
-
import { unsafeCSS as
|
|
2
|
-
|
|
3
|
-
|
|
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)}
|
|
4
|
+
`;
|
|
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;
|
|
9
|
+
};
|
|
10
|
+
const h = "pie-form-label";
|
|
11
|
+
class r extends b {
|
|
4
12
|
render() {
|
|
5
|
-
|
|
13
|
+
const {
|
|
14
|
+
optional: e,
|
|
15
|
+
trailing: o
|
|
16
|
+
} = this;
|
|
17
|
+
return s`
|
|
18
|
+
<label
|
|
19
|
+
data-test-id="pie-form-label"
|
|
20
|
+
class="c-formLabel"
|
|
21
|
+
for=${this.for}>
|
|
22
|
+
<div>
|
|
23
|
+
<slot></slot>
|
|
24
|
+
${e ? s`<span class="c-formLabel-optional">${e}</span>` : p}
|
|
25
|
+
</div>
|
|
26
|
+
${o ? s`<span class="c-formLabel-trailing">${o}</span>` : p}
|
|
27
|
+
</label>`;
|
|
6
28
|
}
|
|
7
29
|
}
|
|
8
|
-
|
|
9
|
-
|
|
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);
|
|
10
41
|
export {
|
|
11
|
-
|
|
42
|
+
r as PieFormLabel
|
|
12
43
|
};
|
package/dist/react.d.ts
CHANGED
|
@@ -4,11 +4,26 @@ import type { ReactWebComponent } from '@lit-labs/react';
|
|
|
4
4
|
import type { TemplateResult } from 'lit-html';
|
|
5
5
|
|
|
6
6
|
export declare interface FormLabelProps {
|
|
7
|
+
/**
|
|
8
|
+
* The native for HTML attribute.
|
|
9
|
+
*/
|
|
10
|
+
for?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Optional text to be placed next to the main label.
|
|
13
|
+
*/
|
|
14
|
+
optional?: string;
|
|
15
|
+
/**
|
|
16
|
+
* What the trailing text of the label component should be.
|
|
17
|
+
*/
|
|
18
|
+
trailing?: string;
|
|
7
19
|
}
|
|
8
20
|
|
|
9
21
|
export declare const PieFormLabel: ReactWebComponent<PieFormLabel_2, {}>;
|
|
10
22
|
|
|
11
23
|
declare class PieFormLabel_2 extends LitElement implements FormLabelProps {
|
|
24
|
+
for?: string;
|
|
25
|
+
optional?: string;
|
|
26
|
+
trailing?: string;
|
|
12
27
|
render(): TemplateResult<1>;
|
|
13
28
|
static styles: CSSResult;
|
|
14
29
|
}
|
package/dist/react.js
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
import * as L from "react";
|
|
2
2
|
import { PieFormLabel as E } from "./index.js";
|
|
3
3
|
import "lit";
|
|
4
|
+
import "lit/decorators.js";
|
|
4
5
|
/**
|
|
5
6
|
* @license
|
|
6
7
|
* Copyright 2018 Google LLC
|
|
7
8
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
8
9
|
*/
|
|
9
10
|
const g = /* @__PURE__ */ new Set(["children", "localName", "ref", "style", "className"]), w = /* @__PURE__ */ new WeakMap(), F = (m, a, d, p, h) => {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
let
|
|
13
|
-
|
|
14
|
-
let l =
|
|
15
|
-
u !== void 0 ? l === void 0 ? (
|
|
16
|
-
})(m,
|
|
11
|
+
const o = h == null ? void 0 : h[a];
|
|
12
|
+
o === void 0 || d === p ? d == null && a in HTMLElement.prototype ? m.removeAttribute(a) : m[a] = d : ((s, t, u) => {
|
|
13
|
+
let n = w.get(s);
|
|
14
|
+
n === void 0 && w.set(s, n = /* @__PURE__ */ new Map());
|
|
15
|
+
let l = n.get(t);
|
|
16
|
+
u !== void 0 ? l === void 0 ? (n.set(t, l = { handleEvent: u }), s.addEventListener(t, l)) : l.handleEvent = u : l !== void 0 && (n.delete(t), s.removeEventListener(t, l));
|
|
17
|
+
})(m, o, d);
|
|
17
18
|
};
|
|
18
19
|
function M(m = window.React, a, d, p, h) {
|
|
19
|
-
let
|
|
20
|
+
let o, s, t;
|
|
20
21
|
if (a === void 0) {
|
|
21
22
|
const r = m;
|
|
22
|
-
({ tagName:
|
|
23
|
+
({ tagName: s, elementClass: t, events: p, displayName: h } = r), o = r.react;
|
|
23
24
|
} else
|
|
24
|
-
|
|
25
|
-
const u =
|
|
25
|
+
o = m, t = d, s = a;
|
|
26
|
+
const u = o.Component, n = o.createElement, l = new Set(Object.keys(p ?? {}));
|
|
26
27
|
class f extends u {
|
|
27
28
|
constructor() {
|
|
28
29
|
super(...arguments), this.o = null;
|
|
@@ -48,14 +49,14 @@ function M(m = window.React, a, d, p, h) {
|
|
|
48
49
|
const y = { ref: this.u };
|
|
49
50
|
for (const [i, c] of Object.entries(v))
|
|
50
51
|
g.has(i) ? y[i === "className" ? "class" : i] = c : l.has(i) || i in t.prototype ? this.i[i] = c : y[i] = c;
|
|
51
|
-
return
|
|
52
|
+
return n(s, y);
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
f.displayName = h ?? t.name;
|
|
55
|
-
const N =
|
|
56
|
+
const N = o.forwardRef((r, e) => n(f, { ...r, _$Gl: e }, r == null ? void 0 : r.children));
|
|
56
57
|
return N.displayName = f.displayName, N;
|
|
57
58
|
}
|
|
58
|
-
const
|
|
59
|
+
const $ = M({
|
|
59
60
|
displayName: "PieFormLabel",
|
|
60
61
|
elementClass: E,
|
|
61
62
|
react: L,
|
|
@@ -63,5 +64,5 @@ const R = M({
|
|
|
63
64
|
events: {}
|
|
64
65
|
});
|
|
65
66
|
export {
|
|
66
|
-
|
|
67
|
+
$ as PieFormLabel
|
|
67
68
|
};
|
package/package.json
CHANGED
package/src/defs.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export interface FormLabelProps {
|
|
2
|
+
/**
|
|
3
|
+
* The native for HTML attribute.
|
|
4
|
+
*/
|
|
5
|
+
for?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Optional text to be placed next to the main label.
|
|
8
|
+
*/
|
|
9
|
+
optional?: string;
|
|
10
|
+
/**
|
|
11
|
+
* What the trailing text of the label component should be.
|
|
12
|
+
*/
|
|
13
|
+
trailing?: string;
|
|
14
|
+
}
|
package/src/form-label.scss
CHANGED
|
@@ -1 +1,32 @@
|
|
|
1
1
|
@use '@justeattakeaway/pie-css/scss' as p;
|
|
2
|
+
|
|
3
|
+
.c-formLabel {
|
|
4
|
+
--form-label-font-size: #{p.font-size(--dt-font-size-14)};
|
|
5
|
+
--form-label-line-height: calc(var(--dt-font-size-14-line-height) * 1px);
|
|
6
|
+
--form-label-font-weight: var(--dt-font-weight-bold);
|
|
7
|
+
--form-label-color: var(--dt-color-content-default);
|
|
8
|
+
|
|
9
|
+
display: flex;
|
|
10
|
+
justify-content: space-between;
|
|
11
|
+
gap: var(--dt-spacing-d);
|
|
12
|
+
color: var(--form-label-color);
|
|
13
|
+
font-size: var(--form-label-font-size);
|
|
14
|
+
line-height: var(--form-label-line-height);
|
|
15
|
+
font-weight: var(--form-label-font-weight);
|
|
16
|
+
margin-block-end: var(--dt-spacing-a);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.c-formLabel-optional,
|
|
20
|
+
.c-formLabel-trailing {
|
|
21
|
+
color: var(--dt-color-content-subdued);
|
|
22
|
+
font-weight: var(--dt-font-weight-regular);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.c-formLabel-optional {
|
|
26
|
+
margin-inline-start: var(--dt-spacing-b);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.c-formLabel-trailing {
|
|
30
|
+
flex-shrink: 0;
|
|
31
|
+
white-space: var(--dt-spacing-d);
|
|
32
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
LitElement, html, nothing, unsafeCSS,
|
|
3
|
+
} from 'lit';
|
|
4
|
+
import { property } from 'lit/decorators.js';
|
|
3
5
|
import styles from './form-label.scss?inline';
|
|
4
6
|
import { FormLabelProps } from './defs';
|
|
5
7
|
|
|
@@ -9,8 +11,32 @@ export * from './defs';
|
|
|
9
11
|
const componentSelector = 'pie-form-label';
|
|
10
12
|
|
|
11
13
|
export class PieFormLabel extends LitElement implements FormLabelProps {
|
|
14
|
+
@property({ type: String, reflect: true })
|
|
15
|
+
public for?: string;
|
|
16
|
+
|
|
17
|
+
@property({ type: String })
|
|
18
|
+
public optional?: string;
|
|
19
|
+
|
|
20
|
+
@property({ type: String })
|
|
21
|
+
public trailing?: string;
|
|
22
|
+
|
|
12
23
|
render () {
|
|
13
|
-
|
|
24
|
+
const {
|
|
25
|
+
optional,
|
|
26
|
+
trailing,
|
|
27
|
+
} = this;
|
|
28
|
+
|
|
29
|
+
return html`
|
|
30
|
+
<label
|
|
31
|
+
data-test-id="pie-form-label"
|
|
32
|
+
class="c-formLabel"
|
|
33
|
+
for=${this.for}>
|
|
34
|
+
<div>
|
|
35
|
+
<slot></slot>
|
|
36
|
+
${optional ? html`<span class="c-formLabel-optional">${optional}</span>` : nothing}
|
|
37
|
+
</div>
|
|
38
|
+
${trailing ? html`<span class="c-formLabel-trailing">${trailing}</span>` : nothing}
|
|
39
|
+
</label>`;
|
|
14
40
|
}
|
|
15
41
|
|
|
16
42
|
// Renders a `CSSResult` generated from SCSS by Vite
|