@descope/web-components-ui 1.0.50 → 1.0.52

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,77 +2,108 @@ import { getCssVarName, kebabCaseJoin } from '../../helpers';
2
2
  import { createStyle, createCssVarsList } from './helpers';
3
3
 
4
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);
5
+ ({ mappings = {}, nestedMappings = {} }) =>
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];
64
14
  }
65
- }
66
-
67
- connectedCallback() {
68
- super.connectedCallback?.();
69
- if (this.shadowRoot.isConnected) {
70
- Array.from(this.attributes).forEach(attr => {
71
- if (styleAttributes.includes(attr.nodeName)) {
72
- this.#updateAttrOverrideStyle(attr.nodeName, attr.value)
73
- }
74
- });
75
- }
76
- }
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
+ #createComponentNestingStyle() {
60
+ // we need these selectors to be more specific from the theme selectors
61
+ // in order to do it, we are repeating the class name for specificity
62
+ const numOfClassNameSpecifier = 3
63
+
64
+ const rootNode = this.shadowRoot.host.getRootNode()
65
+ const styleId = `${superclass.componentName}-style-mixin-component`
66
+
67
+ const className = superclass.componentName
68
+ this.shadowRoot.host.classList.add(className)
69
+
70
+ if(rootNode.querySelector(`style#${styleId}`)) return;
71
+
72
+ const themeStyle = document.createElement('style');
73
+ themeStyle.id = styleId;
74
+ themeStyle.innerHTML = createStyle(
75
+ superclass.componentName,
76
+ `${superclass.componentName}${Array(numOfClassNameSpecifier).fill(`.${className}`).join('')}`,
77
+ nestedMappings
78
+ );
79
+
80
+ // rootNode can be either a shadow DOM or a light DOM
81
+ if (rootNode.nodeName === '#document') {
82
+ rootNode.head.append(themeStyle)
83
+ } else {
84
+ rootNode.append(themeStyle)
85
+ }
86
+ }
87
+
88
+ attributeChangedCallback(attrName, oldValue, newValue) {
89
+ super.attributeChangedCallback?.(attrName, oldValue, newValue);
90
+
91
+ if (styleAttributes.includes(attrName)) {
92
+ this.#updateAttrOverrideStyle(attrName, newValue);
93
+ }
94
+ }
95
+
96
+ connectedCallback() {
97
+ super.connectedCallback?.();
98
+ if (this.shadowRoot.isConnected) {
99
+ this.#createComponentNestingStyle();
100
+
101
+ Array.from(this.attributes).forEach(attr => {
102
+ if (styleAttributes.includes(attr.nodeName)) {
103
+ this.#updateAttrOverrideStyle(attr.nodeName, attr.value)
104
+ }
105
+ });
106
+ }
107
+ }
108
+ };
77
109
  };
78
- };
@@ -54,40 +54,40 @@ export const inputMixin = (superclass) =>
54
54
  }
55
55
 
56
56
  connectedCallback() {
57
- this.baseEle = this.shadowRoot.querySelector(this.baseSelector);
58
57
  super.connectedCallback?.();
59
58
 
59
+ this.baseEle = this.shadowRoot.querySelector(this.baseSelector);
60
+
60
61
  // this is needed in order to make sure the form input validation is working
61
62
  if (!this.hasAttribute('tabindex')) {
62
63
  this.setAttribute('tabindex', 0);
63
64
  }
64
65
 
65
- const input =
66
- this.baseEle.querySelector('input') ||
67
- this.baseEle.querySelector('textarea');
68
- if (!input) throw Error('no input was found');
66
+ this.inputElement ??= this.baseEle.shadowRoot.querySelector('slot[name="input"]')?.assignedElements()[0] ||
67
+ this.baseEle.shadowRoot.querySelector('slot[name="textarea"]')?.assignedElements()[0]
68
+ if (!this.inputElement) throw Error('no input was found');
69
69
 
70
70
  // sync properties
71
- propertyObserver(this, input, 'value');
72
- this.setSelectionRange = input.setSelectionRange.bind(input);
71
+ propertyObserver(this, this.inputElement, 'value');
72
+ this.setSelectionRange = this.inputElement.setSelectionRange?.bind(this.inputElement);
73
73
 
74
- this.validity = input.validity;
74
+ this.validity = this.inputElement.validity;
75
75
 
76
76
  this.setValidity = () => {
77
- this.#internals.setValidity(input.validity, input.validationMessage);
77
+ this.#internals.setValidity(this.inputElement.validity, this.inputElement.validationMessage);
78
78
  };
79
79
 
80
- input.oninput = () => {
81
- this.value = input.value;
80
+ this.inputElement.oninput = () => {
81
+ this.value = this.inputElement.value;
82
82
  this.setValidity();
83
83
  };
84
84
 
85
85
  this.onfocus = () => {
86
- setTimeout(() => input.reportValidity(), 0);
86
+ setTimeout(() => this.inputElement.reportValidity(), 0);
87
87
  this.validate();
88
88
  };
89
89
 
90
- input.oninvalid = () => {
90
+ this.inputElement.oninvalid = () => {
91
91
  this.validate();
92
92
  };
93
93
  }
package/src/index.js CHANGED
@@ -7,6 +7,7 @@ import './components/descope-password-field';
7
7
  import './components/descope-text-area';
8
8
  import './components/descope-date-picker';
9
9
  import './components/descope-container';
10
+ import './components/descope-text';
10
11
 
11
12
  export {
12
13
  globalsThemeToStyle,
@@ -8,6 +8,8 @@ import checkbox from './checkbox';
8
8
  import switchToggle from './switchToggle';
9
9
  import container from './container';
10
10
  import logo from './logo';
11
+ import text from './text';
12
+ import passcode from './passcode';
11
13
 
12
14
  export default {
13
15
  button,
@@ -19,5 +21,7 @@ export default {
19
21
  checkbox,
20
22
  switchToggle,
21
23
  container,
22
- logo
24
+ logo,
25
+ text,
26
+ passcode
23
27
  };
@@ -0,0 +1,8 @@
1
+ import Passcode from '../../components/descope-passcode/Passcode';
2
+ import { textField } from './textField';
3
+
4
+ const passcode = {
5
+ ...textField(Passcode.cssVarList),
6
+ };
7
+
8
+ export default passcode;
@@ -0,0 +1,79 @@
1
+ import globals from '../globals';
2
+ import { getThemeRefs } from '../../themeHelpers';
3
+ import Text from '../../components/descope-text/Text';
4
+
5
+ const globalRefs = getThemeRefs(globals);
6
+
7
+ const vars = Text.cssVarList;
8
+
9
+ const text = {
10
+ [vars.lineHeight]: '1em',
11
+ [vars.display]: 'inline-block',
12
+ [vars.textAlign]: 'left',
13
+ [vars.color]: globalRefs.colors.surface.dark,
14
+ variant: {
15
+ h1: {
16
+ [vars.fontSize]: globalRefs.typography.h1.size,
17
+ [vars.fontWeight]: globalRefs.typography.h1.weight,
18
+ [vars.fontFamily]: globalRefs.typography.h1.font
19
+ },
20
+ h2: {
21
+ [vars.fontSize]: globalRefs.typography.h2.size,
22
+ [vars.fontWeight]: globalRefs.typography.h2.weight,
23
+ [vars.fontFamily]: globalRefs.typography.h2.font
24
+ },
25
+ h3: {
26
+ [vars.fontSize]: globalRefs.typography.h3.size,
27
+ [vars.fontWeight]: globalRefs.typography.h3.weight,
28
+ [vars.fontFamily]: globalRefs.typography.h3.font
29
+ },
30
+ subtitle1: {
31
+ [vars.fontSize]: globalRefs.typography.subtitle1.size,
32
+ [vars.fontWeight]: globalRefs.typography.subtitle1.weight,
33
+ [vars.fontFamily]: globalRefs.typography.subtitle1.font
34
+ },
35
+ subtitle2: {
36
+ [vars.fontSize]: globalRefs.typography.subtitle2.size,
37
+ [vars.fontWeight]: globalRefs.typography.subtitle2.weight,
38
+ [vars.fontFamily]: globalRefs.typography.subtitle2.font
39
+ },
40
+ body1: {
41
+ [vars.fontSize]: globalRefs.typography.body1.size,
42
+ [vars.fontWeight]: globalRefs.typography.body1.weight,
43
+ [vars.fontFamily]: globalRefs.typography.body1.font
44
+ },
45
+ body2: {
46
+ [vars.fontSize]: globalRefs.typography.body2.size,
47
+ [vars.fontWeight]: globalRefs.typography.body2.weight,
48
+ [vars.fontFamily]: globalRefs.typography.body2.font
49
+ }
50
+ },
51
+ mode: {
52
+ primary: {
53
+ [vars.color]: globalRefs.colors.primary.main
54
+ },
55
+ secondary: {
56
+ [vars.color]: globalRefs.colors.secondary.main
57
+ },
58
+ error: {
59
+ [vars.color]: globalRefs.colors.error.main
60
+ },
61
+ success: {
62
+ [vars.color]: globalRefs.colors.success.main
63
+ }
64
+ },
65
+ textAlign: {
66
+ right: { [vars.textAlign]: 'right' },
67
+ left: { [vars.textAlign]: 'left' },
68
+ center: { [vars.textAlign]: 'center' }
69
+ },
70
+ _fullWidth: {
71
+ [vars.width]: '100%',
72
+ [vars.display]: 'block'
73
+ },
74
+ _italic: {
75
+ [vars.fontStyle]: 'italic'
76
+ }
77
+ };
78
+
79
+ export default text;
@@ -1,3 +1,4 @@
1
+ import { getThemeRefs } from '../themeHelpers';
1
2
  import { genColors } from '../themeHelpers/processColors';
2
3
 
3
4
  export const colors = genColors({
@@ -12,21 +13,47 @@ export const colors = genColors({
12
13
  error: 'red'
13
14
  });
14
15
 
16
+ const fonts = {
17
+ font1: ['Roboto', 'sans-serif'],
18
+ font2: ['Oswald', 'serif']
19
+ };
20
+ const fontsRef = getThemeRefs({ fonts }).fonts;
21
+
15
22
  const typography = {
16
23
  h1: {
17
- font: ['Courier New', 'Arial', 'sans-serif'],
18
- weight: '700',
24
+ font: fontsRef.font1,
25
+ weight: '900',
19
26
  size: '48px'
20
27
  },
21
28
  h2: {
22
- font: ['Courier New', 'sans-serif'],
23
- weight: '500',
29
+ font: fontsRef.font1,
30
+ weight: '800',
24
31
  size: '38px'
25
32
  },
26
33
  h3: {
27
- font: ['Courier New', 'sans-serif'],
28
- weight: '300',
34
+ font: fontsRef.font1,
35
+ weight: '600',
29
36
  size: '28px'
37
+ },
38
+ subtitle1: {
39
+ font: fontsRef.font2,
40
+ weight: '500',
41
+ size: '22px'
42
+ },
43
+ subtitle2: {
44
+ font: fontsRef.font2,
45
+ weight: '400',
46
+ size: '20px'
47
+ },
48
+ body1: {
49
+ font: fontsRef.font1,
50
+ weight: '300',
51
+ size: '16px'
52
+ },
53
+ body2: {
54
+ font: fontsRef.font1,
55
+ weight: '200',
56
+ size: '14px'
30
57
  }
31
58
  };
32
59
 
@@ -51,20 +78,20 @@ const radius = {
51
78
  };
52
79
 
53
80
  const shadow = {
54
- wide: {
55
- sm: '0 2px 3px -0.5px',
56
- md: '0 4px 6px -1px',
57
- lg: '0 10px 15px -3px',
58
- xl: '0 20px 25px -5px',
59
- '2xl': '0 25px 50px -12px',
60
- },
61
- narrow: {
62
- sm: '0 1px 2px -1px',
63
- md: '0 2px 4px -2px',
64
- lg: '0 4px 6px -4px',
65
- xl: '0 8px 10px -6px',
66
- '2xl': '0 16px 16px -8px',
67
- }
81
+ wide: {
82
+ sm: '0 2px 3px -0.5px',
83
+ md: '0 4px 6px -1px',
84
+ lg: '0 10px 15px -3px',
85
+ xl: '0 20px 25px -5px',
86
+ '2xl': '0 25px 50px -12px'
87
+ },
88
+ narrow: {
89
+ sm: '0 1px 2px -1px',
90
+ md: '0 2px 4px -2px',
91
+ lg: '0 4px 6px -4px',
92
+ xl: '0 8px 10px -6px',
93
+ '2xl': '0 16px 16px -8px'
94
+ }
68
95
  };
69
96
 
70
97
  export default {
@@ -73,5 +100,6 @@ export default {
73
100
  spacing,
74
101
  border,
75
102
  radius,
76
- shadow
103
+ shadow,
104
+ fonts
77
105
  };