Skip to content

Commit

Permalink
refactor: rename MenuItemConfig to ComponentConfig for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
wz2k committed Dec 2, 2024
1 parent 8e3e416 commit 09b9b76
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions helpers/factory.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { FC } from "react";

interface MenuItemConfig {
interface ComponentConfig {
Component: FC<any>;
key: string;
getProps: (baseProps: any) => any;
condition?: (baseProps: any) => boolean; // Optional condition to include/exclude item
}

export interface FactoryConfig {
items: MenuItemConfig[];
items: ComponentConfig[];
}

export const createDynamicComponentFactory = (config: FactoryConfig) => ({
generateItems: (baseProps: any) => {
return config.items
.filter(
(itemConfig) => !itemConfig.condition || itemConfig.condition(baseProps)
(componentConfig) =>
!componentConfig.condition || componentConfig.condition(baseProps)
)
.map(({ Component, key, getProps }) => (
<Component key={key} {...getProps(baseProps)} />
Expand Down

0 comments on commit 09b9b76

Please sign in to comment.