@descope/web-components-ui 1.0.40 → 1.0.41
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/cjs/index.cjs.js +35 -18
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/index.esm.js +382 -327
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/descope-button/index.js +3 -3
- package/src/components/descope-checkbox/index.js +2 -2
- package/src/components/descope-combo/index.js +12 -12
- package/src/components/descope-container/Container.js +57 -51
- package/src/components/descope-container/index.js +1 -1
- package/src/components/descope-date-picker/index.js +13 -7
- package/src/components/descope-email-field/index.js +2 -2
- package/src/components/descope-number-field/index.js +2 -2
- package/src/components/descope-password-field/index.js +2 -2
- package/src/components/descope-switch-toggle/index.js +2 -2
- package/src/components/descope-text-area/index.js +2 -2
- package/src/components/descope-text-field/index.js +3 -3
- package/src/componentsHelpers/componentNameValidationMixin.js +21 -17
- package/src/componentsHelpers/createProxy/helpers.js +31 -27
- package/src/componentsHelpers/createStyleMixin/helpers.js +65 -47
- package/src/componentsHelpers/createStyleMixin/index.js +64 -55
- package/src/componentsHelpers/draggableMixin.js +25 -26
- package/src/constants.js +1 -1
- package/src/dev/index.js +4 -3
- package/src/helpers.js +8 -6
- package/src/index.cjs.js +1 -1
- package/src/index.js +13 -13
- package/src/index.umd.js +11 -5
- package/src/theme/components/button.js +37 -37
- package/src/theme/components/textArea.js +3 -3
- package/src/theme/components/textField.js +1 -1
- package/src/theme/globals.js +32 -32
- package/src/theme/index.js +2 -2
- package/src/themeHelpers/index.js +45 -30
- package/src/themeHelpers/processColors.js +10 -7
package/dist/index.esm.js
CHANGED
@@ -11,202 +11,235 @@ import Color from 'color';
|
|
11
11
|
|
12
12
|
const DESCOPE_PREFIX = 'descope';
|
13
13
|
|
14
|
-
const kebabCase = str =>
|
15
|
-
|
16
|
-
.replace(/[
|
17
|
-
.
|
14
|
+
const kebabCase = (str) =>
|
15
|
+
str
|
16
|
+
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
17
|
+
.replace(/[\s_.]+/g, '-')
|
18
|
+
.toLowerCase();
|
18
19
|
|
19
20
|
const kebabCaseJoin = (...args) => kebabCase(args.join('-'));
|
20
21
|
|
21
|
-
const getCssVarName = (...args) =>
|
22
|
+
const getCssVarName = (...args) =>
|
23
|
+
`--${kebabCaseJoin(...args.filter((arg) => !!arg))}`;
|
22
24
|
|
23
|
-
const createCssVarFallback = (first, ...rest) =>
|
25
|
+
const createCssVarFallback = (first, ...rest) =>
|
26
|
+
`var(${first}${rest.length ? ` , ${createCssVarFallback(...rest)}` : ''})`;
|
24
27
|
|
25
|
-
const createCssSelector = (
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
const createCssSelector = (
|
29
|
+
baseSelector = '',
|
30
|
+
relativeSelectorOrSelectorFn = ''
|
31
|
+
) =>
|
32
|
+
typeof relativeSelectorOrSelectorFn === 'function'
|
33
|
+
? relativeSelectorOrSelectorFn(baseSelector)
|
34
|
+
: `${baseSelector}${relativeSelectorOrSelectorFn}`;
|
29
35
|
|
30
36
|
class StyleBuilder {
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
37
|
+
constructor() {
|
38
|
+
this.styleMap = new Map();
|
39
|
+
}
|
40
|
+
|
41
|
+
add(selector, property, value) {
|
42
|
+
if (!this.styleMap.has(selector)) {
|
43
|
+
this.styleMap.set(selector, []);
|
44
|
+
}
|
45
|
+
|
46
|
+
this.styleMap.set(selector, [
|
47
|
+
...this.styleMap.get(selector),
|
48
|
+
{ property, value }
|
49
|
+
]);
|
50
|
+
}
|
51
|
+
|
52
|
+
toString() {
|
53
|
+
return Array.from(this.styleMap.entries()).reduce(
|
54
|
+
(style, [selector, propValArr]) =>
|
55
|
+
(style += `${selector} { \n${propValArr
|
56
|
+
.map(({ property, value }) => `${property}: ${value}`)
|
57
|
+
.join(';\n')} \n}\n\n`),
|
58
|
+
''
|
59
|
+
);
|
60
|
+
}
|
48
61
|
}
|
49
62
|
|
50
63
|
const normalizeConfig = (attr, config) => {
|
51
|
-
|
64
|
+
const defaultMapping = { selector: '', property: kebabCase(attr) };
|
52
65
|
|
53
|
-
|
66
|
+
if (!config || !Object.keys(config).length) return [defaultMapping];
|
54
67
|
|
55
|
-
|
68
|
+
if (Array.isArray(config))
|
69
|
+
return config.map((entry) => Object.assign({}, defaultMapping, entry));
|
56
70
|
|
57
|
-
|
71
|
+
return [Object.assign({}, defaultMapping, config)];
|
58
72
|
};
|
59
73
|
|
60
74
|
const createStyle = (componentName, baseSelector, mappings) => {
|
61
|
-
|
75
|
+
const style = new StyleBuilder();
|
62
76
|
|
63
|
-
|
64
|
-
|
77
|
+
Object.keys(mappings).forEach((attr) => {
|
78
|
+
const attrConfig = normalizeConfig(attr, mappings[attr]);
|
65
79
|
|
66
|
-
|
80
|
+
const cssVarName = getCssVarName(componentName, attr);
|
67
81
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
82
|
+
attrConfig.forEach(
|
83
|
+
({ selector: relativeSelectorOrSelectorFn, property }) => {
|
84
|
+
style.add(
|
85
|
+
createCssSelector(baseSelector, relativeSelectorOrSelectorFn),
|
86
|
+
property,
|
87
|
+
createCssVarFallback(cssVarName)
|
88
|
+
);
|
89
|
+
}
|
90
|
+
);
|
91
|
+
});
|
76
92
|
|
77
|
-
|
93
|
+
return style.toString();
|
78
94
|
};
|
79
95
|
|
80
96
|
const createCssVarsList = (componentName, mappings) =>
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
97
|
+
Object.keys(mappings).reduce(
|
98
|
+
(acc, attr) =>
|
99
|
+
Object.assign(acc, { [attr]: getCssVarName(componentName, attr) }),
|
100
|
+
{}
|
101
|
+
);
|
85
102
|
|
86
103
|
// match the host selector with the inner element selector
|
87
104
|
// e.g. when we want to set the same size for the host & the inner element this can be useful
|
88
|
-
const matchHostStyle = (mappingObj) => [
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
105
|
+
const matchHostStyle = (mappingObj) => [
|
106
|
+
mappingObj,
|
107
|
+
{ ...mappingObj, selector: () => `:host${mappingObj.selector || ''}` }
|
108
|
+
];
|
109
|
+
|
110
|
+
const createStyleMixin =
|
111
|
+
({ mappings = {} }) =>
|
112
|
+
(superclass) => {
|
113
|
+
const styleAttributes = Object.keys(mappings).map((key) =>
|
114
|
+
kebabCaseJoin('st', key)
|
115
|
+
);
|
116
|
+
return class CustomStyleMixinClass extends superclass {
|
117
|
+
static get observedAttributes() {
|
118
|
+
const superAttrs = superclass.observedAttributes || [];
|
119
|
+
return [...superAttrs, ...styleAttributes];
|
120
|
+
}
|
121
|
+
|
122
|
+
static get cssVarList() {
|
123
|
+
return createCssVarsList(superclass.componentName, mappings);
|
124
|
+
}
|
125
|
+
|
126
|
+
#styleEle = null;
|
127
|
+
|
128
|
+
constructor() {
|
129
|
+
super();
|
130
|
+
|
131
|
+
this.#createComponentStyle();
|
132
|
+
this.#createAttrOverrideStyle();
|
133
|
+
}
|
134
|
+
|
135
|
+
#createAttrOverrideStyle() {
|
136
|
+
this.#styleEle = document.createElement('style');
|
137
|
+
this.#styleEle.id = 'style-mixin-overrides';
|
138
|
+
|
139
|
+
this.#styleEle.innerText = '* {}';
|
140
|
+
this.shadowRoot.prepend(this.#styleEle);
|
141
|
+
}
|
142
|
+
|
143
|
+
#updateAttrOverrideStyle(attrName, value) {
|
144
|
+
const style = this.#styleEle.sheet.cssRules[0].style;
|
145
|
+
const varName = getCssVarName(
|
146
|
+
superclass.componentName,
|
147
|
+
attrName.replace(/^st-/, '')
|
148
|
+
);
|
149
|
+
|
150
|
+
if (value) style.setProperty(varName, value);
|
151
|
+
else style.removeProperty(varName);
|
152
|
+
}
|
153
|
+
|
154
|
+
#createComponentStyle() {
|
155
|
+
const themeStyle = document.createElement('style');
|
156
|
+
themeStyle.id = 'style-mixin-component';
|
157
|
+
themeStyle.innerHTML = createStyle(
|
158
|
+
superclass.componentName,
|
159
|
+
this.baseSelector,
|
160
|
+
mappings
|
161
|
+
);
|
162
|
+
this.shadowRoot.prepend(themeStyle);
|
163
|
+
}
|
164
|
+
|
165
|
+
attributeChangedCallback(attrName, oldValue, newValue) {
|
166
|
+
super.attributeChangedCallback?.(attrName, oldValue, newValue);
|
167
|
+
|
168
|
+
if (styleAttributes.includes(attrName)) {
|
169
|
+
this.#updateAttrOverrideStyle(attrName, newValue);
|
170
|
+
}
|
171
|
+
}
|
172
|
+
};
|
173
|
+
};
|
145
174
|
|
146
175
|
const draggableMixin = (superclass) =>
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
};
|
176
|
+
class DraggableMixinClass extends superclass {
|
177
|
+
#styleEle = null;
|
178
|
+
|
179
|
+
static get observedAttributes() {
|
180
|
+
const superAttrs = superclass.observedAttributes || [];
|
181
|
+
return [...superAttrs, 'draggable'];
|
182
|
+
}
|
183
|
+
|
184
|
+
constructor() {
|
185
|
+
super();
|
186
|
+
|
187
|
+
this.#styleEle = document.createElement('style');
|
188
|
+
this.#styleEle.innerText = `${this.baseSelector} { cursor: inherit }`;
|
189
|
+
}
|
190
|
+
|
191
|
+
#handleDraggableStyle(isDraggable) {
|
192
|
+
if (isDraggable) {
|
193
|
+
this.shadowRoot.appendChild(this.#styleEle);
|
194
|
+
} else {
|
195
|
+
this.#styleEle.remove();
|
196
|
+
}
|
197
|
+
}
|
198
|
+
|
199
|
+
attributeChangedCallback(attrName, oldValue, newValue) {
|
200
|
+
super.attributeChangedCallback?.(attrName, oldValue, newValue);
|
201
|
+
if (attrName === 'draggable') {
|
202
|
+
this.#handleDraggableStyle(newValue === 'true');
|
203
|
+
}
|
204
|
+
}
|
205
|
+
};
|
178
206
|
|
179
207
|
const observeAttributes = (ele, callback, excludeAttrs) => {
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
};
|
208
|
+
// sync all attrs on init
|
209
|
+
callback(...Array.from(ele.attributes).map((attr) => attr.name));
|
210
|
+
|
211
|
+
const observer = new MutationObserver((mutationsList) => {
|
212
|
+
for (const mutation of mutationsList) {
|
213
|
+
if (
|
214
|
+
mutation.type === 'attributes' &&
|
215
|
+
!excludeAttrs.includes(mutation.attributeName)
|
216
|
+
) {
|
217
|
+
callback(mutation.attributeName);
|
218
|
+
}
|
219
|
+
}
|
220
|
+
});
|
193
221
|
|
194
|
-
|
195
|
-
attrNames.forEach(attrName => {
|
196
|
-
const srcAttrVal = srcEle.getAttribute(attrName);
|
197
|
-
if (srcAttrVal !== null) {
|
198
|
-
if (targetEle.getAttribute(attrName) !== srcAttrVal) {
|
199
|
-
targetEle.setAttribute(attrName, srcAttrVal);
|
200
|
-
}
|
201
|
-
} else {
|
202
|
-
targetEle.removeAttribute(attrName);
|
203
|
-
}
|
204
|
-
});
|
222
|
+
observer.observe(ele, { attributes: true });
|
205
223
|
};
|
206
224
|
|
225
|
+
const createSyncAttrsCb =
|
226
|
+
(srcEle, targetEle) =>
|
227
|
+
(...attrNames) => {
|
228
|
+
attrNames.forEach((attrName) => {
|
229
|
+
const srcAttrVal = srcEle.getAttribute(attrName);
|
230
|
+
if (srcAttrVal !== null) {
|
231
|
+
if (targetEle.getAttribute(attrName) !== srcAttrVal) {
|
232
|
+
targetEle.setAttribute(attrName, srcAttrVal);
|
233
|
+
}
|
234
|
+
} else {
|
235
|
+
targetEle.removeAttribute(attrName);
|
236
|
+
}
|
237
|
+
});
|
238
|
+
};
|
239
|
+
|
207
240
|
const syncAttrs = (ele1, ele2, excludeAttrs) => {
|
208
|
-
|
209
|
-
|
241
|
+
observeAttributes(ele1, createSyncAttrsCb(ele1, ele2), excludeAttrs);
|
242
|
+
observeAttributes(ele2, createSyncAttrsCb(ele2, ele1), excludeAttrs);
|
210
243
|
};
|
211
244
|
|
212
245
|
const createProxy = ({
|
@@ -341,26 +374,30 @@ const inputMixin = (superclass) =>
|
|
341
374
|
};
|
342
375
|
|
343
376
|
const componentNameValidationMixin = (superclass) =>
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
377
|
+
class DraggableMixinClass extends superclass {
|
378
|
+
#checkComponentName() {
|
379
|
+
const currentComponentName = this.shadowRoot.host.tagName.toLowerCase();
|
380
|
+
|
381
|
+
if (!superclass.componentName) {
|
382
|
+
throw Error(
|
383
|
+
`component name is not defined on super class, make sure you have a static get for "componentName"`
|
384
|
+
);
|
385
|
+
}
|
386
|
+
|
387
|
+
if (currentComponentName !== superclass.componentName) {
|
388
|
+
throw Error(
|
389
|
+
`component name mismatch, expected "${superclass.componentName}", current "${currentComponentName}"`
|
390
|
+
);
|
391
|
+
}
|
392
|
+
}
|
393
|
+
|
394
|
+
connectedCallback() {
|
395
|
+
super.connectedCallback?.();
|
396
|
+
if (this.shadowRoot.isConnected) {
|
397
|
+
this.#checkComponentName();
|
398
|
+
}
|
399
|
+
}
|
400
|
+
};
|
364
401
|
|
365
402
|
const getComponentName = (name) => kebabCaseJoin(DESCOPE_PREFIX, name);
|
366
403
|
|
@@ -552,7 +589,7 @@ customElements.define(componentName$9, TextField);
|
|
552
589
|
|
553
590
|
const template = document.createElement('template');
|
554
591
|
|
555
|
-
const componentName$8 = getComponentName(
|
592
|
+
const componentName$8 = getComponentName('combo');
|
556
593
|
|
557
594
|
template.innerHTML = `
|
558
595
|
<descope-button></descope-button>
|
@@ -560,13 +597,13 @@ template.innerHTML = `
|
|
560
597
|
`;
|
561
598
|
|
562
599
|
class Combo extends HTMLElement {
|
563
|
-
|
564
|
-
|
600
|
+
constructor() {
|
601
|
+
super();
|
565
602
|
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
603
|
+
this.attachShadow({ mode: 'open' }).appendChild(
|
604
|
+
template.content.cloneNode(true)
|
605
|
+
);
|
606
|
+
}
|
570
607
|
}
|
571
608
|
|
572
609
|
customElements.define(componentName$8, Combo);
|
@@ -822,7 +859,7 @@ overrides$1 = `
|
|
822
859
|
|
823
860
|
customElements.define(componentName$4, TextArea);
|
824
861
|
|
825
|
-
const componentName$3 = getComponentName(
|
862
|
+
const componentName$3 = getComponentName('date-picker');
|
826
863
|
|
827
864
|
const DatePicker = compose(
|
828
865
|
draggableMixin,
|
@@ -830,66 +867,66 @@ const DatePicker = compose(
|
|
830
867
|
)(
|
831
868
|
createProxy({
|
832
869
|
componentName: componentName$3,
|
833
|
-
slots: [
|
834
|
-
wrappedEleName:
|
835
|
-
style:
|
870
|
+
slots: ['prefix', 'suffix'],
|
871
|
+
wrappedEleName: 'vaadin-date-picker',
|
872
|
+
style: ``
|
836
873
|
})
|
837
874
|
);
|
838
875
|
|
839
876
|
customElements.define(componentName$3, DatePicker);
|
840
877
|
|
841
|
-
const componentName$2 = getComponentName(
|
878
|
+
const componentName$2 = getComponentName('container');
|
842
879
|
|
843
880
|
class RawContainer extends HTMLElement {
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
881
|
+
static get componentName() {
|
882
|
+
return componentName$2;
|
883
|
+
}
|
884
|
+
constructor() {
|
885
|
+
super();
|
886
|
+
const template = document.createElement('template');
|
887
|
+
template.innerHTML = `<slot></slot>`;
|
888
|
+
|
889
|
+
this.attachShadow({ mode: 'open' });
|
890
|
+
this.shadowRoot.appendChild(template.content.cloneNode(true));
|
891
|
+
|
892
|
+
this.baseSelector = ':host > slot';
|
893
|
+
}
|
857
894
|
}
|
858
895
|
|
859
896
|
const Container = compose(
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
897
|
+
createStyleMixin({
|
898
|
+
// todo: do we want to change the mapping structure to this? ['aa', 'aaa', {'color': [{ selector: '::part(label)' }]}],
|
899
|
+
mappings: {
|
900
|
+
height: {},
|
901
|
+
width: {},
|
902
|
+
|
903
|
+
verticalPadding: [
|
904
|
+
{ property: 'padding-top' },
|
905
|
+
{ property: 'padding-bottom' }
|
906
|
+
],
|
907
|
+
horizontalPadding: [
|
908
|
+
{ property: 'padding-left' },
|
909
|
+
{ property: 'padding-right' }
|
910
|
+
],
|
911
|
+
|
912
|
+
display: {},
|
913
|
+
flexDirection: {},
|
914
|
+
justifyContent: {},
|
915
|
+
alignItems: {},
|
916
|
+
gap: {},
|
917
|
+
|
918
|
+
backgroundColor: {},
|
919
|
+
borderRadius: {},
|
920
|
+
|
921
|
+
borderColor: {},
|
922
|
+
borderStyle: {},
|
923
|
+
borderWidth: {},
|
924
|
+
|
925
|
+
boxShadow: {}
|
926
|
+
}
|
927
|
+
}),
|
928
|
+
draggableMixin,
|
929
|
+
componentNameValidationMixin
|
893
930
|
)(RawContainer);
|
894
931
|
|
895
932
|
customElements.define(componentName$2, Container);
|
@@ -906,21 +943,25 @@ const transformTheme = (theme, path, getTransformation) => {
|
|
906
943
|
}, {});
|
907
944
|
};
|
908
945
|
|
909
|
-
const stringifyArray = (strArr) =>
|
946
|
+
const stringifyArray = (strArr) =>
|
947
|
+
strArr.map((str) => (str.includes(' ') ? `"${str}"` : str)).join(', ');
|
910
948
|
|
911
949
|
const themeToCSSVarsObj = (theme) =>
|
912
950
|
transformTheme(theme, [], (path, val) => ({
|
913
|
-
[getVarName(path)]: Array.isArray(val) ? stringifyArray(val) : val
|
951
|
+
[getVarName(path)]: Array.isArray(val) ? stringifyArray(val) : val
|
914
952
|
}));
|
915
953
|
|
916
954
|
const getThemeRefs = (theme, prefix) =>
|
917
|
-
transformTheme(theme, [], (path) =>
|
955
|
+
transformTheme(theme, [], (path) =>
|
956
|
+
set({}, path, `var(${getVarName(prefix ? [prefix, ...path] : path)})`)
|
957
|
+
);
|
918
958
|
|
919
959
|
const globalsThemeToStyle = (theme, themeName = '') => `
|
920
960
|
*[data-theme="${themeName}"] {
|
921
961
|
${Object.entries(themeToCSSVarsObj(theme)).reduce(
|
922
|
-
|
923
|
-
|
962
|
+
(acc, entry) => (acc += `${entry.join(':')};\n`),
|
963
|
+
''
|
964
|
+
)}
|
924
965
|
}
|
925
966
|
`;
|
926
967
|
|
@@ -933,16 +974,22 @@ const componentsThemeToStyleObj = (componentsTheme) =>
|
|
933
974
|
// starts with underscore -> attribute selector
|
934
975
|
|
935
976
|
const attrsSelector = restPath.reduce((acc, section, idx) => {
|
936
|
-
if (section.startsWith('_'))
|
977
|
+
if (section.startsWith('_'))
|
978
|
+
return (acc += `[${kebabCase(section.replace(/^_/, ''))}="true"]`);
|
937
979
|
|
938
980
|
const nextSection = restPath[idx + 1];
|
939
981
|
|
940
982
|
if (typeof nextSection !== 'string' || nextSection.startsWith('_')) {
|
941
|
-
console.error(
|
983
|
+
console.error(
|
984
|
+
'theme generator',
|
985
|
+
`your theme structure is invalid, attribute "${section}" is followed by "${nextSection}" which is not allowed`
|
986
|
+
);
|
942
987
|
return acc;
|
943
988
|
}
|
944
989
|
|
945
|
-
return acc += `[${kebabCase(section)}="${restPath
|
990
|
+
return (acc += `[${kebabCase(section)}="${restPath
|
991
|
+
.splice(idx + 1, 1)
|
992
|
+
.join('')}"]`);
|
946
993
|
}, '');
|
947
994
|
|
948
995
|
let selector = `${getComponentName(component)}${attrsSelector}`;
|
@@ -951,12 +998,17 @@ const componentsThemeToStyleObj = (componentsTheme) =>
|
|
951
998
|
[selector]: {
|
952
999
|
[property]: val
|
953
1000
|
}
|
954
|
-
}
|
1001
|
+
};
|
955
1002
|
});
|
956
1003
|
|
957
1004
|
const componentsThemeToStyle = (componentsTheme, themeName = '') =>
|
958
1005
|
Object.entries(componentsThemeToStyleObj(componentsTheme)).reduce(
|
959
|
-
(acc, [selector, vars]) =>
|
1006
|
+
(acc, [selector, vars]) =>
|
1007
|
+
(acc += `*[data-theme="${themeName}"] ${selector} { \n${Object.entries(
|
1008
|
+
vars
|
1009
|
+
)
|
1010
|
+
.map(([key, val]) => `${key}: ${val}`)
|
1011
|
+
.join(';\n')} \n}\n\n`),
|
960
1012
|
''
|
961
1013
|
);
|
962
1014
|
|
@@ -965,7 +1017,7 @@ ${globalsThemeToStyle(globals, themeName)}
|
|
965
1017
|
${componentsThemeToStyle(components, themeName)}
|
966
1018
|
`;
|
967
1019
|
|
968
|
-
const useVar = varName => `var(${varName})`;
|
1020
|
+
const useVar = (varName) => `var(${varName})`;
|
969
1021
|
|
970
1022
|
const createHelperVars = (theme, prefix) => {
|
971
1023
|
const res = transformTheme(theme, [], (path, value) => {
|
@@ -977,17 +1029,20 @@ const createHelperVars = (theme, prefix) => {
|
|
977
1029
|
const theme = set({}, [...modifiedPath, varName], value);
|
978
1030
|
const useVars = { [property]: useVar(varName) };
|
979
1031
|
|
980
|
-
return { theme, useVars, vars }
|
1032
|
+
return { theme, useVars, vars };
|
981
1033
|
});
|
982
1034
|
|
983
|
-
return [res.theme, res.useVars, res.vars]
|
1035
|
+
return [res.theme, res.useVars, res.vars];
|
984
1036
|
};
|
985
1037
|
|
986
1038
|
const genDark = (c, percentage = 0.5) => c.darken(percentage).hex();
|
987
1039
|
const genLight = (c, percentage = 0.5) => c.lighten(percentage).hex();
|
988
1040
|
const genContrast = (c, percentage = 0.9) => {
|
989
1041
|
const isDark = c.isDark();
|
990
|
-
return c
|
1042
|
+
return c
|
1043
|
+
.mix(Color(isDark ? 'white' : 'black'), percentage)
|
1044
|
+
.saturate(1)
|
1045
|
+
.hex();
|
991
1046
|
};
|
992
1047
|
|
993
1048
|
const genColor = (color) => {
|
@@ -997,8 +1052,8 @@ const genColor = (color) => {
|
|
997
1052
|
main: mainColor.hex(),
|
998
1053
|
dark: color.dark || genDark(mainColor),
|
999
1054
|
light: color.light || genLight(mainColor),
|
1000
|
-
contrast: color.contrast || genContrast(mainColor)
|
1001
|
-
}
|
1055
|
+
contrast: color.contrast || genContrast(mainColor)
|
1056
|
+
};
|
1002
1057
|
};
|
1003
1058
|
|
1004
1059
|
const genColors = (colors) => {
|
@@ -1006,59 +1061,59 @@ const genColors = (colors) => {
|
|
1006
1061
|
const currentColor = colors[colorName];
|
1007
1062
|
|
1008
1063
|
return Object.assign(acc, {
|
1009
|
-
[colorName]: genColor(currentColor)
|
1010
|
-
})
|
1064
|
+
[colorName]: genColor(currentColor)
|
1065
|
+
});
|
1011
1066
|
}, {});
|
1012
1067
|
};
|
1013
1068
|
|
1014
1069
|
const colors = genColors({
|
1015
1070
|
surface: {
|
1016
|
-
main:
|
1017
|
-
light:
|
1018
|
-
dark:
|
1071
|
+
main: 'lightgray',
|
1072
|
+
light: '#fff',
|
1073
|
+
dark: '#000'
|
1019
1074
|
},
|
1020
|
-
primary:
|
1021
|
-
secondary:
|
1022
|
-
success:
|
1023
|
-
error:
|
1075
|
+
primary: '#0082B5',
|
1076
|
+
secondary: '#7D14EB',
|
1077
|
+
success: 'green',
|
1078
|
+
error: 'red'
|
1024
1079
|
});
|
1025
1080
|
|
1026
1081
|
const typography = {
|
1027
1082
|
h1: {
|
1028
|
-
font: [
|
1029
|
-
weight:
|
1030
|
-
size:
|
1083
|
+
font: ['Courier New', 'Arial', 'sans-serif'],
|
1084
|
+
weight: '700',
|
1085
|
+
size: '48px'
|
1031
1086
|
},
|
1032
1087
|
h2: {
|
1033
|
-
font: [
|
1034
|
-
weight:
|
1035
|
-
size:
|
1088
|
+
font: ['Courier New', 'sans-serif'],
|
1089
|
+
weight: '500',
|
1090
|
+
size: '38px'
|
1036
1091
|
},
|
1037
1092
|
h3: {
|
1038
|
-
font: [
|
1039
|
-
weight:
|
1040
|
-
size:
|
1041
|
-
}
|
1093
|
+
font: ['Courier New', 'sans-serif'],
|
1094
|
+
weight: '300',
|
1095
|
+
size: '28px'
|
1096
|
+
}
|
1042
1097
|
};
|
1043
1098
|
|
1044
1099
|
const spacing = {
|
1045
|
-
xs:
|
1046
|
-
sm:
|
1047
|
-
md:
|
1048
|
-
lg:
|
1049
|
-
xl:
|
1100
|
+
xs: '2px',
|
1101
|
+
sm: '4px',
|
1102
|
+
md: '8px',
|
1103
|
+
lg: '16px',
|
1104
|
+
xl: '32px'
|
1050
1105
|
};
|
1051
1106
|
|
1052
1107
|
const border = {
|
1053
|
-
sm:
|
1054
|
-
md:
|
1055
|
-
lg:
|
1108
|
+
sm: '1px',
|
1109
|
+
md: '2px',
|
1110
|
+
lg: '3px'
|
1056
1111
|
};
|
1057
1112
|
|
1058
1113
|
const radius = {
|
1059
|
-
sm:
|
1060
|
-
md:
|
1061
|
-
lg:
|
1114
|
+
sm: '5px',
|
1115
|
+
md: '25px',
|
1116
|
+
lg: '50px'
|
1062
1117
|
};
|
1063
1118
|
|
1064
1119
|
const shadow = {
|
@@ -1066,8 +1121,8 @@ const shadow = {
|
|
1066
1121
|
size: {
|
1067
1122
|
sm: `0 0 10px`,
|
1068
1123
|
md: `0 0 20px`,
|
1069
|
-
lg: `0 0 30px
|
1070
|
-
}
|
1124
|
+
lg: `0 0 30px`
|
1125
|
+
}
|
1071
1126
|
};
|
1072
1127
|
|
1073
1128
|
var globals = {
|
@@ -1076,7 +1131,7 @@ var globals = {
|
|
1076
1131
|
spacing,
|
1077
1132
|
border,
|
1078
1133
|
radius,
|
1079
|
-
shadow
|
1134
|
+
shadow
|
1080
1135
|
};
|
1081
1136
|
|
1082
1137
|
const globalRefs$3 = getThemeRefs(globals);
|
@@ -1087,7 +1142,7 @@ const mode = {
|
|
1087
1142
|
secondary: globalRefs$3.colors.secondary,
|
1088
1143
|
success: globalRefs$3.colors.success,
|
1089
1144
|
error: globalRefs$3.colors.error,
|
1090
|
-
surface: globalRefs$3.colors.surface
|
1145
|
+
surface: globalRefs$3.colors.surface
|
1091
1146
|
};
|
1092
1147
|
|
1093
1148
|
const [helperTheme$1, helperRefs$1] = createHelperVars({ mode }, componentName$a);
|
@@ -1097,43 +1152,43 @@ const button = {
|
|
1097
1152
|
|
1098
1153
|
size: {
|
1099
1154
|
xs: {
|
1100
|
-
[vars$6.height]:
|
1101
|
-
[vars$6.fontSize]:
|
1102
|
-
[vars$6.padding]: `0 ${globalRefs$3.spacing.xs}
|
1155
|
+
[vars$6.height]: '10px',
|
1156
|
+
[vars$6.fontSize]: '10px',
|
1157
|
+
[vars$6.padding]: `0 ${globalRefs$3.spacing.xs}`
|
1103
1158
|
},
|
1104
1159
|
sm: {
|
1105
|
-
[vars$6.height]:
|
1106
|
-
[vars$6.fontSize]:
|
1107
|
-
[vars$6.padding]: `0 ${globalRefs$3.spacing.sm}
|
1160
|
+
[vars$6.height]: '20px',
|
1161
|
+
[vars$6.fontSize]: '10px',
|
1162
|
+
[vars$6.padding]: `0 ${globalRefs$3.spacing.sm}`
|
1108
1163
|
},
|
1109
1164
|
md: {
|
1110
|
-
[vars$6.height]:
|
1111
|
-
[vars$6.fontSize]:
|
1112
|
-
[vars$6.padding]: `0 ${globalRefs$3.spacing.md}
|
1165
|
+
[vars$6.height]: '30px',
|
1166
|
+
[vars$6.fontSize]: '14px',
|
1167
|
+
[vars$6.padding]: `0 ${globalRefs$3.spacing.md}`
|
1113
1168
|
},
|
1114
1169
|
lg: {
|
1115
|
-
[vars$6.height]:
|
1116
|
-
[vars$6.fontSize]:
|
1117
|
-
[vars$6.padding]: `0 ${globalRefs$3.spacing.lg}
|
1170
|
+
[vars$6.height]: '40px',
|
1171
|
+
[vars$6.fontSize]: '20px',
|
1172
|
+
[vars$6.padding]: `0 ${globalRefs$3.spacing.lg}`
|
1118
1173
|
},
|
1119
1174
|
xl: {
|
1120
|
-
[vars$6.height]:
|
1121
|
-
[vars$6.fontSize]:
|
1122
|
-
[vars$6.padding]: `0 ${globalRefs$3.spacing.xl}
|
1123
|
-
}
|
1175
|
+
[vars$6.height]: '50px',
|
1176
|
+
[vars$6.fontSize]: '25px',
|
1177
|
+
[vars$6.padding]: `0 ${globalRefs$3.spacing.xl}`
|
1178
|
+
}
|
1124
1179
|
},
|
1125
1180
|
|
1126
1181
|
[vars$6.borderRadius]: globalRefs$3.radius.lg,
|
1127
|
-
[vars$6.cursor]:
|
1128
|
-
[vars$6.borderWidth]:
|
1129
|
-
[vars$6.borderStyle]:
|
1130
|
-
[vars$6.borderColor]:
|
1182
|
+
[vars$6.cursor]: 'pointer',
|
1183
|
+
[vars$6.borderWidth]: '2px',
|
1184
|
+
[vars$6.borderStyle]: 'solid',
|
1185
|
+
[vars$6.borderColor]: 'transparent',
|
1131
1186
|
|
1132
|
-
|
1133
|
-
[vars$6.width]:
|
1187
|
+
_fullWidth: {
|
1188
|
+
[vars$6.width]: '100%'
|
1134
1189
|
},
|
1135
1190
|
_loading: {
|
1136
|
-
[vars$6.cursor]:
|
1191
|
+
[vars$6.cursor]: 'wait'
|
1137
1192
|
},
|
1138
1193
|
|
1139
1194
|
variant: {
|
@@ -1141,11 +1196,11 @@ const button = {
|
|
1141
1196
|
[vars$6.color]: helperRefs$1.contrast,
|
1142
1197
|
[vars$6.backgroundColor]: helperRefs$1.main,
|
1143
1198
|
_hover: {
|
1144
|
-
[vars$6.backgroundColor]: helperRefs$1.dark
|
1199
|
+
[vars$6.backgroundColor]: helperRefs$1.dark
|
1145
1200
|
},
|
1146
1201
|
_loading: {
|
1147
|
-
[vars$6.backgroundColor]: helperRefs$1.main
|
1148
|
-
}
|
1202
|
+
[vars$6.backgroundColor]: helperRefs$1.main
|
1203
|
+
}
|
1149
1204
|
},
|
1150
1205
|
outline: {
|
1151
1206
|
[vars$6.color]: helperRefs$1.main,
|
@@ -1154,9 +1209,9 @@ const button = {
|
|
1154
1209
|
[vars$6.color]: helperRefs$1.dark,
|
1155
1210
|
[vars$6.borderColor]: helperRefs$1.dark,
|
1156
1211
|
_error: {
|
1157
|
-
[vars$6.color]: helperRefs$1.error
|
1158
|
-
}
|
1159
|
-
}
|
1212
|
+
[vars$6.color]: helperRefs$1.error
|
1213
|
+
}
|
1214
|
+
}
|
1160
1215
|
},
|
1161
1216
|
link: {
|
1162
1217
|
[vars$6.color]: helperRefs$1.main,
|
@@ -1166,10 +1221,10 @@ const button = {
|
|
1166
1221
|
[vars$6.borderRadius]: 0,
|
1167
1222
|
_hover: {
|
1168
1223
|
[vars$6.color]: helperRefs$1.main,
|
1169
|
-
[vars$6.textDecoration]:
|
1170
|
-
}
|
1171
|
-
}
|
1172
|
-
}
|
1224
|
+
[vars$6.textDecoration]: 'underline'
|
1225
|
+
}
|
1226
|
+
}
|
1227
|
+
}
|
1173
1228
|
};
|
1174
1229
|
|
1175
1230
|
const globalRefs$2 = getThemeRefs(globals);
|
@@ -1231,7 +1286,7 @@ const textField = (vars) => ({
|
|
1231
1286
|
[vars.backgroundColor]: globalRefs$2.colors.surface.main
|
1232
1287
|
},
|
1233
1288
|
|
1234
|
-
|
1289
|
+
_fullWidth: {
|
1235
1290
|
[vars.width]: '100%'
|
1236
1291
|
},
|
1237
1292
|
|
@@ -1274,12 +1329,12 @@ const textArea = {
|
|
1274
1329
|
[vars$3.borderStyle]: 'solid',
|
1275
1330
|
[vars$3.borderColor]: 'transparent',
|
1276
1331
|
|
1277
|
-
|
1332
|
+
_borderOffset: {
|
1278
1333
|
[vars$3.outlineOffset]: '2px'
|
1279
1334
|
},
|
1280
1335
|
|
1281
1336
|
_bordered: {
|
1282
|
-
[vars$3.
|
1337
|
+
[vars$3.borderColor]: globalRefs$1.colors.surface.main
|
1283
1338
|
},
|
1284
1339
|
|
1285
1340
|
_focused: {
|
@@ -1287,7 +1342,7 @@ const textArea = {
|
|
1287
1342
|
[vars$3.outline]: `2px solid ${globalRefs$1.colors.surface.main}`
|
1288
1343
|
},
|
1289
1344
|
|
1290
|
-
|
1345
|
+
_fullWidth: {
|
1291
1346
|
[vars$3.width]: '100%'
|
1292
1347
|
},
|
1293
1348
|
|