@justeattakeaway/pie-tag 0.21.3 → 0.22.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 +136 -15
- package/custom-elements.json +6 -79
- package/dist/index.d.ts +14 -26
- package/dist/index.js +84 -108
- package/dist/react.d.ts +14 -26
- package/dist/react.js +4 -5
- package/package.json +4 -4
- package/src/defs.ts +29 -15
- package/src/index.ts +19 -96
- package/src/tag.scss +385 -133
package/src/index.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
html, unsafeCSS,
|
|
2
|
+
html, unsafeCSS,
|
|
3
3
|
} from 'lit';
|
|
4
4
|
import { PieElement } from '@justeattakeaway/pie-webc-core/src/internals/PieElement';
|
|
5
|
-
import { property
|
|
6
|
-
import { classMap
|
|
5
|
+
import { property } from 'lit/decorators.js';
|
|
6
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
7
7
|
import { safeCustomElement, validPropertyValues } from '@justeattakeaway/pie-webc-core';
|
|
8
8
|
import styles from './tag.scss?inline';
|
|
9
9
|
import {
|
|
10
10
|
variants,
|
|
11
11
|
sizes,
|
|
12
12
|
defaultProps,
|
|
13
|
-
iconPlacements,
|
|
14
13
|
type TagProps,
|
|
15
14
|
} from './defs';
|
|
16
15
|
|
|
@@ -40,118 +39,42 @@ export class PieTag extends PieElement implements TagProps {
|
|
|
40
39
|
public isStrong = defaultProps.isStrong;
|
|
41
40
|
|
|
42
41
|
@property({ type: Boolean })
|
|
43
|
-
public
|
|
42
|
+
public isDimmed = defaultProps.isDimmed;
|
|
44
43
|
|
|
45
44
|
@property({ type: Boolean })
|
|
46
|
-
public
|
|
45
|
+
public isIconOnly = defaultProps.isIconOnly;
|
|
47
46
|
|
|
48
|
-
@property({ type:
|
|
49
|
-
|
|
50
|
-
public iconPlacement = defaultProps.iconPlacement;
|
|
51
|
-
|
|
52
|
-
@queryAssignedElements({ slot: 'icon', flatten: true }) _iconSlotNodes!: Array<HTMLElement>;
|
|
53
|
-
|
|
54
|
-
private isIconOnly = false;
|
|
55
|
-
|
|
56
|
-
updated (changedProperties: PropertyValues<this>) {
|
|
57
|
-
if (changedProperties.has('size')) this.checkIfIsIconOnly();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
private checkIfIsIconOnly () {
|
|
61
|
-
const { size, textContent, _iconSlotNodes } = this;
|
|
62
|
-
|
|
63
|
-
// The instance size must be large
|
|
64
|
-
const isLargeSize = size === 'large';
|
|
65
|
-
|
|
66
|
-
// The default slot must be empty
|
|
67
|
-
const defaultSlotText = textContent?.trim();
|
|
68
|
-
const isDefaultSlotEmpty = defaultSlotText === '';
|
|
69
|
-
|
|
70
|
-
// The icon slot must have some content
|
|
71
|
-
const iconsSlotNotEmpty = _iconSlotNodes.length > 0;
|
|
72
|
-
|
|
73
|
-
if (isLargeSize && isDefaultSlotEmpty && iconsSlotNotEmpty) {
|
|
74
|
-
// The icon slot content must be an icon
|
|
75
|
-
if (_iconSlotNodes && _iconSlotNodes.length === 1) {
|
|
76
|
-
const firstNode = (_iconSlotNodes[0] as Element);
|
|
77
|
-
const tag = firstNode.tagName.toUpperCase();
|
|
78
|
-
const isIcon = tag.startsWith('ICON-') || tag === 'SVG';
|
|
79
|
-
|
|
80
|
-
this.isIconOnly = isIcon;
|
|
81
|
-
this.requestUpdate();
|
|
82
|
-
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
this.isIconOnly = false;
|
|
88
|
-
this.requestUpdate();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
private handleSlotChange () {
|
|
92
|
-
this.checkIfIsIconOnly();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
private renderIconSlot () {
|
|
96
|
-
if (this.size !== 'large') return nothing;
|
|
97
|
-
|
|
98
|
-
return html`<slot part="icon" name="icon" @slotchange=${this.handleSlotChange}></slot>`;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
private renderTag (classes: ClassInfo) {
|
|
102
|
-
return html`
|
|
103
|
-
<div
|
|
104
|
-
part="body"
|
|
105
|
-
class="${classMap(classes)}"
|
|
106
|
-
data-test-id="pie-tag">
|
|
107
|
-
${this.renderIconSlot()}
|
|
108
|
-
<slot @slotchange=${this.handleSlotChange}></slot>
|
|
109
|
-
</div>`;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
private renderButtonTag (classes: ClassInfo) {
|
|
113
|
-
return html`
|
|
114
|
-
<button
|
|
115
|
-
part="body"
|
|
116
|
-
type="button"
|
|
117
|
-
?disabled="${this.disabled}"
|
|
118
|
-
class="${classMap(classes)}"
|
|
119
|
-
data-test-id="pie-tag">
|
|
120
|
-
${this.renderIconSlot()}
|
|
121
|
-
<slot></slot>
|
|
122
|
-
</button>`;
|
|
123
|
-
}
|
|
47
|
+
@property({ type: Boolean })
|
|
48
|
+
public hasLeadingIcon = defaultProps.hasLeadingIcon;
|
|
124
49
|
|
|
125
50
|
render () {
|
|
126
51
|
const {
|
|
127
|
-
|
|
128
|
-
isInteractive,
|
|
52
|
+
isDimmed,
|
|
129
53
|
isStrong,
|
|
130
54
|
size,
|
|
131
55
|
variant,
|
|
132
|
-
iconPlacement,
|
|
133
56
|
isIconOnly,
|
|
57
|
+
hasLeadingIcon,
|
|
134
58
|
} = this;
|
|
135
59
|
|
|
136
|
-
// isInteractive can only be true when isIconOnly is false
|
|
137
|
-
const _isInteractive = isIconOnly ? false : isInteractive;
|
|
138
|
-
|
|
139
60
|
const classes = {
|
|
140
61
|
'c-tag': true,
|
|
141
62
|
[`c-tag--${size}`]: true,
|
|
142
63
|
[`c-tag--${variant}`]: true,
|
|
143
|
-
'is-
|
|
64
|
+
'c-tag--is-dimmed': isDimmed,
|
|
144
65
|
'c-tag--strong': isStrong,
|
|
145
|
-
'c-tag--interactive': _isInteractive,
|
|
146
66
|
'c-tag--icon-only': isIconOnly,
|
|
147
|
-
|
|
67
|
+
'c-tag--has-icon': hasLeadingIcon,
|
|
148
68
|
};
|
|
149
69
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
70
|
+
return html`
|
|
71
|
+
<div
|
|
72
|
+
part="body"
|
|
73
|
+
class="${classMap(classes)}"
|
|
74
|
+
data-test-id="pie-tag">
|
|
75
|
+
<slot part="icon" name="icon"></slot>
|
|
76
|
+
<slot></slot>
|
|
77
|
+
</div>`;
|
|
155
78
|
}
|
|
156
79
|
|
|
157
80
|
// Renders a `CSSResult` generated from SCSS by Vite
|