UNPKG

2.69 kBTypeScriptView Raw
1import type { Assign } from "@ark-ui/react";
2import type { ComponentProps, ComponentPropsWithoutRef, ElementType, FunctionComponent, JSX } from "react";
3import type { Dict, DistributiveOmit, DistributiveUnion, Pretty } from "../utils";
4import type { MinimalNested, SystemStyleObject } from "./css.types";
5import type { SystemProperties } from "./generated/system.gen";
6import type { RecipeDefinition, RecipeSelection, RecipeVariantRecord } from "./recipe.types";
7export interface UnstyledProp {
8 /**
9 * If `true`, the element will opt out of the theme styles.
10 */
11 unstyled?: boolean;
12}
13export interface PolymorphicProps {
14 as?: ElementType;
15 asChild?: boolean;
16}
17export interface HtmlProps {
18 htmlSize?: number;
19 htmlWidth?: string | number;
20 htmlHeight?: string | number;
21 htmlTranslate?: "yes" | "no" | undefined;
22 htmlContent?: string;
23}
24export type HtmlProp = "color" | "size" | "translate" | "transition" | "width" | "height" | "content";
25export type PatchHtmlProps<T> = DistributiveOmit<T, HtmlProp> & HtmlProps;
26export type JsxHtmlProps<T extends Dict, P extends Dict = {}> = Assign<PatchHtmlProps<T>, P>;
27export type ChakraComponent<T extends ElementType, P extends Dict = {}> = FunctionComponent<HTMLChakraProps<T, P> & {
28 ref?: any;
29}>;
30export type HTMLChakraProps<T extends ElementType, P extends Dict = {}> = JsxHtmlProps<ComponentPropsWithoutRef<T>, Assign<JsxStyleProps, P> & PolymorphicProps>;
31export type JsxElement<T extends ElementType, P extends Dict> = T extends ChakraComponent<infer A, infer B> ? ChakraComponent<A, Pretty<DistributiveUnion<P, B>>> : ChakraComponent<T, P>;
32export interface JsxFactory {
33 <T extends ElementType>(component: T): ChakraComponent<T, {}>;
34 <T extends ElementType, P extends RecipeVariantRecord>(component: T, recipe: RecipeDefinition<P>, options?: JsxFactoryOptions<Assign<ComponentProps<T>, RecipeSelection<P>>>): JsxElement<T, RecipeSelection<P>>;
35}
36type JsxElements = {
37 [K in keyof JSX.IntrinsicElements]: ChakraComponent<K, {}>;
38};
39export type StyledFactoryFn = JsxFactory & JsxElements;
40export type DataAttr = Record<`data-${string}`, string | number | undefined | null | boolean>;
41export interface JsxFactoryOptions<TProps> {
42 forwardProps?: string[];
43 defaultProps?: Partial<TProps> & DataAttr;
44 forwardAsChild?: boolean;
45 shouldForwardProp?(prop: string, variantKeys: string[]): boolean;
46}
47export interface JsxStyleProps extends SystemProperties, MinimalNested<SystemStyleObject> {
48 css?: SystemStyleObject | undefined | Omit<(SystemStyleObject | undefined)[], keyof any[]>;
49}
50export type InferRecipeProps<T> = T extends ChakraComponent<any, infer P> ? P : {};
51export {};