import React, { ComponentType, FunctionComponent } from "react"; import { Fn, IntersectionFn, Pipe, SetOptionalFn, ToSchema } from "../types/Fn"; import { Hoc } from "../types/Hoc"; import { newHoc } from "../utils/newHoc"; interface WithDefaultsFn extends Fn { return: Pipe< this["arg0"], [IntersectionFn, SetOptionalFn] >; } type WithDefaultsHoc = >( map: Map, ) => Hoc<[WithDefaultsFn>]>; /** * adds default values to many props, so they can still receive values but they now have a default * @see {@link withDefault} {@link withFactory} {@link withOverrides} {@link withOverride} * @example * function Card({ content, icon, border }: { * content: string; * icon: "star" | "heart" | ...; * border: "none" | "dashed" | ... * }) { * return <>... * } * const StandardCard = withDefaults({icon: "star", border: "rounded"})(Card); * * * // is equivalent to * * * // but * * // is equivalent to * // it propagates the new value */ export const withDefaults = newHoc(function withDefaults( Component: ComponentType, map: object, ): FunctionComponent { return function WithDefaults(props: object): JSX.Element { return ; }; });