(styletron: Styletron)
| 438 | } |
| 439 | |
| 440 | export function createStyledElementComponent(styletron: Styletron) { |
| 441 | const {reducers, base, driver, wrapper, getInitialStyle, ext} = styletron; |
| 442 | |
| 443 | if (__BROWSER__ && __DEV__) { |
| 444 | var debugStackInfo, debugStackIndex; |
| 445 | if (styletron.debug) { |
| 446 | debugStackInfo = styletron.debug.stackInfo; |
| 447 | debugStackIndex = styletron.debug.stackIndex; |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | if (__BROWSER__ && __DEV__) { |
| 452 | var debugClassName; |
| 453 | } |
| 454 | |
| 455 | const StyledElement = React.forwardRef<StyletronProps, any>((props, ref) => { |
| 456 | const styletron: StandardEngine = React.useContext(StyletronContext); |
| 457 | const debugEngine = React.useContext(DebugEngineContext); |
| 458 | const hydrating = React.useContext(HydrationContext); |
| 459 | checkNoopEngine(styletron); |
| 460 | |
| 461 | const elementProps: any = omitPrefixedKeys(props); |
| 462 | let style = resolveStyle(getInitialStyle, reducers, props); |
| 463 | |
| 464 | if (props.$style) { |
| 465 | if (typeof props.$style === "function") { |
| 466 | style = deepMerge(style, props.$style(props)); |
| 467 | } else { |
| 468 | style = deepMerge(style, props.$style); |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | const styleClassString = driver(style, styletron); |
| 473 | const Element = props.$as ? props.$as : base; |
| 474 | elementProps.className = props.className |
| 475 | ? `${props.className} ${styleClassString}` |
| 476 | : styleClassString; |
| 477 | |
| 478 | if (__BROWSER__ && __DEV__ && debugEngine && !hydrating) { |
| 479 | if (!debugClassName) { |
| 480 | debugClassName = debugEngine.debug({ |
| 481 | stackInfo: debugStackInfo, |
| 482 | stackIndex: debugStackIndex, |
| 483 | }); |
| 484 | } |
| 485 | |
| 486 | const joined = `${debugClassName} ${elementProps.className}`; |
| 487 | elementProps.className = joined; |
| 488 | } |
| 489 | |
| 490 | if (__BROWSER__ && __DEV__ && window.__STYLETRON_DEVTOOLS__) { |
| 491 | window.__STYLETRON_DEVTOOLS__.stylesMap.set( |
| 492 | elementProps.className, |
| 493 | style, |
| 494 | ); |
| 495 | if (ext) { |
| 496 | window.__STYLETRON_DEVTOOLS__.extensionsMap.set( |
| 497 | elementProps.className, |
no test coverage detected