mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 02:37:05 +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
Whitespace-only changes.
@@ -1,75 +1,5 @@
|
||||
import {
|
||||
Menubar,
|
||||
MenubarCheckboxItem,
|
||||
MenubarContent,
|
||||
MenubarLabel,
|
||||
MenubarRadioGroup,
|
||||
MenubarRadioItem,
|
||||
MenubarSub,
|
||||
MenubarSubContent,
|
||||
MenubarSubTrigger,
|
||||
MenubarTrigger,
|
||||
type MenubarCheckboxItemProps,
|
||||
type MenubarContentProps,
|
||||
type MenubarLabelProps,
|
||||
type MenubarProps,
|
||||
type MenubarRadioGroupProps,
|
||||
type MenubarRadioItemProps,
|
||||
type MenubarSubContentProps,
|
||||
type MenubarSubProps,
|
||||
type MenubarSubTriggerProps,
|
||||
type MenubarTriggerProps,
|
||||
} from "radix-ui/menubar";
|
||||
import { DropdownMenu as _ } from "radix-ui";
|
||||
import { composeRadixComponents } from "../../ui/compose";
|
||||
import styles from "./index.module.css";
|
||||
|
||||
function Root(props: MenubarProps) {
|
||||
return <Menubar {...props} />;
|
||||
}
|
||||
|
||||
function Trigger(props: MenubarTriggerProps) {
|
||||
return <MenubarTrigger {...props} />;
|
||||
}
|
||||
|
||||
function Content(props: MenubarContentProps) {
|
||||
return <MenubarContent {...props} />;
|
||||
}
|
||||
|
||||
function Sub(props: MenubarSubProps) {
|
||||
return <MenubarSub {...props} />;
|
||||
}
|
||||
|
||||
function SubTrigger(props: MenubarSubTriggerProps) {
|
||||
return <MenubarSubTrigger {...props} />;
|
||||
}
|
||||
|
||||
function SubContent(props: MenubarSubContentProps) {
|
||||
return <MenubarSubContent {...props} />;
|
||||
}
|
||||
|
||||
function Label(props: MenubarLabelProps) {
|
||||
return <MenubarLabel {...props} />;
|
||||
}
|
||||
|
||||
function CheckboxItem(props: MenubarCheckboxItemProps) {
|
||||
return <MenubarCheckboxItem {...props} />;
|
||||
}
|
||||
|
||||
function RadioGroup(props: MenubarRadioGroupProps) {
|
||||
return <MenubarRadioGroup {...props} />;
|
||||
}
|
||||
|
||||
function RadioItem(props: MenubarRadioItemProps) {
|
||||
return <MenubarRadioItem {...props} />;
|
||||
}
|
||||
|
||||
export const DropdownMenu = {
|
||||
Root,
|
||||
Trigger,
|
||||
Content,
|
||||
Sub,
|
||||
SubTrigger,
|
||||
SubContent,
|
||||
Label,
|
||||
CheckboxItem,
|
||||
RadioGroup,
|
||||
RadioItem,
|
||||
};
|
||||
export const DropdownMenu = composeRadixComponents(_, styles);
|
||||
@@ -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