void };
-export interface AppSegmentedProps extends SegmentedProps {
+type SegmentedOption = {
+ value: string;
+ label?: string;
+ link?: string;
+ onHover?: () => void;
+ icon?: React.ReactNode;
+ tooltip?: string;
+};
+export interface AppSegmentedProps extends Omit
{
bordered?: boolean;
options: SegmentedOption[];
}
@@ -31,8 +41,9 @@ const THEME_CONFIG: ThemeConfig = {
};
export const AppSegmented = React.memo(
- ({ size = 'small', bordered = true, options: optionsProps, ...props }) => {
+ ({ size = 'small', bordered = true, onChange, options: optionsProps, ...props }) => {
const { cx, styles } = useStyles();
+ const router = useRouter();
const options = useMemo(() => {
return optionsProps.map((option) => ({
@@ -41,10 +52,19 @@ export const AppSegmented = React.memo(
}));
}, [optionsProps]);
+ const onChangePreflight = useMemoizedFn((value: string | number) => {
+ const link = optionsProps.find((option) => option.value === value)?.link;
+ if (link) {
+ router.push(link);
+ }
+ onChange?.(value);
+ });
+
return (
= ({ option }) => {
return (
-
- {option.label}
-
+
+
+
+ {option.icon}
+ {option.label}
+
+
+
);
};
@@ -73,5 +98,9 @@ const SegmentedItemLink: React.FC<{ href?: string; children: React.ReactNode }>
children
}) => {
if (!href) return children;
- return {children};
+ return (
+
+ {children}
+
+ );
};