import React, { ComponentType, FunctionComponent } from "react"; import { Fn, IntersectionFn, KeepNeversFn, OmitFn, Pipe, ToSchema, } from "../types/Fn"; import { Hoc } from "../types/Hoc"; import { newHoc } from "../utils/newHoc"; interface WithOverridesFn extends Fn { return: Pipe< this["arg0"], [IntersectionFn, KeepNeversFn>] >; } type WithOverridesHoc = >( map: Map, ) => Hoc<[WithOverridesFn>]>; /** * adds values to many props, they can not be override, which means the given values override others * @see {@link withOverride} {@link withFactory} {@link withDefaults} {@link withDefault} * @example * function Card({ content, icon, border }: { * content: string; * icon: "star" | "heart" | ...; * border: "none" | "dashed" | ... * }) { * return <>... * } * const StandardCard = withOverrides({icon: "star", border: "rounded"})(Card); * * * // is equivalent to * * * // and * // ❌ is a typescript error, but even though * // is equivalent to * */ export const withOverrides = newHoc(function withOverrides( Component: ComponentType, map: object, ): FunctionComponent { return function WithOverrides(props: object): JSX.Element { return ; }; });