@descope/flow-components 2.0.38 → 2.0.40

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.
Files changed (157) hide show
  1. package/dist/index.cjs.js +1 -93
  2. package/dist/index.d.ts +2 -54
  3. package/dist/index.esm.js +2 -92
  4. package/package.json +8 -9
  5. package/.eslintrc +0 -119
  6. package/.github/actions/setup/action.yml +0 -42
  7. package/.github/workflows/ci.yml +0 -105
  8. package/.github/workflows/publish.yml +0 -41
  9. package/.github/workflows/release.yml +0 -44
  10. package/.husky/pre-commit +0 -1
  11. package/.prettierrc +0 -8
  12. package/.storybook/main.js +0 -23
  13. package/.storybook/manager.js +0 -10
  14. package/.storybook/preview-head.html +0 -29
  15. package/.storybook/preview.js +0 -44
  16. package/LICENSE +0 -21
  17. package/babel.config.js +0 -7
  18. package/jest.config.js +0 -33
  19. package/jest.setup.js +0 -2
  20. package/renovate.json +0 -4
  21. package/rollup.config.mjs +0 -47
  22. package/src/Boolean/Boolean.tsx +0 -24
  23. package/src/Boolean/index.ts +0 -1
  24. package/src/Button/Button.tsx +0 -49
  25. package/src/Button/index.ts +0 -1
  26. package/src/Checkbox/Checkbox.tsx +0 -16
  27. package/src/Checkbox/index.ts +0 -1
  28. package/src/Code/Code.tsx +0 -21
  29. package/src/Code/index.ts +0 -1
  30. package/src/Container/Container.tsx +0 -111
  31. package/src/Container/index.ts +0 -1
  32. package/src/CssVarImage/CssVarImage.tsx +0 -38
  33. package/src/CssVarImage/index.ts +0 -1
  34. package/src/Divider/Divider.tsx +0 -33
  35. package/src/Divider/index.ts +0 -1
  36. package/src/EmailField/EmailField.tsx +0 -20
  37. package/src/EmailField/index.ts +0 -1
  38. package/src/Image/Image.tsx +0 -32
  39. package/src/Image/index.ts +0 -1
  40. package/src/Input/Input.tsx +0 -27
  41. package/src/Input/index.ts +0 -1
  42. package/src/Link/Link.tsx +0 -33
  43. package/src/Link/index.ts +0 -1
  44. package/src/Loader/Loader.tsx +0 -40
  45. package/src/Loader/index.ts +0 -1
  46. package/src/Logo/Logo.tsx +0 -27
  47. package/src/Logo/index.ts +0 -1
  48. package/src/NewPassword/NewPassword.tsx +0 -25
  49. package/src/NewPassword/index.ts +0 -1
  50. package/src/NumberField/NumberField.tsx +0 -20
  51. package/src/NumberField/index.ts +0 -1
  52. package/src/Password/Password.tsx +0 -20
  53. package/src/Password/index.ts +0 -1
  54. package/src/Phone/Phone.tsx +0 -22
  55. package/src/Phone/index.ts +0 -1
  56. package/src/Select/Select.tsx +0 -29
  57. package/src/Select/index.ts +0 -1
  58. package/src/Switch/Switch.tsx +0 -21
  59. package/src/Switch/index.ts +0 -1
  60. package/src/TOTPImage/TOTPImage.tsx +0 -18
  61. package/src/TOTPImage/index.ts +0 -1
  62. package/src/TOTPLink/TOTPLink.tsx +0 -16
  63. package/src/TOTPLink/index.ts +0 -1
  64. package/src/Text/Text.tsx +0 -36
  65. package/src/Text/index.ts +0 -1
  66. package/src/TextField/TextField.tsx +0 -20
  67. package/src/TextField/index.ts +0 -1
  68. package/src/Textarea/Textarea.tsx +0 -20
  69. package/src/Textarea/index.ts +0 -1
  70. package/src/icons/apple.tsx +0 -14
  71. package/src/icons/discord.tsx +0 -14
  72. package/src/icons/facebook.tsx +0 -14
  73. package/src/icons/fingerprint.tsx +0 -14
  74. package/src/icons/github.tsx +0 -14
  75. package/src/icons/gitlab.tsx +0 -41
  76. package/src/icons/google.tsx +0 -29
  77. package/src/icons/index.ts +0 -11
  78. package/src/icons/input-hidden.tsx +0 -17
  79. package/src/icons/input-visible.tsx +0 -17
  80. package/src/icons/linkedin.tsx +0 -18
  81. package/src/icons/microsoft.tsx +0 -41
  82. package/src/icons/passkey.tsx +0 -16
  83. package/src/icons/sso.tsx +0 -14
  84. package/src/index.ts +0 -29
  85. package/src/inputHelpers.ts +0 -41
  86. package/src/themeToCssVars/constants.ts +0 -13
  87. package/src/themeToCssVars/index.ts +0 -153
  88. package/src/themeToCssVars/types.ts +0 -56
  89. package/src/types.ts +0 -52
  90. package/src/utils.tsx +0 -69
  91. package/stories/Boolean.stories.jsx +0 -37
  92. package/stories/Button.stories.jsx +0 -71
  93. package/stories/Checkbox.stories.jsx +0 -29
  94. package/stories/Code.stories.jsx +0 -60
  95. package/stories/Container.stories.jsx +0 -53
  96. package/stories/Divider.stories.jsx +0 -23
  97. package/stories/EmailField.stories.jsx +0 -36
  98. package/stories/Image.stories.jsx +0 -16
  99. package/stories/Input.stories.jsx +0 -63
  100. package/stories/Link.stories.jsx +0 -21
  101. package/stories/Loader.stories.jsx +0 -34
  102. package/stories/Logo.stories.jsx +0 -14
  103. package/stories/NewPassword.stories.jsx +0 -52
  104. package/stories/NumberField.stories.jsx +0 -35
  105. package/stories/Password.stories.jsx +0 -37
  106. package/stories/Phone.stories.jsx +0 -61
  107. package/stories/Switch.stories.jsx +0 -29
  108. package/stories/TOTPImage.stories.jsx +0 -22
  109. package/stories/TOTPLink.stories.jsx +0 -20
  110. package/stories/Text.stories.jsx +0 -35
  111. package/stories/TextField.stories.jsx +0 -39
  112. package/stories/Textarea.stories.jsx +0 -25
  113. package/storybook-static/favicon.ico +0 -0
  114. package/test/__snapshots__/boolean.test.tsx.snap +0 -47
  115. package/test/__snapshots__/buttons.test.tsx.snap +0 -843
  116. package/test/__snapshots__/checkbox.test.tsx.snap +0 -51
  117. package/test/__snapshots__/code.test.tsx.snap +0 -1184
  118. package/test/__snapshots__/container.test.tsx.snap +0 -218
  119. package/test/__snapshots__/divider.test.tsx.snap +0 -73
  120. package/test/__snapshots__/image.test.tsx.snap +0 -62
  121. package/test/__snapshots__/input.test.tsx.snap +0 -80
  122. package/test/__snapshots__/link.test.tsx.snap +0 -120
  123. package/test/__snapshots__/loader.test.tsx.snap +0 -53
  124. package/test/__snapshots__/logo.test.tsx.snap +0 -10
  125. package/test/__snapshots__/newPassword.test.tsx.snap +0 -69
  126. package/test/__snapshots__/numeric-input.test.tsx.snap +0 -21
  127. package/test/__snapshots__/password.test.tsx.snap +0 -26
  128. package/test/__snapshots__/phone.test.tsx.snap +0 -504
  129. package/test/__snapshots__/switch.test.tsx.snap +0 -51
  130. package/test/__snapshots__/text.test.tsx.snap +0 -89
  131. package/test/__snapshots__/textarea.test.tsx.snap +0 -73
  132. package/test/__snapshots__/themeToCssVars.test.ts.snap +0 -45
  133. package/test/__snapshots__/totpImage.test.tsx.snap +0 -10
  134. package/test/__snapshots__/totpLink.test.tsx.snap +0 -13
  135. package/test/boolean.test.tsx +0 -28
  136. package/test/buttons.test.tsx +0 -66
  137. package/test/checkbox.test.tsx +0 -67
  138. package/test/code.test.tsx +0 -182
  139. package/test/container.test.tsx +0 -91
  140. package/test/divider.test.tsx +0 -50
  141. package/test/image.test.tsx +0 -40
  142. package/test/input.test.tsx +0 -82
  143. package/test/inputHelpers.test.tsx +0 -58
  144. package/test/link.test.tsx +0 -71
  145. package/test/loader.test.tsx +0 -25
  146. package/test/logo.test.tsx +0 -10
  147. package/test/newPassword.test.tsx +0 -132
  148. package/test/numeric-input.test.tsx +0 -114
  149. package/test/password.test.tsx +0 -55
  150. package/test/phone.test.tsx +0 -158
  151. package/test/switch.test.tsx +0 -67
  152. package/test/text.test.tsx +0 -60
  153. package/test/textarea.test.tsx +0 -64
  154. package/test/themeToCssVars.test.ts +0 -82
  155. package/test/totpImage.test.tsx +0 -10
  156. package/test/totpLink.test.tsx +0 -10
  157. package/tsconfig.json +0 -20
@@ -1,18 +0,0 @@
1
- import React from 'react';
2
-
3
- export default ({ noColor }) => (
4
- <svg
5
- xmlns="http://www.w3.org/2000/svg"
6
- width="1.5em"
7
- height="1.5em"
8
- viewBox="0 0 40 40"
9
- fill={noColor ? 'currentColor' : '#2867B2'}
10
- data-icon="linkedin"
11
- >
12
- <path
13
- fillRule="evenodd"
14
- clipRule="evenodd"
15
- d="M37.1429 0H2.84821C1.27679 0 0 1.29464 0 2.88393V37.1161C0 38.7054 1.27679 40 2.84821 40H37.1429C38.7143 40 40 38.7054 40 37.1161V2.88393C40 1.29464 38.7143 0 37.1429 0ZM12.0893 34.2857H6.16071V15.1964H12.0982V34.2857H12.0893ZM9.125 12.5893C7.22321 12.5893 5.6875 11.0446 5.6875 9.15179C5.6875 7.25893 7.22321 5.71429 9.125 5.71429C11.0179 5.71429 12.5625 7.25893 12.5625 9.15179C12.5625 11.0536 11.0268 12.5893 9.125 12.5893V12.5893ZM34.3125 34.2857H28.3839V25C28.3839 22.7857 28.3393 19.9375 25.3036 19.9375C22.2143 19.9375 21.7411 22.3482 21.7411 24.8393V34.2857H15.8125V15.1964H21.5V17.8036H21.5804C22.375 16.3036 24.3125 14.7232 27.1964 14.7232C33.1964 14.7232 34.3125 18.6786 34.3125 23.8214V34.2857V34.2857Z"
16
- />
17
- </svg>
18
- );
@@ -1,41 +0,0 @@
1
- import React from 'react';
2
-
3
- export default ({ noColor }) => (
4
- <svg
5
- width="1.5em"
6
- height="1.5em"
7
- xmlns="http://www.w3.org/2000/svg"
8
- fill={noColor ? 'currentColor' : ''}
9
- viewBox="3 3 24 24"
10
- data-icon="microsoft"
11
- >
12
- <rect
13
- x="5"
14
- y="15.7143"
15
- width="9.28571"
16
- height="9.28571"
17
- fill={noColor ? '' : '#05A6F0'}
18
- />
19
- <rect
20
- x="5"
21
- y="5"
22
- width="9.28571"
23
- height="9.28571"
24
- fill={noColor ? '' : '#F35325'}
25
- />
26
- <rect
27
- x="15.7143"
28
- y="15.7143"
29
- width="9.28571"
30
- height="9.28571"
31
- fill={noColor ? '' : '#FFBA08'}
32
- />
33
- <rect
34
- x="15.7143"
35
- y="5"
36
- width="9.28571"
37
- height="9.28571"
38
- fill={noColor ? '' : '#81BC06'}
39
- />{' '}
40
- </svg>
41
- );
@@ -1,16 +0,0 @@
1
- import React from 'react';
2
-
3
- export default ({ noColor }) => (
4
- <svg
5
- xmlns="http://www.w3.org/2000/svg"
6
- viewBox="0 0 24 24"
7
- width="1.5em"
8
- height="1.5em"
9
- fill={noColor ? 'currentColor' : '#000000'}
10
- data-icon="passkey"
11
- >
12
- <circle cx="10.5" cy="6" r="4.5" />
13
- <path d="M22.5,10.5a3.5,3.5,0,1,0-5,3.15V19L19,20.5,21.5,18,20,16.5,21.5,15l-1.24-1.24A3.5,3.5,0,0,0,22.5,10.5Zm-3.5,0a1,1,0,1,1,1-1A1,1,0,0,1,19,10.5Z" />
14
- <path d="M14.44,12.52A6,6,0,0,0,12,12H9a6,6,0,0,0-6,6v2H16V14.49A5.16,5.16,0,0,1,14.44,12.52Z" />
15
- </svg>
16
- );
package/src/icons/sso.tsx DELETED
@@ -1,14 +0,0 @@
1
- import React from 'react';
2
-
3
- export default ({ noColor }) => (
4
- <svg
5
- xmlns="http://www.w3.org/2000/svg"
6
- width="1.5em"
7
- height="1.5em"
8
- viewBox="50 30 410 450"
9
- fill={noColor ? 'currentColor' : '#000000'}
10
- data-icon="sso"
11
- >
12
- <path d="M56.629,379.2c-14.09,14.071-14.09,36.975,0,51.055 c14.08,14.087,36.981,14.087,50.965,0l10.177-10.08l42.438,42.428c7.257,7.268,18.888,7.268,26.155,0l63.244-63.244 c7.268-7.255,7.268-18.89,0-26.157l-42.429-42.427l75.586-75.682c16.174,8.357,34.61,13.075,54.059,13.075 c65.234,0,118.111-52.869,118.111-118.109c0-65.232-52.877-118.111-118.111-118.111c-65.238,0-118.11,52.879-118.11,118.111 c0,19.449,4.721,37.886,13.077,54.06L56.629,379.2z M291.396,150.059c0-25.075,20.354-45.429,45.427-45.429 c25.076,0,45.426,20.354,45.426,45.429s-20.35,45.426-45.426,45.426C311.751,195.485,291.396,175.133,291.396,150.059z" />
13
- </svg>
14
- );
package/src/index.ts DELETED
@@ -1,29 +0,0 @@
1
- import '@descope/web-components-ui';
2
-
3
- export * from './Boolean';
4
- export * from './Button';
5
- export * from './Checkbox';
6
- export * from './Code';
7
- export * from './Container';
8
- export * from './Divider';
9
- export * from './icons';
10
- export * from './Image';
11
- export * from './Input';
12
- export * from './Link';
13
- export * from './Loader';
14
- export * from './Logo';
15
- export * from './NewPassword';
16
- export * from './NumberField';
17
- export * from './Password';
18
- export * from './Phone';
19
- export * from './Select';
20
- export * from './Switch';
21
- export * from './Text';
22
- export * from './Textarea';
23
- export * from './TextField';
24
- export * from './TOTPImage';
25
- export * from './TOTPLink';
26
- export { default as themeToCssVars } from './themeToCssVars';
27
- export type { Theme } from './themeToCssVars/types';
28
-
29
- export * from '@descope/web-components-ui';
@@ -1,41 +0,0 @@
1
- export function handleCustomValidationMessages() {
2
- const kebabCase = (str: string) =>
3
- str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
4
-
5
- if (!this) {
6
- return;
7
- }
8
-
9
- const targetEle = this.querySelector('.descope-input');
10
- if (!targetEle) {
11
- return;
12
- }
13
-
14
- const disabledChars = ['e'];
15
-
16
- if (targetEle.type === 'number') {
17
- targetEle.addEventListener('keypress', (e: KeyboardEvent) => {
18
- if (disabledChars.includes(e.key.toLowerCase())) {
19
- e.preventDefault();
20
- }
21
- });
22
- }
23
-
24
- targetEle.addEventListener('input', () => {
25
- if (targetEle.classList.contains('invalid:input-error')) {
26
- targetEle.checkValidity();
27
- }
28
- });
29
-
30
- targetEle.addEventListener('invalid', () => {
31
- targetEle.setCustomValidity('');
32
- targetEle.classList.add('invalid:input-error');
33
- ['patternMismatch', 'valueMissing'].forEach((type) => {
34
- if (targetEle.validity[type]) {
35
- const attrName = `data-errormessage-${kebabCase(type)}`;
36
- const customMessage = targetEle.getAttribute(attrName);
37
- if (customMessage) targetEle.setCustomValidity(customMessage);
38
- }
39
- });
40
- });
41
- }
@@ -1,13 +0,0 @@
1
- export const optionalColors = {
2
- p: { focus: true },
3
- s: { focus: true },
4
- a: { focus: true }
5
- };
6
-
7
- export enum CssVarNameMapping {
8
- primary = 'p',
9
- error = 'er',
10
- warning = 'wa',
11
- secondary = 's',
12
- accent = 'a'
13
- }
@@ -1,153 +0,0 @@
1
- import Color from 'color';
2
- import { Theme, OptionalColorsVars } from './types';
3
- import { optionalColors, CssVarNameMapping } from './constants';
4
-
5
- // adds starting & trailing quotes to string with spaces that missing it
6
- const addMissingQuotesWhenSpace = (str: string) =>
7
- /\s/g.test(str) ? str.replace(/(^[^""]*$)/g, '"$1"') : str;
8
-
9
- const getVarName = (name: string) =>
10
- CssVarNameMapping[name as keyof CssVarNameMapping] || name;
11
-
12
- const contrastMaker = (color: string, percentage = 0.9) => {
13
- const isDark = Color(color).isDark();
14
-
15
- return Color(color)
16
- .mix(Color(isDark ? 'white' : 'black'), percentage)
17
- .saturate(1)
18
- .hex();
19
- };
20
-
21
- const darken = (color: string, percentage = 0.2) =>
22
- Color(color).darken(percentage).hex();
23
-
24
- const toHsl = (hex: string) => {
25
- const { h, s, l } = Color(hex).hsl().object();
26
-
27
- return { h, s, l };
28
- };
29
-
30
- const toHslString = (hsl: { h: number; s: number; l: number }) =>
31
- `${hsl.h} ${hsl.s}% ${hsl.l}%`;
32
-
33
- const generateCssVar = (varName: string, value: string) =>
34
- value !== undefined
35
- ? {
36
- [`--${varName}`]: value
37
- }
38
- : {};
39
-
40
- const generateColorCssVar = (varName: string, hex: string) =>
41
- generateCssVar(varName, toHslString(toHsl(hex)));
42
-
43
- const generateOptionalColorsVars = (
44
- varName: OptionalColorsVars,
45
- hex: string
46
- ) => {
47
- const optsColors: Record<string, string> = generateColorCssVar(
48
- `${varName}c`,
49
- contrastMaker(hex)
50
- );
51
- if (optionalColors[varName]?.focus)
52
- Object.assign(optsColors, generateColorCssVar(`${varName}f`, darken(hex)));
53
-
54
- return optsColors;
55
- };
56
-
57
- const generateColorsCssVars = (values: Record<string, string> | undefined) =>
58
- Object.entries(values || {}).reduce((acc, [name, hex]) => {
59
- const varName = getVarName(name);
60
- const update = generateColorCssVar(varName, hex);
61
- const optsColors = generateOptionalColorsVars(
62
- varName as OptionalColorsVars,
63
- hex
64
- );
65
-
66
- return Object.assign(acc, update, optsColors);
67
- }, {});
68
-
69
- const toCssUrl = (str: string) => `url(${str})`;
70
-
71
- const mapObjValues = (
72
- obj: Object,
73
- mapper: (val: any, key: string, idx: number) => any
74
- ) =>
75
- obj &&
76
- Object.fromEntries(
77
- Object.entries(obj).map(([k, v], i) => [k, mapper(v, k, i)])
78
- );
79
-
80
- const pickNonFalsy = (obj: Object, keys: string[]) =>
81
- obj &&
82
- Object.fromEntries(
83
- Object.entries(obj).filter(([k, v]) => v && keys.includes(k))
84
- );
85
-
86
- /**
87
- * Takes and object and flatten its keys
88
- * for example: for {a: {b: {c: 1}}}
89
- * we will get {'a-b-c': 1}
90
- */
91
- const flattenObj = (obj: Object, roots = [], sep = '-') =>
92
- obj &&
93
- Object.keys(obj).reduce(
94
- (acc, key) => ({
95
- ...acc,
96
- ...(Object.prototype.toString.call(obj[key]) === '[object Object]'
97
- ? flattenObj(obj[key], roots.concat([key]), sep)
98
- : { [roots.concat([key]).join(sep)]: obj[key] })
99
- }),
100
- {}
101
- );
102
-
103
- const generateCssVars = (values: Record<string, string> | undefined) =>
104
- Object.entries(values || {}).reduce(
105
- (acc, [varName, value]) =>
106
- Object.assign(acc, generateCssVar(varName, value)),
107
- {}
108
- );
109
-
110
- const generateTypographyCssVars = (
111
- typography: Theme['typography'] | undefined,
112
- fontSizeUnit = 'px'
113
- ) => {
114
- const fontFamiliesVars = typography?.fontFamilies?.reduce(
115
- (acc, val, idx) =>
116
- Object.assign(acc, {
117
- [`font-family-${idx}`]: val.family
118
- .map(addMissingQuotesWhenSpace)
119
- .join(',')
120
- }),
121
- {}
122
- );
123
-
124
- const typographyVars = flattenObj(
125
- mapObjValues(typography?.variants, (val) => ({
126
- ...val,
127
- 'font-family': `var(--font-family-${val['font-family']})`,
128
- 'font-size': val['font-size'] && val['font-size'] + fontSizeUnit
129
- }))
130
- );
131
-
132
- return generateCssVars(
133
- Object.assign(fontFamiliesVars || {}, typographyVars || {})
134
- );
135
- };
136
-
137
- const generateLogoCssVars = (logo: Theme['logo'] | undefined) =>
138
- generateCssVars(
139
- mapObjValues(
140
- // we want to generate the logo-url var only if it has a value
141
- pickNonFalsy(logo || {}, ['logo-url']),
142
- toCssUrl
143
- )
144
- );
145
-
146
- const generateCssVarsFromTheme = (theme: Partial<Theme> = {}) => ({
147
- ...generateColorsCssVars(theme.colors),
148
- ...generateCssVars(theme.components),
149
- ...generateLogoCssVars(theme.logo),
150
- ...generateTypographyCssVars(theme.typography)
151
- });
152
-
153
- export default generateCssVarsFromTheme;
@@ -1,56 +0,0 @@
1
- import { optionalColors } from './constants';
2
-
3
- type TypographyShallowVariant = {
4
- 'font-family': string;
5
- };
6
-
7
- type FontFamily = {
8
- label: string;
9
- family: string[];
10
- url?: string;
11
- };
12
-
13
- export type TypographyVariant = TypographyShallowVariant & {
14
- 'font-size': string;
15
- 'font-weight': string;
16
- };
17
-
18
- export type Theme = {
19
- components: {
20
- 'input-border-opacity': '0' | undefined;
21
- 'container-background-color': string;
22
- 'button-border-radius': string;
23
- 'input-background-color': string;
24
- 'input-label-color': string;
25
- 'input-color': string;
26
- 'input-placeholder-color': string;
27
- 'input-border-radius': string;
28
- 'primary-text-color': string;
29
- 'secondary-text-color': string;
30
- };
31
- colors: {
32
- primary: string;
33
- secondary: string;
34
- error: string;
35
- accent: string;
36
- };
37
- logo: { 'logo-url'?: string };
38
- typography: {
39
- fontFamilies: [FontFamily, FontFamily];
40
- variants: {
41
- h1: TypographyVariant;
42
- h2: TypographyVariant;
43
- h3: TypographyVariant;
44
- subtitle1: TypographyVariant;
45
- subtitle2: TypographyVariant;
46
- body1: TypographyVariant;
47
- body2: TypographyVariant;
48
- input: TypographyShallowVariant;
49
- button: TypographyShallowVariant;
50
- };
51
- };
52
- };
53
-
54
- export type ColorNames = keyof Theme['colors'];
55
-
56
- export type OptionalColorsVars = keyof typeof optionalColors;
package/src/types.ts DELETED
@@ -1,52 +0,0 @@
1
- type KebabCase<S extends string> = S extends `${infer First}${infer Rest}`
2
- ? Rest extends Uncapitalize<Rest>
3
- ? `${Uncapitalize<First>}${KebabCase<Rest>}`
4
- : `${Uncapitalize<First>}-${KebabCase<Rest>}`
5
- : S;
6
-
7
- export type ExcludeMatchingProperties<F, S extends Partial<F>> = Pick<
8
- F,
9
- { [K in keyof F]: S[K] extends F[K] ? never : K }[keyof F]
10
- >;
11
-
12
- export type CustomInputEvent = InputEvent & {
13
- target: HTMLSelectElement;
14
- };
15
-
16
- export type ComponentSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
17
-
18
- export type InputType = 'number' | 'email' | 'text' | 'password';
19
-
20
- export type TextAlign = 'left' | 'right' | 'center';
21
-
22
- export type FlexAlignment = 'start' | 'center' | 'end';
23
-
24
- export type HTMLInputAttrs = Omit<JSX.IntrinsicElements['input'], 'size'>;
25
-
26
- export type DescopeInputExtraProps = {
27
- 'full-width'?: boolean;
28
- bordered?: boolean;
29
- label?: string;
30
- placeholder?: string;
31
- size?: ComponentSize;
32
- 'helper-text'?: string;
33
- 'data-errormessage-pattern-mismatch'?: string;
34
- 'data-errormessage-value-missing'?: string;
35
- };
36
-
37
- export type DescopeInputProps = HTMLInputAttrs & DescopeInputExtraProps;
38
-
39
- export type PropsToAttrs<R extends Record<string, any>> = {
40
- [K in keyof R as KebabCase<K & string>]: R[K];
41
- };
42
-
43
- export type TypographyVariants =
44
- | 'h1'
45
- | 'h2'
46
- | 'h3'
47
- | 'subtitle1'
48
- | 'subtitle2'
49
- | 'body1'
50
- | 'body2';
51
-
52
- export type Mode = 'primary' | 'secondary' | 'error' | 'success';
package/src/utils.tsx DELETED
@@ -1,69 +0,0 @@
1
- import React, { useCallback, useImperativeHandle, useRef } from 'react';
2
- import { ExcludeMatchingProperties } from './types';
3
-
4
- // eslint-disable-next-line import/exports-last
5
- export const withFixedProps = <P extends {}, F extends Partial<P>>(
6
- Component: React.ComponentType<P>,
7
- fixedProps: F
8
- ) =>
9
- React.forwardRef<HTMLElement, ExcludeMatchingProperties<P, F>>(
10
- (props, ref) => {
11
- const allProps = { ...props, ...fixedProps } as unknown as P;
12
- return <Component {...allProps} ref={ref} />;
13
- }
14
- );
15
-
16
- const getFnBodyStr = (fn: Function) =>
17
- fn.toString().match(/[^{]+\{([\s\S]*)\}$/)[1];
18
-
19
- type CustomScriptFn = () => void;
20
-
21
- const hash = (s: string) =>
22
- // eslint-disable-next-line no-return-assign, no-bitwise, no-param-reassign
23
- s.split('').reduce((a, b) => (a = (a << 5) - a + b.charCodeAt(0)) & a, 0);
24
-
25
- /**
26
- * This HOC allows us to bind a script (in vanilla JS) to the component and consume it in 2 different ways
27
- * 1. By rendering the component using React
28
- * 2. By adding a script tag next to the dom element that is later parsed and run by the web-component
29
- */
30
- export const withCustomScripts = <T extends {}>(
31
- Component: React.ComponentType<T>,
32
- ...nonArrowFns: CustomScriptFn[]
33
- ) =>
34
- React.forwardRef<HTMLElement, T>((props, ref) => {
35
- const internalRef = useRef<HTMLElement>();
36
-
37
- const refFn = useCallback((recRef: HTMLElement) => {
38
- if (!recRef) return;
39
-
40
- internalRef.current = recRef;
41
- // when in React, the context is taken from the root node,
42
- // when in web-component, the context is injected to the function
43
- nonArrowFns.forEach((fn) =>
44
- fn.bind(recRef, (recRef?.getRootNode() as any)?.context)()
45
- );
46
- }, []);
47
-
48
- useImperativeHandle(ref, () => internalRef.current);
49
-
50
- return (
51
- <>
52
- <Component {...props} ref={refFn} />
53
- {global?.process?.env?.SSR &&
54
- nonArrowFns.map((fn, i) => {
55
- const fnStr = getFnBodyStr(fn);
56
- return (
57
- // eslint-disable-next-line react/no-array-index-key
58
- <script
59
- // eslint-disable-next-line react/no-array-index-key
60
- key={i}
61
- data-id={hash(fnStr)}
62
- // eslint-disable-next-line react/no-danger
63
- dangerouslySetInnerHTML={{ __html: fnStr }}
64
- />
65
- );
66
- })}
67
- </>
68
- );
69
- });
@@ -1,37 +0,0 @@
1
- import React from 'react';
2
- import { Boolean as Bool } from '../src';
3
-
4
- export default {
5
- title: 'WCUI/Boolean',
6
- component: Bool,
7
- argTypes: {
8
- type: {
9
- options: ['checkbox', 'switch'],
10
- control: { type: 'radio' }
11
- }
12
- }
13
- };
14
-
15
- const BooleanTemplate = (args) => (
16
- <form
17
- onSubmit={(e) => {
18
- e.preventDefault();
19
- }}
20
- style={{ display: 'flex', flexWrap: 'wrap' }}
21
- >
22
- <Bool {...args} />
23
-
24
- <div>
25
- <button type="submit">Submit</button>
26
- </div>
27
- </form>
28
- );
29
-
30
- export const Boolean = BooleanTemplate.bind({});
31
- Boolean.args = {
32
- label: 'Boolean Input Label',
33
- size: 'md',
34
- 'full-width': false,
35
- required: true,
36
- type: 'checkbox'
37
- };
@@ -1,71 +0,0 @@
1
- import React from 'react';
2
- import { Button } from '../src';
3
- import * as icons from '../src/icons';
4
- export default {
5
- title: 'WCUI/Button',
6
- component: Button,
7
- parameters: {
8
- controls: { expanded: true }
9
- },
10
- argTypes: {
11
- variant: {
12
- options: ['contained', 'outline', 'link'],
13
- control: { type: 'radio' }
14
- },
15
- color: {
16
- options: ['primary', 'secondary', 'success', 'error'],
17
- control: { type: 'radio' }
18
- },
19
- size: {
20
- options: ['xs', 'sm', 'md', 'lg', 'xl'],
21
- control: { type: 'radio' }
22
- },
23
- startIcon: {
24
- options: Object.keys(icons),
25
- control: { type: 'select' }
26
- }
27
- }
28
- };
29
-
30
- const StandardTemplate = (args) => <Button {...args} />;
31
- export const Standard = StandardTemplate.bind({});
32
- Standard.args = {
33
- variant: 'contained',
34
- children: 'Button',
35
- color: 'primary',
36
- loading: false,
37
- size: 'md',
38
- 'full-width': false,
39
- startIconColorText: true
40
- };
41
-
42
- const ProvidersTemplate = (args) => (
43
- <div className="flex">
44
- <div
45
- className="flex"
46
- style={{ gap: '0.5rem', display: 'flex', flexWrap: 'wrap' }}
47
- >
48
- <Button {...args} startIcon="facebook" />
49
- <Button {...args} startIcon="google" />
50
- <Button {...args} startIcon="microsoft" />
51
- <Button {...args} startIcon="github" />
52
- <Button {...args} startIcon="gitlab" />
53
- <Button {...args} startIcon="apple" />
54
- <Button {...args} startIcon="discord" />
55
- <Button {...args} startIcon="linkedin" />
56
- <Button {...args} startIcon="sso" />
57
- <Button {...args} startIcon="fingerprint" />
58
- <Button {...args} startIcon="passkey" />
59
- </div>
60
- </div>
61
- );
62
- export const Providers = ProvidersTemplate.bind({});
63
- Providers.args = {
64
- variant: 'contained',
65
- children: '',
66
- color: 'primary',
67
- loading: false,
68
- size: 'md',
69
- 'full-width': false,
70
- startIconColorText: true
71
- };
@@ -1,29 +0,0 @@
1
- import React from 'react';
2
- import { Checkbox } from '../src';
3
-
4
- export default {
5
- title: 'WCUI/Checkbox',
6
- component: Checkbox
7
- };
8
-
9
- const CheckboxTemplate = (args) => (
10
- <form
11
- onSubmit={(e) => {
12
- e.preventDefault();
13
- }}
14
- style={{ display: 'flex', flexWrap: 'wrap', gap: '0.5rem' }}
15
- >
16
- <Checkbox {...args} />
17
- <div>
18
- <button type="submit">Submit</button>
19
- </div>
20
- </form>
21
- );
22
-
23
- export const Check = CheckboxTemplate.bind({});
24
- Check.args = {
25
- label: 'Checkbox Label',
26
- size: 'sm',
27
- 'full-width': false,
28
- required: true
29
- };