import { FunctionComponent , Component , ComponentState , ComponentClass , ClassType , ForwardRefExoticComponent , RefAttributes , ComponentType , } from 'react' ; import { isValidElementType } from 'react-is' ; import type { Style } from '@glitz/core' ; import { isElementLikeType , StyledElementLike } from './apply-class-name' ; import createComponent , { StyledComponent , StyledComponentWithRef , WithoutRefProp } from './create' ; import { Styles } from './custom' ; import { sanitizeStyle , DirtyStyle } from './use-glitz' ; import { isElementType , StyledElementProps } from './predefined' ; import { DECORATOR_TYPE , SECRET_GLITZ_PROPERTY } from './constants' ; import { isForwardStyleType } from './forward-style' ; export interface StyledDecorator { [ SECRET_GLITZ_PROPERTY ] : typeof DECORATOR_TYPE ; deprecated < TProps = { } > ( component , ... styles ) : StyledComponent < WithoutRefProp < TProps > > ; deprecated < TProps , TInstance > ( component , ... styles ) : StyledComponentWithRef < TProps , TInstance > ; deprecated < TProps > ( component , ... styles ) : StyledComponent < TProps > ; deprecated < TProps extends StyledElementProps > ( component , ... styles ) : StyledComponent < WithoutRefProp < TProps > > ; deprecated < TProps extends StyledElementProps , TInstance extends Component < TProps , ComponentState > > ( component , ... styles ) : StyledComponentWithRef < TProps , TInstance > ; deprecated < TProps , TInstance > ( component , ... styles ) : StyledComponentWithRef < TProps , TInstance > ; deprecated < TProps , TInstance extends Component < TProps , ComponentState > > ( component , ... styles ) : StyledComponentWithRef < TProps , TInstance > ; deprecated ( style , ... styles ) : StyledDecorator ; /** Apply decorator style */ ( ) : readonly Style [ ] ; deprecated ( component , ... styles ) : StyledComponent < any > ; deprecated ( style ) : StyledDecorator ; } export default function createDecorator ( dirtyStyle ? ) { const style = sanitizeStyle ( dirtyStyle ) ; function decorator < TProps > ( arg1 , ... arg2 ) ; function decorator ( ... styles ) ; function decorator ( ) ; function decorator < TProps > ( arg1 ? , ... arg2 ) { if ( arguments . length === 0 ) { return style ; } if ( isStyle ( arg1 ) ) { return createDecorator ( [ style , arg1 , arg2 ] ) ; } return createComponent < TProps > ( arg1 , [ style , arg2 ] ) ; } return Object . assign ( decorator , { [ SECRET_GLITZ_PROPERTY ] : DECORATOR_TYPE } ) ; } export function isStyle ( arg ) { return ( arg === false || typeof arg === 'undefined' || ( typeof arg === 'function' && ( arg as StyledDecorator ) [ SECRET_GLITZ_PROPERTY ] === DECORATOR_TYPE ) || ( typeof arg === 'object' && ! isElementType ( arg ) && ! isElementLikeType ( arg ) && ! isForwardStyleType ( arg ) && ! isValidElementType ( arg ) ) ) ; }