@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.
Files changed (100) hide show
  1. package/dist/cjs/index.cjs.js +35 -18
  2. package/dist/cjs/index.cjs.js.map +1 -1
  3. package/dist/index.esm.js +1128 -481
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/umd/101.js +148 -0
  6. package/dist/umd/208.js +2 -0
  7. package/dist/umd/208.js.LICENSE.txt +5 -0
  8. package/dist/umd/211.js +312 -0
  9. package/dist/umd/211.js.LICENSE.txt +5 -0
  10. package/dist/umd/233.js +573 -0
  11. package/dist/umd/{511.js.LICENSE.txt → 233.js.LICENSE.txt} +0 -6
  12. package/dist/umd/422.js +2 -0
  13. package/dist/umd/422.js.LICENSE.txt +5 -0
  14. package/dist/umd/437.js +19 -0
  15. package/dist/umd/437.js.LICENSE.txt +5 -0
  16. package/dist/umd/513.js +1 -0
  17. package/dist/umd/515.js +202 -0
  18. package/dist/umd/515.js.LICENSE.txt +11 -0
  19. package/dist/umd/54.js +4 -4
  20. package/dist/umd/56.js +48 -0
  21. package/dist/umd/56.js.LICENSE.txt +5 -0
  22. package/dist/umd/599.js +1 -1
  23. package/dist/umd/63.js +1 -0
  24. package/dist/umd/725.js +37 -0
  25. package/dist/umd/725.js.LICENSE.txt +11 -0
  26. package/dist/umd/729.js +1 -1
  27. package/dist/umd/767.js +2 -0
  28. package/dist/umd/{9.js.LICENSE.txt → 767.js.LICENSE.txt} +0 -6
  29. package/dist/umd/786.js +2 -0
  30. package/dist/umd/786.js.LICENSE.txt +17 -0
  31. package/dist/umd/789.js +1 -0
  32. package/dist/umd/806.js +109 -0
  33. package/dist/umd/806.js.LICENSE.txt +5 -0
  34. package/dist/umd/938.js +1 -0
  35. package/dist/umd/97.js +1 -1
  36. package/dist/umd/descope-button-index-js.js +1 -1
  37. package/dist/umd/descope-checkbox-index-js.js +1 -0
  38. package/dist/umd/descope-combo-index-js.js +1 -1
  39. package/dist/umd/descope-container-index-js.js +1 -1
  40. package/dist/umd/descope-email-field-index-js.js +1 -0
  41. package/dist/umd/descope-number-field-index-js.js +1 -0
  42. package/dist/umd/descope-password-field-index-js.js +1 -0
  43. package/dist/umd/descope-switch-toggle-index-js.js +1 -0
  44. package/dist/umd/descope-text-area-index-js.js +1 -0
  45. package/dist/umd/descope-text-field-index-js.js +1 -1
  46. package/dist/umd/index.js +1 -1
  47. package/package.json +9 -2
  48. package/src/components/descope-button/Button.js +90 -30
  49. package/src/components/descope-button/index.js +3 -3
  50. package/src/components/descope-checkbox/Checkbox.js +33 -0
  51. package/src/components/descope-checkbox/index.js +6 -0
  52. package/src/components/descope-combo/index.js +12 -12
  53. package/src/components/descope-container/Container.js +57 -51
  54. package/src/components/descope-container/index.js +1 -1
  55. package/src/components/descope-date-picker/index.js +13 -7
  56. package/src/components/descope-email-field/EmailField.js +72 -0
  57. package/src/components/descope-email-field/index.js +6 -0
  58. package/src/components/descope-number-field/NumberField.js +72 -0
  59. package/src/components/descope-number-field/index.js +6 -0
  60. package/src/components/descope-password-field/PasswordField.js +79 -0
  61. package/src/components/descope-password-field/index.js +6 -0
  62. package/src/components/descope-switch-toggle/SwitchToggle.js +81 -0
  63. package/src/components/descope-switch-toggle/index.js +6 -0
  64. package/src/components/descope-text-area/TextArea.js +66 -0
  65. package/src/components/descope-text-area/index.js +6 -0
  66. package/src/components/descope-text-field/TextField.js +98 -28
  67. package/src/components/descope-text-field/index.js +3 -3
  68. package/src/componentsHelpers/componentNameValidationMixin.js +21 -17
  69. package/src/componentsHelpers/createProxy/helpers.js +31 -27
  70. package/src/componentsHelpers/createProxy/index.js +27 -17
  71. package/src/componentsHelpers/createStyleMixin/helpers.js +65 -47
  72. package/src/componentsHelpers/createStyleMixin/index.js +64 -55
  73. package/src/componentsHelpers/draggableMixin.js +25 -26
  74. package/src/componentsHelpers/index.js +12 -9
  75. package/src/componentsHelpers/inputMixin.js +38 -37
  76. package/src/constants.js +1 -1
  77. package/src/dev/index.js +4 -3
  78. package/src/helpers.js +8 -6
  79. package/src/index.cjs.js +1 -1
  80. package/src/index.js +16 -8
  81. package/src/index.umd.js +11 -5
  82. package/src/theme/components/button.js +32 -21
  83. package/src/theme/components/checkbox.js +9 -0
  84. package/src/theme/components/container.js +32 -27
  85. package/src/theme/components/emailField.js +8 -0
  86. package/src/theme/components/index.js +19 -7
  87. package/src/theme/components/input.js +106 -0
  88. package/src/theme/components/numberField.js +8 -0
  89. package/src/theme/components/passwordField.js +11 -0
  90. package/src/theme/components/switchToggle.js +10 -0
  91. package/src/theme/components/textArea.js +44 -0
  92. package/src/theme/components/textField.js +69 -45
  93. package/src/theme/globals.js +27 -26
  94. package/src/theme/index.js +2 -2
  95. package/src/themeHelpers/index.js +45 -30
  96. package/src/themeHelpers/processColors.js +10 -7
  97. package/dist/umd/221.js +0 -37
  98. package/dist/umd/511.js +0 -573
  99. package/dist/umd/9.js +0 -312
  100. /package/dist/umd/{221.js.LICENSE.txt → 101.js.LICENSE.txt} +0 -0
@@ -1,35 +1,105 @@
1
- import { getComponentName, createStyleMixin, draggableMixin, createProxy, inputMixin, compose, componentNameValidationMixin } from "../../componentsHelpers";
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("text-field")
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
- createStyleMixin({
7
- mappings: {
8
- 'placeholderColor': { selector: '> input:placeholder-shown', property: 'color' },
9
- 'color': {},
10
- 'borderColor': { selector: '::part(input-field)' },
11
- 'borderWidth': { selector: '::part(input-field)' },
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
- createProxy({
26
- slots: ["prefix", "suffix"],
27
- wrappedEleName: "vaadin-text-field",
28
- style: ``,
29
- excludeAttrsSync: ['tabindex'],
30
- componentName
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 "@vaadin/text-field";
2
- import TextField, { componentName } from "./TextField";
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
- class DraggableMixinClass extends superclass {
3
- #checkComponentName() {
4
- const currentComponentName = this.shadowRoot.host.tagName.toLowerCase();
2
+ class DraggableMixinClass extends superclass {
3
+ #checkComponentName() {
4
+ const currentComponentName = this.shadowRoot.host.tagName.toLowerCase();
5
5
 
6
- if (!superclass.componentName) {
7
- throw Error(`component name is not defined on super class, make sure you have a static get for "componentName"`)
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
- if (currentComponentName !== superclass.componentName) {
11
- throw Error(`component name mismatch, expected "${superclass.componentName}", current "${currentComponentName}"`)
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
- connectedCallback() {
16
- super.connectedCallback?.();
17
- if (this.shadowRoot.isConnected) {
18
- this.#checkComponentName()
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
- // sync all attrs on init
4
- callback(...Array.from(ele.attributes).map(attr => attr.name));
2
+ // sync all attrs on init
3
+ callback(...Array.from(ele.attributes).map((attr) => attr.name));
5
4
 
6
- const observer = new MutationObserver((mutationsList) => {
7
- for (const mutation of mutationsList) {
8
- if (mutation.type === "attributes" && !excludeAttrs.includes(mutation.attributeName)) {
9
- callback(mutation.attributeName);
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
- observer.observe(ele, { attributes: true });
15
- }
16
+ observer.observe(ele, { attributes: true });
17
+ };
16
18
 
17
- const createSyncAttrsCb = (srcEle, targetEle) => (...attrNames) => {
18
- attrNames.forEach(attrName => {
19
- const srcAttrVal = srcEle.getAttribute(attrName);
20
- if (srcAttrVal !== null) {
21
- if (targetEle.getAttribute(attrName) !== srcAttrVal) {
22
- targetEle.setAttribute(attrName, srcAttrVal);
23
- }
24
- } else {
25
- targetEle.removeAttribute(attrName);
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
- observeAttributes(ele1, createSyncAttrsCb(ele1, ele2), excludeAttrs)
32
- observeAttributes(ele2, createSyncAttrsCb(ele2, ele1), excludeAttrs)
33
- }
35
+ observeAttributes(ele1, createSyncAttrsCb(ele1, ele2), excludeAttrs);
36
+ observeAttributes(ele2, createSyncAttrsCb(ele2, ele1), excludeAttrs);
37
+ };
@@ -1,12 +1,17 @@
1
- import { syncAttrs } from "./helpers";
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
- ${style ? `<style id="create-proxy">${style}</style>` : ''}
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: "open" }).innerHTML = template;
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('mouseleave', () =>
50
- this.proxyElement.removeAttribute('hover'), { once: true })
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 "../../helpers"
1
+ import { getCssVarName, kebabCase } from '../../helpers';
2
2
 
3
- const createCssVarFallback = (first, ...rest) => `var(${first}${rest.length ? ` , ${createCssVarFallback(...rest)}` : ''})`;
3
+ const createCssVarFallback = (first, ...rest) =>
4
+ `var(${first}${rest.length ? ` , ${createCssVarFallback(...rest)}` : ''})`;
4
5
 
5
- const createCssSelector = (baseSelector = '', relativeSelectorOrSelectorFn = '') =>
6
- typeof relativeSelectorOrSelectorFn === 'function' ?
7
- relativeSelectorOrSelectorFn(baseSelector) :
8
- `${baseSelector}${relativeSelectorOrSelectorFn}`;
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
- constructor() {
12
- this.styleMap = new Map()
13
- }
14
-
15
- add(selector, property, value) {
16
- if (!this.styleMap.has(selector)) {
17
- this.styleMap.set(selector, [])
18
- }
19
-
20
- this.styleMap.set(selector, [...this.styleMap.get(selector), { property, value }])
21
- }
22
-
23
- toString() {
24
- return Array.from(this.styleMap.entries()).reduce((style, [selector, propValArr]) =>
25
- style += `${selector} { \n${propValArr.map(({ property, value }) => `${property}: ${value}`).join(';\n')} \n}\n\n`
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
- const defaultMapping = { selector: '', property: kebabCase(attr) }
42
+ const defaultMapping = { selector: '', property: kebabCase(attr) };
32
43
 
33
- if (!config || !Object.keys(config).length) return [defaultMapping];
44
+ if (!config || !Object.keys(config).length) return [defaultMapping];
34
45
 
35
- if (Array.isArray(config)) return config.map(entry => Object.assign({}, defaultMapping, entry));
46
+ if (Array.isArray(config))
47
+ return config.map((entry) => Object.assign({}, defaultMapping, entry));
36
48
 
37
- return [Object.assign({}, defaultMapping, config)];
38
- }
49
+ return [Object.assign({}, defaultMapping, config)];
50
+ };
39
51
 
40
52
  export const createStyle = (componentName, baseSelector, mappings) => {
41
- const style = new StyleBuilder();
53
+ const style = new StyleBuilder();
42
54
 
43
- Object.keys(mappings).forEach((attr) => {
44
- const attrConfig = normalizeConfig(attr, mappings[attr])
55
+ Object.keys(mappings).forEach((attr) => {
56
+ const attrConfig = normalizeConfig(attr, mappings[attr]);
45
57
 
46
- const cssVarName = getCssVarName(componentName, attr)
58
+ const cssVarName = getCssVarName(componentName, attr);
47
59
 
48
- attrConfig.forEach(({ selector: relativeSelectorOrSelectorFn, property }) => {
49
- style.add(
50
- createCssSelector(baseSelector, relativeSelectorOrSelectorFn),
51
- property,
52
- createCssVarFallback(cssVarName)
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
- return style.toString();
58
- }
71
+ return style.toString();
72
+ };
59
73
 
60
74
  export const createCssVarsList = (componentName, mappings) =>
61
- Object.keys(mappings).reduce(
62
- (acc, attr) => Object.assign(acc, { [attr]: getCssVarName(componentName, attr) }),
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) => [mappingObj, {...mappingObj, selector: () => `:host${mappingObj.selector || ''}`}];
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 = ({ mappings = {} }) => (superclass) => {
5
- const styleAttributes = Object.keys(mappings).map(key => kebabCaseJoin('st', key))
6
- return class CustomStyleMixinClass extends superclass {
7
- static get observedAttributes() {
8
- const superAttrs = superclass.observedAttributes || []
9
- return [...superAttrs, ...styleAttributes]
10
- }
11
-
12
- static get cssVarList() {
13
- return createCssVarsList(superclass.componentName, mappings)
14
- }
15
-
16
- #styleEle = null;
17
-
18
- constructor() {
19
- super();
20
-
21
- this.#createComponentStyle()
22
- this.#createAttrOverrideStyle()
23
- }
24
-
25
- #createAttrOverrideStyle() {
26
- this.#styleEle = document.createElement('style');
27
- this.#styleEle.id = 'style-mixin-overrides'
28
-
29
- this.#styleEle.innerText = '* {}'
30
- this.shadowRoot.prepend(this.#styleEle);
31
- }
32
-
33
- #updateAttrOverrideStyle(attrName, value) {
34
- const style = this.#styleEle.sheet.cssRules[0].style;
35
- const varName = getCssVarName(superclass.componentName, attrName.replace(/^st-/, ''))
36
-
37
- if (value)
38
- style.setProperty(varName, value)
39
- else
40
- style.removeProperty(varName)
41
- }
42
-
43
- #createComponentStyle() {
44
- const themeStyle = document.createElement('style');
45
- themeStyle.id = 'style-mixin-component'
46
- themeStyle.innerHTML = createStyle(superclass.componentName, this.baseSelector, mappings)
47
- this.shadowRoot.prepend(themeStyle);
48
- }
49
-
50
- attributeChangedCallback(attrName, oldValue, newValue) {
51
- super.attributeChangedCallback?.(attrName, oldValue, newValue);
52
-
53
- if (styleAttributes.includes(attrName)) {
54
- this.#updateAttrOverrideStyle(attrName, newValue)
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
- class DraggableMixinClass extends superclass {
2
+ class DraggableMixinClass extends superclass {
3
+ #styleEle = null;
3
4
 
4
- #styleEle = null;
5
+ static get observedAttributes() {
6
+ const superAttrs = superclass.observedAttributes || [];
7
+ return [...superAttrs, 'draggable'];
8
+ }
5
9
 
6
- static get observedAttributes() {
7
- const superAttrs = superclass.observedAttributes || []
8
- return [...superAttrs, 'draggable']
9
- }
10
+ constructor() {
11
+ super();
10
12
 
11
- constructor() {
12
- super();
13
+ this.#styleEle = document.createElement('style');
14
+ this.#styleEle.innerText = `${this.baseSelector} { cursor: inherit }`;
15
+ }
13
16
 
14
- this.#styleEle = document.createElement('style');
15
- this.#styleEle.innerText = `${this.baseSelector} { cursor: inherit }`;
16
- }
17
+ #handleDraggableStyle(isDraggable) {
18
+ if (isDraggable) {
19
+ this.shadowRoot.appendChild(this.#styleEle);
20
+ } else {
21
+ this.#styleEle.remove();
22
+ }
23
+ }
17
24
 
18
- #handleDraggableStyle(isDraggable) {
19
- if (isDraggable) {
20
- this.shadowRoot.appendChild(this.#styleEle)
21
- } else {
22
- this.#styleEle.remove();
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
+ };