Skip to content

Commit 4f44e11

Browse files
committed
perf(alert): reduce package size
1 parent c5dceea commit 4f44e11

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

packages/components/alert/src/use-alert.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from "vue";
1818
import { pureObject } from "@vue-nextui/shared";
1919
import { alert } from "@heroui/theme";
20-
import { mapPropsVariants } from "@heroui/system";
20+
import { mapPropsVariants } from "@vue-nextui/shared";
2121
import { dataAttr, isEmpty } from "@heroui/shared-utils";
2222

2323
export interface AlertDefineProps extends /* @vue-ignore */ HTMLNextUIVueProps {

packages/components/shared/src/utils.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,38 @@ export function pureObject(obj: Record<string, any>): Record<string, any> {
66
return acc;
77
}, Object.create(null));
88
}
9+
10+
/**
11+
* This function is copied from heroui souce code
12+
*/
13+
export const mapPropsVariants = <
14+
T extends Record<string, any>,
15+
K extends keyof T,
16+
>(
17+
props: T,
18+
variantKeys?: K[],
19+
removeVariantProps = true,
20+
): readonly [Omit<T, K> | T, Pick<T, K> | {}] => {
21+
if (!variantKeys) {
22+
return [props, {}];
23+
}
24+
25+
const picked = variantKeys.reduce((acc, key) => {
26+
// Only include the key in `picked` if it exists in `props`
27+
if (key in props) {
28+
return { ...acc, [key]: props[key] };
29+
} else {
30+
return acc;
31+
}
32+
}, {});
33+
34+
if (removeVariantProps) {
35+
const omitted = Object.keys(props)
36+
.filter((key) => !variantKeys.includes(key as K))
37+
.reduce((acc, key) => ({ ...acc, [key]: props[key as keyof T] }), {});
38+
39+
return [omitted, picked] as [Omit<T, K>, Pick<T, K>];
40+
} else {
41+
return [props, picked] as [T, Pick<T, K>];
42+
}
43+
};

0 commit comments

Comments
 (0)