@descope/web-components-ui 1.0.135 → 1.0.148

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. package/package.json +77 -56
  2. package/src/baseClasses/createBaseClass.js +18 -16
  3. package/src/baseClasses/createBaseInputClass.js +14 -8
  4. package/src/baseClasses/createCssVarImageClass.js +27 -23
  5. package/src/components/boolean-fields/booleanFieldMixin.js +18 -29
  6. package/src/components/boolean-fields/commonStyles.js +1 -1
  7. package/src/components/boolean-fields/descope-boolean-field-internal/BooleanFieldInternal.js +46 -51
  8. package/src/components/boolean-fields/descope-boolean-field-internal/index.js +1 -1
  9. package/src/components/boolean-fields/descope-checkbox/CheckboxClass.js +80 -85
  10. package/src/components/boolean-fields/descope-checkbox/index.js +2 -2
  11. package/src/components/boolean-fields/descope-switch-toggle/SwitchToggleClass.js +88 -95
  12. package/src/components/boolean-fields/descope-switch-toggle/index.js +2 -2
  13. package/src/components/descope-button/ButtonClass.js +57 -47
  14. package/src/components/descope-button/clickableMixin.js +10 -0
  15. package/src/components/descope-combo-box/ComboBoxClass.js +156 -160
  16. package/src/components/descope-container/ContainerClass.js +32 -42
  17. package/src/components/descope-date-picker/index.js +9 -14
  18. package/src/components/descope-divider/DividerClass.js +52 -62
  19. package/src/components/descope-email-field/EmailFieldClass.js +25 -20
  20. package/src/components/descope-image/ImageClass.js +21 -24
  21. package/src/components/descope-link/LinkClass.js +31 -35
  22. package/src/components/descope-loader-linear/LoaderLinearClass.js +31 -36
  23. package/src/components/descope-loader-radial/LoaderRadialClass.js +23 -30
  24. package/src/components/descope-logo/LogoClass.js +5 -1
  25. package/src/components/descope-new-password/NewPasswordClass.js +63 -81
  26. package/src/components/descope-new-password/descope-new-password-internal/NewPasswordInternal.js +157 -162
  27. package/src/components/descope-new-password/descope-new-password-internal/componentName.js +1 -1
  28. package/src/components/descope-new-password/descope-new-password-internal/index.js +3 -3
  29. package/src/components/descope-new-password/index.js +3 -3
  30. package/src/components/descope-number-field/NumberFieldClass.js +25 -20
  31. package/src/components/descope-passcode/PasscodeClass.js +95 -95
  32. package/src/components/descope-passcode/descope-passcode-internal/PasscodeInternal.js +151 -157
  33. package/src/components/descope-passcode/descope-passcode-internal/helpers.js +7 -8
  34. package/src/components/descope-passcode/descope-passcode-internal/index.js +2 -2
  35. package/src/components/descope-passcode/index.js +2 -2
  36. package/src/components/descope-password/PasswordClass.js +75 -83
  37. package/src/components/descope-password/passwordDraggableMixin.js +28 -27
  38. package/src/components/descope-phone-field/CountryCodes.js +1210 -1210
  39. package/src/components/descope-phone-field/PhoneFieldClass.js +139 -141
  40. package/src/components/descope-phone-field/descope-phone-field-internal/PhoneFieldInternal.js +157 -173
  41. package/src/components/descope-phone-field/helpers.js +3 -3
  42. package/src/components/descope-text/TextClass.js +25 -29
  43. package/src/components/descope-text-area/TextAreaClass.js +68 -67
  44. package/src/components/descope-text-field/TextFieldClass.js +42 -37
  45. package/src/components/descope-text-field/textFieldMappings.js +40 -55
  46. package/src/components/descope-totp-image/TotpImageClass.js +5 -1
  47. package/src/components/descope-upload-file/UploadFileClass.js +202 -0
  48. package/src/components/descope-upload-file/helpers.js +11 -0
  49. package/src/components/descope-upload-file/index.js +6 -0
  50. package/src/constants.js +3 -3
  51. package/src/helpers/componentHelpers.js +68 -74
  52. package/src/helpers/index.js +17 -16
  53. package/src/helpers/mixinsHelpers.js +21 -10
  54. package/src/helpers/themeHelpers/colorsHelpers.js +18 -18
  55. package/src/helpers/themeHelpers/componentsThemeManager.js +7 -6
  56. package/src/helpers/themeHelpers/index.js +114 -124
  57. package/src/helpers/themeHelpers/resetHelpers.js +16 -16
  58. package/src/index.cjs.js +3 -3
  59. package/src/index.d.ts +22 -21
  60. package/src/index.js +5 -4
  61. package/src/index.umd.js +14 -13
  62. package/src/mixins/changeMixin.js +18 -17
  63. package/src/mixins/componentNameValidationMixin.js +19 -19
  64. package/src/mixins/createProxy.js +33 -33
  65. package/src/mixins/createStyleMixin/helpers.js +54 -64
  66. package/src/mixins/createStyleMixin/index.js +155 -141
  67. package/src/mixins/draggableMixin.js +61 -61
  68. package/src/mixins/hoverableMixin.js +11 -13
  69. package/src/mixins/index.js +6 -6
  70. package/src/mixins/inputEventsDispatchingMixin.js +61 -60
  71. package/src/mixins/inputValidationMixin.js +153 -148
  72. package/src/mixins/lifecycleEventsMixin.js +17 -15
  73. package/src/mixins/normalizeBooleanAttributesMixin.js +31 -23
  74. package/src/mixins/portalMixin.js +58 -52
  75. package/src/mixins/proxyInputMixin.js +138 -132
  76. package/src/theme/components/button.js +86 -81
  77. package/src/theme/components/checkbox.js +26 -28
  78. package/src/theme/components/comboBox.js +32 -31
  79. package/src/theme/components/container.js +99 -89
  80. package/src/theme/components/divider.js +30 -31
  81. package/src/theme/components/emailField.js +20 -19
  82. package/src/theme/components/image.js +3 -3
  83. package/src/theme/components/index.js +33 -25
  84. package/src/theme/components/inputWrapper.js +28 -25
  85. package/src/theme/components/link.js +29 -36
  86. package/src/theme/components/loader/index.js +3 -3
  87. package/src/theme/components/loader/loaderLinear.js +34 -34
  88. package/src/theme/components/loader/loaderRadial.js +40 -34
  89. package/src/theme/components/logo.js +4 -4
  90. package/src/theme/components/newPassword.js +14 -13
  91. package/src/theme/components/numberField.js +20 -19
  92. package/src/theme/components/passcode.js +20 -22
  93. package/src/theme/components/password.js +22 -21
  94. package/src/theme/components/phoneField.js +23 -23
  95. package/src/theme/components/switchToggle.js +47 -46
  96. package/src/theme/components/text.js +72 -72
  97. package/src/theme/components/textArea.js +27 -25
  98. package/src/theme/components/textField.js +23 -22
  99. package/src/theme/components/totpImage.js +4 -4
  100. package/src/theme/components/uploadFile.js +60 -0
  101. package/src/theme/globals.js +123 -124
  102. package/src/theme/index.js +1 -1
  103. package/dist/cjs/index.cjs.js +0 -5924
  104. package/dist/cjs/index.cjs.js.map +0 -1
  105. package/dist/cjs/package.json +0 -1
  106. package/dist/index.d.ts +0 -51
  107. package/dist/index.esm.js +0 -6606
  108. package/dist/index.esm.js.map +0 -1
  109. package/dist/umd/1018.js +0 -577
  110. package/dist/umd/1018.js.LICENSE.txt +0 -23
  111. package/dist/umd/2481.js +0 -1
  112. package/dist/umd/3208.js +0 -2
  113. package/dist/umd/3208.js.LICENSE.txt +0 -5
  114. package/dist/umd/3585.js +0 -1
  115. package/dist/umd/3878.js +0 -1
  116. package/dist/umd/4201.js +0 -1
  117. package/dist/umd/422.js +0 -2
  118. package/dist/umd/422.js.LICENSE.txt +0 -5
  119. package/dist/umd/4447.js +0 -1
  120. package/dist/umd/4513.js +0 -1
  121. package/dist/umd/4803.js +0 -1
  122. package/dist/umd/541.js +0 -744
  123. package/dist/umd/541.js.LICENSE.txt +0 -21
  124. package/dist/umd/5767.js +0 -2
  125. package/dist/umd/5767.js.LICENSE.txt +0 -15
  126. package/dist/umd/5806.js +0 -109
  127. package/dist/umd/5806.js.LICENSE.txt +0 -5
  128. package/dist/umd/7056.js +0 -48
  129. package/dist/umd/7056.js.LICENSE.txt +0 -5
  130. package/dist/umd/7101.js +0 -148
  131. package/dist/umd/7101.js.LICENSE.txt +0 -11
  132. package/dist/umd/729.js +0 -1
  133. package/dist/umd/7824.js +0 -229
  134. package/dist/umd/7824.js.LICENSE.txt +0 -27
  135. package/dist/umd/7840.js +0 -356
  136. package/dist/umd/7840.js.LICENSE.txt +0 -61
  137. package/dist/umd/8725.js +0 -37
  138. package/dist/umd/8725.js.LICENSE.txt +0 -11
  139. package/dist/umd/9211.js +0 -312
  140. package/dist/umd/9211.js.LICENSE.txt +0 -5
  141. package/dist/umd/9241.js +0 -1
  142. package/dist/umd/9314.js +0 -283
  143. package/dist/umd/9314.js.LICENSE.txt +0 -27
  144. package/dist/umd/9437.js +0 -19
  145. package/dist/umd/9437.js.LICENSE.txt +0 -5
  146. package/dist/umd/9515.js +0 -202
  147. package/dist/umd/9515.js.LICENSE.txt +0 -11
  148. package/dist/umd/9789.js +0 -1
  149. package/dist/umd/boolean-fields-descope-boolean-field-internal-index-js.js +0 -1
  150. package/dist/umd/boolean-fields-descope-checkbox-index-js.js +0 -1
  151. package/dist/umd/boolean-fields-descope-switch-toggle-index-js.js +0 -1
  152. package/dist/umd/descope-button-index-js.js +0 -1
  153. package/dist/umd/descope-combo-box-index-js.js +0 -1
  154. package/dist/umd/descope-container-index-js.js +0 -1
  155. package/dist/umd/descope-date-picker-index-js.js +0 -1
  156. package/dist/umd/descope-divider-index-js.js +0 -1
  157. package/dist/umd/descope-email-field-index-js.js +0 -1
  158. package/dist/umd/descope-image-index-js.js +0 -1
  159. package/dist/umd/descope-link-index-js.js +0 -1
  160. package/dist/umd/descope-loader-linear-index-js.js +0 -1
  161. package/dist/umd/descope-loader-radial-index-js.js +0 -1
  162. package/dist/umd/descope-logo-index-js.js +0 -1
  163. package/dist/umd/descope-new-password-descope-new-password-internal-index-js.js +0 -1
  164. package/dist/umd/descope-new-password-index-js.js +0 -1
  165. package/dist/umd/descope-number-field-index-js.js +0 -1
  166. package/dist/umd/descope-passcode-descope-passcode-internal-index-js.js +0 -1
  167. package/dist/umd/descope-passcode-index-js.js +0 -1
  168. package/dist/umd/descope-password-index-js.js +0 -1
  169. package/dist/umd/descope-phone-field-descope-phone-field-internal-index-js.js +0 -1
  170. package/dist/umd/descope-phone-field-index-js.js +0 -1
  171. package/dist/umd/descope-text-area-index-js.js +0 -1
  172. package/dist/umd/descope-text-field-index-js.js +0 -1
  173. package/dist/umd/descope-text-index-js.js +0 -1
  174. package/dist/umd/descope-totp-image-index-js.js +0 -1
  175. package/dist/umd/index.js +0 -1
@@ -1,61 +1,66 @@
1
1
  import {
2
- createStyleMixin,
3
- draggableMixin,
4
- createProxy,
5
- proxyInputMixin,
6
- componentNameValidationMixin
2
+ createStyleMixin,
3
+ draggableMixin,
4
+ createProxy,
5
+ proxyInputMixin,
6
+ componentNameValidationMixin,
7
7
  } from '../../mixins';
8
8
  import textFieldMappings from './textFieldMappings';
9
9
  import { compose } from '../../helpers';
10
10
  import { getComponentName } from '../../helpers/componentHelpers';
11
- import { resetInputOverrides, useHostExternalPadding } from '../../helpers/themeHelpers/resetHelpers';
11
+ import {
12
+ resetInputOverrides,
13
+ useHostExternalPadding,
14
+ } from '../../helpers/themeHelpers/resetHelpers';
12
15
 
13
16
  export const componentName = getComponentName('text-field');
14
17
 
15
18
  const observedAttrs = ['type'];
16
19
 
17
20
  const customMixin = (superclass) =>
18
- class TextFieldClass extends superclass {
19
- static get observedAttributes() {
20
- return observedAttrs.concat(superclass.observedAttributes || []);
21
- }
21
+ class TextFieldClass extends superclass {
22
+ static get observedAttributes() {
23
+ return observedAttrs.concat(superclass.observedAttributes || []);
24
+ }
22
25
 
23
- attributeChangedCallback(attrName, oldVal, newVal) {
24
- super.attributeChangeCallback?.(attrName, oldVal, newVal);
26
+ attributeChangedCallback(attrName, oldVal, newVal) {
27
+ super.attributeChangeCallback?.(attrName, oldVal, newVal);
25
28
 
26
- // Vaadin doesn't allow to change the input type attribute.
27
- // We need the ability to do that, so we're overriding their
28
- // behavior with their private API.
29
- // When receiving a `type` attribute, we use their private API
30
- // to set it on the input.
31
- if (attrName === 'type') {
32
- this.baseElement._setType(newVal);
33
- }
34
- }
35
- }
29
+ // Vaadin doesn't allow to change the input type attribute.
30
+ // We need the ability to do that, so we're overriding their
31
+ // behavior with their private API.
32
+ // When receiving a `type` attribute, we use their private API
33
+ // to set it on the input.
34
+ if (attrName === 'type') {
35
+ this.baseElement._setType(newVal);
36
+ }
37
+ }
38
+ };
36
39
 
37
40
  export const TextFieldClass = compose(
38
- createStyleMixin({
39
- mappings: textFieldMappings
40
- }),
41
- draggableMixin,
42
- proxyInputMixin,
43
- componentNameValidationMixin,
44
- customMixin
41
+ createStyleMixin({
42
+ mappings: textFieldMappings,
43
+ }),
44
+ draggableMixin,
45
+ proxyInputMixin,
46
+ componentNameValidationMixin,
47
+ customMixin
45
48
  )(
46
- createProxy({
47
- slots: ['prefix', 'suffix'],
48
- wrappedEleName: 'vaadin-text-field',
49
- style: () => `
49
+ createProxy({
50
+ slots: ['prefix', 'suffix'],
51
+ wrappedEleName: 'vaadin-text-field',
52
+ style: () => `
50
53
  :host {
51
54
  display: inline-block;
52
55
  max-width: 100%;
53
- padding: calc(var(${TextFieldClass.cssVarList.inputOutlineWidth}) + var(${TextFieldClass.cssVarList.inputOutlineOffset}));
56
+ padding: calc(var(${TextFieldClass.cssVarList.inputOutlineWidth}) + var(${
57
+ TextFieldClass.cssVarList.inputOutlineOffset
58
+ }));
54
59
  }
55
60
  ${useHostExternalPadding(TextFieldClass.cssVarList)}
56
61
  ${resetInputOverrides('vaadin-text-field', TextFieldClass.cssVarList)}
57
62
  `,
58
- excludeAttrsSync: ['tabindex'],
59
- componentName
60
- })
63
+ excludeAttrsSync: ['tabindex'],
64
+ componentName,
65
+ })
61
66
  );
@@ -1,68 +1,53 @@
1
- const {
2
- host,
3
- label,
4
- placeholder,
5
- requiredIndicator,
6
- inputField,
7
- input,
8
- helperText,
9
- errorMessage
10
- } = {
11
- host: { selector: () => ':host' },
12
- label: { selector: '::part(label)' },
13
- requiredIndicator: { selector: '[required]::part(required-indicator)::after' },
14
- placeholder: { selector: '> input:placeholder-shown' },
15
- inputField: { selector: '::part(input-field)' },
16
- input: { selector: 'input' },
17
- helperText: { selector: '::part(helper-text)' },
18
- errorMessage: { selector: '::part(error-message)' }
19
- };
1
+ const { host, label, placeholder, requiredIndicator, inputField, input, helperText, errorMessage } =
2
+ {
3
+ host: { selector: () => ':host' },
4
+ label: { selector: '::part(label)' },
5
+ requiredIndicator: { selector: '[required]::part(required-indicator)::after' },
6
+ placeholder: { selector: '> input:placeholder-shown' },
7
+ inputField: { selector: '::part(input-field)' },
8
+ input: { selector: 'input' },
9
+ helperText: { selector: '::part(helper-text)' },
10
+ errorMessage: { selector: '::part(error-message)' },
11
+ };
20
12
 
21
13
  export default {
22
- // we apply font-size also on the host so we can set its width with em
23
- fontSize: [
24
- {},
25
- host,
26
- ],
27
- fontFamily: [
28
- label,
29
- inputField,
30
- helperText,
31
- errorMessage,
32
- ],
14
+ // we apply font-size also on the host so we can set its width with em
15
+ fontSize: [{}, host],
16
+ fontFamily: [label, inputField, helperText, errorMessage],
33
17
 
34
- hostWidth: { ...host, property: 'width' },
35
- hostMinWidth: { ...host, property: 'min-width' },
18
+ hostWidth: { ...host, property: 'width' },
19
+ hostMinWidth: { ...host, property: 'min-width' },
36
20
 
37
- inputBackgroundColor: { ...inputField, property: 'background-color' },
21
+ inputBackgroundColor: { ...inputField, property: 'background-color' },
38
22
 
39
- labelTextColor: [
40
- { ...label, property: 'color' },
41
- { ...requiredIndicator, property: 'color' }
42
- ],
23
+ labelTextColor: [
24
+ { ...label, property: 'color' },
25
+ { ...requiredIndicator, property: 'color' },
26
+ ],
27
+ errorMessageTextColor: { ...errorMessage, property: 'color' },
43
28
 
44
- inputValueTextColor: { ...inputField, property: 'color' },
45
- inputCaretTextColor: { ...input, property: 'color' },
29
+ inputValueTextColor: { ...inputField, property: 'color' },
30
+ inputCaretTextColor: { ...input, property: 'color' },
46
31
 
47
- labelRequiredIndicator: { ...requiredIndicator, property: 'content' },
32
+ labelRequiredIndicator: { ...requiredIndicator, property: 'content' },
48
33
 
49
- inputBorderColor: { ...inputField, property: 'border-color' },
50
- inputBorderWidth: { ...inputField, property: 'border-width' },
51
- inputBorderStyle: { ...inputField, property: 'border-style' },
52
- inputBorderRadius: { ...inputField, property: 'border-radius' },
34
+ inputBorderColor: { ...inputField, property: 'border-color' },
35
+ inputBorderWidth: { ...inputField, property: 'border-width' },
36
+ inputBorderStyle: { ...inputField, property: 'border-style' },
37
+ inputBorderRadius: { ...inputField, property: 'border-radius' },
53
38
 
54
- inputHeight: { ...inputField, property: 'height' },
55
- inputHorizontalPadding: [
56
- { ...input, property: 'padding-left' },
57
- { ...input, property: 'padding-right' }
58
- ],
39
+ inputHeight: { ...inputField, property: 'height' },
40
+ inputHorizontalPadding: [
41
+ { ...input, property: 'padding-left' },
42
+ { ...input, property: 'padding-right' },
43
+ ],
59
44
 
60
- inputOutlineColor: { ...inputField, property: 'outline-color' },
61
- inputOutlineStyle: { ...inputField, property: 'outline-style' },
62
- inputOutlineWidth: { ...inputField, property: 'outline-width' },
63
- inputOutlineOffset: { ...inputField, property: 'outline-offset' },
45
+ inputOutlineColor: { ...inputField, property: 'outline-color' },
46
+ inputOutlineStyle: { ...inputField, property: 'outline-style' },
47
+ inputOutlineWidth: { ...inputField, property: 'outline-width' },
48
+ inputOutlineOffset: { ...inputField, property: 'outline-offset' },
64
49
 
65
- inputTextAlign: { ...input, property: 'text-align' },
50
+ inputTextAlign: { ...input, property: 'text-align' },
66
51
 
67
- inputPlaceholderColor: { ...placeholder, property: 'color' }
52
+ inputPlaceholderColor: { ...placeholder, property: 'color' },
68
53
  };
@@ -3,4 +3,8 @@ import { createCssVarImageClass } from '../../baseClasses/createCssVarImageClass
3
3
 
4
4
  export const componentName = getComponentName('totp-image');
5
5
 
6
- export const TotpImageClass = createCssVarImageClass({ componentName, varName: 'url', fallbackVarName: 'fallbackUrl' })
6
+ export const TotpImageClass = createCssVarImageClass({
7
+ componentName,
8
+ varName: 'url',
9
+ fallbackVarName: 'fallbackUrl',
10
+ });
@@ -0,0 +1,202 @@
1
+ import { createStyleMixin, draggableMixin, componentNameValidationMixin } from '../../mixins';
2
+ import { compose } from '../../helpers';
3
+ import { getComponentName } from '../../helpers/componentHelpers';
4
+ import { createBaseInputClass } from '../../baseClasses/createBaseInputClass';
5
+ import { getFileBase64, getFilename } from './helpers';
6
+
7
+ export const componentName = getComponentName('upload-file');
8
+
9
+ const observedAttributes = [
10
+ 'title',
11
+ 'description',
12
+ 'button-label',
13
+ 'accept',
14
+ 'button-mode',
15
+ 'button-variant',
16
+ 'required',
17
+ 'size',
18
+ ];
19
+
20
+ const BaseInputClass = createBaseInputClass({ componentName, baseSelector: ':host > div.wrapper' });
21
+
22
+ class RawUploadFile extends BaseInputClass {
23
+ static get observedAttributes() {
24
+ return observedAttributes.concat(BaseInputClass.observedAttributes || []);
25
+ }
26
+
27
+ constructor() {
28
+ super();
29
+
30
+ this.attachShadow({ mode: 'open' }).innerHTML = `
31
+ <style>
32
+ .wrapper {
33
+ display: flex;
34
+ align-items: center;
35
+ justify-content: center;
36
+ text-align: center;
37
+ flex-direction: column;
38
+ }
39
+ .button-wrapper {
40
+ position: relative;
41
+ width: fit-content;
42
+ }
43
+ input {
44
+ position: absolute;
45
+ width: 100%;
46
+ height: 100%;
47
+ opacity: 0;
48
+ }
49
+ </style>
50
+ <div class="wrapper">
51
+ <div class="icon"></div>
52
+ <div class="title">
53
+ <span class="title-text"></span>
54
+ <span class="required-indicator"></span>
55
+ </div>
56
+ <div class="description"></div>
57
+ <div class="button-wrapper">
58
+ <input type="file" tabindex="-1" />
59
+ <descope-button></descope-button>
60
+ </div>
61
+ </div>
62
+ `;
63
+
64
+ this.wrapperEle = this.shadowRoot.querySelector('.wrapper');
65
+ this.inputElement = this.shadowRoot.querySelector('input');
66
+
67
+ this.button.onclick = () => this.inputElement.click();
68
+
69
+ this.inputElement.onchange = async (e) => {
70
+ const receivedFileList = e.target.files;
71
+
72
+ if (!receivedFileList.length) {
73
+ return;
74
+ }
75
+
76
+ this.value = await getFileBase64(receivedFileList[0]);
77
+
78
+ this.updateDescription(getFilename(receivedFileList[0]));
79
+ };
80
+
81
+ this.oninvalid = () => {
82
+ this.setAttribute('invalid', 'true');
83
+ };
84
+ }
85
+
86
+ getValidity() {
87
+ if (this.isRequired && !this.value) {
88
+ return { valueMissing: true };
89
+ }
90
+ return {};
91
+ }
92
+
93
+ initInputs() {
94
+ const button = this.rootElement.querySelector('descope-button');
95
+ button.onclick = () => this.inputElement.click();
96
+ }
97
+
98
+ attributeChangedCallback(attrName, oldValue, newValue) {
99
+ super.attributeChangedCallback?.(attrName, oldValue, newValue);
100
+
101
+ if (oldValue !== newValue) {
102
+ if (attrName === 'title') {
103
+ this.updateTitle(newValue);
104
+ } else if (attrName === 'description') {
105
+ this.updateDescription(newValue);
106
+ } else if (attrName === 'button-label') {
107
+ this.updateButtonLabel(newValue);
108
+ } else if (attrName === 'button-mode') {
109
+ this.updateButtonMode(newValue);
110
+ } else if (attrName === 'button-variant') {
111
+ this.updateButtonVariant(newValue);
112
+ } else if (attrName === 'size') {
113
+ this.updateButtonSize(newValue);
114
+ } else if (attrName === 'accept') {
115
+ this.updateInputAccept(newValue);
116
+ }
117
+ }
118
+ }
119
+
120
+ get button() {
121
+ return this.shadowRoot.querySelector('descope-button');
122
+ }
123
+
124
+ get input() {
125
+ return this.shadowRoot.querySelector('input');
126
+ }
127
+
128
+ get title() {
129
+ return this.shadowRoot.querySelector('.title-text');
130
+ }
131
+
132
+ get description() {
133
+ return this.shadowRoot.querySelector('.description');
134
+ }
135
+
136
+ updateTitle(val) {
137
+ this.title.innerHTML = val;
138
+ }
139
+
140
+ updateDescription(val) {
141
+ this.description.innerHTML = val;
142
+ }
143
+
144
+ updateButtonLabel(val) {
145
+ this.button.innerHTML = val;
146
+ }
147
+
148
+ updateButtonSize(val) {
149
+ this.button.setAttribute('size', val);
150
+ }
151
+
152
+ updateButtonMode(val) {
153
+ this.button.setAttribute('mode', val);
154
+ }
155
+
156
+ updateButtonVariant(val) {
157
+ this.button.setAttribute('variant', val);
158
+ }
159
+
160
+ updateInputAccept(val) {
161
+ this.input.setAttribute('accept', val);
162
+ }
163
+ }
164
+
165
+ const { host, icon, title, description, requiredIndicator } = {
166
+ host: { selector: () => '.wrapper' },
167
+ icon: { selector: () => '.icon' },
168
+ title: { selector: () => '.title' },
169
+ description: { selector: () => '.description' },
170
+ requiredIndicator: { selector: () => '.title::after' },
171
+ };
172
+
173
+ export const UploadFileClass = compose(
174
+ createStyleMixin({ componentNameOverride: getComponentName('input-wrapper') }),
175
+ createStyleMixin({
176
+ mappings: {
177
+ fontSize: {},
178
+ fontFamily: {},
179
+ hostWidth: { ...host, property: 'width' },
180
+ hostHeight: { ...host, property: 'height' },
181
+ hostPadding: { ...host, property: 'padding' },
182
+ gap: { ...host },
183
+ lineHeight: { ...host, property: 'line-height' },
184
+ borderColor: { ...host, property: 'border-color' },
185
+ borderWidth: { ...host, property: 'border-width' },
186
+ borderStyle: { ...host, property: 'border-style' },
187
+ borderRadius: { ...host, property: 'border-radius' },
188
+ titleFontSize: { ...title, property: 'font-size' },
189
+ titleFontWeight: { ...title, property: 'font-weight' },
190
+ descriptionFontSize: { ...description, property: 'font-size' },
191
+ labelTextColor: [
192
+ { ...title, property: 'color' },
193
+ { ...description, property: 'color' },
194
+ ],
195
+ icon: { ...icon, property: 'content' },
196
+ iconSize: { ...icon, property: 'width' },
197
+ requiredIndicator: { ...requiredIndicator, property: 'content' },
198
+ },
199
+ }),
200
+ draggableMixin,
201
+ componentNameValidationMixin
202
+ )(RawUploadFile);
@@ -0,0 +1,11 @@
1
+ export const getFileBase64 = (fileObj) => {
2
+ return new Promise((resolve) => {
3
+ const reader = new FileReader();
4
+ reader.onload = (e) => resolve(e.target.result);
5
+ reader.readAsDataURL(fileObj);
6
+ });
7
+ };
8
+
9
+ export const getFilename = (fileObj) => {
10
+ return fileObj.name.replace(/^.*\\/, '');
11
+ };
@@ -0,0 +1,6 @@
1
+ import { componentName, UploadFileClass } from './UploadFileClass';
2
+ import '../descope-button';
3
+
4
+ customElements.define(componentName, UploadFileClass);
5
+
6
+ export { UploadFileClass };
package/src/constants.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export const DESCOPE_PREFIX = 'descope';
2
- export const CSS_SELECTOR_SPECIFIER_MULTIPLY = 3
3
- export const BASE_THEME_SECTION = 'host'
4
- export const PORTAL_THEME_PREFIX = '@'
2
+ export const CSS_SELECTOR_SPECIFIER_MULTIPLY = 3;
3
+ export const BASE_THEME_SECTION = 'host';
4
+ export const PORTAL_THEME_PREFIX = '@';
@@ -1,101 +1,95 @@
1
1
  import { kebabCaseJoin } from '.';
2
2
  import { DESCOPE_PREFIX } from '../constants';
3
3
 
4
- export const observeAttributes = (
5
- ele,
6
- callback,
7
- { excludeAttrs = [], includeAttrs = [] }
8
- ) => {
9
- // sync all attrs on init
10
- const filteredAttrs = Array.from(ele.attributes)
11
- .filter((attr) =>
12
- !excludeAttrs.includes(attr.name) &&
13
- (!includeAttrs.length || includeAttrs.includes(attr.name))
14
- )
15
- .map((attr) => attr.name)
4
+ export const observeAttributes = (ele, callback, { excludeAttrs = [], includeAttrs = [] }) => {
5
+ // sync all attrs on init
6
+ const filteredAttrs = Array.from(ele.attributes)
7
+ .filter(
8
+ (attr) =>
9
+ !excludeAttrs.includes(attr.name) &&
10
+ (!includeAttrs.length || includeAttrs.includes(attr.name))
11
+ )
12
+ .map((attr) => attr.name);
16
13
 
17
- callback(filteredAttrs);
14
+ callback(filteredAttrs);
18
15
 
19
- const observer = new MutationObserver((mutationsList) => {
20
- for (const mutation of mutationsList) {
21
- if (
22
- mutation.type === 'attributes' &&
23
- !excludeAttrs.includes(mutation.attributeName) &&
24
- (!includeAttrs.length || includeAttrs.includes(mutation.attributeName))
25
- ) {
26
- callback([mutation.attributeName]);
27
- }
28
- }
29
- });
16
+ const observer = new MutationObserver((mutationsList) => {
17
+ mutationsList.forEach((mutation) => {
18
+ if (
19
+ mutation.type === 'attributes' &&
20
+ !excludeAttrs.includes(mutation.attributeName) &&
21
+ (!includeAttrs.length || includeAttrs.includes(mutation.attributeName))
22
+ ) {
23
+ callback([mutation.attributeName]);
24
+ }
25
+ });
26
+ });
30
27
 
31
- observer.observe(ele, { attributes: true });
28
+ observer.observe(ele, { attributes: true });
32
29
  };
33
30
 
34
31
  // calling the callback with this object: { addedNodes, removedNodes }
35
- export const observeChildren = (
36
- ele,
37
- callback,
38
- ) => {
39
- callback({ addedNodes: Array.from(ele.children), removedNodes: [] });
32
+ export const observeChildren = (ele, callback) => {
33
+ callback({ addedNodes: Array.from(ele.children), removedNodes: [] });
40
34
 
41
- const observer = new MutationObserver((mutationsList) => {
42
- for (const mutation of mutationsList) {
43
- if (mutation.type === 'childList') {
44
- callback(mutation);
45
- }
46
- }
47
- });
35
+ const observer = new MutationObserver((mutationsList) => {
36
+ mutationsList.forEach((mutation) => {
37
+ if (mutation.type === 'childList') {
38
+ callback(mutation);
39
+ }
40
+ });
41
+ });
48
42
 
49
- observer.observe(ele, { childList: true });
43
+ observer.observe(ele, { childList: true });
50
44
  };
51
45
 
52
46
  const createSyncAttrsCb =
53
- (srcEle, targetEle, mapAttrs = {}) =>
54
- (attrNames) => {
55
- attrNames.forEach((attrName) => {
56
- const targetAttrName = mapAttrs[attrName] || attrName;
57
- const srcAttrVal = srcEle.getAttribute(attrName);
58
- if (srcAttrVal !== null) {
59
- if (targetEle.getAttribute(targetAttrName) !== srcAttrVal) {
60
- targetEle.setAttribute(targetAttrName, srcAttrVal);
61
- }
62
- } else {
63
- targetEle.removeAttribute(targetAttrName);
64
- }
65
- });
66
- };
47
+ (srcEle, targetEle, mapAttrs = {}) =>
48
+ (attrNames) => {
49
+ attrNames.forEach((attrName) => {
50
+ const targetAttrName = mapAttrs[attrName] || attrName;
51
+ const srcAttrVal = srcEle.getAttribute(attrName);
52
+ if (srcAttrVal !== null) {
53
+ if (targetEle.getAttribute(targetAttrName) !== srcAttrVal) {
54
+ targetEle.setAttribute(targetAttrName, srcAttrVal);
55
+ }
56
+ } else {
57
+ targetEle.removeAttribute(targetAttrName);
58
+ }
59
+ });
60
+ };
67
61
 
68
62
  export const syncAttrs = (ele1, ele2, options) => {
69
- observeAttributes(ele1, createSyncAttrsCb(ele1, ele2), options);
70
- observeAttributes(ele2, createSyncAttrsCb(ele2, ele1), options);
63
+ observeAttributes(ele1, createSyncAttrsCb(ele1, ele2), options);
64
+ observeAttributes(ele2, createSyncAttrsCb(ele2, ele1), options);
71
65
  };
72
66
 
73
67
  export const getComponentName = (name) => kebabCaseJoin(DESCOPE_PREFIX, name);
74
68
 
75
- export const getCssVarName = (...args) =>
76
- `--${kebabCaseJoin(...args)}`;
69
+ export const getCssVarName = (...args) => `--${kebabCaseJoin(...args)}`;
77
70
 
78
71
  export const forwardAttrs = (source, dest, options = {}) => {
79
- observeAttributes(
80
- source,
81
- createSyncAttrsCb(source, dest, options.mapAttrs),
82
- options
83
- );
72
+ observeAttributes(source, createSyncAttrsCb(source, dest, options.mapAttrs), options);
84
73
  };
85
74
 
86
75
  export const forwardProps = (src, target, props = []) => {
87
- if (!props.length) return;
76
+ if (!props.length) return;
88
77
 
89
- const config = props.reduce((acc, prop) => Object.assign(acc, {
90
- [prop]: {
91
- get() {
92
- return src[prop]
93
- },
94
- set(v) {
95
- src[prop] = v
96
- }
97
- }
98
- }), {})
78
+ const config = props.reduce(
79
+ (acc, prop) =>
80
+ Object.assign(acc, {
81
+ [prop]: {
82
+ get() {
83
+ return src[prop];
84
+ },
85
+ set(v) {
86
+ // eslint-disable-next-line no-param-reassign
87
+ src[prop] = v;
88
+ },
89
+ },
90
+ }),
91
+ {}
92
+ );
99
93
 
100
- Object.defineProperties(target, config)
101
- }
94
+ Object.defineProperties(target, config);
95
+ };
@@ -1,26 +1,27 @@
1
-
2
1
  export const kebabCase = (str) =>
3
- str
4
- .replace(/([a-z])([A-Z])/g, '$1-$2')
5
- .replace(/[\s_.]+/g, '-')
6
- .toLowerCase();
2
+ str
3
+ .replace(/([a-z])([A-Z])/g, '$1-$2')
4
+ .replace(/[\s_.]+/g, '-')
5
+ .toLowerCase();
7
6
 
8
7
  export const kebabCaseJoin = (...args) => kebabCase(args.filter((arg) => !!arg).join('-'));
9
8
 
10
- export const compose = (...fns) =>
11
- (val) =>
12
- fns.reduceRight((res, fn) => fn(res), val);
9
+ export const compose =
10
+ (...fns) =>
11
+ (val) =>
12
+ fns.reduceRight((res, fn) => fn(res), val);
13
13
 
14
- export const upperFirst = (str) => str.charAt(0).toUpperCase() + str.slice(1)
14
+ export const upperFirst = (str) => str.charAt(0).toUpperCase() + str.slice(1);
15
15
 
16
16
  export const isFunction = (maybeFunc) => typeof maybeFunc === 'function';
17
17
 
18
18
  export const isUrl = (maybeUrl) => {
19
- try {
20
- new URL(maybeUrl)
19
+ try {
20
+ // eslint-disable-next-line no-new
21
+ new URL(maybeUrl);
21
22
 
22
- return true;
23
- } catch (e) {
24
- return false;
25
- }
26
- }
23
+ return true;
24
+ } catch (e) {
25
+ return false;
26
+ }
27
+ };