import { getClassNames, withSchema } from '@websolutespa/bom-core'; import { ComponentPropsWithRef, forwardRef } from 'react'; import styled, { css } from 'styled-components'; import { UIComponentWithRef, UIStyledComponentProps } from '../../components/types'; import { getCssResponsive } from '../../components/utils'; import { IThemeFontVariant } from '../../theme'; import { IResponsiveVariant, getFontVariantResponsive } from '../../variants'; export type ITextProps = IResponsiveVariant & { gradient?: boolean; }; export type TextProps = UIStyledComponentProps; export type TextComponent = UIComponentWithRef; const StyledText = styled.div` ${props => getFontVariantResponsive(props, (variant, font) => css` ${font.fontFamily ? css`font-family: var(--font-${variant}-font-family, var(--base-font-family));` : ''} ${font.fontSize ? css`font-size: var(--font-${variant}-font-size, 1rem);` : ''} ${font.lineHeight ? css`line-height: var(--font-${variant}-line-height, 1);` : ''} ${font.fontWeight ? css`font-weight: var(--font-${variant}-font-weight, inherit);` : ''} ${font.fontStyle ? css`font-style: var(--font-${variant}-font-style, inherit);` : ''} ${font.letterSpacing ? css`letter-spacing: var(--font-${variant}-letter-spacing, inherit);` : ''} ${font.textTransform ? css`text-transform: var(--font-${variant}-text-transform, inherit);` : ''} // ${font.family ? css`font-family: var(--font-${variant}-family, var(--base-font-family));` : ''} ${font.size ? css`font-size: var(--font-${variant}-size, 1rem);` : ''} `)}; ${props => props.gradient ? css` display: -webkit-inline-box; background: -webkit-linear-gradient(0deg, var(--color-secondary-500), var(--color-primary-500)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; ` : ''} ${props => getCssResponsive(props)} `; export const TextBase: TextComponent = forwardRef( function Text({ children, className, as = 'div', ...props }, ref) { const classNames = getClassNames('text', className, props.variant); return ({children}); } ); export type TextBaseProps = ComponentPropsWithRef; export type ITextHtmlProps = Omit & { children?: string }; export type TextHtmlProps = UIStyledComponentProps; export type TextHtmlComponent = UIComponentWithRef; export const TextHtml: TextHtmlComponent = forwardRef( function TextHtml({ children, className, as = 'div', ...props }, ref) { const classNames = getClassNames('text', 'wysiwyg', className, props.variant); return (); } ); const TextSROnly = styled.div` position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border-width: 0; `; export const Text = withSchema( TextBase, { Html: TextHtml, SROnly: TextSROnly, });