react-auto-classnames
Version:
JSX runtime for applying `clsx()` automatically
46 lines (39 loc) • 1.56 kB
TypeScript
import 'react';
import { ClassValue } from 'clsx';
type WithConditionalCSSProp<P> = 'className' extends keyof P
? string extends P['className' & keyof P]
? { className?: ClassValue }
: {}
: {};
// unpack all here to avoid infinite self-referencing when defining our own JSX namespace
type ReactJSXElement = JSX.Element;
type ReactJSXElementClass = JSX.ElementClass;
type ReactJSXElementAttributesProperty = JSX.ElementAttributesProperty;
type ReactJSXElementChildrenAttribute = JSX.ElementChildrenAttribute;
type ReactJSXLibraryManagedAttributes<C, P> = JSX.LibraryManagedAttributes<
C,
P
>;
type ReactJSXIntrinsicAttributes = JSX.IntrinsicAttributes;
type ReactJSXIntrinsicClassAttributes<T> = JSX.IntrinsicClassAttributes<T>;
type ReactJSXIntrinsicElements = JSX.IntrinsicElements;
export namespace CJSX {
interface Element extends ReactJSXElement {}
interface ElementClass extends ReactJSXElementClass {}
interface ElementAttributesProperty
extends ReactJSXElementAttributesProperty {}
interface ElementChildrenAttribute extends ReactJSXElementChildrenAttribute {}
type LibraryManagedAttributes<C, P> = WithConditionalCSSProp<P> &
ReactJSXLibraryManagedAttributes<C, P>;
interface IntrinsicAttributes extends ReactJSXIntrinsicAttributes {}
interface IntrinsicClassAttributes<T>
extends ReactJSXIntrinsicClassAttributes<T> {}
type IntrinsicElements = {
[K in keyof ReactJSXIntrinsicElements]: Omit<
ReactJSXIntrinsicElements[K],
'className'
> & {
className?: ClassValue;
};
};
}