@rettangoli/ui 1.0.0-rc13 → 1.0.0-rc14
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/rettangoli-iife-layout.min.js +3 -0
- package/dist/rettangoli-iife-ui.min.js +133 -61
- package/package.json +7 -3
- package/src/components/form/form.handlers.js +328 -152
- package/src/components/form/form.methods.js +199 -0
- package/src/components/form/form.schema.yaml +16 -271
- package/src/components/form/form.store.js +398 -95
- package/src/components/form/form.view.yaml +67 -52
- package/src/components/popoverInput/popoverInput.handlers.js +61 -50
- package/src/components/popoverInput/popoverInput.schema.yaml +0 -1
- package/src/components/popoverInput/popoverInput.store.js +7 -3
- package/src/components/popoverInput/popoverInput.view.yaml +2 -2
- package/src/components/select/select.handlers.js +15 -19
- package/src/components/select/select.schema.yaml +2 -0
- package/src/components/select/select.store.js +8 -6
- package/src/components/select/select.view.yaml +4 -4
- package/src/components/sliderInput/sliderInput.handlers.js +15 -1
- package/src/entry-iife-ui.js +2 -0
- package/src/index.js +2 -0
- package/src/primitives/checkbox.js +295 -0
- package/src/primitives/textarea.js +3 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import {
|
|
2
|
+
css,
|
|
3
|
+
dimensionWithUnit,
|
|
4
|
+
convertObjectToCssString,
|
|
5
|
+
styleMapKeys,
|
|
6
|
+
permutateBreakpoints,
|
|
7
|
+
} from "../common.js";
|
|
8
|
+
import cursorStyles from "../styles/cursorStyles.js";
|
|
9
|
+
import marginStyles from "../styles/marginStyles.js";
|
|
10
|
+
|
|
11
|
+
class RettangoliCheckboxElement extends HTMLElement {
|
|
12
|
+
static styleSheet = null;
|
|
13
|
+
|
|
14
|
+
static initializeStyleSheet() {
|
|
15
|
+
if (!RettangoliCheckboxElement.styleSheet) {
|
|
16
|
+
RettangoliCheckboxElement.styleSheet = new CSSStyleSheet();
|
|
17
|
+
RettangoliCheckboxElement.styleSheet.replaceSync(css`
|
|
18
|
+
:host {
|
|
19
|
+
display: inline-flex;
|
|
20
|
+
}
|
|
21
|
+
.checkbox-wrapper {
|
|
22
|
+
display: inline-flex;
|
|
23
|
+
align-items: flex-start;
|
|
24
|
+
cursor: pointer;
|
|
25
|
+
color: var(--foreground);
|
|
26
|
+
}
|
|
27
|
+
:host([has-label]) .checkbox-wrapper {
|
|
28
|
+
gap: var(--spacing-sm);
|
|
29
|
+
}
|
|
30
|
+
:host([disabled]) .checkbox-wrapper {
|
|
31
|
+
cursor: not-allowed;
|
|
32
|
+
}
|
|
33
|
+
.checkbox-label {
|
|
34
|
+
display: none;
|
|
35
|
+
font-size: var(--sm-font-size);
|
|
36
|
+
font-weight: var(--sm-font-weight);
|
|
37
|
+
line-height: var(--sm-line-height);
|
|
38
|
+
letter-spacing: var(--sm-letter-spacing);
|
|
39
|
+
user-select: none;
|
|
40
|
+
}
|
|
41
|
+
:host([has-label]) .checkbox-label {
|
|
42
|
+
display: block;
|
|
43
|
+
}
|
|
44
|
+
input[type="checkbox"] {
|
|
45
|
+
-webkit-appearance: none;
|
|
46
|
+
appearance: none;
|
|
47
|
+
width: 18px;
|
|
48
|
+
height: 18px;
|
|
49
|
+
border: 2px solid var(--muted-foreground);
|
|
50
|
+
border-radius: var(--border-radius-sm);
|
|
51
|
+
background: var(--muted);
|
|
52
|
+
cursor: pointer;
|
|
53
|
+
transition: all 0.2s ease;
|
|
54
|
+
position: relative;
|
|
55
|
+
margin: 0;
|
|
56
|
+
flex-shrink: 0;
|
|
57
|
+
}
|
|
58
|
+
input[type="checkbox"]:checked {
|
|
59
|
+
background: var(--muted);
|
|
60
|
+
border-color: var(--foreground);
|
|
61
|
+
}
|
|
62
|
+
input[type="checkbox"]:checked::after {
|
|
63
|
+
content: "";
|
|
64
|
+
position: absolute;
|
|
65
|
+
left: 4px;
|
|
66
|
+
top: 1px;
|
|
67
|
+
width: 6px;
|
|
68
|
+
height: 10px;
|
|
69
|
+
border: solid var(--foreground);
|
|
70
|
+
border-width: 0 2px 2px 0;
|
|
71
|
+
transform: rotate(45deg);
|
|
72
|
+
}
|
|
73
|
+
input[type="checkbox"]:hover {
|
|
74
|
+
border-color: var(--foreground);
|
|
75
|
+
}
|
|
76
|
+
input[type="checkbox"]:focus {
|
|
77
|
+
outline: 2px solid var(--ring);
|
|
78
|
+
outline-offset: 2px;
|
|
79
|
+
}
|
|
80
|
+
input[type="checkbox"]:disabled {
|
|
81
|
+
cursor: not-allowed;
|
|
82
|
+
opacity: 0.5;
|
|
83
|
+
}
|
|
84
|
+
${marginStyles}
|
|
85
|
+
${cursorStyles}
|
|
86
|
+
`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
constructor() {
|
|
91
|
+
super();
|
|
92
|
+
RettangoliCheckboxElement.initializeStyleSheet();
|
|
93
|
+
this.shadow = this.attachShadow({ mode: "open" });
|
|
94
|
+
this.shadow.adoptedStyleSheets = [RettangoliCheckboxElement.styleSheet];
|
|
95
|
+
|
|
96
|
+
this._styles = {
|
|
97
|
+
default: {},
|
|
98
|
+
sm: {},
|
|
99
|
+
md: {},
|
|
100
|
+
lg: {},
|
|
101
|
+
xl: {},
|
|
102
|
+
};
|
|
103
|
+
this._lastStyleString = "";
|
|
104
|
+
|
|
105
|
+
this._inputElement = document.createElement('input');
|
|
106
|
+
this._inputElement.type = 'checkbox';
|
|
107
|
+
this._wrapperElement = document.createElement('label');
|
|
108
|
+
this._wrapperElement.className = 'checkbox-wrapper';
|
|
109
|
+
this._labelElement = document.createElement('span');
|
|
110
|
+
this._labelElement.className = 'checkbox-label';
|
|
111
|
+
this._labelSlotElement = document.createElement('slot');
|
|
112
|
+
this._labelSlotElement.addEventListener('slotchange', () => {
|
|
113
|
+
this._updateLabelState();
|
|
114
|
+
});
|
|
115
|
+
this._labelElement.appendChild(this._labelSlotElement);
|
|
116
|
+
this._styleElement = document.createElement('style');
|
|
117
|
+
|
|
118
|
+
this.shadow.appendChild(this._styleElement);
|
|
119
|
+
this._wrapperElement.appendChild(this._inputElement);
|
|
120
|
+
this._wrapperElement.appendChild(this._labelElement);
|
|
121
|
+
this.shadow.appendChild(this._wrapperElement);
|
|
122
|
+
|
|
123
|
+
this._inputElement.addEventListener('change', this._onChange);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
static get observedAttributes() {
|
|
127
|
+
return [
|
|
128
|
+
"key",
|
|
129
|
+
"checked",
|
|
130
|
+
"disabled",
|
|
131
|
+
"label",
|
|
132
|
+
...permutateBreakpoints([
|
|
133
|
+
...styleMapKeys,
|
|
134
|
+
"wh",
|
|
135
|
+
"w",
|
|
136
|
+
"h",
|
|
137
|
+
"hide",
|
|
138
|
+
"show",
|
|
139
|
+
"op",
|
|
140
|
+
"z",
|
|
141
|
+
])
|
|
142
|
+
];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
get checked() {
|
|
146
|
+
return this._inputElement.checked;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
set checked(val) {
|
|
150
|
+
this._inputElement.checked = Boolean(val);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
get value() {
|
|
154
|
+
return this._inputElement.checked;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
set value(val) {
|
|
158
|
+
this._inputElement.checked = Boolean(val);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
_onChange = () => {
|
|
162
|
+
this.dispatchEvent(new CustomEvent('value-change', {
|
|
163
|
+
detail: {
|
|
164
|
+
value: this._inputElement.checked,
|
|
165
|
+
},
|
|
166
|
+
bubbles: true,
|
|
167
|
+
}));
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
171
|
+
if (name === "key" && oldValue !== newValue) {
|
|
172
|
+
requestAnimationFrame(() => {
|
|
173
|
+
const checked = this.hasAttribute("checked");
|
|
174
|
+
this._inputElement.checked = checked;
|
|
175
|
+
});
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (name === "checked") {
|
|
180
|
+
this._inputElement.checked = newValue !== null;
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (name === "disabled") {
|
|
185
|
+
if (newValue !== null) {
|
|
186
|
+
this._inputElement.setAttribute("disabled", "");
|
|
187
|
+
} else {
|
|
188
|
+
this._inputElement.removeAttribute("disabled");
|
|
189
|
+
}
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (name === "label") {
|
|
194
|
+
this._updateLabelState();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
this._styles = {
|
|
199
|
+
default: {},
|
|
200
|
+
sm: {},
|
|
201
|
+
md: {},
|
|
202
|
+
lg: {},
|
|
203
|
+
xl: {},
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
["default", "sm", "md", "lg", "xl"].forEach((size) => {
|
|
207
|
+
const addSizePrefix = (tag) => {
|
|
208
|
+
return `${size === "default" ? "" : `${size}-`}${tag}`;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const wh = this.getAttribute(addSizePrefix("wh"));
|
|
212
|
+
const width = dimensionWithUnit(
|
|
213
|
+
wh === null ? this.getAttribute(addSizePrefix("w")) : wh,
|
|
214
|
+
);
|
|
215
|
+
const height = dimensionWithUnit(
|
|
216
|
+
wh === null ? this.getAttribute(addSizePrefix("h")) : wh,
|
|
217
|
+
);
|
|
218
|
+
const opacity = this.getAttribute(addSizePrefix("op"));
|
|
219
|
+
const zIndex = this.getAttribute(addSizePrefix("z"));
|
|
220
|
+
|
|
221
|
+
if (zIndex !== null) {
|
|
222
|
+
this._styles[size]["z-index"] = zIndex;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (opacity !== null) {
|
|
226
|
+
this._styles[size].opacity = opacity;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (width === "f") {
|
|
230
|
+
this._styles[size].width = "var(--width-stretch)";
|
|
231
|
+
} else if (width !== undefined) {
|
|
232
|
+
this._styles[size].width = width;
|
|
233
|
+
this._styles[size]["min-width"] = width;
|
|
234
|
+
this._styles[size]["max-width"] = width;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (height === "f") {
|
|
238
|
+
this._styles[size].height = "100%";
|
|
239
|
+
} else if (height !== undefined) {
|
|
240
|
+
this._styles[size].height = height;
|
|
241
|
+
this._styles[size]["min-height"] = height;
|
|
242
|
+
this._styles[size]["max-height"] = height;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (this.hasAttribute(addSizePrefix("hide"))) {
|
|
246
|
+
this._styles[size].display = "none";
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (this.hasAttribute(addSizePrefix("show"))) {
|
|
250
|
+
this._styles[size].display = "block";
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
const newStyleString = convertObjectToCssString(this._styles, 'input[type="checkbox"]');
|
|
255
|
+
if (newStyleString !== this._lastStyleString) {
|
|
256
|
+
this._styleElement.textContent = newStyleString;
|
|
257
|
+
this._lastStyleString = newStyleString;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
connectedCallback() {
|
|
262
|
+
const checked = this.hasAttribute("checked");
|
|
263
|
+
this._inputElement.checked = checked;
|
|
264
|
+
|
|
265
|
+
if (this.hasAttribute("disabled")) {
|
|
266
|
+
this._inputElement.setAttribute("disabled", "");
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
this._updateLabelState();
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
_updateLabelState() {
|
|
273
|
+
const fallbackLabel = this.getAttribute("label");
|
|
274
|
+
this._labelSlotElement.textContent = fallbackLabel ?? "";
|
|
275
|
+
|
|
276
|
+
const assignedNodes = this._labelSlotElement.assignedNodes({ flatten: true });
|
|
277
|
+
const hasAssignedLabel = assignedNodes.some((node) => {
|
|
278
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
279
|
+
return node.textContent.trim().length > 0;
|
|
280
|
+
}
|
|
281
|
+
return node.nodeType === Node.ELEMENT_NODE;
|
|
282
|
+
});
|
|
283
|
+
const hasFallbackLabel = typeof fallbackLabel === "string" && fallbackLabel.trim().length > 0;
|
|
284
|
+
|
|
285
|
+
if (hasAssignedLabel || hasFallbackLabel) {
|
|
286
|
+
this.setAttribute("has-label", "");
|
|
287
|
+
} else {
|
|
288
|
+
this.removeAttribute("has-label");
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export default ({ render, html }) => {
|
|
294
|
+
return RettangoliCheckboxElement;
|
|
295
|
+
};
|