( type: ElementType, className: string | Record<string, string>, ...classes: string[] )
| 125 | ): ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<Component<P>>>; |
| 126 | |
| 127 | function classed<T, P extends Record<string, unknown>>( |
| 128 | type: ElementType, |
| 129 | className: string | Record<string, string>, |
| 130 | ...classes: string[] |
| 131 | ): ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<T>> { |
| 132 | return forwardRef<T, P>(function Classed(props, ref) { |
| 133 | if (typeof className === 'string') { |
| 134 | const inputClassName = |
| 135 | typeof props.className === 'string' ? props.className : undefined; |
| 136 | |
| 137 | return React.createElement(type, { |
| 138 | ...props, |
| 139 | className: classNames(inputClassName, className, ...classes), |
| 140 | ref, |
| 141 | }); |
| 142 | } |
| 143 | |
| 144 | if ( |
| 145 | !isNullOrUndefined(props.className) && |
| 146 | typeof className !== typeof props.className |
| 147 | ) { |
| 148 | throw new Error('Incompatible className and parameter'); |
| 149 | } |
| 150 | |
| 151 | return React.createElement(type, { |
| 152 | ...props, |
| 153 | className: isNullOrUndefined(props.className) |
| 154 | ? className |
| 155 | : combineObjectStrings( |
| 156 | className, |
| 157 | props.className as Record<string, string>, |
| 158 | ), |
| 159 | ref, |
| 160 | }); |
| 161 | }); |
| 162 | } |
| 163 | |
| 164 | export default classed; |
no test coverage detected