mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
radix composing styles
This commit is contained in:
1 parent
37efc2b4a4
commit
d477a3a7a4
3 files changed
+39
-74
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import type { FC } from "react";
|
||||
import { classNames } from "./classNames";
|
||||
|
||||
function composeRadixComponent<Props>(
|
||||
Component: FC<Props>,
|
||||
style: CSSModuleClasses[string],
|
||||
) {
|
||||
return function (props: Props & { className?: string }) {
|
||||
return (
|
||||
<Component {...props} className={classNames(style, props.className)} />
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export function composeRadixComponents<
|
||||
Components extends Record<string, unknown>,
|
||||
>(components: Components, styles: CSSModuleClasses) {
|
||||
const mapped: Partial<Components> = {};
|
||||
|
||||
for (const key in components) {
|
||||
const isMethod = key[0].toLowerCase() === key[0];
|
||||
|
||||
if (isMethod) {
|
||||
mapped[key] = components[key];
|
||||
continue;
|
||||
}
|
||||
|
||||
mapped[key] = composeRadixComponent(
|
||||
components[key] as FC,
|
||||
styles[key],
|
||||
) as Components[Extract<keyof Components, string>];
|
||||
}
|
||||
|
||||
return mapped as Components;
|
||||
}
|
||||
Reference in new issue
Block a user