@xqmsg/ui-core 0.12.0 → 0.14.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 (38) hide show
  1. package/dist/components/form/Form.stories.d.ts +1 -1
  2. package/dist/components/form/hooks/useFormHandler.d.ts +1 -1
  3. package/dist/components/input/Input.stories.d.ts +1 -0
  4. package/dist/components/input/StackedSelect/StackedSelect.d.ts +1 -0
  5. package/dist/components/input/index.d.ts +3 -3
  6. package/dist/index.d.ts +1 -0
  7. package/dist/theme/components/form-error.d.ts +2 -0
  8. package/dist/theme/components/form.d.ts +2 -0
  9. package/dist/theme/components/table.d.ts +4 -1
  10. package/dist/theme/foundations/colors.d.ts +1 -1
  11. package/dist/ui-core.cjs.development.js +127 -95
  12. package/dist/ui-core.cjs.development.js.map +1 -1
  13. package/dist/ui-core.cjs.production.min.js +1 -1
  14. package/dist/ui-core.cjs.production.min.js.map +1 -1
  15. package/dist/ui-core.esm.js +238 -207
  16. package/dist/ui-core.esm.js.map +1 -1
  17. package/package.json +8 -7
  18. package/src/components/banner/index.tsx +1 -1
  19. package/src/components/form/Form.stories.tsx +4 -4
  20. package/src/components/form/hooks/useFormHandler.tsx +2 -2
  21. package/src/components/form/section/FormSection.stories.tsx +1 -1
  22. package/src/components/form/section/index.tsx +4 -3
  23. package/src/components/input/Input.stories.tsx +9 -1
  24. package/src/components/input/StackedPilledInput/index.tsx +12 -1
  25. package/src/components/input/StackedSelect/StackedSelect.tsx +21 -4
  26. package/src/components/input/StackedSwitch/index.tsx +0 -2
  27. package/src/components/input/components/dropdown/index.tsx +1 -1
  28. package/src/components/input/components/label/index.tsx +1 -1
  29. package/src/components/input/components/token/index.tsx +2 -2
  30. package/src/components/input/index.tsx +8 -9
  31. package/src/components/table/components/text/index.tsx +1 -1
  32. package/src/components/table/index.tsx +2 -1
  33. package/src/index.tsx +3 -0
  34. package/src/theme/components/form-error.ts +2 -0
  35. package/src/theme/components/form.ts +2 -0
  36. package/src/theme/components/table.ts +5 -5
  37. package/src/theme/foundations/colors.ts +1 -1
  38. package/src/theme/provider/index.tsx +6 -1
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.12.0",
2
+ "version": "0.14.0",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -25,9 +25,6 @@
25
25
  "release:minor": "changelog -m && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version minor && git push origin && git push origin --tags",
26
26
  "release:patch": "changelog -p && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version patch && git push origin && git push origin --tags"
27
27
  },
28
- "peerDependencies": {
29
- "react": ">=16"
30
- },
31
28
  "husky": {
32
29
  "hooks": {
33
30
  "pre-commit": "tsdx lint"
@@ -56,6 +53,8 @@
56
53
  "@babel/core": "^7.18.13",
57
54
  "@babel/preset-env": "^7.19.0",
58
55
  "@babel/preset-react": "^7.18.6",
56
+ "@rollup/plugin-image": "^3.0.1",
57
+ "@rollup/plugin-url": "^8.0.1",
59
58
  "@size-limit/preset-small-lib": "^8.0.1",
60
59
  "@storybook/addon-essentials": "^6.5.10",
61
60
  "@storybook/addon-info": "^5.3.21",
@@ -64,6 +63,7 @@
64
63
  "@storybook/builder-webpack5": "^6.5.10",
65
64
  "@storybook/manager-webpack5": "^6.5.10",
66
65
  "@storybook/react": "^6.5.10",
66
+ "@svgr/rollup": "^6.5.1",
67
67
  "@svgr/webpack": "^6.3.1",
68
68
  "@types/react": "^18.0.18",
69
69
  "@types/react-dom": "^18.0.6",
@@ -71,15 +71,18 @@
71
71
  "@typescript-eslint/parser": "^5.36.2",
72
72
  "babel-loader": "8.1.0",
73
73
  "babel-preset-react-app": "^9.1.2",
74
+ "generate-changelog": "^1.8.0",
74
75
  "husky": "^8.0.1",
76
+ "react": "^18.0.0",
77
+ "react-dom": "^18.0.0",
75
78
  "rollup-plugin-cjs-es": "^1.1.0",
79
+ "rollup-plugin-image-files": "^1.4.2",
76
80
  "rollup-plugin-svg": "^2.0.0",
77
81
  "size-limit": "^8.0.1",
78
82
  "tsconfig-paths-webpack-plugin": "^4.0.0",
79
83
  "tsdx": "^0.14.1",
80
84
  "tslib": "^2.4.0",
81
85
  "typescript": "^4.8.2",
82
- "generate-changelog": "^1.8.0",
83
86
  "yalc": "^1.0.0-pre.53"
84
87
  },
85
88
  "dependencies": {
@@ -98,8 +101,6 @@
98
101
  "@hookform/resolvers": "^2.9.7",
99
102
  "axios": "^0.27.2",
100
103
  "framer-motion": "6.3.0",
101
- "react": "^18.0.0",
102
- "react-dom": "^18.0.0",
103
104
  "react-hook-form": "^7.34.0",
104
105
  "react-icons": "^4.4.0",
105
106
  "react-is": "^18.2.0",
@@ -11,7 +11,7 @@ import ErrorIcon from './assets/svg/error.svg';
11
11
  import PositiveIcon from './assets/svg/positive.svg';
12
12
  import NeutralIcon from './assets/svg/neutral.svg';
13
13
  import WarningIcon from './assets/svg/warning.svg';
14
- import colors from 'src/theme/foundations/colors';
14
+ import colors from '../../../src/theme/foundations/colors';
15
15
 
16
16
  export type BannerVariant = 'positive' | 'warning' | 'error' | 'neutral';
17
17
 
@@ -2,10 +2,10 @@ import React from 'react';
2
2
  import { Meta, Story } from '@storybook/react';
3
3
  import * as Yup from 'yup';
4
4
 
5
- import { useFormHandler } from 'src/components/form/hooks/useFormHandler';
6
- import { Form, FormProps } from 'src/components/form';
7
- import { FormSection } from 'src/components/form/section';
8
- import { formSectionStoryArgs } from 'src/components/form/section/FormSection.stories';
5
+ import { useFormHandler } from '../../../src/components/form/hooks/useFormHandler';
6
+ import { Form, FormProps } from '../../../src/components/form';
7
+ import { FormSection } from '../../../src/components/form/section';
8
+ import { formSectionStoryArgs } from '../../../src/components/form/section/FormSection.stories';
9
9
  import { FormStructure } from './FormTypes';
10
10
 
11
11
  const meta: Meta<FormProps<StoryFormSchema>> = {
@@ -12,8 +12,8 @@ import * as Yup from 'yup';
12
12
  import {
13
13
  ErrorResponse,
14
14
  formatErrorResponse,
15
- } from 'src/components/form/utils/formErrors';
16
- import useDeepEffect from 'src/hooks/useDeepEffect';
15
+ } from '../../../../src/components/form/utils/formErrors';
16
+ import useDeepEffect from '../../../../src/hooks/useDeepEffect';
17
17
 
18
18
  // Default Yup error message for required fields
19
19
  Yup.setLocale({
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { Meta, Story } from '@storybook/react';
3
3
  import * as Yup from 'yup';
4
4
 
5
- import { useFormHandler } from 'src/components/form/hooks/useFormHandler';
5
+ import { useFormHandler } from '../../../../src/components/form/hooks/useFormHandler';
6
6
 
7
7
  import { FormSection, FormSectionProps } from '.';
8
8
  import { FormStructure } from '../FormTypes';
@@ -1,6 +1,6 @@
1
1
  import { SimpleGrid } from '@chakra-ui/react';
2
2
  import React from 'react';
3
- import { Control, FieldValues, UseFormReturn } from 'react-hook-form';
3
+ import { FieldValues, UseFormReturn } from 'react-hook-form';
4
4
  import { Input } from '../../input';
5
5
  import { FormInput, FormStructure } from '../FormTypes';
6
6
 
@@ -61,8 +61,8 @@ export function FormSection<
61
61
  disabled,
62
62
  defaultValue,
63
63
  }: FormInput) => (
64
- <Input
65
- control={form.control as Control<FieldValues, any>}
64
+ <Input<U>
65
+ control={form.control}
66
66
  label={label}
67
67
  inputType={inputType}
68
68
  name={name}
@@ -73,6 +73,7 @@ export function FormSection<
73
73
  maxLength={maxLength}
74
74
  isInvalid={!!form.formState.errors[name]}
75
75
  defaultValue={defaultValue}
76
+ setValue={form.setValue}
76
77
  />
77
78
  )
78
79
  )}
@@ -5,7 +5,6 @@ import { Input, InputProps } from '.';
5
5
  import { useFormHandler } from '../form/hooks/useFormHandler';
6
6
  import * as Yup from 'yup';
7
7
  import { Form } from '../form';
8
- import { useMemo } from '@storybook/addons';
9
8
 
10
9
  const meta: Meta<InputProps<StoryFormSchema>> = {
11
10
  title: 'Input example',
@@ -62,6 +61,7 @@ interface StoryFormSchema {
62
61
  prop3?: string;
63
62
  prop4?: string;
64
63
  prop5?: string;
64
+ prop6?: boolean;
65
65
  }
66
66
 
67
67
  const onStubbedSubmit = () => null;
@@ -72,6 +72,7 @@ const storyFormDefaultValues: StoryFormSchema = {
72
72
  prop3: '',
73
73
  prop4: '',
74
74
  prop5: '',
75
+ prop6: true,
75
76
  };
76
77
 
77
78
  const storyFormSchema: Yup.SchemaOf<StoryFormSchema> = Yup.object().shape({
@@ -80,6 +81,7 @@ const storyFormSchema: Yup.SchemaOf<StoryFormSchema> = Yup.object().shape({
80
81
  prop3: Yup.string(),
81
82
  prop4: Yup.string(),
82
83
  prop5: Yup.string(),
84
+ prop6: Yup.boolean(),
83
85
  });
84
86
 
85
87
  export default meta;
@@ -126,6 +128,12 @@ const Template: Story<InputProps<StoryFormSchema>> = args => {
126
128
  inputType="pilled-text"
127
129
  setValue={form.setValue}
128
130
  />
131
+ <Input
132
+ {...args}
133
+ name="prop6"
134
+ inputType="switch"
135
+ setValue={form.setValue}
136
+ />
129
137
  </Form>
130
138
  );
131
139
  };
@@ -199,7 +199,16 @@ const StackedPilledInput = React.forwardRef<
199
199
  cursor={disabled ? 'not-allowed' : 'pointer'}
200
200
  ref={inputWrapperRef}
201
201
  >
202
- <Flex height="28px" alignItems="center" width="fit-content">
202
+ <Flex
203
+ height="28px"
204
+ alignItems="center"
205
+ // width="fit-content"
206
+ // maxW="70%"
207
+ overflowX="auto"
208
+ style={{
209
+ scrollbarWidth: 'none' /* Firefox */,
210
+ }}
211
+ >
203
212
  {lastestFormValueToArray.length ? (
204
213
  lastestFormValueToArray.map((label, index) => (
205
214
  <Box
@@ -211,6 +220,8 @@ const StackedPilledInput = React.forwardRef<
211
220
  }
212
221
  borderRadius="full"
213
222
  onClick={() => setTokenIndex(index)}
223
+ // width="fit-content"
224
+ width="100%"
214
225
  >
215
226
  <Token
216
227
  label={label}
@@ -9,7 +9,7 @@ import {
9
9
  } from '@chakra-ui/react';
10
10
  import { FieldOptions } from '../InputTypes';
11
11
  import { StackedInputProps } from '../StackedInput/StackedInput';
12
- import colors from 'src/theme/foundations/colors';
12
+ import colors from '../../../../src/theme/foundations/colors';
13
13
  import { UseFormSetValue, FieldValues, Control } from 'react-hook-form';
14
14
  import SubtractIcon from './assets/svg/subtract.svg';
15
15
  import { Dropdown } from '../components/dropdown';
@@ -18,16 +18,30 @@ export interface StackedSelectProps extends StackedInputProps {
18
18
  options: FieldOptions;
19
19
  setValue: UseFormSetValue<FieldValues>;
20
20
  control: Control<FieldValues, any>;
21
+ handleOnChange: (value?: string) => void;
21
22
  }
22
23
 
23
24
  /**
24
25
  * A functional React component utilized to render the `StackedSelect` component.
25
26
  */
26
27
  const StackedSelect = React.forwardRef<HTMLInputElement, StackedSelectProps>(
27
- ({ isRequired, options, name, setValue, onChange, ...props }, _ref) => {
28
+ (
29
+ {
30
+ isRequired,
31
+ options,
32
+ name,
33
+ setValue,
34
+ handleOnChange,
35
+ defaultValue,
36
+ ...props
37
+ },
38
+ _ref
39
+ ) => {
28
40
  const dropdownRef = useRef(null);
29
41
  const [isFocussed, setIsFocussed] = useState(false);
30
- const [selectedOption, setSelectedOption] = useState('');
42
+ const [selectedOption, setSelectedOption] = useState(
43
+ options.find(option => option.value === defaultValue)?.label ?? ''
44
+ );
31
45
 
32
46
  useOutsideClick({ ref: dropdownRef, handler: () => setIsFocussed(false) });
33
47
 
@@ -36,6 +50,9 @@ const StackedSelect = React.forwardRef<HTMLInputElement, StackedSelectProps>(
36
50
  value: string;
37
51
  sortValue: number;
38
52
  }) => {
53
+ if (handleOnChange) {
54
+ handleOnChange(option.value);
55
+ }
39
56
  setValue(name as string, option.value);
40
57
  setSelectedOption(option.label);
41
58
  setIsFocussed(false);
@@ -64,7 +81,7 @@ const StackedSelect = React.forwardRef<HTMLInputElement, StackedSelectProps>(
64
81
  </InputGroup>
65
82
  {isFocussed && (
66
83
  <Dropdown
67
- onSelectItem={(option) => handleOnSelectItem(option)}
84
+ onSelectItem={option => handleOnSelectItem(option)}
68
85
  options={options}
69
86
  />
70
87
  )}
@@ -8,8 +8,6 @@ export interface StackedSwitchProps extends SwitchProps {}
8
8
  */
9
9
  const StackedSwitch = React.forwardRef<HTMLInputElement, StackedSwitchProps>(
10
10
  ({ isRequired, onChange, value }, _ref) => {
11
- if (value === undefined) return null;
12
-
13
11
  return (
14
12
  <Switch
15
13
  size="lg"
@@ -1,6 +1,6 @@
1
1
  import React, { useMemo } from 'react';
2
2
  import { Box } from '@chakra-ui/react';
3
- import colors from 'src/theme/foundations/colors';
3
+ import colors from '../../../../../src/theme/foundations/colors';
4
4
  import { FieldOption, FieldOptions } from '../../InputTypes';
5
5
 
6
6
  export interface DropdownProps {
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { Box, FormLabel } from '@chakra-ui/react';
3
- import colors from 'src/theme/foundations/colors';
3
+ import colors from '../../../../../src/theme/foundations/colors';
4
4
 
5
5
  export interface LabelProps {
6
6
  label: string;
@@ -1,6 +1,6 @@
1
1
  import { Flex, Image, Text } from '@chakra-ui/react';
2
2
  import React from 'react';
3
- import colors from 'src/theme/foundations/colors';
3
+ import colors from '../../../../../src/theme/foundations/colors';
4
4
  import CloseIcon from './assets/svg/close.svg';
5
5
 
6
6
  export interface TokenProps {
@@ -15,7 +15,7 @@ const Token: React.FC<TokenProps> = ({ label, onDelete }) => {
15
15
  borderRadius="full"
16
16
  backgroundColor="#7676801F"
17
17
  alignItems="center"
18
- width="fit-content"
18
+ // width="100%"
19
19
  pl="8px"
20
20
  pr="4px"
21
21
  py="2px"
@@ -35,11 +35,10 @@ export interface InputProps<T extends FieldValues> extends ValidationProps {
35
35
  options?: FieldOptions;
36
36
  maxLength?: number;
37
37
  helperText?: React.ReactNode;
38
-
39
- control?: Control<T, any>;
40
- onChange?: (args?: any) => void;
38
+ control: Control<T, any>;
39
+ onChange?: (value?: string) => void;
41
40
  disabled?: boolean;
42
- setValue?: UseFormSetValue<T>;
41
+ setValue: UseFormSetValue<T>;
43
42
  }
44
43
 
45
44
  /**
@@ -97,7 +96,6 @@ export function Input<T extends FieldValues>({
97
96
  className={`input-${inputType} ${className ?? ''}`}
98
97
  name={name}
99
98
  id={name}
100
- isRequired={isRequired}
101
99
  isInvalid={isInvalid}
102
100
  options={options as FieldOptions}
103
101
  onChange={onChange}
@@ -116,13 +114,14 @@ export function Input<T extends FieldValues>({
116
114
  isRequired={isRequired}
117
115
  isInvalid={isInvalid}
118
116
  options={options as FieldOptions}
119
- onChange={onChange}
117
+ handleOnChange={onChange}
120
118
  onBlur={onBlur}
121
119
  setValue={setValue as UseFormSetValue<FieldValues>}
122
120
  control={control as Control<FieldValues, any>}
123
121
  ref={ref}
124
122
  disabled={disabled}
125
123
  value={value}
124
+ defaultValue={defaultValue}
126
125
  placeholder={placeholder}
127
126
  />
128
127
  );
@@ -133,7 +132,6 @@ export function Input<T extends FieldValues>({
133
132
  name={name}
134
133
  id={name}
135
134
  maxLength={maxLength}
136
- isRequired={isRequired}
137
135
  isInvalid={isInvalid}
138
136
  onChange={onChange}
139
137
  onBlur={onBlur}
@@ -148,7 +146,6 @@ export function Input<T extends FieldValues>({
148
146
  className={`input-${inputType} ${className ?? ''}`}
149
147
  name={name}
150
148
  id={name}
151
- isRequired={isRequired}
152
149
  isInvalid={isInvalid}
153
150
  options={options as FieldOptions}
154
151
  onChange={onChange}
@@ -214,6 +211,7 @@ export function Input<T extends FieldValues>({
214
211
  ariaLabel,
215
212
  className,
216
213
  control,
214
+ defaultValue,
217
215
  disabled,
218
216
  inputType,
219
217
  isInvalid,
@@ -232,12 +230,13 @@ export function Input<T extends FieldValues>({
232
230
  name={name as Path<T>}
233
231
  defaultValue={defaultValue as PathValue<T, Path<T>>}
234
232
  rules={{ required: isRequired }}
233
+ /** @ts-ignore: issues with implicit */
235
234
  render={({ field: { onBlur, onChange: fieldOnChange, ref, value } }) => (
236
235
  <FormControl
237
236
  id={name}
238
237
  isInvalid={isInvalid}
239
238
  position="relative"
240
- py={label ? 6 : 0}
239
+ py={label || helperText || isInvalid ? 6 : 0}
241
240
  >
242
241
  {label && <Label label={label} isRequired={isRequired} />}
243
242
  {selectedInputField(
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { Box, Text } from '@chakra-ui/react';
3
- import colors from 'src/theme/foundations/colors';
3
+ import colors from '../../../../../src/theme/foundations/colors';
4
4
 
5
5
  export interface TableTextProps {
6
6
  primaryText: string;
@@ -18,6 +18,7 @@ import {
18
18
  Tr,
19
19
  } from '@chakra-ui/react';
20
20
  import { TableLoadingRows } from './components/loading';
21
+ import colors from '../../theme/foundations/colors';
21
22
 
22
23
  export interface TableProps<T extends ReadonlyTableColumns> {
23
24
  columns: TableColumns;
@@ -55,7 +56,7 @@ export function Table<T extends ReadonlyTableColumns>({
55
56
  >
56
57
  <ChakraTable variant="unstyled">
57
58
  <Thead>
58
- <Tr>
59
+ <Tr _odd={{ bg: colors.label.primary.dark }}>
59
60
  {columnsAsConst.map(column => (
60
61
  // @ts-ignore
61
62
  <Th>{headers[column]}</Th>
package/src/index.tsx CHANGED
@@ -46,3 +46,6 @@ export * from './theme/provider';
46
46
 
47
47
  //Utils
48
48
  export * from './components/form/utils/formErrors';
49
+
50
+ // Colors
51
+ export * from './theme/foundations/colors';
@@ -5,6 +5,8 @@ const parts = ['text', 'icon'];
5
5
  function baseStyleText() {
6
6
  return {
7
7
  color: colors.label.error,
8
+ position: 'absolute',
9
+ bottom: 0,
8
10
  mt: 1,
9
11
  ml: 1,
10
12
  fontSize: '13px',
@@ -11,9 +11,11 @@ function baseStyleRequiredIndicator() {
11
11
 
12
12
  function baseStyleHelperText() {
13
13
  return {
14
+ position: 'absolute',
14
15
  color: colors.label.secondary.light,
15
16
  mt: 1,
16
17
  ml: 1,
18
+ bottom: 0,
17
19
  fontSize: '13px',
18
20
  };
19
21
  }
@@ -1,10 +1,11 @@
1
1
  import colors from '../foundations/colors';
2
2
 
3
- const parts = ['th', 'td', 'tr', 'body'];
3
+ const parts = ['th', 'td', 'tr', 'body', 'thead'];
4
4
 
5
5
  const baseStyle = {
6
+ thead: { bg: colors.label.primary.dark },
6
7
  th: {
7
- height: 'fit-content',
8
+ height: '100%',
8
9
  width: '100%',
9
10
  bg: colors.label.primary.dark,
10
11
  padding: '5px 8px !important',
@@ -14,11 +15,10 @@ const baseStyle = {
14
15
  display: 'flex',
15
16
  alignItems: 'center',
16
17
  width: '100%',
17
-
18
- height: 'fit-content',
18
+ height: '100%',
19
19
  borderRadius: 'md',
20
20
  _odd: {
21
- background: colors.fill.light.tertiary,
21
+ bg: colors.fill.light.tertiary,
22
22
  },
23
23
  },
24
24
  td: {
@@ -94,7 +94,7 @@ const semantic = {
94
94
  error: '#f96057',
95
95
  };
96
96
 
97
- const colors = {
97
+ export const colors = {
98
98
  label,
99
99
  border,
100
100
  fill,
@@ -7,9 +7,14 @@ import customXQChakraTheme from '../customXQChakraTheme';
7
7
  */
8
8
  export const XQThemeProvider: React.FC<ChakraProviderProps> = ({
9
9
  children,
10
+ cssVarsRoot,
10
11
  }) => {
11
12
  return (
12
- <ChakraProvider theme={customXQChakraTheme} resetCSS>
13
+ <ChakraProvider
14
+ theme={customXQChakraTheme}
15
+ resetCSS
16
+ cssVarsRoot={cssVarsRoot}
17
+ >
13
18
  {children}
14
19
  </ChakraProvider>
15
20
  );