import React, { forwardRef } from 'react'; import { useTheme, ClassNames } from '@emotion/react'; import colorscheme_dataset from '@techytools/ui/helpers/colorscheme_dataset'; import { styleProps } from '@techytools/ui/types/styles'; import style_string_from_props from '@techytools/ui/helpers/style_string_from_props'; import style_string_from_variants from '@techytools/ui/helpers/style_string_from_variants'; export default (Component: any, componentName: string, variants: any) => forwardRef(({ ...props }: styleProps, ref: any) => { /* * TODO: Refactor. This logic is run every time the component or its children receives different props. * Maybe it's ok. But needs more testing. To fix: 1) Manipulate component props only once on initial compile (add theme, data-component or className attribute based on component name so it can be found in dev tools, data-colorscheme, data-bggradient, etc.) 2) Wrap in styled() component outside the function so styled-components library can take care of restyling and rerendering. */ props.theme = useTheme(); const inlineStyles = style_string_from_props({ props, }); const variantStyles = style_string_from_variants({ props, variants, }); const colorScheme = colorscheme_dataset(props); // cleanup after styles have been generated and applied delete props.theme; return ( {({ css, cx }) => ( )} ); });