@descope/web-components-ui 1.0.58 → 1.0.60

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/index.esm.js CHANGED
@@ -342,12 +342,29 @@ const forwardAttrs = (source, dest, options = {}) => {
342
342
  );
343
343
  };
344
344
 
345
+ const forwardProps = (src, target, props = []) => {
346
+ if(!props.length) return;
347
+
348
+ const config = props.reduce((acc, prop) => Object.assign(acc, {[prop] : {
349
+ get () {
350
+ return target[prop]
351
+ },
352
+ set (v) {
353
+ target[prop] = v;
354
+ }
355
+ }}), {});
356
+
357
+ Object.defineProperties(src, config);
358
+ };
359
+
345
360
  const createProxy = ({
346
361
  componentName,
347
362
  wrappedEleName,
348
363
  slots = [],
349
364
  style,
350
- excludeAttrsSync = []
365
+ excludeAttrsSync = [],
366
+ includeAttrsSync = [],
367
+ includeForwardProps = []
351
368
  }) => {
352
369
  const template = `
353
370
  <style id="create-proxy"></style>
@@ -373,6 +390,10 @@ const createProxy = ({
373
390
  connectedCallback() {
374
391
  if (this.shadowRoot.isConnected) {
375
392
  this.proxyElement = this.shadowRoot.querySelector(wrappedEleName);
393
+
394
+ // this is needed for components that uses props, such as combo box
395
+ forwardProps(this.hostElement, this.proxyElement, includeForwardProps);
396
+
376
397
  this.setAttribute('tabindex', '0');
377
398
 
378
399
  // we want to focus on the proxy element when focusing our WC
@@ -397,7 +418,8 @@ const createProxy = ({
397
418
  this.proxyElement.addEventListener(...args);
398
419
 
399
420
  syncAttrs(this.proxyElement, this.hostElement, {
400
- excludeAttrs: excludeAttrsSync
421
+ excludeAttrs: excludeAttrsSync,
422
+ includeAttrs: includeAttrsSync
401
423
  });
402
424
  }
403
425
  }
@@ -1475,7 +1497,9 @@ class PasscodeInternal extends HTMLElement {
1475
1497
  return [
1476
1498
  'disabled',
1477
1499
  'bordered',
1478
- 'size'
1500
+ 'size',
1501
+ 'required',
1502
+ 'pattern'
1479
1503
  ];
1480
1504
  }
1481
1505
 
@@ -1669,9 +1693,15 @@ class PasscodeInternal extends HTMLElement {
1669
1693
  oldValue,
1670
1694
  newValue
1671
1695
  ) {
1672
- if (oldValue !== newValue &&
1673
- PasscodeInternal.observedAttributes.includes(attrName)) {
1674
- this.inputs.forEach((input) => input.setAttribute(attrName, newValue));
1696
+ const validationRelatedAttributes = ['required', 'pattern'];
1697
+
1698
+ if (oldValue !== newValue) {
1699
+ if (validationRelatedAttributes.includes(attrName)) {
1700
+ this.setValidity();
1701
+ }
1702
+ else if (PasscodeInternal.observedAttributes.includes(attrName)) {
1703
+ this.inputs.forEach((input) => input.setAttribute(attrName, newValue));
1704
+ }
1675
1705
  }
1676
1706
  }
1677
1707
  }
@@ -1692,15 +1722,12 @@ const customMixin = (superclass) =>
1692
1722
  super.connectedCallback?.();
1693
1723
  const template = document.createElement('template');
1694
1724
 
1695
- //forward required & pattern TODO use forwardAttrs
1696
1725
  template.innerHTML = `
1697
1726
  <${componentName$4}
1698
1727
  bordered="true"
1699
1728
  name="code"
1700
1729
  tabindex="0"
1701
1730
  slot="input"
1702
- required="${this.shadowRoot.host.getAttribute('required')}"
1703
- pattern="${this.shadowRoot.host.getAttribute('pattern')}"
1704
1731
  ></${componentName$4}>
1705
1732
  `;
1706
1733
 
@@ -1714,11 +1741,13 @@ const customMixin = (superclass) =>
1714
1741
 
1715
1742
  // we want to control when the element is out of focus
1716
1743
  // so the validations will be triggered blur event is dispatched from descope-passcode internal (and not every time focusing a digit)
1717
- this.proxyElement._setFocused = () => {};
1744
+ this.proxyElement._setFocused = () => { };
1718
1745
 
1719
1746
  this.shadowRoot.host.appendChild(template.content.cloneNode(true));
1720
1747
  this.inputElement = this.querySelector(componentName$4);
1721
1748
 
1749
+ forwardAttrs(this.shadowRoot.host, this.inputElement, { includeAttrs: ['required', 'pattern'] });
1750
+
1722
1751
  // we want to trigger validation only when dispatching a blur event from the descope-passcode-internal
1723
1752
  this.inputElement.addEventListener('blur', () => {
1724
1753
  this.proxyElement.validate();
@@ -2156,99 +2185,6 @@ const genColors = (colors) => {
2156
2185
  }, {});
2157
2186
  };
2158
2187
 
2159
- const globalRefs$7 = getThemeRefs(globals);
2160
- const vars$c = Button.cssVarList;
2161
-
2162
- const mode = {
2163
- primary: globalRefs$7.colors.primary,
2164
- secondary: globalRefs$7.colors.secondary,
2165
- success: globalRefs$7.colors.success,
2166
- error: globalRefs$7.colors.error,
2167
- surface: globalRefs$7.colors.surface
2168
- };
2169
-
2170
- const [helperTheme$1, helperRefs$1] = createHelperVars({ mode }, componentName$i);
2171
-
2172
- const button = {
2173
- ...helperTheme$1,
2174
-
2175
- size: {
2176
- xs: {
2177
- [vars$c.height]: '10px',
2178
- [vars$c.fontSize]: '10px',
2179
- [vars$c.padding]: `0 ${globalRefs$7.spacing.xs}`
2180
- },
2181
- sm: {
2182
- [vars$c.height]: '20px',
2183
- [vars$c.fontSize]: '10px',
2184
- [vars$c.padding]: `0 ${globalRefs$7.spacing.sm}`
2185
- },
2186
- md: {
2187
- [vars$c.height]: '30px',
2188
- [vars$c.fontSize]: '14px',
2189
- [vars$c.padding]: `0 ${globalRefs$7.spacing.md}`
2190
- },
2191
- lg: {
2192
- [vars$c.height]: '40px',
2193
- [vars$c.fontSize]: '20px',
2194
- [vars$c.padding]: `0 ${globalRefs$7.spacing.lg}`
2195
- },
2196
- xl: {
2197
- [vars$c.height]: '50px',
2198
- [vars$c.fontSize]: '25px',
2199
- [vars$c.padding]: `0 ${globalRefs$7.spacing.xl}`
2200
- }
2201
- },
2202
-
2203
- [vars$c.borderRadius]: globalRefs$7.radius.lg,
2204
- [vars$c.cursor]: 'pointer',
2205
- [vars$c.borderWidth]: '2px',
2206
- [vars$c.borderStyle]: 'solid',
2207
- [vars$c.borderColor]: 'transparent',
2208
-
2209
- _fullWidth: {
2210
- [vars$c.width]: '100%'
2211
- },
2212
- _loading: {
2213
- [vars$c.cursor]: 'wait'
2214
- },
2215
-
2216
- variant: {
2217
- contained: {
2218
- [vars$c.color]: helperRefs$1.contrast,
2219
- [vars$c.backgroundColor]: helperRefs$1.main,
2220
- _hover: {
2221
- [vars$c.backgroundColor]: helperRefs$1.dark
2222
- },
2223
- _loading: {
2224
- [vars$c.backgroundColor]: helperRefs$1.main
2225
- }
2226
- },
2227
- outline: {
2228
- [vars$c.color]: helperRefs$1.main,
2229
- [vars$c.borderColor]: helperRefs$1.main,
2230
- _hover: {
2231
- [vars$c.color]: helperRefs$1.dark,
2232
- [vars$c.borderColor]: helperRefs$1.dark,
2233
- _error: {
2234
- [vars$c.color]: helperRefs$1.error
2235
- }
2236
- }
2237
- },
2238
- link: {
2239
- [vars$c.color]: helperRefs$1.main,
2240
- [vars$c.padding]: 0,
2241
- [vars$c.margin]: 0,
2242
- [vars$c.lineHeight]: helperRefs$1.height,
2243
- [vars$c.borderRadius]: 0,
2244
- _hover: {
2245
- [vars$c.color]: helperRefs$1.main,
2246
- [vars$c.textDecoration]: 'underline'
2247
- }
2248
- }
2249
- }
2250
- };
2251
-
2252
2188
  const colors = genColors({
2253
2189
  surface: {
2254
2190
  main: 'lightgray',
@@ -2352,6 +2288,99 @@ var globals = {
2352
2288
  fonts
2353
2289
  };
2354
2290
 
2291
+ const globalRefs$7 = getThemeRefs(globals);
2292
+ const vars$c = Button.cssVarList;
2293
+
2294
+ const mode = {
2295
+ primary: globalRefs$7.colors.primary,
2296
+ secondary: globalRefs$7.colors.secondary,
2297
+ success: globalRefs$7.colors.success,
2298
+ error: globalRefs$7.colors.error,
2299
+ surface: globalRefs$7.colors.surface
2300
+ };
2301
+
2302
+ const [helperTheme$1, helperRefs$1] = createHelperVars({ mode }, componentName$i);
2303
+
2304
+ const button = {
2305
+ ...helperTheme$1,
2306
+
2307
+ size: {
2308
+ xs: {
2309
+ [vars$c.height]: '10px',
2310
+ [vars$c.fontSize]: '10px',
2311
+ [vars$c.padding]: `0 ${globalRefs$7.spacing.xs}`
2312
+ },
2313
+ sm: {
2314
+ [vars$c.height]: '20px',
2315
+ [vars$c.fontSize]: '10px',
2316
+ [vars$c.padding]: `0 ${globalRefs$7.spacing.sm}`
2317
+ },
2318
+ md: {
2319
+ [vars$c.height]: '30px',
2320
+ [vars$c.fontSize]: '14px',
2321
+ [vars$c.padding]: `0 ${globalRefs$7.spacing.md}`
2322
+ },
2323
+ lg: {
2324
+ [vars$c.height]: '40px',
2325
+ [vars$c.fontSize]: '20px',
2326
+ [vars$c.padding]: `0 ${globalRefs$7.spacing.lg}`
2327
+ },
2328
+ xl: {
2329
+ [vars$c.height]: '50px',
2330
+ [vars$c.fontSize]: '25px',
2331
+ [vars$c.padding]: `0 ${globalRefs$7.spacing.xl}`
2332
+ }
2333
+ },
2334
+
2335
+ [vars$c.borderRadius]: globalRefs$7.radius.lg,
2336
+ [vars$c.cursor]: 'pointer',
2337
+ [vars$c.borderWidth]: '2px',
2338
+ [vars$c.borderStyle]: 'solid',
2339
+ [vars$c.borderColor]: 'transparent',
2340
+
2341
+ _fullWidth: {
2342
+ [vars$c.width]: '100%'
2343
+ },
2344
+ _loading: {
2345
+ [vars$c.cursor]: 'wait'
2346
+ },
2347
+
2348
+ variant: {
2349
+ contained: {
2350
+ [vars$c.color]: helperRefs$1.contrast,
2351
+ [vars$c.backgroundColor]: helperRefs$1.main,
2352
+ _hover: {
2353
+ [vars$c.backgroundColor]: helperRefs$1.dark
2354
+ },
2355
+ _loading: {
2356
+ [vars$c.backgroundColor]: helperRefs$1.main
2357
+ }
2358
+ },
2359
+ outline: {
2360
+ [vars$c.color]: helperRefs$1.main,
2361
+ [vars$c.borderColor]: helperRefs$1.main,
2362
+ _hover: {
2363
+ [vars$c.color]: helperRefs$1.dark,
2364
+ [vars$c.borderColor]: helperRefs$1.dark,
2365
+ _error: {
2366
+ [vars$c.color]: helperRefs$1.error
2367
+ }
2368
+ }
2369
+ },
2370
+ link: {
2371
+ [vars$c.color]: helperRefs$1.main,
2372
+ [vars$c.padding]: 0,
2373
+ [vars$c.margin]: 0,
2374
+ [vars$c.lineHeight]: helperRefs$1.height,
2375
+ [vars$c.borderRadius]: 0,
2376
+ _hover: {
2377
+ [vars$c.color]: helperRefs$1.main,
2378
+ [vars$c.textDecoration]: 'underline'
2379
+ }
2380
+ }
2381
+ }
2382
+ };
2383
+
2355
2384
  const globalRefs$6 = getThemeRefs(globals);
2356
2385
 
2357
2386
  const vars$b = TextField.cssVarList;