import { Component, JSX } from "preact"
import { FoodExcludeTypes } from "./types";
export const FoodItemsContainer = (props: {
children: JSX.Element | JSX.Element[] | null
title: string,
}): JSX.Element => {
return (
{props.title}
{props.children}
);
}
function shouldShowItem(contents, exclude: FoodExcludeTypes): boolean {
if (!exclude) return false;
for (let key of Object.keys(exclude)) {
if (Object.keys(contents).includes(key)) {
if (!exclude[key]) return false;
}
}
return true;
}
type BaseFoodItemProps = {
contents?: Partial,
exclude?: FoodExcludeTypes,
}
const HideIfFoodExcluded = (props: BaseFoodItemProps & { children: JSX.Element }) => {
if (!props.contents) {
return props.children;
} else if (shouldShowItem(props.contents, props.exclude)) {
return props.children;
} else {
return <>>;
}
}
type FoodItemProps = BaseFoodItemProps & {
title: string,
};
export class FoodItem extends Component {
render() {
return (
)
}
}
export class AdvancedFoodItem extends Component {
render() {
return (
{this.props.title}
{this.props.extra}
)
}
}