@descope/web-components-ui 1.0.39 → 1.0.41
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/index.cjs.js +35 -18
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/index.esm.js +1128 -481
- package/dist/index.esm.js.map +1 -1
- package/dist/umd/101.js +148 -0
- package/dist/umd/208.js +2 -0
- package/dist/umd/208.js.LICENSE.txt +5 -0
- package/dist/umd/211.js +312 -0
- package/dist/umd/211.js.LICENSE.txt +5 -0
- package/dist/umd/233.js +573 -0
- package/dist/umd/{511.js.LICENSE.txt → 233.js.LICENSE.txt} +0 -6
- package/dist/umd/422.js +2 -0
- package/dist/umd/422.js.LICENSE.txt +5 -0
- package/dist/umd/437.js +19 -0
- package/dist/umd/437.js.LICENSE.txt +5 -0
- package/dist/umd/513.js +1 -0
- package/dist/umd/515.js +202 -0
- package/dist/umd/515.js.LICENSE.txt +11 -0
- package/dist/umd/54.js +4 -4
- package/dist/umd/56.js +48 -0
- package/dist/umd/56.js.LICENSE.txt +5 -0
- package/dist/umd/599.js +1 -1
- package/dist/umd/63.js +1 -0
- package/dist/umd/725.js +37 -0
- package/dist/umd/725.js.LICENSE.txt +11 -0
- package/dist/umd/729.js +1 -1
- package/dist/umd/767.js +2 -0
- package/dist/umd/{9.js.LICENSE.txt → 767.js.LICENSE.txt} +0 -6
- package/dist/umd/786.js +2 -0
- package/dist/umd/786.js.LICENSE.txt +17 -0
- package/dist/umd/789.js +1 -0
- package/dist/umd/806.js +109 -0
- package/dist/umd/806.js.LICENSE.txt +5 -0
- package/dist/umd/938.js +1 -0
- package/dist/umd/97.js +1 -1
- package/dist/umd/descope-button-index-js.js +1 -1
- package/dist/umd/descope-checkbox-index-js.js +1 -0
- package/dist/umd/descope-combo-index-js.js +1 -1
- package/dist/umd/descope-container-index-js.js +1 -1
- package/dist/umd/descope-email-field-index-js.js +1 -0
- package/dist/umd/descope-number-field-index-js.js +1 -0
- package/dist/umd/descope-password-field-index-js.js +1 -0
- package/dist/umd/descope-switch-toggle-index-js.js +1 -0
- package/dist/umd/descope-text-area-index-js.js +1 -0
- package/dist/umd/descope-text-field-index-js.js +1 -1
- package/dist/umd/index.js +1 -1
- package/package.json +9 -2
- package/src/components/descope-button/Button.js +90 -30
- package/src/components/descope-button/index.js +3 -3
- package/src/components/descope-checkbox/Checkbox.js +33 -0
- package/src/components/descope-checkbox/index.js +6 -0
- 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/EmailField.js +72 -0
- package/src/components/descope-email-field/index.js +6 -0
- package/src/components/descope-number-field/NumberField.js +72 -0
- package/src/components/descope-number-field/index.js +6 -0
- package/src/components/descope-password-field/PasswordField.js +79 -0
- package/src/components/descope-password-field/index.js +6 -0
- package/src/components/descope-switch-toggle/SwitchToggle.js +81 -0
- package/src/components/descope-switch-toggle/index.js +6 -0
- package/src/components/descope-text-area/TextArea.js +66 -0
- package/src/components/descope-text-area/index.js +6 -0
- package/src/components/descope-text-field/TextField.js +98 -28
- 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/createProxy/index.js +27 -17
- 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/componentsHelpers/index.js +12 -9
- package/src/componentsHelpers/inputMixin.js +38 -37
- 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 +16 -8
- package/src/index.umd.js +11 -5
- package/src/theme/components/button.js +32 -21
- package/src/theme/components/checkbox.js +9 -0
- package/src/theme/components/container.js +32 -27
- package/src/theme/components/emailField.js +8 -0
- package/src/theme/components/index.js +19 -7
- package/src/theme/components/input.js +106 -0
- package/src/theme/components/numberField.js +8 -0
- package/src/theme/components/passwordField.js +11 -0
- package/src/theme/components/switchToggle.js +10 -0
- package/src/theme/components/textArea.js +44 -0
- package/src/theme/components/textField.js +69 -45
- package/src/theme/globals.js +27 -26
- package/src/theme/index.js +2 -2
- package/src/themeHelpers/index.js +45 -30
- package/src/themeHelpers/processColors.js +10 -7
- package/dist/umd/221.js +0 -37
- package/dist/umd/511.js +0 -573
- package/dist/umd/9.js +0 -312
- /package/dist/umd/{221.js.LICENSE.txt → 101.js.LICENSE.txt} +0 -0
@@ -1,35 +1,105 @@
|
|
1
|
-
import {
|
1
|
+
import {
|
2
|
+
getComponentName,
|
3
|
+
createStyleMixin,
|
4
|
+
draggableMixin,
|
5
|
+
createProxy,
|
6
|
+
inputMixin,
|
7
|
+
compose,
|
8
|
+
componentNameValidationMixin
|
9
|
+
} from '../../componentsHelpers';
|
10
|
+
import { matchHostStyle } from '../../componentsHelpers/createStyleMixin/helpers';
|
2
11
|
|
3
|
-
export const componentName = getComponentName(
|
12
|
+
export const componentName = getComponentName('text-field');
|
13
|
+
|
14
|
+
const selectors = {
|
15
|
+
label: '::part(label)',
|
16
|
+
input: '::part(input-field)',
|
17
|
+
readOnlyInput: '[readonly]::part(input-field)::after',
|
18
|
+
placeholder: '> input:placeholder-shown'
|
19
|
+
};
|
20
|
+
|
21
|
+
let overrides = ``;
|
22
|
+
|
23
|
+
export const textFieldMappings = {
|
24
|
+
color: { selector: selectors.input },
|
25
|
+
backgroundColor: { selector: selectors.input },
|
26
|
+
width: [matchHostStyle()],
|
27
|
+
color: { selector: selectors.input },
|
28
|
+
borderColor: [
|
29
|
+
{ selector: selectors.input },
|
30
|
+
{ selector: selectors.readOnlyInput }
|
31
|
+
],
|
32
|
+
borderWidth: [
|
33
|
+
{ selector: selectors.input },
|
34
|
+
{ selector: selectors.readOnlyInput }
|
35
|
+
],
|
36
|
+
borderStyle: [
|
37
|
+
{ selector: selectors.input },
|
38
|
+
{ selector: selectors.readOnlyInput }
|
39
|
+
],
|
40
|
+
borderRadius: { selector: selectors.input },
|
41
|
+
boxShadow: { selector: selectors.input },
|
42
|
+
fontSize: {},
|
43
|
+
height: { selector: selectors.input },
|
44
|
+
padding: { selector: selectors.input },
|
45
|
+
outline: { selector: selectors.input },
|
46
|
+
outlineOffset: { selector: selectors.input },
|
47
|
+
|
48
|
+
placeholderColor: { selector: selectors.placeholder, property: 'color' }
|
49
|
+
};
|
4
50
|
|
5
51
|
const TextField = compose(
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
'borderStyle': { selector: '::part(input-field)' },
|
13
|
-
'borderRadius': { selector: '::part(input-field)' },
|
14
|
-
'boxShadow': { selector: '::part(input-field)' },
|
15
|
-
'height': { selector: '::part(input-field)' },
|
16
|
-
'padding': { selector: '::part(input-field)' },
|
17
|
-
'backgroundColor': { selector: '::part(input-field)' },
|
18
|
-
'labelColor': { selector: '::part(label)', property: 'color' },
|
19
|
-
},
|
20
|
-
}),
|
21
|
-
draggableMixin,
|
22
|
-
inputMixin,
|
23
|
-
componentNameValidationMixin
|
52
|
+
createStyleMixin({
|
53
|
+
mappings: textFieldMappings
|
54
|
+
}),
|
55
|
+
draggableMixin,
|
56
|
+
inputMixin,
|
57
|
+
componentNameValidationMixin
|
24
58
|
)(
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
59
|
+
createProxy({
|
60
|
+
slots: ['prefix', 'suffix'],
|
61
|
+
wrappedEleName: 'vaadin-text-field',
|
62
|
+
style: () => overrides,
|
63
|
+
excludeAttrsSync: ['tabindex'],
|
64
|
+
componentName
|
65
|
+
})
|
32
66
|
);
|
33
67
|
|
68
|
+
overrides = `
|
69
|
+
vaadin-text-field {
|
70
|
+
margin: 0;
|
71
|
+
padding: 0;
|
72
|
+
}
|
73
|
+
vaadin-text-field::part(input-field) {
|
74
|
+
overflow: hidden;
|
75
|
+
}
|
76
|
+
vaadin-text-field[readonly] > input:placeholder-shown {
|
77
|
+
opacity: 1;
|
78
|
+
}
|
79
|
+
vaadin-text-field input:-webkit-autofill,
|
80
|
+
vaadin-text-field input:-webkit-autofill::first-line,
|
81
|
+
vaadin-text-field input:-webkit-autofill:hover,
|
82
|
+
vaadin-text-field input:-webkit-autofill:active,
|
83
|
+
vaadin-text-field input:-webkit-autofill:focus {
|
84
|
+
-webkit-text-fill-color: var(${TextField.cssVarList.color});
|
85
|
+
box-shadow: 0 0 0 var(${TextField.cssVarList.height}) var(${TextField.cssVarList.backgroundColor}) inset;
|
86
|
+
}
|
87
|
+
vaadin-text-field > label,
|
88
|
+
vaadin-text-field::part(input-field) {
|
89
|
+
cursor: pointer;
|
90
|
+
color: var(${TextField.cssVarList.color});
|
91
|
+
}
|
92
|
+
vaadin-text-field::part(input-field):focus {
|
93
|
+
cursor: text;
|
94
|
+
}
|
95
|
+
vaadin-text-field[required]::part(required-indicator)::after {
|
96
|
+
font-size: "12px";
|
97
|
+
content: "*";
|
98
|
+
color: var(${TextField.cssVarList.color});
|
99
|
+
}
|
100
|
+
vaadin-text-field[readonly]::part(input-field)::after {
|
101
|
+
border: 0 solid;
|
102
|
+
}
|
103
|
+
`;
|
34
104
|
|
35
|
-
export default TextField
|
105
|
+
export default TextField;
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import
|
2
|
-
import TextField, { componentName } from
|
1
|
+
import '@vaadin/text-field';
|
2
|
+
import TextField, { componentName } from './TextField';
|
3
3
|
|
4
4
|
customElements.define(componentName, TextField);
|
5
5
|
|
6
|
-
export { TextField }
|
6
|
+
export { TextField };
|
@@ -1,21 +1,25 @@
|
|
1
1
|
export const componentNameValidationMixin = (superclass) =>
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
class DraggableMixinClass extends superclass {
|
3
|
+
#checkComponentName() {
|
4
|
+
const currentComponentName = this.shadowRoot.host.tagName.toLowerCase();
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
if (!superclass.componentName) {
|
7
|
+
throw Error(
|
8
|
+
`component name is not defined on super class, make sure you have a static get for "componentName"`
|
9
|
+
);
|
10
|
+
}
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
if (currentComponentName !== superclass.componentName) {
|
13
|
+
throw Error(
|
14
|
+
`component name mismatch, expected "${superclass.componentName}", current "${currentComponentName}"`
|
15
|
+
);
|
16
|
+
}
|
17
|
+
}
|
14
18
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
connectedCallback() {
|
20
|
+
super.connectedCallback?.();
|
21
|
+
if (this.shadowRoot.isConnected) {
|
22
|
+
this.#checkComponentName();
|
23
|
+
}
|
24
|
+
}
|
25
|
+
};
|
@@ -1,33 +1,37 @@
|
|
1
|
-
|
2
1
|
const observeAttributes = (ele, callback, excludeAttrs) => {
|
3
|
-
|
4
|
-
|
2
|
+
// sync all attrs on init
|
3
|
+
callback(...Array.from(ele.attributes).map((attr) => attr.name));
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
const observer = new MutationObserver((mutationsList) => {
|
6
|
+
for (const mutation of mutationsList) {
|
7
|
+
if (
|
8
|
+
mutation.type === 'attributes' &&
|
9
|
+
!excludeAttrs.includes(mutation.attributeName)
|
10
|
+
) {
|
11
|
+
callback(mutation.attributeName);
|
12
|
+
}
|
13
|
+
}
|
14
|
+
});
|
13
15
|
|
14
|
-
|
15
|
-
}
|
16
|
+
observer.observe(ele, { attributes: true });
|
17
|
+
};
|
16
18
|
|
17
|
-
const createSyncAttrsCb =
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
}
|
19
|
+
const createSyncAttrsCb =
|
20
|
+
(srcEle, targetEle) =>
|
21
|
+
(...attrNames) => {
|
22
|
+
attrNames.forEach((attrName) => {
|
23
|
+
const srcAttrVal = srcEle.getAttribute(attrName);
|
24
|
+
if (srcAttrVal !== null) {
|
25
|
+
if (targetEle.getAttribute(attrName) !== srcAttrVal) {
|
26
|
+
targetEle.setAttribute(attrName, srcAttrVal);
|
27
|
+
}
|
28
|
+
} else {
|
29
|
+
targetEle.removeAttribute(attrName);
|
30
|
+
}
|
31
|
+
});
|
32
|
+
};
|
29
33
|
|
30
34
|
export const syncAttrs = (ele1, ele2, excludeAttrs) => {
|
31
|
-
|
32
|
-
|
33
|
-
}
|
35
|
+
observeAttributes(ele1, createSyncAttrsCb(ele1, ele2), excludeAttrs);
|
36
|
+
observeAttributes(ele2, createSyncAttrsCb(ele2, ele1), excludeAttrs);
|
37
|
+
};
|
@@ -1,12 +1,17 @@
|
|
1
|
-
import { syncAttrs } from
|
2
|
-
|
3
|
-
export const createProxy = ({ componentName, wrappedEleName, slots = [], style, excludeAttrsSync = [] }) => {
|
1
|
+
import { syncAttrs } from './helpers';
|
4
2
|
|
3
|
+
export const createProxy = ({
|
4
|
+
componentName,
|
5
|
+
wrappedEleName,
|
6
|
+
slots = [],
|
7
|
+
style,
|
8
|
+
excludeAttrsSync = []
|
9
|
+
}) => {
|
5
10
|
const template = `
|
6
|
-
|
11
|
+
<style id="create-proxy"></style>
|
7
12
|
<${wrappedEleName}>
|
8
13
|
<slot></slot>
|
9
|
-
${slots.map((slot) => `<slot name="${slot}" slot="${slot}"></slot>`).join(
|
14
|
+
${slots.map((slot) => `<slot name="${slot}" slot="${slot}"></slot>`).join('')}
|
10
15
|
</${wrappedEleName}>
|
11
16
|
`;
|
12
17
|
|
@@ -16,21 +21,23 @@ export const createProxy = ({ componentName, wrappedEleName, slots = [], style,
|
|
16
21
|
}
|
17
22
|
|
18
23
|
constructor() {
|
19
|
-
super().attachShadow({ mode:
|
24
|
+
super().attachShadow({ mode: 'open' }).innerHTML = template;
|
20
25
|
this.hostElement = this.shadowRoot.host;
|
21
|
-
this.componentName = this.hostElement.tagName.toLowerCase()
|
22
|
-
this.baseSelector = wrappedEleName
|
26
|
+
this.componentName = this.hostElement.tagName.toLowerCase();
|
27
|
+
this.baseSelector = wrappedEleName;
|
28
|
+
this.shadowRoot.getElementById('create-proxy').innerHTML =
|
29
|
+
typeof style === 'function' ? style() : style;
|
23
30
|
}
|
24
31
|
|
25
32
|
connectedCallback() {
|
26
33
|
if (this.shadowRoot.isConnected) {
|
27
34
|
this.proxyElement = this.shadowRoot.querySelector(wrappedEleName);
|
28
35
|
this.setAttribute('tabindex', '0');
|
29
|
-
|
36
|
+
|
30
37
|
// we want to focus on the proxy element when focusing our WC
|
31
38
|
this.onfocus = (e) => {
|
32
|
-
this.proxyElement.focus()
|
33
|
-
}
|
39
|
+
this.proxyElement.focus();
|
40
|
+
};
|
34
41
|
|
35
42
|
// `onkeydown` is set on `proxyElement` support proper tab-index navigation
|
36
43
|
// this support is needed since both proxy host and element catch `focus`/`blur` event
|
@@ -40,15 +47,18 @@ export const createProxy = ({ componentName, wrappedEleName, slots = [], style,
|
|
40
47
|
this.removeAttribute('tabindex');
|
41
48
|
// We want to defer the action of setting the tab index back
|
42
49
|
// so it will happen after focusing the previous element
|
43
|
-
setTimeout(() => this.setAttribute('tabindex', '0'), 0)
|
50
|
+
setTimeout(() => this.setAttribute('tabindex', '0'), 0);
|
44
51
|
}
|
45
|
-
}
|
52
|
+
};
|
46
53
|
|
47
54
|
this.mouseoverCbRef = () => {
|
48
55
|
this.proxyElement.setAttribute('hover', '');
|
49
|
-
this.proxyElement.addEventListener(
|
50
|
-
|
51
|
-
|
56
|
+
this.proxyElement.addEventListener(
|
57
|
+
'mouseleave',
|
58
|
+
() => this.proxyElement.removeAttribute('hover'),
|
59
|
+
{ once: true }
|
60
|
+
);
|
61
|
+
};
|
52
62
|
|
53
63
|
this.proxyElement.addEventListener('mouseover', this.mouseoverCbRef);
|
54
64
|
|
@@ -60,7 +70,7 @@ export const createProxy = ({ componentName, wrappedEleName, slots = [], style,
|
|
60
70
|
}
|
61
71
|
|
62
72
|
disconnectedCallback() {
|
63
|
-
this.proxyElement.removeEventListener('mouseover', this.mouseoverCbRef)
|
73
|
+
this.proxyElement.removeEventListener('mouseover', this.mouseoverCbRef);
|
64
74
|
}
|
65
75
|
|
66
76
|
attributeChangedCallback() {
|
@@ -1,68 +1,86 @@
|
|
1
|
-
import { getCssVarName, kebabCase } from
|
1
|
+
import { getCssVarName, kebabCase } from '../../helpers';
|
2
2
|
|
3
|
-
const createCssVarFallback = (first, ...rest) =>
|
3
|
+
const createCssVarFallback = (first, ...rest) =>
|
4
|
+
`var(${first}${rest.length ? ` , ${createCssVarFallback(...rest)}` : ''})`;
|
4
5
|
|
5
|
-
const createCssSelector = (
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
const createCssSelector = (
|
7
|
+
baseSelector = '',
|
8
|
+
relativeSelectorOrSelectorFn = ''
|
9
|
+
) =>
|
10
|
+
typeof relativeSelectorOrSelectorFn === 'function'
|
11
|
+
? relativeSelectorOrSelectorFn(baseSelector)
|
12
|
+
: `${baseSelector}${relativeSelectorOrSelectorFn}`;
|
9
13
|
|
10
14
|
class StyleBuilder {
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
15
|
+
constructor() {
|
16
|
+
this.styleMap = new Map();
|
17
|
+
}
|
18
|
+
|
19
|
+
add(selector, property, value) {
|
20
|
+
if (!this.styleMap.has(selector)) {
|
21
|
+
this.styleMap.set(selector, []);
|
22
|
+
}
|
23
|
+
|
24
|
+
this.styleMap.set(selector, [
|
25
|
+
...this.styleMap.get(selector),
|
26
|
+
{ property, value }
|
27
|
+
]);
|
28
|
+
}
|
29
|
+
|
30
|
+
toString() {
|
31
|
+
return Array.from(this.styleMap.entries()).reduce(
|
32
|
+
(style, [selector, propValArr]) =>
|
33
|
+
(style += `${selector} { \n${propValArr
|
34
|
+
.map(({ property, value }) => `${property}: ${value}`)
|
35
|
+
.join(';\n')} \n}\n\n`),
|
36
|
+
''
|
37
|
+
);
|
38
|
+
}
|
28
39
|
}
|
29
40
|
|
30
41
|
const normalizeConfig = (attr, config) => {
|
31
|
-
|
42
|
+
const defaultMapping = { selector: '', property: kebabCase(attr) };
|
32
43
|
|
33
|
-
|
44
|
+
if (!config || !Object.keys(config).length) return [defaultMapping];
|
34
45
|
|
35
|
-
|
46
|
+
if (Array.isArray(config))
|
47
|
+
return config.map((entry) => Object.assign({}, defaultMapping, entry));
|
36
48
|
|
37
|
-
|
38
|
-
}
|
49
|
+
return [Object.assign({}, defaultMapping, config)];
|
50
|
+
};
|
39
51
|
|
40
52
|
export const createStyle = (componentName, baseSelector, mappings) => {
|
41
|
-
|
53
|
+
const style = new StyleBuilder();
|
42
54
|
|
43
|
-
|
44
|
-
|
55
|
+
Object.keys(mappings).forEach((attr) => {
|
56
|
+
const attrConfig = normalizeConfig(attr, mappings[attr]);
|
45
57
|
|
46
|
-
|
58
|
+
const cssVarName = getCssVarName(componentName, attr);
|
47
59
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
60
|
+
attrConfig.forEach(
|
61
|
+
({ selector: relativeSelectorOrSelectorFn, property }) => {
|
62
|
+
style.add(
|
63
|
+
createCssSelector(baseSelector, relativeSelectorOrSelectorFn),
|
64
|
+
property,
|
65
|
+
createCssVarFallback(cssVarName)
|
66
|
+
);
|
67
|
+
}
|
68
|
+
);
|
69
|
+
});
|
56
70
|
|
57
|
-
|
58
|
-
}
|
71
|
+
return style.toString();
|
72
|
+
};
|
59
73
|
|
60
74
|
export const createCssVarsList = (componentName, mappings) =>
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
75
|
+
Object.keys(mappings).reduce(
|
76
|
+
(acc, attr) =>
|
77
|
+
Object.assign(acc, { [attr]: getCssVarName(componentName, attr) }),
|
78
|
+
{}
|
79
|
+
);
|
65
80
|
|
66
81
|
// match the host selector with the inner element selector
|
67
82
|
// e.g. when we want to set the same size for the host & the inner element this can be useful
|
68
|
-
export const matchHostStyle = (mappingObj) => [
|
83
|
+
export const matchHostStyle = (mappingObj) => [
|
84
|
+
mappingObj,
|
85
|
+
{ ...mappingObj, selector: () => `:host${mappingObj.selector || ''}` }
|
86
|
+
];
|
@@ -1,58 +1,67 @@
|
|
1
1
|
import { getCssVarName, kebabCaseJoin } from '../../helpers';
|
2
2
|
import { createStyle, createCssVarsList } from './helpers';
|
3
3
|
|
4
|
-
export const createStyleMixin =
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
4
|
+
export const createStyleMixin =
|
5
|
+
({ mappings = {} }) =>
|
6
|
+
(superclass) => {
|
7
|
+
const styleAttributes = Object.keys(mappings).map((key) =>
|
8
|
+
kebabCaseJoin('st', key)
|
9
|
+
);
|
10
|
+
return class CustomStyleMixinClass extends superclass {
|
11
|
+
static get observedAttributes() {
|
12
|
+
const superAttrs = superclass.observedAttributes || [];
|
13
|
+
return [...superAttrs, ...styleAttributes];
|
14
|
+
}
|
15
|
+
|
16
|
+
static get cssVarList() {
|
17
|
+
return createCssVarsList(superclass.componentName, mappings);
|
18
|
+
}
|
19
|
+
|
20
|
+
#styleEle = null;
|
21
|
+
|
22
|
+
constructor() {
|
23
|
+
super();
|
24
|
+
|
25
|
+
this.#createComponentStyle();
|
26
|
+
this.#createAttrOverrideStyle();
|
27
|
+
}
|
28
|
+
|
29
|
+
#createAttrOverrideStyle() {
|
30
|
+
this.#styleEle = document.createElement('style');
|
31
|
+
this.#styleEle.id = 'style-mixin-overrides';
|
32
|
+
|
33
|
+
this.#styleEle.innerText = '* {}';
|
34
|
+
this.shadowRoot.prepend(this.#styleEle);
|
35
|
+
}
|
36
|
+
|
37
|
+
#updateAttrOverrideStyle(attrName, value) {
|
38
|
+
const style = this.#styleEle.sheet.cssRules[0].style;
|
39
|
+
const varName = getCssVarName(
|
40
|
+
superclass.componentName,
|
41
|
+
attrName.replace(/^st-/, '')
|
42
|
+
);
|
43
|
+
|
44
|
+
if (value) style.setProperty(varName, value);
|
45
|
+
else style.removeProperty(varName);
|
46
|
+
}
|
47
|
+
|
48
|
+
#createComponentStyle() {
|
49
|
+
const themeStyle = document.createElement('style');
|
50
|
+
themeStyle.id = 'style-mixin-component';
|
51
|
+
themeStyle.innerHTML = createStyle(
|
52
|
+
superclass.componentName,
|
53
|
+
this.baseSelector,
|
54
|
+
mappings
|
55
|
+
);
|
56
|
+
this.shadowRoot.prepend(themeStyle);
|
57
|
+
}
|
58
|
+
|
59
|
+
attributeChangedCallback(attrName, oldValue, newValue) {
|
60
|
+
super.attributeChangedCallback?.(attrName, oldValue, newValue);
|
61
|
+
|
62
|
+
if (styleAttributes.includes(attrName)) {
|
63
|
+
this.#updateAttrOverrideStyle(attrName, newValue);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
};
|
67
|
+
};
|
@@ -1,32 +1,31 @@
|
|
1
1
|
export const draggableMixin = (superclass) =>
|
2
|
-
|
2
|
+
class DraggableMixinClass extends superclass {
|
3
|
+
#styleEle = null;
|
3
4
|
|
4
|
-
|
5
|
+
static get observedAttributes() {
|
6
|
+
const superAttrs = superclass.observedAttributes || [];
|
7
|
+
return [...superAttrs, 'draggable'];
|
8
|
+
}
|
5
9
|
|
6
|
-
|
7
|
-
|
8
|
-
return [...superAttrs, 'draggable']
|
9
|
-
}
|
10
|
+
constructor() {
|
11
|
+
super();
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
+
this.#styleEle = document.createElement('style');
|
14
|
+
this.#styleEle.innerText = `${this.baseSelector} { cursor: inherit }`;
|
15
|
+
}
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
#handleDraggableStyle(isDraggable) {
|
18
|
+
if (isDraggable) {
|
19
|
+
this.shadowRoot.appendChild(this.#styleEle);
|
20
|
+
} else {
|
21
|
+
this.#styleEle.remove();
|
22
|
+
}
|
23
|
+
}
|
17
24
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
attributeChangedCallback(attrName, oldValue, newValue) {
|
27
|
-
super.attributeChangedCallback?.(attrName, oldValue, newValue);
|
28
|
-
if (attrName === 'draggable') {
|
29
|
-
this.#handleDraggableStyle(newValue === 'true')
|
30
|
-
}
|
31
|
-
}
|
32
|
-
}
|
25
|
+
attributeChangedCallback(attrName, oldValue, newValue) {
|
26
|
+
super.attributeChangedCallback?.(attrName, oldValue, newValue);
|
27
|
+
if (attrName === 'draggable') {
|
28
|
+
this.#handleDraggableStyle(newValue === 'true');
|
29
|
+
}
|
30
|
+
}
|
31
|
+
};
|