import React, { forwardRef, useContext, createContext } from 'react' import type { HTMLAttributes } from 'react' type Variant = 'primary' | 'secondary' type ColorVariant = 'main' | 'light' | 'accent' interface BannerTextContext { variant: Variant colorVariant: ColorVariant } const BannerTextContext = createContext( undefined ) export interface BannerTextProps extends HTMLAttributes { /** * Specifies the component direction variant. */ variant?: Variant /** * Specifies the component's color variant combination. */ colorVariant?: ColorVariant /** * ID to find this component in testing tools (e.g.: cypress, * testing-library, and jest). */ testId?: string } const BannerText = forwardRef( function BannerText( { children, testId = 'fs-banner-text', variant = 'primary', colorVariant = 'main', ...otherProps }, ref ) { const context = { variant, colorVariant } return (
{children}
) } ) export function useBannerText() { const context = useContext(BannerTextContext) if (context === undefined) { throw new Error( 'Do not use BannerText components outside the BannerText context.' ) } return context } export default BannerText