@xqmsg/ui-core 0.23.3 → 0.24.1

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.23.3",
2
+ "version": "0.24.1",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -8,7 +8,7 @@
8
8
  "src"
9
9
  ],
10
10
  "engines": {
11
- "node": ">=10"
11
+ "node": ">=14"
12
12
  },
13
13
  "scripts": {
14
14
  "start": "tsdx watch",
@@ -57,6 +57,9 @@ const Template: Story<ButtonProps> = args => (
57
57
  width="fixed"
58
58
  />
59
59
  </Box>
60
+ <Box p={5}>
61
+ <Button {...args} text="danger Fixed" variant="danger" width="fixed" />
62
+ </Box>
60
63
  <Box p={5}>
61
64
  <Button
62
65
  {...args}
@@ -81,6 +84,14 @@ const Template: Story<ButtonProps> = args => (
81
84
  width="variable"
82
85
  />
83
86
  </Box>
87
+ <Box p={5}>
88
+ <Button
89
+ {...args}
90
+ text="danger Variable"
91
+ variant="danger"
92
+ width="variable"
93
+ />
94
+ </Box>
84
95
  <Box p={5}>
85
96
  <Button
86
97
  {...args}
@@ -105,6 +116,14 @@ const Template: Story<ButtonProps> = args => (
105
116
  width="variable"
106
117
  />
107
118
  </Box>
119
+ <Box p={5}>
120
+ <Button
121
+ {...args}
122
+ text="danger Fixed variable"
123
+ variant="flat-danger"
124
+ width="variable"
125
+ />
126
+ </Box>
108
127
  <Box p={5}>
109
128
  <Button
110
129
  {...args}
@@ -129,6 +148,14 @@ const Template: Story<ButtonProps> = args => (
129
148
  width="fixed"
130
149
  />
131
150
  </Box>
151
+ <Box p={5}>
152
+ <Button
153
+ {...args}
154
+ text="danger Fixed Flat"
155
+ variant="flat-danger"
156
+ width="fixed"
157
+ />
158
+ </Box>
132
159
  </Flex>
133
160
  );
134
161
 
@@ -38,7 +38,13 @@ export interface InputFieldProps
38
38
  React.InputHTMLAttributes<HTMLInputElement>,
39
39
  HTMLInputElement
40
40
  >,
41
- 'color' | 'height' | 'width' | 'size' | 'ref'
41
+ | 'color'
42
+ | 'height'
43
+ | 'width'
44
+ | 'size'
45
+ | 'ref'
46
+ | 'onChange'
47
+ | 'defaultValue'
42
48
  >,
43
49
  FieldProps,
44
50
  Partial<InputProps> {}
@@ -219,7 +219,7 @@ const StackedSelect = React.forwardRef<HTMLInputElement, StackedSelectProps>(
219
219
  <Dropdown
220
220
  position={position}
221
221
  dropdownRef={dropdownMenuRef}
222
- onSelectItem={option => handleOnSelectItem(option)}
222
+ onSelectItem={handleOnSelectItem}
223
223
  options={options}
224
224
  optionIndex={optionIndex}
225
225
  />
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { ChangeEvent } from 'react';
2
2
  import StackedCheckBox from './StackedCheckbox/StackedCheckbox';
3
3
  import StackedInput from './StackedInput/StackedInput';
4
4
  import StackedRadioGroup from './StackedRadio/StackedRadioGroup';
@@ -26,7 +26,8 @@ import StackedPilledInput from './StackedPilledInput';
26
26
  import StackedSwitch from './StackedSwitch';
27
27
  import { Label } from './components/label';
28
28
 
29
- export interface InputProps<T extends FieldValues> extends ValidationProps {
29
+ export interface InputProps<T extends FieldValues = FieldValues>
30
+ extends ValidationProps {
30
31
  inputType: InputType;
31
32
  name: string;
32
33
  ariaLabel: string;
@@ -39,7 +40,7 @@ export interface InputProps<T extends FieldValues> extends ValidationProps {
39
40
  maxLength?: number;
40
41
  helperText?: React.ReactNode;
41
42
  control: Control<T, any>;
42
- onChange?: (value?: string) => void;
43
+ onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
43
44
  disabled?: boolean;
44
45
  tooltipText?: string;
45
46
  setValue: UseFormSetValue<T>;
@@ -84,12 +85,12 @@ export function Input<T extends FieldValues>({
84
85
  clearErrors,
85
86
  separators,
86
87
  }: InputProps<T>) {
87
- const selectedInputField = (
88
- onChange: () => void,
88
+ function selectedInputField<T extends Element = Element>(
89
+ onChange: ((e: ChangeEvent<T>) => void) | ((v?: string) => void),
89
90
  onBlur: () => void,
90
91
  ref: RefCallBack,
91
92
  value: string
92
- ) => {
93
+ ) {
93
94
  switch (inputType) {
94
95
  case 'text':
95
96
  return (
@@ -102,7 +103,7 @@ export function Input<T extends FieldValues>({
102
103
  maxLength={maxLength}
103
104
  isRequired={isRequired}
104
105
  isInvalid={isInvalid}
105
- onChange={onChange}
106
+ onChange={onChange as (e: ChangeEvent) => void}
106
107
  onBlur={onBlur}
107
108
  ref={ref}
108
109
  rightElement={rightElement}
@@ -123,7 +124,7 @@ export function Input<T extends FieldValues>({
123
124
  id={name}
124
125
  isInvalid={isInvalid}
125
126
  options={options as FieldOptions}
126
- onChange={onChange}
127
+ onChange={onChange as (e: ChangeEvent) => void}
127
128
  onBlur={onBlur}
128
129
  ref={ref}
129
130
  disabled={disabled}
@@ -139,7 +140,7 @@ export function Input<T extends FieldValues>({
139
140
  isRequired={isRequired}
140
141
  isInvalid={isInvalid}
141
142
  options={options as FieldOptions}
142
- handleOnChange={onChange}
143
+ handleOnChange={onChange as (v?: string) => void}
143
144
  onBlur={onBlur}
144
145
  setValue={setValue as UseFormSetValue<FieldValues>}
145
146
  control={control as Control<FieldValues, any>}
@@ -162,7 +163,7 @@ export function Input<T extends FieldValues>({
162
163
  maxLength={maxLength}
163
164
  isRequired={isRequired}
164
165
  isInvalid={isInvalid}
165
- onChange={onChange}
166
+ onChange={onChange as (e: ChangeEvent) => void}
166
167
  onBlur={onBlur}
167
168
  ref={ref}
168
169
  disabled={disabled}
@@ -178,7 +179,7 @@ export function Input<T extends FieldValues>({
178
179
  name={name}
179
180
  id={name}
180
181
  isInvalid={isInvalid}
181
- onChange={onChange}
182
+ onChange={onChange as (e: ChangeEvent) => void}
182
183
  onBlur={onBlur}
183
184
  ref={ref}
184
185
  value={value}
@@ -196,7 +197,7 @@ export function Input<T extends FieldValues>({
196
197
  id={name}
197
198
  isInvalid={isInvalid}
198
199
  options={options as FieldOptions}
199
- onChange={onChange}
200
+ onChange={onChange as (e: ChangeEvent) => void}
200
201
  onBlur={onBlur}
201
202
  ref={ref}
202
203
  disabled={disabled}
@@ -216,7 +217,7 @@ export function Input<T extends FieldValues>({
216
217
  name={name}
217
218
  id={name}
218
219
  isInvalid={isInvalid}
219
- onChange={onChange}
220
+ onChange={onChange as (e: ChangeEvent) => void}
220
221
  onBlur={onBlur}
221
222
  ref={ref}
222
223
  disabled={disabled}
@@ -239,7 +240,7 @@ export function Input<T extends FieldValues>({
239
240
  name={name}
240
241
  id={name}
241
242
  isInvalid={isInvalid}
242
- onChange={onChange}
243
+ onChange={onChange as (e: ChangeEvent) => void}
243
244
  onBlur={onBlur}
244
245
  ref={ref}
245
246
  value={value}
@@ -249,7 +250,7 @@ export function Input<T extends FieldValues>({
249
250
  default:
250
251
  return null;
251
252
  }
252
- };
253
+ }
253
254
  const nonLabeledInputs = ['checkbox'];
254
255
 
255
256
  return (
@@ -284,7 +285,7 @@ export function Input<T extends FieldValues>({
284
285
  />
285
286
  )}
286
287
  {selectedInputField(
287
- onChange ? onChange : fieldOnChange,
288
+ onChange ? onChange : (fieldOnChange as (e: ChangeEvent) => void),
288
289
  onBlur,
289
290
  ref,
290
291
  value
@@ -1,5 +1,5 @@
1
- import React, { useEffect } from 'react';
2
- import { Select } from '@chakra-ui/react';
1
+ import React from 'react';
2
+ import { Select, SelectProps } from '@chakra-ui/react';
3
3
  import {
4
4
  FormControl,
5
5
  FormErrorMessage,
@@ -9,6 +9,8 @@ import {
9
9
  Control,
10
10
  Controller,
11
11
  FieldValues,
12
+ Path,
13
+ PathValue,
12
14
  UseFormClearErrors,
13
15
  UseFormSetError,
14
16
  UseFormSetValue,
@@ -16,10 +18,11 @@ import {
16
18
  import { FieldOptions, ValidationProps } from 'src/components/input/InputTypes';
17
19
 
18
20
  export interface SelectNativeProps<T extends FieldValues>
19
- extends ValidationProps {
21
+ extends ValidationProps,
22
+ SelectProps {
20
23
  isRequired: boolean;
21
24
 
22
- name: string;
25
+ name: Path<T>;
23
26
  ariaLabel: string;
24
27
  placeholder?: string;
25
28
  defaultValue?: string;
@@ -29,7 +32,7 @@ export interface SelectNativeProps<T extends FieldValues>
29
32
  fullOptions?: FieldOptions;
30
33
  helperText?: React.ReactNode;
31
34
  control: Control<T, unknown>;
32
- onChange?: (value?: string) => void;
35
+ onChange?: (e: React.ChangeEvent<HTMLSelectElement>) => void;
33
36
  disabled?: boolean;
34
37
  tooltipText?: string;
35
38
  setValue: UseFormSetValue<T>;
@@ -41,7 +44,7 @@ export interface SelectNativeProps<T extends FieldValues>
41
44
  /**
42
45
  * A functional React component utilized to render the `SelectNative` component.
43
46
  */
44
- export const SelectNative: React.FC<SelectNativeProps<HTMLSelectElement>> = ({
47
+ export function SelectNative<T extends FieldValues = FieldValues>({
45
48
  label,
46
49
  ariaLabel,
47
50
  className,
@@ -62,7 +65,7 @@ export const SelectNative: React.FC<SelectNativeProps<HTMLSelectElement>> = ({
62
65
  setError,
63
66
  clearErrors,
64
67
  ...props
65
- }) => {
68
+ }: SelectNativeProps<T>): React.ReactElement {
66
69
  // const [selectedOption, setSelectedOption] = useState(
67
70
  // options ? options[0] ?? '' : ''
68
71
  // );
@@ -81,27 +84,22 @@ export const SelectNative: React.FC<SelectNativeProps<HTMLSelectElement>> = ({
81
84
  borderRight: 'none',
82
85
  };
83
86
 
84
- const handleOnSelectItem = (selectedValue: string) => {
87
+ const handleOnSelectItem = (e: React.ChangeEvent<HTMLSelectElement>) => {
88
+ const selectedValue = e.target.value;
85
89
  const selectedOption = options?.find(
86
90
  ({ value: val }) => selectedValue === val
87
91
  );
88
92
 
89
93
  if (selectedOption) {
90
94
  if (onChange) {
91
- onChange(selectedOption.value);
95
+ onChange(e);
92
96
  }
93
- setValue(name as string, selectedOption.value);
97
+ setValue(name, selectedOption.value as PathValue<T, Path<T>>);
94
98
  } else {
95
- setValue(name as string, selectedValue);
99
+ setValue(name, selectedValue as PathValue<T, Path<T>>);
96
100
  }
97
101
  };
98
102
 
99
- useEffect(() => {
100
- if (defaultValue) {
101
- handleOnSelectItem(defaultValue);
102
- }
103
- // eslint-disable-next-line react-hooks/exhaustive-deps
104
- }, [defaultValue]);
105
103
  return (
106
104
  <Controller
107
105
  control={control}
@@ -116,7 +114,8 @@ export const SelectNative: React.FC<SelectNativeProps<HTMLSelectElement>> = ({
116
114
  ref={ref}
117
115
  value={value}
118
116
  disabled={disabled ?? false}
119
- onChange={e => handleOnSelectItem(e.target.value)}
117
+ onChange={handleOnSelectItem}
118
+ defaultValue={defaultValue}
120
119
  style={style}
121
120
  >
122
121
  {options &&
@@ -137,4 +136,4 @@ export const SelectNative: React.FC<SelectNativeProps<HTMLSelectElement>> = ({
137
136
  )}
138
137
  />
139
138
  );
140
- };
139
+ }
@@ -2,9 +2,9 @@ import React, { PropsWithChildren } from 'react';
2
2
  import { Text as ChakraText } from '@chakra-ui/react';
3
3
  import textTheme from '../../theme/components/text';
4
4
 
5
- export interface TextProps extends PropsWithChildren {
5
+ export type TextProps = PropsWithChildren & {
6
6
  variant: keyof typeof textTheme.variants;
7
- }
7
+ };
8
8
 
9
9
  /**
10
10
  * A functional React component utilized to render the `Text` component. The component is mainly
@@ -79,6 +79,30 @@ const variantTertiary = () => {
79
79
  };
80
80
  };
81
81
 
82
+ const variantDanger = () => {
83
+ return {
84
+ ...baseStyle,
85
+ fontWeight: '400',
86
+ color: colors.label.primary.dark,
87
+ bg: colors.label.error,
88
+ _hover: {
89
+ bg: colors.label.error,
90
+ },
91
+ _active: {
92
+ color: colors.label.primary.dark,
93
+ bg: colors.label.error,
94
+ },
95
+ _focus: {
96
+ color: colors.label.primary.dark,
97
+ bg: colors.label.error,
98
+ },
99
+ _disabled: {
100
+ backgroundColor: colors.label.error,
101
+ color: colors.label.secondary.light,
102
+ },
103
+ };
104
+ };
105
+
82
106
  const variantPrimaryFlat = () => {
83
107
  return {
84
108
  ...baseStyle,
@@ -142,14 +166,39 @@ const variantTertiaryFlat = () => {
142
166
  },
143
167
  };
144
168
  };
169
+ const variantDangerFlat = () => {
170
+ return {
171
+ ...variantPrimaryFlat(),
172
+ fontWeight: '400',
173
+ color: colors.label.primary.dark,
174
+ bg: colors.label.error,
175
+ _hover: {
176
+ bg: colors.label.error,
177
+ },
178
+ _active: {
179
+ color: colors.label.primary.dark,
180
+ bg: colors.label.error,
181
+ },
182
+ _focus: {
183
+ color: colors.label.primary.dark,
184
+ bg: colors.label.error,
185
+ },
186
+ _disabled: {
187
+ backgroundColor: colors.label.error,
188
+ color: colors.label.secondary.light,
189
+ },
190
+ };
191
+ };
145
192
 
146
193
  const variants = {
147
194
  primary: variantPrimary(),
148
195
  secondary: variantSecondary(),
149
196
  tertiary: variantTertiary(),
197
+ danger: variantDanger(),
150
198
  'flat-primary': variantPrimaryFlat(),
151
199
  'flat-secondary': variantSecondaryFlat(),
152
200
  'flat-tertiary': variantTertiaryFlat(),
201
+ 'flat-danger': variantDangerFlat(),
153
202
  };
154
203
 
155
204
  const defaultProps = {