@xqmsg/ui-core 0.15.4 → 0.16.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/dist/components/banner/index.d.ts +1 -0
- package/dist/components/input/StackedSelect/{StackedSelect.d.ts → index.d.ts} +0 -0
- package/dist/components/input/components/dropdown/index.d.ts +1 -0
- package/dist/theme/components/button.d.ts +3 -0
- package/dist/theme/components/table.d.ts +6 -0
- package/dist/theme/styles.d.ts +1 -0
- package/dist/ui-core.cjs.development.js +245 -60
- package/dist/ui-core.cjs.development.js.map +1 -1
- package/dist/ui-core.cjs.production.min.js +1 -1
- package/dist/ui-core.cjs.production.min.js.map +1 -1
- package/dist/ui-core.esm.js +247 -62
- package/dist/ui-core.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/banner/Banner.stories.tsx +32 -0
- package/src/components/banner/index.tsx +24 -13
- package/src/components/button/Button.stories.tsx +1 -1
- package/src/components/button/spinner/index.tsx +2 -3
- package/src/components/input/Input.stories.tsx +0 -1
- package/src/components/input/StackedMultiSelect/index.tsx +113 -21
- package/src/components/input/StackedSelect/index.tsx +236 -0
- package/src/components/input/components/dropdown/index.tsx +10 -3
- package/src/components/input/index.tsx +1 -1
- package/src/components/table/empty/index.tsx +1 -1
- package/src/theme/components/button.ts +1 -0
- package/src/theme/components/table.ts +6 -0
- package/src/theme/components/text.ts +1 -1
- package/src/theme/styles.ts +1 -0
- package/src/components/input/StackedSelect/StackedSelect.tsx +0 -127
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
Box,
|
|
4
|
-
Image,
|
|
5
|
-
Input,
|
|
6
|
-
InputGroup,
|
|
7
|
-
InputRightElement,
|
|
8
|
-
} from '@chakra-ui/react';
|
|
9
|
-
import { FieldOptions } from '../InputTypes';
|
|
10
|
-
import { StackedInputProps } from '../StackedInput/StackedInput';
|
|
11
|
-
import colors from '../../../../src/theme/foundations/colors';
|
|
12
|
-
import { UseFormSetValue, FieldValues, Control } from 'react-hook-form';
|
|
13
|
-
import SubtractIcon from './assets/svg/subtract.svg';
|
|
14
|
-
import { Dropdown } from '../components/dropdown';
|
|
15
|
-
import useDidMountEffect from '../../../hooks/useDidMountEffect';
|
|
16
|
-
import { useOnClickOutside } from '../../../hooks/useOnOutsideClick';
|
|
17
|
-
|
|
18
|
-
export interface StackedSelectProps extends StackedInputProps {
|
|
19
|
-
options: FieldOptions;
|
|
20
|
-
setValue: UseFormSetValue<FieldValues>;
|
|
21
|
-
control: Control<FieldValues, any>;
|
|
22
|
-
handleOnChange: (value?: string) => void;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* A functional React component utilized to render the `StackedSelect` component.
|
|
27
|
-
*/
|
|
28
|
-
const StackedSelect = React.forwardRef<HTMLInputElement, StackedSelectProps>(
|
|
29
|
-
(
|
|
30
|
-
{ isRequired, options, name, setValue, handleOnChange, value, ...props },
|
|
31
|
-
_ref
|
|
32
|
-
) => {
|
|
33
|
-
const dropdownRef = useRef<HTMLDivElement>(null);
|
|
34
|
-
const dropdownMenuRef = useRef<HTMLDivElement>(null);
|
|
35
|
-
|
|
36
|
-
const [isFocussed, setIsFocussed] = useState(false);
|
|
37
|
-
const [selectedOption, setSelectedOption] = useState(
|
|
38
|
-
options.find(option => option.value === value)?.label ?? ''
|
|
39
|
-
);
|
|
40
|
-
const [position, setPosition] = useState<'top' | 'bottom'>('top');
|
|
41
|
-
|
|
42
|
-
const boundingClientRect = dropdownRef.current?.getBoundingClientRect() as DOMRect;
|
|
43
|
-
|
|
44
|
-
useEffect(() => {
|
|
45
|
-
const boundingClientRect = dropdownRef.current?.getBoundingClientRect() as DOMRect;
|
|
46
|
-
|
|
47
|
-
if (window.innerHeight - (boundingClientRect?.y + 240) >= 0) {
|
|
48
|
-
setPosition('top');
|
|
49
|
-
} else {
|
|
50
|
-
setPosition('bottom');
|
|
51
|
-
}
|
|
52
|
-
}, [boundingClientRect]);
|
|
53
|
-
|
|
54
|
-
useDidMountEffect(() => {
|
|
55
|
-
setSelectedOption(
|
|
56
|
-
options.find(option => option.value === value)?.label ?? ''
|
|
57
|
-
);
|
|
58
|
-
}, [value]);
|
|
59
|
-
|
|
60
|
-
useOnClickOutside(dropdownRef, () => setIsFocussed(false));
|
|
61
|
-
|
|
62
|
-
const handleOnSelectItem = (option: {
|
|
63
|
-
label: string;
|
|
64
|
-
value: string;
|
|
65
|
-
sortValue: number;
|
|
66
|
-
}) => {
|
|
67
|
-
if (handleOnChange) {
|
|
68
|
-
handleOnChange(option.value);
|
|
69
|
-
}
|
|
70
|
-
setValue(name as string, option.value);
|
|
71
|
-
setSelectedOption(option.label);
|
|
72
|
-
setIsFocussed(false);
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
return (
|
|
76
|
-
<Box ref={dropdownRef} position="relative">
|
|
77
|
-
<InputGroup>
|
|
78
|
-
<Input
|
|
79
|
-
isRequired={isRequired}
|
|
80
|
-
{...props}
|
|
81
|
-
ref={_ref}
|
|
82
|
-
onClick={() => setIsFocussed(!isFocussed)}
|
|
83
|
-
cursor="pointer"
|
|
84
|
-
color="transparent"
|
|
85
|
-
fontSize="13px"
|
|
86
|
-
textShadow={`0 0 0 ${colors.label.primary.light}`}
|
|
87
|
-
value={selectedOption}
|
|
88
|
-
autoComplete="off"
|
|
89
|
-
onKeyDown={e => {
|
|
90
|
-
if (isFocussed) {
|
|
91
|
-
if (e.key === 'Tab') {
|
|
92
|
-
return setIsFocussed(false);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const idx = options.findIndex(
|
|
96
|
-
option => option.label[0].toLocaleLowerCase() === e.key
|
|
97
|
-
);
|
|
98
|
-
console.log(idx);
|
|
99
|
-
|
|
100
|
-
dropdownMenuRef.current?.scrollTo({
|
|
101
|
-
top: idx * 27,
|
|
102
|
-
behavior: 'smooth',
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}}
|
|
106
|
-
/>
|
|
107
|
-
<InputRightElement
|
|
108
|
-
cursor="pointer"
|
|
109
|
-
onClick={() => setIsFocussed(!isFocussed)}
|
|
110
|
-
>
|
|
111
|
-
<Image src={SubtractIcon} alt="subtract" boxSize="16px" />
|
|
112
|
-
</InputRightElement>
|
|
113
|
-
</InputGroup>
|
|
114
|
-
{isFocussed && (
|
|
115
|
-
<Dropdown
|
|
116
|
-
position={position}
|
|
117
|
-
dropdownRef={dropdownMenuRef}
|
|
118
|
-
onSelectItem={option => handleOnSelectItem(option)}
|
|
119
|
-
options={options}
|
|
120
|
-
/>
|
|
121
|
-
)}
|
|
122
|
-
</Box>
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
export default StackedSelect;
|