@takaro/lib-components 0.0.1 → 0.0.5
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 +5 -6
- package/src/components/actions/Button/index.tsx +68 -70
- package/src/components/actions/Button/style.ts +1 -1
- package/src/components/actions/ContextMenu/Group.tsx +1 -1
- package/src/components/actions/ContextMenu/MenuItem.tsx +4 -1
- package/src/components/actions/ContextMenu/index.tsx +11 -12
- package/src/components/actions/Dropdown/DropdownMenu.tsx +5 -2
- package/src/components/actions/Dropdown/DropdownTrigger.tsx +55 -57
- package/src/components/actions/Dropdown/useDropdown.tsx +1 -1
- package/src/components/actions/IconButton/index.tsx +11 -10
- package/src/components/actions/IconButton/style.ts +5 -2
- package/src/components/actions/ToggleButton/ToggleButton.tsx +26 -28
- package/src/components/actions/ToggleButton/ToggleButtonGroup.tsx +3 -8
- package/src/components/actions/ToggleButton/style.ts +5 -7
- package/src/components/charts/AreaChart/index.tsx +7 -8
- package/src/components/charts/BarChart/index.tsx +4 -4
- package/src/components/charts/GeoMercator/index.tsx +1 -1
- package/src/components/charts/Heatmap/index.tsx +3 -4
- package/src/components/charts/LineChart/index.tsx +3 -3
- package/src/components/charts/PieChart/index.tsx +1 -1
- package/src/components/charts/RadarChart/index.tsx +1 -1
- package/src/components/charts/RadialBarChart/index.tsx +1 -1
- package/src/components/charts/index.tsx +3 -0
- package/src/components/data/Avatar/index.tsx +7 -3
- package/src/components/data/Avatar/style.ts +2 -2
- package/src/components/data/Chip/index.tsx +39 -41
- package/src/components/data/Chip/style.ts +3 -2
- package/src/components/data/Console/Console.tsx +14 -12
- package/src/components/data/CopyId/index.tsx +3 -2
- package/src/components/data/Drawer/Drawer.stories.tsx +3 -5
- package/src/components/data/Drawer/DrawerContent.tsx +1 -1
- package/src/components/data/Drawer/DrawerHeading.tsx +30 -29
- package/src/components/data/Drawer/useDrawer.tsx +1 -1
- package/src/components/data/InfiniteScroll/index.tsx +37 -36
- package/src/components/data/Table/Table.stories.tsx +6 -2
- package/src/components/data/Table/index.tsx +63 -44
- package/src/components/data/Table/style.ts +3 -2
- package/src/components/data/Table/subcomponents/ColumnHeader/ColumnSettings.tsx +22 -19
- package/src/components/data/Table/subcomponents/ColumnHeader/index.tsx +3 -3
- package/src/components/data/Table/subcomponents/ColumnHeader/style.ts +2 -1
- package/src/components/data/Table/subcomponents/Filter/field.tsx +2 -3
- package/src/components/data/Table/subcomponents/Filter/index.tsx +6 -10
- package/src/components/data/Table/subcomponents/Pagination/{index.tsx → PagePicker.tsx} +7 -7
- package/src/components/data/Table/subcomponents/Pagination/PageSizeSelect.tsx +37 -0
- package/src/components/data/Table/subcomponents/Pagination/style.ts +1 -1
- package/src/components/dialogs/Dialog/Dialog.stories.tsx +1 -2
- package/src/components/dialogs/Dialog/DialogBody.tsx +18 -17
- package/src/components/dialogs/Dialog/DialogContent.tsx +30 -28
- package/src/components/dialogs/Dialog/DialogHeading.tsx +1 -1
- package/src/components/dialogs/Dialog/useDialog.tsx +1 -1
- package/src/components/feedback/Alert/index.tsx +74 -73
- package/src/components/feedback/NotificationBanner/NotificationBanner.test.tsx +1 -1
- package/src/components/feedback/NotificationBanner/index.tsx +1 -1
- package/src/components/feedback/Popover/PopoverContent.tsx +4 -1
- package/src/components/feedback/Popover/PopoverTrigger.tsx +33 -31
- package/src/components/feedback/Popover/usePopover.tsx +1 -1
- package/src/components/feedback/ProgressBar/index.tsx +1 -1
- package/src/components/feedback/QuestionTooltip/index.tsx +1 -2
- package/src/components/feedback/Tooltip/TooltipContent.tsx +4 -1
- package/src/components/feedback/Tooltip/TooltipTrigger.tsx +3 -3
- package/src/components/feedback/Tooltip/useTooltip.tsx +1 -1
- package/src/components/feedback/snacks/CookieConsent/index.tsx +5 -2
- package/src/components/feedback/snacks/Default/index.tsx +51 -50
- package/src/components/feedback/snacks/Drawer/index.tsx +22 -21
- package/src/components/feedback/snacks/NetworkDetector/index.tsx +35 -31
- package/src/components/inputs/CheckBox/Controlled.tsx +2 -3
- package/src/components/inputs/CheckBox/Generic.tsx +18 -72
- package/src/components/inputs/CheckBox/style.ts +40 -97
- package/src/components/inputs/CodeField/CodeField.stories.tsx +4 -5
- package/src/components/inputs/CodeField/index.tsx +1 -0
- package/src/components/inputs/Date/DatePicker/DatePicker.stories.tsx +2 -3
- package/src/components/inputs/Date/DatePicker/Generic.tsx +20 -10
- package/src/components/inputs/Date/DateRangePicker/Context.tsx +12 -1
- package/src/components/inputs/Date/DateRangePicker/Controlled.tsx +74 -0
- package/src/components/inputs/Date/DateRangePicker/DateRangePicker.stories.tsx +11 -6
- package/src/components/inputs/Date/DateRangePicker/DateSelector/Absolute.tsx +3 -3
- package/src/components/inputs/Date/DateRangePicker/DateSelector/Relative.tsx +1 -1
- package/src/components/inputs/Date/DateRangePicker/DateSelector/index.tsx +1 -1
- package/src/components/inputs/Date/DateRangePicker/{index.tsx → Generic.tsx} +43 -11
- package/src/components/inputs/Date/DateRangePicker/QuickSelect/index.tsx +1 -1
- package/src/components/inputs/Date/DateRangePicker/style.ts +19 -5
- package/src/components/inputs/Date/subcomponents/Calendar/index.tsx +1 -1
- package/src/components/inputs/Date/subcomponents/RelativePicker/index.tsx +1 -1
- package/src/components/inputs/DurationField/Generic.tsx +149 -152
- package/src/components/inputs/FileField/FileField.stories.tsx +6 -6
- package/src/components/inputs/FileField/Generic.tsx +101 -99
- package/src/components/inputs/InputProps.ts +0 -2
- package/src/components/inputs/RadioGroup/Controlled.tsx +1 -2
- package/src/components/inputs/RadioGroup/RadioGroup.stories.tsx +6 -4
- package/src/components/inputs/RadioGroup/RadioItem.tsx +54 -53
- package/src/components/inputs/Slider/Generic.tsx +1 -1
- package/src/components/inputs/Slider/Slider.stories.tsx +1 -1
- package/src/components/inputs/Slider/handle.tsx +1 -0
- package/src/components/inputs/Switch/Controlled.tsx +1 -2
- package/src/components/inputs/Switch/Generic.tsx +18 -45
- package/src/components/inputs/Switch/Switch.stories.tsx +2 -4
- package/src/components/inputs/Switch/style.ts +44 -38
- package/src/components/inputs/TagField/Generic.tsx +109 -109
- package/src/components/inputs/TextAreaField/Generic.tsx +41 -39
- package/src/components/inputs/TextAreaField/TextAreaField.stories.tsx +2 -3
- package/src/components/inputs/TextField/Generic.tsx +81 -79
- package/src/components/inputs/TextField/TextField.stories.tsx +3 -4
- package/src/components/inputs/index.ts +3 -2
- package/src/components/inputs/layout/Description.tsx +1 -2
- package/src/components/inputs/layout/InputWrapper.ts +2 -2
- package/src/components/inputs/selects/SelectField/Controlled.tsx +1 -2
- package/src/components/inputs/selects/SelectField/Generic/FilterInput.tsx +4 -1
- package/src/components/inputs/selects/SelectField/SelectField.stories.tsx +9 -10
- package/src/components/inputs/selects/SelectQueryField/Generic/index.tsx +200 -197
- package/src/components/inputs/selects/SelectQueryField/SelectQueryField.stories.tsx +1 -1
- package/src/components/inputs/selects/SubComponents/Option.tsx +3 -3
- package/src/components/inputs/selects/SubComponents/OptionGroup.tsx +1 -1
- package/src/components/inputs/selects/SubComponents/style.ts +18 -4
- package/src/components/inputs/selects/index.tsx +5 -2
- package/src/components/inputs/selects/sharedStyle.ts +1 -0
- package/src/components/navigation/HorizontalNav/index.tsx +5 -32
- package/src/components/navigation/HorizontalNav/style.ts +11 -26
- package/src/components/navigation/IconNav/index.tsx +1 -1
- package/src/components/navigation/Steppers/SlimStepper/index.tsx +1 -1
- package/src/components/navigation/Steppers/SlimStepper/style.ts +1 -2
- package/src/components/navigation/Steppers/Stepper/index.tsx +1 -1
- package/src/components/navigation/Steppers/context.tsx +2 -2
- package/src/components/navigation/Tabs/Content.tsx +4 -1
- package/src/components/navigation/Tabs/Trigger.tsx +24 -23
- package/src/components/navigation/index.ts +1 -1
- package/src/components/other/ActionMenu/ActionMenu.stories.tsx +1 -2
- package/src/components/other/ActionMenu/index.tsx +30 -29
- package/src/components/other/Collapsible/CollapsibleTrigger.tsx +8 -4
- package/src/components/other/Company/index.tsx +25 -26
- package/src/components/other/Empty/Empty.stories.tsx +1 -1
- package/src/components/other/Empty/index.tsx +1 -3
- package/src/components/other/PermissionsGuard/index.tsx +2 -2
- package/src/components/visual/Card/index.tsx +4 -1
- package/src/errors/base.ts +4 -1
- package/src/errors/errors.ts +19 -2
- package/src/helpers/getSnackbarProvider.tsx +3 -3
- package/src/helpers/regexprs.ts +1 -0
- package/src/hooks/useFocus.tsx +3 -1
- package/src/hooks/useOnScreen.ts +1 -1
- package/src/hooks/useTableActions.ts +10 -5
- package/src/styled/GlobalStyle.ts +2 -1
- package/src/styled/zIndex.ts +1 -1
- package/src/test/testUtils.tsx +3 -0
- package/src/components/data/Table/subcomponents/index.ts +0 -4
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takaro/lib-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Takaro UI is a simple and customizable component library to build React apps faster within the Takaro eco system",
|
|
6
|
-
"author": "Takaro Team",
|
|
7
6
|
"license": "AGPL-3.0-or-later",
|
|
8
7
|
"main": "src/index.ts",
|
|
9
8
|
"types": "src/index.ts",
|
|
@@ -26,7 +25,7 @@
|
|
|
26
25
|
"react": "^18.2.0",
|
|
27
26
|
"react-dom": "^18.2.0",
|
|
28
27
|
"sort-package-json": "^1.53.1",
|
|
29
|
-
"storybook": "7.
|
|
28
|
+
"storybook": "7.6.20"
|
|
30
29
|
},
|
|
31
30
|
"peerDependencies": {
|
|
32
31
|
"@floating-ui/react": "^0.24.0 || ^0.26.0",
|
|
@@ -34,10 +33,9 @@
|
|
|
34
33
|
"@rjsf/core": "^5.6.2",
|
|
35
34
|
"@rjsf/utils": "^5.6.2",
|
|
36
35
|
"@rjsf/validator-ajv8": "^5.6.2",
|
|
37
|
-
"@tanstack/react-query": "^4.26.1",
|
|
38
36
|
"@tanstack/react-table": "^8.7.9",
|
|
39
|
-
"@tanstack/react-router": "
|
|
40
|
-
"@types/luxon": "3.
|
|
37
|
+
"@tanstack/react-router": "1.35.3",
|
|
38
|
+
"@types/luxon": "3.4.2",
|
|
41
39
|
"framer-motion": "^10.16.12",
|
|
42
40
|
"luxon": "3.3.0",
|
|
43
41
|
"notistack": "^3.0.1",
|
|
@@ -45,6 +43,7 @@
|
|
|
45
43
|
"rc-slider": "^9.7.5",
|
|
46
44
|
"react": "^18.2.0",
|
|
47
45
|
"react-dnd": "^16.0.1",
|
|
46
|
+
"@sentry/react": "^8.5.0",
|
|
48
47
|
"react-dnd-html5-backend": "^16.0.1",
|
|
49
48
|
"react-dom": "^18.2.0",
|
|
50
49
|
"react-hook-form": "^7.50.1",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cloneElement, forwardRef, MouseEvent as ReactMouseEvent, ReactElement } from 'react';
|
|
1
|
+
import { JSX, cloneElement, forwardRef, MouseEvent as ReactMouseEvent, ReactElement } from 'react';
|
|
2
2
|
import { Spinner } from '../../../components';
|
|
3
3
|
import { ButtonColor, Default, Outline, Clear, White } from './style';
|
|
4
4
|
import { Size, Variant } from '../../../styled';
|
|
@@ -22,78 +22,76 @@ export interface ButtonProps {
|
|
|
22
22
|
form?: string;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
if (isLoading) return <Spinner color={variant === 'default' ? 'white' : color} size="small" />;
|
|
25
|
+
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button(
|
|
26
|
+
{
|
|
27
|
+
icon,
|
|
28
|
+
iconPosition = 'left',
|
|
29
|
+
size = 'medium',
|
|
30
|
+
type = 'button',
|
|
31
|
+
isLoading = false,
|
|
32
|
+
className,
|
|
33
|
+
form,
|
|
34
|
+
text,
|
|
35
|
+
color = 'primary',
|
|
36
|
+
disabled = false,
|
|
37
|
+
fullWidth = false,
|
|
38
|
+
variant = 'default',
|
|
39
|
+
onClick = () => {},
|
|
40
|
+
},
|
|
41
|
+
ref,
|
|
42
|
+
) {
|
|
43
|
+
function getIcon(): JSX.Element {
|
|
44
|
+
if (isLoading) return <Spinner color={variant === 'default' ? 'white' : color} size="small" />;
|
|
46
45
|
|
|
47
|
-
|
|
46
|
+
if (icon) return cloneElement(icon, { size: 20 });
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
return <></>;
|
|
49
|
+
}
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
51
|
+
function getVariant(): JSX.Element {
|
|
52
|
+
const props = {
|
|
53
|
+
className: className,
|
|
54
|
+
color: color,
|
|
55
|
+
disabled: disabled,
|
|
56
|
+
iconPosition: iconPosition,
|
|
57
|
+
form: form,
|
|
58
|
+
icon: !!icon,
|
|
59
|
+
isLoading: isLoading,
|
|
60
|
+
onClick: !disabled || !isLoading ? onClick : undefined,
|
|
61
|
+
size: size,
|
|
62
|
+
fullWidth: fullWidth,
|
|
63
|
+
type: type,
|
|
64
|
+
ref: ref,
|
|
65
|
+
tabIndex: disabled ? -1 : 0,
|
|
66
|
+
};
|
|
68
67
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
68
|
+
switch (variant) {
|
|
69
|
+
case 'default':
|
|
70
|
+
return (
|
|
71
|
+
<Default {...props}>
|
|
72
|
+
{iconPosition === 'left' && getIcon()} <span>{text}</span> {iconPosition === 'right' && getIcon()}
|
|
73
|
+
</Default>
|
|
74
|
+
);
|
|
75
|
+
case 'outline':
|
|
76
|
+
return (
|
|
77
|
+
<Outline {...props}>
|
|
78
|
+
{iconPosition === 'left' && getIcon()} <span>{text}</span> {iconPosition === 'right' && getIcon()}
|
|
79
|
+
</Outline>
|
|
80
|
+
);
|
|
81
|
+
case 'clear':
|
|
82
|
+
return (
|
|
83
|
+
<Clear {...props}>
|
|
84
|
+
{iconPosition === 'left' && getIcon()} <span>{text}</span> {iconPosition === 'right' && getIcon()}
|
|
85
|
+
</Clear>
|
|
86
|
+
);
|
|
87
|
+
case 'white':
|
|
88
|
+
return (
|
|
89
|
+
<White {...props}>
|
|
90
|
+
{iconPosition === 'left' && getIcon()} <span>{text}</span> {iconPosition === 'right' && getIcon()}
|
|
91
|
+
</White>
|
|
92
|
+
);
|
|
95
93
|
}
|
|
96
|
-
|
|
97
|
-
return getVariant();
|
|
98
94
|
}
|
|
99
|
-
|
|
95
|
+
|
|
96
|
+
return getVariant();
|
|
97
|
+
});
|
|
@@ -22,7 +22,7 @@ interface DropdownGroupProps {
|
|
|
22
22
|
divider?: boolean;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export const
|
|
25
|
+
export const Group: FC<PropsWithChildren<DropdownGroupProps>> = ({ label, divider = false, children }) => {
|
|
26
26
|
const showDivider = divider || label ? true : false;
|
|
27
27
|
|
|
28
28
|
return (
|
|
@@ -44,7 +44,10 @@ export interface MenuItemProps extends React.ButtonHTMLAttributes<HTMLButtonElem
|
|
|
44
44
|
disabled?: boolean;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
export const MenuItem = forwardRef<HTMLButtonElement, MenuItemProps>((
|
|
47
|
+
export const MenuItem = forwardRef<HTMLButtonElement, MenuItemProps>(function MenuItem(
|
|
48
|
+
{ label, shortcut, disabled, ...props },
|
|
49
|
+
ref,
|
|
50
|
+
) {
|
|
48
51
|
const containerRef = useRef<HTMLButtonElement>(null);
|
|
49
52
|
|
|
50
53
|
useEffect(() => {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Children,
|
|
3
3
|
cloneElement,
|
|
4
|
-
forwardRef,
|
|
5
4
|
isValidElement,
|
|
6
5
|
useEffect,
|
|
7
6
|
useRef,
|
|
@@ -9,6 +8,7 @@ import {
|
|
|
9
8
|
HTMLProps,
|
|
10
9
|
RefObject,
|
|
11
10
|
ReactElement,
|
|
11
|
+
FC,
|
|
12
12
|
} from 'react';
|
|
13
13
|
import {
|
|
14
14
|
useFloating,
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
FloatingFocusManager,
|
|
26
26
|
} from '@floating-ui/react';
|
|
27
27
|
import { MenuItem, MenuItemProps } from './MenuItem';
|
|
28
|
-
import {
|
|
28
|
+
import { Group } from './Group';
|
|
29
29
|
|
|
30
30
|
import { styled } from '../../../styled';
|
|
31
31
|
|
|
@@ -45,19 +45,18 @@ export interface ContextMenuProps extends HTMLProps<HTMLButtonElement> {
|
|
|
45
45
|
targetRef?: RefObject<HTMLElement>;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
type
|
|
49
|
-
(props: ContextMenuProps, ref: React.Ref<HTMLButtonElement>): JSX.Element;
|
|
48
|
+
type SubComponentTypes = {
|
|
50
49
|
Item: typeof MenuItem;
|
|
51
|
-
Group: typeof
|
|
50
|
+
Group: typeof Group;
|
|
52
51
|
};
|
|
53
52
|
|
|
54
|
-
export const ContextMenu
|
|
53
|
+
export const ContextMenu: FC<ContextMenuProps> & SubComponentTypes = ({ children, targetRef }) => {
|
|
55
54
|
const [activeIndex, setActiveIndex] = useState<number | null>(null);
|
|
56
55
|
const [isOpen, setIsOpen] = useState(false);
|
|
57
56
|
|
|
58
57
|
const listItemsRef = useRef<Array<HTMLButtonElement | null>>([]);
|
|
59
58
|
const listContentRef = useRef(
|
|
60
|
-
Children.map(children, (child) => (isValidElement(child) ? child.props.label : null)) as Array<string | null
|
|
59
|
+
Children.map(children, (child) => (isValidElement(child) ? child.props.label : null)) as Array<string | null>,
|
|
61
60
|
);
|
|
62
61
|
const allowMouseUpCloseRef = useRef(false);
|
|
63
62
|
|
|
@@ -177,11 +176,11 @@ export const ContextMenu = forwardRef<HTMLButtonElement, ContextMenuProps>(({ ch
|
|
|
177
176
|
groupChild.props.onClick?.(e);
|
|
178
177
|
setIsOpen(false);
|
|
179
178
|
},
|
|
180
|
-
})
|
|
179
|
+
}),
|
|
181
180
|
);
|
|
182
181
|
}
|
|
183
182
|
return groupChild;
|
|
184
|
-
}
|
|
183
|
+
},
|
|
185
184
|
);
|
|
186
185
|
return <ContextMenu.Group {...child.props}>{newGroupChildren}</ContextMenu.Group>;
|
|
187
186
|
}
|
|
@@ -202,7 +201,7 @@ export const ContextMenu = forwardRef<HTMLButtonElement, ContextMenuProps>(({ ch
|
|
|
202
201
|
child.props.onClick?.(e);
|
|
203
202
|
setIsOpen(false);
|
|
204
203
|
},
|
|
205
|
-
})
|
|
204
|
+
}),
|
|
206
205
|
);
|
|
207
206
|
}
|
|
208
207
|
})}
|
|
@@ -211,7 +210,7 @@ export const ContextMenu = forwardRef<HTMLButtonElement, ContextMenuProps>(({ ch
|
|
|
211
210
|
)}
|
|
212
211
|
</FloatingPortal>
|
|
213
212
|
);
|
|
214
|
-
}
|
|
213
|
+
};
|
|
215
214
|
|
|
216
215
|
ContextMenu.Item = MenuItem;
|
|
217
|
-
ContextMenu.Group =
|
|
216
|
+
ContextMenu.Group = Group;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { forwardRef, HTMLProps, Ref } from 'react';
|
|
1
|
+
import { forwardRef, HTMLProps, Ref, JSX } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
useMergeRefs,
|
|
4
4
|
FloatingPortal,
|
|
@@ -24,7 +24,10 @@ type DropdownMenuComponent = {
|
|
|
24
24
|
Group: typeof DropdownMenuGroup;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
export const DropdownMenu = forwardRef<HTMLDivElement, HTMLProps<HTMLDivElement>>((
|
|
27
|
+
export const DropdownMenu = forwardRef<HTMLDivElement, HTMLProps<HTMLDivElement>>(function DropdownMenu(
|
|
28
|
+
{ children, ...props },
|
|
29
|
+
propRef,
|
|
30
|
+
) {
|
|
28
31
|
const { context, floatingStyles, elementsRef, labelsRef, getFloatingProps, descriptionId, labelId } =
|
|
29
32
|
useDropdownContext();
|
|
30
33
|
|
|
@@ -19,71 +19,69 @@ export type DropdownTriggerProps = HTMLProps<HTMLElement> &
|
|
|
19
19
|
tooltipOptions?: TooltipOptions & { content: ReactNode };
|
|
20
20
|
}>;
|
|
21
21
|
|
|
22
|
-
export const DropdownTrigger = forwardRef<HTMLElement, DropdownTriggerProps>(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
placement: 'top', // because dropdown will be below by default
|
|
30
|
-
},
|
|
31
|
-
...props
|
|
22
|
+
export const DropdownTrigger = forwardRef<HTMLElement, DropdownTriggerProps>(function DropdownTrigger(
|
|
23
|
+
{
|
|
24
|
+
children,
|
|
25
|
+
asChild = false,
|
|
26
|
+
tooltipOptions = {
|
|
27
|
+
initialOpen: false,
|
|
28
|
+
placement: 'top', // because dropdown will be below by default
|
|
32
29
|
},
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
...props
|
|
31
|
+
},
|
|
32
|
+
propRef,
|
|
33
|
+
) {
|
|
34
|
+
const context = useDropdownContext();
|
|
35
|
+
const childrenRef = (children as any).ref;
|
|
36
|
+
const ref = useMergeRefs([context.refs.setReference, propRef, childrenRef]);
|
|
38
37
|
|
|
39
|
-
|
|
38
|
+
const [unControlledOpen, setUncontrolledOpen] = useState<boolean>(tooltipOptions?.initialOpen ?? false);
|
|
40
39
|
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
const open = tooltipOptions.open ?? unControlledOpen;
|
|
41
|
+
const setOpen = tooltipOptions.onOpenChange ?? setUncontrolledOpen;
|
|
43
42
|
|
|
44
|
-
|
|
43
|
+
let inner: ReactElement;
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
// `asChild` allows the user to pass any element as the anchor
|
|
46
|
+
if (asChild && isValidElement(children)) {
|
|
47
|
+
inner = cloneElement(
|
|
48
|
+
children,
|
|
49
|
+
context.getReferenceProps({
|
|
50
|
+
ref,
|
|
51
|
+
...props,
|
|
52
|
+
...children.props,
|
|
53
|
+
onClick(event) {
|
|
54
|
+
event.stopPropagation();
|
|
55
|
+
},
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
} else {
|
|
59
|
+
inner = (
|
|
60
|
+
<button
|
|
61
|
+
ref={ref}
|
|
62
|
+
type="button"
|
|
63
|
+
// The user can style the trigger based on the state
|
|
64
|
+
{...context.getReferenceProps({
|
|
52
65
|
...props,
|
|
53
|
-
|
|
66
|
+
ref,
|
|
54
67
|
onClick(event) {
|
|
55
68
|
event.stopPropagation();
|
|
56
69
|
},
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
type="button"
|
|
64
|
-
// The user can style the trigger based on the state
|
|
65
|
-
{...context.getReferenceProps({
|
|
66
|
-
...props,
|
|
67
|
-
ref,
|
|
68
|
-
onClick(event) {
|
|
69
|
-
event.stopPropagation();
|
|
70
|
-
},
|
|
71
|
-
})}
|
|
72
|
-
>
|
|
73
|
-
{children}
|
|
74
|
-
</button>
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (tooltipOptions && tooltipOptions.content) {
|
|
79
|
-
return (
|
|
80
|
-
<Tooltip open={open} onOpenChange={setOpen} placement={tooltipOptions.placement}>
|
|
81
|
-
<Tooltip.Trigger>{inner}</Tooltip.Trigger>
|
|
82
|
-
<Tooltip.Content>{tooltipOptions.content}</Tooltip.Content>
|
|
83
|
-
</Tooltip>
|
|
84
|
-
);
|
|
85
|
-
}
|
|
70
|
+
})}
|
|
71
|
+
>
|
|
72
|
+
{children}
|
|
73
|
+
</button>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
86
76
|
|
|
87
|
-
|
|
77
|
+
if (tooltipOptions && tooltipOptions.content) {
|
|
78
|
+
return (
|
|
79
|
+
<Tooltip open={open} onOpenChange={setOpen} placement={tooltipOptions.placement}>
|
|
80
|
+
<Tooltip.Trigger>{inner}</Tooltip.Trigger>
|
|
81
|
+
<Tooltip.Content>{tooltipOptions.content}</Tooltip.Content>
|
|
82
|
+
</Tooltip>
|
|
83
|
+
);
|
|
88
84
|
}
|
|
89
|
-
|
|
85
|
+
|
|
86
|
+
return inner;
|
|
87
|
+
});
|
|
@@ -28,13 +28,14 @@ const getSize = (size: Size) => {
|
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
export const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
);
|
|
31
|
+
export const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(function IconButton(
|
|
32
|
+
{ icon, color = 'primary', size = 'medium', disabled, onClick = () => {}, ariaLabel, badge },
|
|
33
|
+
ref,
|
|
34
|
+
) {
|
|
35
|
+
return (
|
|
36
|
+
<Default type="button" color={color} onClick={onClick} ref={ref} disabled={disabled} aria-label={ariaLabel}>
|
|
37
|
+
{cloneElement(icon, { size: getSize(size) })}
|
|
38
|
+
{badge && <div>{badge}</div>}
|
|
39
|
+
</Default>
|
|
40
|
+
);
|
|
41
|
+
});
|
|
@@ -5,13 +5,16 @@ export const Default = styled.button<{ color: Color }>`
|
|
|
5
5
|
display: inline-flex;
|
|
6
6
|
align-items: center;
|
|
7
7
|
justify-content: center;
|
|
8
|
-
transition:
|
|
8
|
+
transition:
|
|
9
|
+
background-color 150ms ease,
|
|
10
|
+
fill 150ms ease,
|
|
11
|
+
stroke 150ms ease;
|
|
9
12
|
border-radius: ${({ theme }) => theme.borderRadius.small};
|
|
10
13
|
border: 0.01rem solid transparent;
|
|
11
14
|
background-clip: padding-box;
|
|
12
15
|
cursor: pointer;
|
|
13
16
|
background-color: transparent;
|
|
14
|
-
padding: ${({ theme }) => theme.spacing['
|
|
17
|
+
padding: ${({ theme }) => theme.spacing['0_25']};
|
|
15
18
|
line-height: 1.6rem;
|
|
16
19
|
|
|
17
20
|
&:hover {
|
|
@@ -13,36 +13,34 @@ export interface ToggleButtonProps {
|
|
|
13
13
|
tooltip?: string;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export const ToggleButton = forwardRef<HTMLButtonElement, ToggleButtonProps>(
|
|
17
|
-
(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
) => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
onClick();
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
if (tooltip) {
|
|
30
|
-
return (
|
|
31
|
-
<Tooltip>
|
|
32
|
-
<Tooltip.Trigger asChild>
|
|
33
|
-
<Item isSelected={selected} isDisabled={disabled} onClick={handleOnClick} ref={ref}>
|
|
34
|
-
{children}
|
|
35
|
-
</Item>
|
|
36
|
-
</Tooltip.Trigger>
|
|
37
|
-
<Tooltip.Content>{tooltip}</Tooltip.Content>
|
|
38
|
-
</Tooltip>
|
|
39
|
-
);
|
|
16
|
+
export const ToggleButton = forwardRef<HTMLButtonElement, ToggleButtonProps>(function ToggleButton(
|
|
17
|
+
{ selected = false, disabled = false, onClick = undefined, value, parentClickEvent = () => {}, children, tooltip },
|
|
18
|
+
ref,
|
|
19
|
+
) {
|
|
20
|
+
const handleOnClick = () => {
|
|
21
|
+
if (disabled) return;
|
|
22
|
+
parentClickEvent(value);
|
|
23
|
+
if (onClick) {
|
|
24
|
+
onClick();
|
|
40
25
|
}
|
|
26
|
+
};
|
|
41
27
|
|
|
28
|
+
if (tooltip) {
|
|
42
29
|
return (
|
|
43
|
-
<
|
|
44
|
-
|
|
45
|
-
|
|
30
|
+
<Tooltip>
|
|
31
|
+
<Tooltip.Trigger asChild>
|
|
32
|
+
<Item isSelected={selected} isDisabled={disabled} onClick={handleOnClick} ref={ref}>
|
|
33
|
+
{children}
|
|
34
|
+
</Item>
|
|
35
|
+
</Tooltip.Trigger>
|
|
36
|
+
<Tooltip.Content>{tooltip}</Tooltip.Content>
|
|
37
|
+
</Tooltip>
|
|
46
38
|
);
|
|
47
39
|
}
|
|
48
|
-
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<Item isSelected={selected} isDisabled={disabled} onClick={handleOnClick} ref={ref}>
|
|
43
|
+
{children}
|
|
44
|
+
</Item>
|
|
45
|
+
);
|
|
46
|
+
});
|
|
@@ -40,13 +40,11 @@ export const ToggleButtonGroup: FC<ToggleButtonGroupProps> & SubComponents = ({
|
|
|
40
40
|
fullWidth = false,
|
|
41
41
|
}) => {
|
|
42
42
|
const [selected, setSelected] = useState<string | Map<string, boolean>>(
|
|
43
|
-
exclusive ? defaultValue || '' : handleDefaultValueNonExclusive()
|
|
43
|
+
exclusive ? defaultValue || '' : handleDefaultValueNonExclusive(),
|
|
44
44
|
);
|
|
45
45
|
|
|
46
46
|
function handleDefaultValueNonExclusive() {
|
|
47
47
|
const m = new Map<string, boolean>();
|
|
48
|
-
selected as Map<string, boolean>;
|
|
49
|
-
|
|
50
48
|
Children.forEach(children, (child) => {
|
|
51
49
|
if (isValidElement(child)) {
|
|
52
50
|
m.set(child.props.value, false);
|
|
@@ -66,12 +64,9 @@ export const ToggleButtonGroup: FC<ToggleButtonGroupProps> & SubComponents = ({
|
|
|
66
64
|
return setSelected('');
|
|
67
65
|
}
|
|
68
66
|
return setSelected(value);
|
|
69
|
-
} else {
|
|
70
|
-
// handle case that each button has a seperate state
|
|
71
|
-
setSelected(
|
|
72
|
-
new Map((selected as Map<string, boolean>).set(value, !(selected as Map<string, boolean>).get(value)))
|
|
73
|
-
);
|
|
74
67
|
}
|
|
68
|
+
// handle case that each button has a seperate state
|
|
69
|
+
setSelected(new Map((selected as Map<string, boolean>).set(value, !(selected as Map<string, boolean>).get(value))));
|
|
75
70
|
};
|
|
76
71
|
|
|
77
72
|
useEffect(() => {
|
|
@@ -27,12 +27,11 @@ export const Container = styled.div<{
|
|
|
27
27
|
border-top-left-radius: ${theme.borderRadius.small};
|
|
28
28
|
border-bottom-left-radius: ${theme.borderRadius.small};
|
|
29
29
|
`;
|
|
30
|
-
}
|
|
31
|
-
|
|
30
|
+
}
|
|
31
|
+
return `
|
|
32
32
|
border-top-left-radius: ${theme.borderRadius.small};
|
|
33
33
|
border-top-right-radius: ${theme.borderRadius.small};
|
|
34
34
|
`;
|
|
35
|
-
}
|
|
36
35
|
}}
|
|
37
36
|
}
|
|
38
37
|
|
|
@@ -44,13 +43,12 @@ export const Container = styled.div<{
|
|
|
44
43
|
border-bottom-right-radius: ${theme.borderRadius.small};
|
|
45
44
|
border-right: 0.1rem solid ${theme.colors.backgroundAccent};
|
|
46
45
|
`;
|
|
47
|
-
}
|
|
48
|
-
|
|
46
|
+
}
|
|
47
|
+
return `
|
|
49
48
|
border-bottom-right-radius: ${theme.borderRadius.small};
|
|
50
49
|
border-bottom-left-radius: ${theme.borderRadius.small};
|
|
51
50
|
border-bottom: 0.1rem solid ${theme.colors.backgroundAccent};
|
|
52
51
|
`;
|
|
53
|
-
}
|
|
54
52
|
}}
|
|
55
53
|
}
|
|
56
54
|
}
|
|
@@ -67,7 +65,7 @@ export const Item = styled.button<{ isSelected: boolean; isDisabled: boolean }>`
|
|
|
67
65
|
font-weight: 400;
|
|
68
66
|
border-left: none;
|
|
69
67
|
background-color: ${({ theme, isSelected, isDisabled }) =>
|
|
70
|
-
|
|
68
|
+
isDisabled ? theme.colors.disabled : isSelected ? theme.colors.primary : theme.colors.background};
|
|
71
69
|
cursor: ${({ isDisabled }) => (isDisabled ? 'default' : 'pointer')};
|
|
72
70
|
|
|
73
71
|
svg {
|