@xqmsg/ui-core 0.22.4 → 0.23.1-rc.0

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 (40) hide show
  1. package/dist/components/form/FormTypes.d.ts +2 -0
  2. package/dist/components/input/StackedCheckbox/StackedCheckbox.d.ts +3 -2
  3. package/dist/components/input/StackedInput/StackedInput.d.ts +1 -0
  4. package/dist/components/input/StackedPilledInput/index.d.ts +2 -0
  5. package/dist/components/input/StackedTextarea/StackedTextarea.d.ts +3 -0
  6. package/dist/components/input/components/token/index.d.ts +1 -0
  7. package/dist/components/input/index.d.ts +3 -2
  8. package/dist/components/select/index.d.ts +27 -0
  9. package/dist/index.d.ts +1 -0
  10. package/dist/theme/components/button.d.ts +116 -0
  11. package/dist/theme/components/checkbox.d.ts +28 -0
  12. package/dist/theme/components/input.d.ts +12 -0
  13. package/dist/theme/components/select.d.ts +12 -0
  14. package/dist/theme/components/textarea.d.ts +66 -0
  15. package/dist/ui-core.cjs.development.js +328 -53
  16. package/dist/ui-core.cjs.development.js.map +1 -1
  17. package/dist/ui-core.cjs.production.min.js +1 -1
  18. package/dist/ui-core.cjs.production.min.js.map +1 -1
  19. package/dist/ui-core.esm.js +330 -56
  20. package/dist/ui-core.esm.js.map +1 -1
  21. package/package.json +1 -1
  22. package/src/components/button/Button.stories.tsx +92 -27
  23. package/src/components/form/FormTypes.ts +2 -0
  24. package/src/components/form/section/index.tsx +2 -0
  25. package/src/components/input/Input.stories.tsx +66 -0
  26. package/src/components/input/StackedCheckbox/StackedCheckbox.tsx +12 -4
  27. package/src/components/input/StackedInput/StackedInput.tsx +5 -0
  28. package/src/components/input/StackedPilledInput/index.tsx +286 -266
  29. package/src/components/input/StackedTextarea/StackedTextarea.tsx +29 -5
  30. package/src/components/input/components/dropdown/index.tsx +1 -1
  31. package/src/components/input/components/token/index.tsx +6 -5
  32. package/src/components/input/index.tsx +22 -9
  33. package/src/components/select/index.tsx +184 -0
  34. package/src/components/tabs/TabsWrapper.stories.tsx +1 -1
  35. package/src/index.tsx +3 -0
  36. package/src/theme/components/button.ts +67 -0
  37. package/src/theme/components/checkbox.ts +25 -0
  38. package/src/theme/components/input.ts +15 -1
  39. package/src/theme/components/textarea.ts +20 -0
  40. package/src/theme/customXQChakraTheme.ts +2 -0
@@ -7,19 +7,20 @@ import colors from '../../../../../src/theme/foundations/colors';
7
7
  export interface TokenProps {
8
8
  label: any;
9
9
  onDelete: any;
10
+ isMobile?: boolean;
10
11
  }
11
12
 
12
13
  // For v1 we are truncating the label at 15 characters to avoid overflow
13
- const Token: React.FC<TokenProps> = ({ label, onDelete }) => {
14
+ const Token: React.FC<TokenProps> = ({ label, onDelete, isMobile = false }) => {
14
15
  return (
15
16
  <Flex
16
17
  key={label}
17
- borderRadius="full"
18
+ borderRadius={'full'}
18
19
  backgroundColor="#7676801F"
19
20
  alignItems="center"
20
21
  width="fit-content"
21
22
  w="auto"
22
- h="16px"
23
+ h={isMobile ? '18px' : '16px'}
23
24
  pl="6px"
24
25
  pr="2px"
25
26
  py="2px"
@@ -28,7 +29,7 @@ const Token: React.FC<TokenProps> = ({ label, onDelete }) => {
28
29
  <Text
29
30
  whiteSpace="nowrap"
30
31
  color={colors.label.primary.light}
31
- fontSize="13px"
32
+ fontSize={isMobile ? '17px' : '13px'}
32
33
  pr="4px"
33
34
  >
34
35
  {truncate(label.trim(), {
@@ -36,7 +37,7 @@ const Token: React.FC<TokenProps> = ({ label, onDelete }) => {
36
37
  omission: '...',
37
38
  })}
38
39
  </Text>
39
- <Close boxSize="11px" onClick={onDelete} />
40
+ <Close boxSize={isMobile ? '17px' : '11px'} onClick={onDelete} />
40
41
  </Flex>
41
42
  );
42
43
  };
@@ -38,7 +38,7 @@ export interface InputProps<T extends FieldValues> extends ValidationProps {
38
38
  fullOptions?: FieldOptions;
39
39
  maxLength?: number;
40
40
  helperText?: React.ReactNode;
41
- control: Control<T, any>;
41
+ control: Control<T, unknown>;
42
42
  onChange?: (value?: string) => void;
43
43
  disabled?: boolean;
44
44
  tooltipText?: string;
@@ -48,6 +48,7 @@ export interface InputProps<T extends FieldValues> extends ValidationProps {
48
48
  leftElement?: React.ReactNode;
49
49
  allowDefault?: boolean;
50
50
  rightElement?: React.ReactNode;
51
+ variant: string;
51
52
  }
52
53
 
53
54
  /**
@@ -75,6 +76,7 @@ export function Input<T extends FieldValues>({
75
76
  rightElement,
76
77
  leftElement,
77
78
  allowDefault,
79
+ variant = 'default',
78
80
  onChange,
79
81
  setValue,
80
82
  setError,
@@ -107,6 +109,7 @@ export function Input<T extends FieldValues>({
107
109
  defaultValue={defaultValue}
108
110
  value={value}
109
111
  allowDefault={allowDefault}
112
+ variant={variant}
110
113
  />
111
114
  );
112
115
  case 'radio':
@@ -161,6 +164,7 @@ export function Input<T extends FieldValues>({
161
164
  ref={ref}
162
165
  disabled={disabled}
163
166
  value={value}
167
+ variant={variant}
164
168
  />
165
169
  );
166
170
  case 'checkbox':
@@ -177,6 +181,7 @@ export function Input<T extends FieldValues>({
177
181
  defaultValue={defaultValue}
178
182
  label={label as string}
179
183
  disabled={disabled}
184
+ variant={variant}
180
185
  />
181
186
  );
182
187
  case 'multi-select':
@@ -218,6 +223,7 @@ export function Input<T extends FieldValues>({
218
223
  clearErrors={clearErrors as UseFormClearErrors<FieldValues>}
219
224
  control={control as Control<FieldValues, any>}
220
225
  maxLength={maxLength}
226
+ variant={variant}
221
227
  />
222
228
  );
223
229
  case 'switch':
@@ -238,6 +244,7 @@ export function Input<T extends FieldValues>({
238
244
  return null;
239
245
  }
240
246
  };
247
+ const nonLabeledInputs = ['checkbox'];
241
248
 
242
249
  return (
243
250
  <Controller
@@ -252,18 +259,24 @@ export function Input<T extends FieldValues>({
252
259
  isInvalid={isInvalid}
253
260
  position="relative"
254
261
  py={
255
- (inputType !== 'checkbox' && label) || helperText || isInvalid
262
+ (!nonLabeledInputs.includes(inputType) &&
263
+ variant !== 'mobile' &&
264
+ label) ||
265
+ helperText ||
266
+ isInvalid
256
267
  ? 5
257
268
  : 0
258
269
  }
259
270
  >
260
- {label && inputType !== 'checkbox' && (
261
- <Label
262
- tooltipText={tooltipText}
263
- label={label}
264
- isRequired={isRequired}
265
- />
266
- )}
271
+ {label &&
272
+ !nonLabeledInputs.includes(inputType) &&
273
+ variant !== 'mobile' && (
274
+ <Label
275
+ tooltipText={tooltipText}
276
+ label={label}
277
+ isRequired={isRequired}
278
+ />
279
+ )}
267
280
  {selectedInputField(
268
281
  onChange ? onChange : fieldOnChange,
269
282
  onBlur,
@@ -0,0 +1,184 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { Box, Flex, Select } from '@chakra-ui/react';
3
+ import {
4
+ FormControl,
5
+ FormErrorMessage,
6
+ FormHelperText,
7
+ } from '@chakra-ui/react';
8
+ import {
9
+ Control,
10
+ Controller,
11
+ FieldValues,
12
+ UseFormClearErrors,
13
+ UseFormSetError,
14
+ UseFormSetValue,
15
+ } from 'react-hook-form';
16
+ import { FieldOptions, ValidationProps } from 'src/components/input/InputTypes';
17
+
18
+ export interface SelectNativeProps<T extends FieldValues>
19
+ extends ValidationProps {
20
+ isRequired: boolean;
21
+
22
+ name: string;
23
+ ariaLabel: string;
24
+ placeholder?: string;
25
+ defaultValue?: string;
26
+ label?: string;
27
+ className?: string;
28
+ options?: FieldOptions;
29
+ fullOptions?: FieldOptions;
30
+ helperText?: React.ReactNode;
31
+ control: Control<T, unknown>;
32
+ onChange?: (value?: string) => void;
33
+ disabled?: boolean;
34
+ tooltipText?: string;
35
+ setValue: UseFormSetValue<T>;
36
+ setError: UseFormSetError<T>;
37
+ clearErrors: UseFormClearErrors<T>;
38
+ allowDefault?: boolean;
39
+ }
40
+
41
+ /**
42
+ * A functional React component utilized to render the `SelectNative` component.
43
+ */
44
+ export const SelectNative: React.FC<SelectNativeProps<HTMLSelectElement>> = ({
45
+ label,
46
+ ariaLabel,
47
+ className,
48
+ placeholder,
49
+ name,
50
+ helperText,
51
+ options,
52
+ tooltipText,
53
+ isInvalid,
54
+ errorText,
55
+ isRequired,
56
+ defaultValue,
57
+ fullOptions,
58
+ control,
59
+ disabled,
60
+ onChange,
61
+ setValue,
62
+ setError,
63
+ clearErrors,
64
+ ...props
65
+ }) => {
66
+ // const [selectedOption, setSelectedOption] = useState(
67
+ // options.find(option => option.value === value)?.label ?? ''
68
+ // );
69
+
70
+ const [selectedOption, setSelectedOption] = useState(
71
+ options ? options[0] ?? '' : ''
72
+ );
73
+
74
+ //const [selectedOption, setSelectedOption] = useState(null);
75
+
76
+ // useEffect(() => {
77
+ // if (defaultValue) {
78
+ // setSelectedOption(defaultValue);
79
+ // }
80
+ // setSelectedOption(
81
+ // (fullOptions || options).find(option => option.value === value)?.label ??
82
+ // ''
83
+ // );
84
+ // }, [fullOptions, value]);
85
+
86
+ const handleOnSelectItem = (selectedValue: string) => {
87
+ console.log(selectedValue);
88
+ const selectedOption = options?.find(
89
+ ({ value: val }) => selectedValue === val
90
+ );
91
+ console.log(selectedValue);
92
+ setValue(name as string, selectedValue);
93
+ if (selectedOption) {
94
+ if (onChange) {
95
+ onChange(selectedOption.value);
96
+ }
97
+ setSelectedOption(selectedOption);
98
+ setValue(name as string, selectedOption.value);
99
+ }
100
+ };
101
+ console.log(selectedOption);
102
+
103
+ useEffect(() => {
104
+ if (defaultValue) {
105
+ handleOnSelectItem(defaultValue);
106
+ }
107
+ // eslint-disable-next-line react-hooks/exhaustive-deps
108
+ }, [defaultValue]);
109
+ return (
110
+ <Controller
111
+ control={control}
112
+ name={name}
113
+ // defaultValue={defaultValue as PathValue<T, Path<T>>}
114
+ rules={{ required: isRequired }}
115
+ /** @ts-ignore: issues with implicit */
116
+ render={({ field: { onBlur, onChange: fieldOnChange, ref, value } }) => (
117
+ <FormControl id={name} isInvalid={isInvalid} position="relative" py={0}>
118
+ {/* {label &&
119
+ !nonLabeledInputs.includes(inputType) &&
120
+ variant !== 'mobile' && (
121
+ <Label
122
+ tooltipText={tooltipText}
123
+ label={label}
124
+ isRequired={isRequired}
125
+ />
126
+ )} */}
127
+ <Box //ref={dropdownRef}
128
+ position="relative"
129
+ >
130
+ <Flex
131
+ flexDirection="column"
132
+ //ref={dropdownRef}
133
+ //scrollMargin="15px"
134
+ border="0"
135
+ mt="3px"
136
+ //maxH="240px"
137
+ overflowY="auto"
138
+ width="fit-content"
139
+ minWidth="100%"
140
+ zIndex={100}
141
+ tabIndex={-2000}
142
+ borderTop="0.5px solid #9999991A"
143
+ >
144
+ <Select
145
+ {...props}
146
+ required={isRequired}
147
+ ref={ref}
148
+ //value={selectedOption?.value ?? value}
149
+ // textShadow={`0 0 0 ${colors.label.primary.light}`}
150
+ disabled={disabled ?? false}
151
+ onChange={e => handleOnSelectItem(e.target.value)}
152
+ // onKeyDown={handleOnKeyDown}
153
+ style={{
154
+ cursor: 'pointer',
155
+ color: 'var(--chakra-colors-blue-500)',
156
+ height: '48px',
157
+ fontSize: '17px',
158
+ lineHeight: '20px',
159
+ fontWeight: 400,
160
+ padding: '12px 16px 12px 0px',
161
+ borderRadius: 0,
162
+ }}
163
+ >
164
+ {options &&
165
+ options.map(i => {
166
+ return (
167
+ <option value={i.value} key={i.sortValue}>
168
+ {i.label}
169
+ </option>
170
+ );
171
+ })}
172
+ </Select>
173
+ </Flex>
174
+ </Box>
175
+ {isInvalid ? (
176
+ <FormErrorMessage>{errorText}</FormErrorMessage>
177
+ ) : (
178
+ helperText && <FormHelperText>{helperText}</FormHelperText>
179
+ )}
180
+ </FormControl>
181
+ )}
182
+ />
183
+ );
184
+ };
@@ -3,7 +3,7 @@ import { Meta, Story } from '@storybook/react';
3
3
  import { Text } from '../text';
4
4
  import { Table, TableProps } from '../table';
5
5
  import { TableBody, TableHeaders } from '../table/TableTypes';
6
- import { useArgs, useMemo, useState } from '@storybook/addons';
6
+ import { useMemo, useState } from '@storybook/addons';
7
7
  import { TabsWrapper, TabsWrapperProps } from '.';
8
8
 
9
9
  const tableColumns = ['foo', 'bar'];
package/src/index.tsx CHANGED
@@ -35,6 +35,9 @@ export * from './components/icons';
35
35
  // Input
36
36
  export * from './components/input';
37
37
 
38
+ // Select
39
+ export { SelectNative } from './components/select';
40
+
38
41
  // Layout
39
42
  export * from './components/layout';
40
43
 
@@ -79,10 +79,77 @@ const variantTertiary = () => {
79
79
  };
80
80
  };
81
81
 
82
+ const variantPrimaryFlat = () => {
83
+ return {
84
+ ...baseStyle,
85
+ bg: colors.fill.action,
86
+ bgGradient: null,
87
+ minWidth: '172.5px',
88
+ padding: '10px 16px',
89
+ borderRadius: '8px',
90
+ border: '0.5px',
91
+ gap: '8px',
92
+ height: '44px',
93
+ margin: '8px',
94
+ fontSize: '17px',
95
+ fontWeight: '500',
96
+ lineHeight: '24px',
97
+ letterSpacing: '0.02em',
98
+ textAlign: 'center',
99
+ boxShadow: '0px 0.5px 1px 0.5px #0000001A',
100
+ };
101
+ };
102
+
103
+ const variantSecondaryFlat = () => {
104
+ return {
105
+ ...variantPrimaryFlat(),
106
+ fontWeight: '400',
107
+ color: colors.black,
108
+ bg: colors.label.primary.dark,
109
+ _hover: {
110
+ bg: colors.label.primary.dark,
111
+ },
112
+ _active: {
113
+ color: colors.black,
114
+ bg: colors.label.primary.dark,
115
+ bgGradient: colors.fill.light.quaternary,
116
+ },
117
+ _focus: {
118
+ bg: colors.label.primary.dark,
119
+ },
120
+ };
121
+ };
122
+ const variantTertiaryFlat = () => {
123
+ return {
124
+ ...variantPrimaryFlat(),
125
+ fontWeight: '400',
126
+ color: colors.label.primary.dark,
127
+ bg: colors.blur.quaternary.dark,
128
+ _hover: {
129
+ bg: colors.blur.quaternary.dark,
130
+ },
131
+ _active: {
132
+ color: colors.label.primary.dark,
133
+ bg: colors.blur.tertiary.dark,
134
+ },
135
+ _focus: {
136
+ color: colors.label.primary.dark,
137
+ bg: colors.blur.quaternary.dark,
138
+ },
139
+ _disabled: {
140
+ backgroundColor: colors.blur.quaternary.dark,
141
+ color: colors.blur.tertiary.dark,
142
+ },
143
+ };
144
+ };
145
+
82
146
  const variants = {
83
147
  primary: variantPrimary(),
84
148
  secondary: variantSecondary(),
85
149
  tertiary: variantTertiary(),
150
+ 'flat-primary': variantPrimaryFlat(),
151
+ 'flat-secondary': variantSecondaryFlat(),
152
+ 'flat-tertiary': variantTertiaryFlat(),
86
153
  };
87
154
 
88
155
  const defaultProps = {
@@ -0,0 +1,25 @@
1
+ import { checkboxAnatomy } from '@chakra-ui/anatomy';
2
+ import { createMultiStyleConfigHelpers } from '@chakra-ui/react';
3
+
4
+ const {
5
+ definePartsStyle,
6
+ defineMultiStyleConfig,
7
+ } = createMultiStyleConfigHelpers(checkboxAnatomy.keys);
8
+
9
+ const roundedCheckbox = definePartsStyle({
10
+ control: {
11
+ borderRadius: 50,
12
+ padding: 3,
13
+ },
14
+ label: {
15
+ fontSize: '17px',
16
+ },
17
+ });
18
+
19
+ const variants = {
20
+ mobile: roundedCheckbox,
21
+ };
22
+
23
+ export default defineMultiStyleConfig({
24
+ variants,
25
+ });
@@ -29,7 +29,21 @@ const baseStyle = {
29
29
  },
30
30
  };
31
31
 
32
- const variants = { default: baseStyle };
32
+ const mobileInputs = {
33
+ ...baseStyle,
34
+ field: {
35
+ fontSize: '17px',
36
+ border: 'none',
37
+ py: '14px',
38
+ px: '16px',
39
+ cursor: 'pointer',
40
+ lineHeight: '21px',
41
+ fontWeight: 400,
42
+ borderRadius: 0,
43
+ },
44
+ };
45
+
46
+ const variants = { default: baseStyle, mobile: mobileInputs };
33
47
 
34
48
  const defaultProps = {
35
49
  variant: 'default',
@@ -1,4 +1,5 @@
1
1
  import Input from './input';
2
+ import { defineStyle } from '@chakra-ui/react';
2
3
 
3
4
  const baseStyle = {
4
5
  ...Input.baseStyle.field,
@@ -11,11 +12,30 @@ const baseStyle = {
11
12
  lineHeight: 'short',
12
13
  };
13
14
 
15
+ const mobileInputs = defineStyle({
16
+ ...baseStyle,
17
+ ...Input.variants.mobile.field,
18
+ border: 'none',
19
+ borderRadius: 0,
20
+ paddingY: '14px',
21
+ paddingX: '16px',
22
+ padding: '14px 16px',
23
+ cursor: 'pointer',
24
+ lineHeight: '21px',
25
+ fontWeight: 400,
26
+ resize: 'none',
27
+ overflowY: 'auto',
28
+ fontSize: '17px',
29
+ });
30
+
31
+ const variants = { default: baseStyle, mobile: mobileInputs };
32
+
14
33
  const defaultProps = {
15
34
  variant: 'default',
16
35
  };
17
36
 
18
37
  export default {
19
38
  baseStyle,
39
+ variants,
20
40
  defaultProps,
21
41
  };
@@ -6,6 +6,7 @@ import typography from './foundations/typography';
6
6
  import Alert from './components/alert';
7
7
  import Badge from './components/badge';
8
8
  import Button from './components/button';
9
+ import Checkbox from './components/checkbox';
9
10
  import Code from './components/code';
10
11
  import Form from './components/form';
11
12
  import FormError from './components/form-error';
@@ -30,6 +31,7 @@ const customXQChakraTheme = extendTheme({
30
31
  Alert,
31
32
  Badge,
32
33
  Button,
34
+ Checkbox,
33
35
  Code,
34
36
  Form,
35
37
  FormError,