mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
26 lines
687 B
TypeScript
26 lines
687 B
TypeScript
/* eslint-disable react/display-name */
|
|
|
|
import React from "react";
|
|
|
|
type Variants = {[K: string]: {[P: string]: string}};
|
|
|
|
type StringToBoolean<T> = T extends "true" | "false" ? boolean : T;
|
|
|
|
type StylesProps<V extends Variants> = {
|
|
[K in keyof V]?: StringToBoolean<keyof V[K]>;
|
|
} & {
|
|
variants: V;
|
|
[x: string]: any;
|
|
};
|
|
|
|
type ComponentType<P = {}> = React.ComponentType<P> | React.ForwardRefExoticComponent<P>;
|
|
|
|
export function extendStyles<P extends Variants>(
|
|
Component: ComponentType<StylesProps<P>>,
|
|
styles: {variants: P},
|
|
) {
|
|
return React.forwardRef<HTMLButtonElement, StylesProps<P>>((props, ref) => {
|
|
return <Component ref={ref} {...styles} {...props} />;
|
|
});
|
|
}
|