UNPKG

@rdsaude/pulso-react-components

Version:

Biblioteca de componentes React do Pulso Design System da RD Saúde oferece componentes consistentes e de alto desempenho, alinhados com os padrões da RDSaúde. Ideal para desenvolver aplicações modernas e acessíveis.

1 lines 14.1 kB
{"version":3,"sources":["../../../src/components/icon-dual-color/index.ts","../../../src/components/icon-dual-color/namespace.ts","../../../src/components/icon-dual-color/icon-dual-color-root.tsx","../../../src/hooks/use-enhanced-children.ts","../../../src/utils/inject-props-to-children.ts","../../../src/components/icon/index.tsx","../../../src/hooks/use-theme.ts","../../../src/components/theme-provider/index.tsx","../../../src/components/icon-dual-color/icon-dual-color-top.tsx","../../../src/components/icon-dual-color/icon-dual-color-bottom.tsx"],"sourcesContent":["export * as IconDualColor from './namespace'\nexport type { IconDualColorRootProps as IconDualColorProps } from './icon-dual-color-root'\n","export { IconDualColorRoot as Root } from './icon-dual-color-root'\nexport { IconDualColorTop as Top } from './icon-dual-color-top'\nexport { IconDualColorBottom as Bottom } from './icon-dual-color-bottom'\n","import { ark } from '@ark-ui/react/factory'\nimport { useEnhancedChildren } from '~/hooks/use-enhanced-children'\nimport type { IconProps } from '../icon'\n\nexport type IconDualColorRootProps = Omit<\n React.ComponentPropsWithRef<'div'>,\n 'className'\n> &\n Pick<IconProps, 'size'> & {\n /**\n * Quando `true`, renderiza o componente como um slot via `@radix-ui/react-slot`,\n * permitindo controle externo sobre o elemento raiz.\n */\n asChild?: boolean\n /**\n * Define se o componente está desabilitado.\n * Quando `true`, o componente não pode ser interagido.\n */\n disabled?: boolean\n }\n\nexport function IconDualColorRoot({\n children,\n size = 'small',\n disabled = false,\n asChild,\n ...props\n}: IconDualColorRootProps) {\n const enhancedChildrenWithInjectProps = useEnhancedChildren(children, {\n targets: ['IconDualColorTop', 'IconDualColorBottom'],\n props: {\n size,\n disabled,\n },\n asChild,\n })\n\n return (\n <ark.div\n data-testid=\"icon-dual-color-root\"\n aria-label=\"Ícones\"\n aria-disabled={disabled}\n asChild={asChild}\n {...props}\n className=\"relative flex [&>[data-icon=top]]:absolute\"\n >\n {enhancedChildrenWithInjectProps}\n </ark.div>\n )\n}\n\nIconDualColorRoot.displayName = 'IconDualColorRoot'\n","import * as React from 'react'\n\nimport { injectPropsToChildren } from '~/utils/inject-props-to-children'\n\nexport function useEnhancedChildren<T extends object>(\n children: React.ReactNode,\n {\n targets,\n props,\n asChild,\n }: {\n targets: string[]\n props: T\n asChild?: boolean\n }\n) {\n const keyPrefix = React.useId()\n\n return injectPropsToChildren(children, {\n targets,\n props,\n asChild,\n keyPrefix,\n })\n}\n","import * as React from 'react'\n\ntype InjectPropsToChildrenOptions<T = unknown> = {\n /**\n * List of component displayNames to match.\n * Props will only be injected into components matching these names.\n */\n targets: string[]\n\n /**\n * Props to inject into the matched components.\n */\n props: Partial<T>\n\n /**\n * Optional key prefix for cloned elements.\n */\n keyPrefix?: string\n\n /**\n * Whether to return only the first child (e.g. for Slot-like behavior).\n */\n asChild?: boolean\n}\n\n/**\n * Recursively injects props into React children whose displayName matches a list of target names.\n *\n * This is useful for compound component patterns where parent-level props need to reach\n * specific nested children without direct prop drilling.\n *\n * @param children - The children tree to traverse.\n * @param options - Match configuration and props to inject.\n * @returns The cloned React nodes with props injected into matching components.\n */\nexport function injectPropsToChildren<T = unknown>(\n children: React.ReactNode,\n options: InjectPropsToChildrenOptions<T>\n): React.ReactNode {\n const { targets, props, keyPrefix = 'inject', asChild } = options\n\n const cloned = React.Children.map(children, (child, index) => {\n if (!React.isValidElement(child)) return child\n\n const displayName = (child.type as React.ComponentType)?.displayName ?? ''\n const shouldInject = targets.includes(displayName)\n\n const childProps = child.props as {\n children?: React.ReactNode\n asChild?: boolean\n }\n\n return React.cloneElement(\n child,\n {\n ...(shouldInject ? props : {}),\n key: `${keyPrefix}-${index.toString()}`,\n },\n injectPropsToChildren(childProps?.children, {\n targets,\n props,\n keyPrefix,\n asChild: childProps?.asChild,\n })\n )\n })\n\n return asChild ? cloned?.[0] : cloned\n}\n","import * as React from 'react'\n\nimport type { RDSAUDESISTEMAS_TOKENS } from '@raiadrogasil/pulso-design-tokens'\nimport type { IconName } from '@raiadrogasil/pulso-icons'\n\nimport { useTheme } from '~/hooks/use-theme'\n\ntype IconVisualSize = 'tiny' | 'extra-small' | 'small' | 'medium'\ntype DesignTokens = typeof RDSAUDESISTEMAS_TOKENS\n\ntype TokenColorKeys = {\n [K in keyof DesignTokens as K extends `color${string}`\n ? K\n : never]: DesignTokens[K]\n}\n\n/**\n * Propriedades do componente Icon.\n */\nexport type IconProps = React.ComponentProps<'i'> & {\n /**\n * Define o ícone a ser exibido, com base na lista de nomes disponíveis em `@raiadrogasil/pulso-icons`.\n *\n * @default 'rdicon-default'\n */\n symbol?: IconName\n\n /**\n * Define o tamanho visual do ícone, controlando o `font-size` com base nos tokens de espaçamento.\n *\n * Valores possíveis: 'tiny', 'extra-small', 'small', 'medium'.\n *\n * @default 'small'\n */\n size?: IconVisualSize\n\n /**\n * Define a cor do ícone usando uma chave de token de cor do design system.\n * A cor é aplicada via `style.color`.\n *\n * @default 'colorActionFillBrandPrimaryEnabled'\n */\n color?: keyof TokenColorKeys\n}\n\nexport function Icon({\n symbol = 'rdicon-default',\n size = 'small',\n color = 'colorActionFillBrandPrimaryEnabled',\n ...props\n}: IconProps) {\n const theme = useTheme()\n\n const resolvedFontSizes = React.useMemo(() => {\n return {\n tiny: theme.sizingTiny,\n 'extra-small': theme.sizingExtrasmall,\n small: theme.sizingSmall,\n medium: theme.sizingMedium,\n }\n }, [])\n\n return (\n <i\n {...props}\n className={symbol}\n style={{\n fontSize: resolvedFontSizes[size],\n color: theme[color],\n display: 'inline-flex',\n }}\n />\n )\n}\n\nIcon.displayName = 'Icon'\n\nexport * from './deprecated'\n","import * as React from 'react'\n\nimport {\n DROGASIL_TOKENS,\n GLOBALS_TOKENS,\n PRIME_TOKENS,\n RAIA_TOKENS,\n RDSAUDESISTEMAS_TOKENS,\n SUBSCRIPTION_TOKENS,\n} from '@raiadrogasil/pulso-design-tokens'\n\nimport { ThemeContext } from '~/components/theme-provider'\n\ntype ThemeTokens = typeof RDSAUDESISTEMAS_TOKENS & typeof GLOBALS_TOKENS\n\nexport function useTheme(): ThemeTokens {\n const mappedTheme = React.useMemo(() => {\n return {\n rdsaudesistemas: RDSAUDESISTEMAS_TOKENS,\n drogasil: DROGASIL_TOKENS,\n raia: RAIA_TOKENS,\n subscription: SUBSCRIPTION_TOKENS,\n prime: PRIME_TOKENS,\n }\n }, [])\n\n const context = React.useContext(ThemeContext)\n\n if (!context) {\n throw new Error(\n '[Pulso] useTheme precisa estar dentro de um <ThemeProvider>. Verifique se o provedor está corretamente configurado na raiz da aplicação.'\n )\n }\n\n const { currentTheme } = context\n\n const result = {\n ...GLOBALS_TOKENS,\n ...mappedTheme[currentTheme],\n } as ThemeTokens\n\n return result\n}\n","import * as React from 'react'\n\nimport type { Themes } from '@raiadrogasil/pulso-design-tokens'\n\nexport const ThemeContext = React.createContext({\n currentTheme: 'rdsaudesistemas',\n} as {\n currentTheme: Themes\n})\n\ntype ThemeProviderProps = {\n children: React.ReactNode\n theme?: Themes\n}\n\nexport function ThemeProvider({\n children,\n theme = 'rdsaudesistemas',\n}: ThemeProviderProps) {\n if (typeof window !== 'undefined') {\n document.documentElement.setAttribute('class', theme)\n }\n\n return (\n <ThemeContext.Provider\n value={{\n currentTheme: theme,\n }}\n >\n {children}\n </ThemeContext.Provider>\n )\n}\n","import { Icon, type IconProps } from '../icon'\n\ntype IconDualColorTopProps = Omit<IconProps, 'size'>\n\nexport function IconDualColorTop({\n children,\n color = 'colorActionTextOnbrandDefault',\n // @ts-expect-error size prop is taken from IconDualColorRoot\n size,\n // @ts-expect-error disabled prop is taken from IconDualColorRoot\n disabled,\n ...props\n}: IconDualColorTopProps) {\n const iconColor = disabled ? 'colorTextNeutralDisabled' : color\n\n return (\n <Icon\n data-testid=\"icon-dual-color-top\"\n data-icon=\"top\"\n data-size={size}\n color={iconColor}\n size={size}\n {...props}\n >\n {children}\n </Icon>\n )\n}\n\nIconDualColorTop.displayName = 'IconDualColorTop'\n","import { Icon, type IconProps } from '../icon'\n\ntype IconDualColorBottomProps = Omit<IconProps, 'size'>\n\nexport function IconDualColorBottom({\n children,\n color = 'colorTextNeutralDefault',\n // @ts-expect-error size prop is taken from IconDualColorRoot\n size,\n // @ts-expect-error disabled prop is taken from IconDualColorRoot\n disabled,\n ...props\n}: IconDualColorBottomProps) {\n const iconColor = disabled ? 'colorTextNeutralDisabled' : color\n\n return (\n <Icon\n data-testid=\"icon-dual-color-bottom\"\n data-icon=\"bottom\"\n data-size={size}\n color={iconColor}\n size={size}\n {...props}\n >\n {children}\n </Icon>\n )\n}\n\nIconDualColorBottom.displayName = 'IconDualColorBottom'\n"],"mappings":"mjCAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,IAAA,eAAAC,EAAAH,GCAA,IAAAI,EAAA,GAAAC,EAAAD,EAAA,YAAAE,EAAA,SAAAC,EAAA,QAAAC,ICAA,IAAAC,EAAoB,iCCApB,IAAAC,EAAuB,sBCAvB,IAAAC,EAAuB,sBAmChB,SAASC,EACdC,EACAC,EACiB,CACjB,GAAM,CAAE,QAAAC,EAAS,MAAAC,EAAO,UAAAC,EAAY,SAAU,QAAAC,CAAQ,EAAIJ,EAEpDK,EAAe,WAAS,IAAIN,EAAU,CAACO,EAAOC,IAAU,CAzChE,IAAAC,EAAAC,EA0CI,GAAI,CAAO,iBAAeH,CAAK,EAAG,OAAOA,EAEzC,IAAMI,GAAeD,GAAAD,EAAAF,EAAM,OAAN,YAAAE,EAAoC,cAApC,KAAAC,EAAmD,GAClEE,EAAeV,EAAQ,SAASS,CAAW,EAE3CE,EAAaN,EAAM,MAKzB,OAAa,eACXA,EACAO,EAAAC,EAAA,GACMH,EAAeT,EAAQ,CAAC,GAD9B,CAEE,IAAK,GAAGC,CAAS,IAAII,EAAM,SAAS,CAAC,EACvC,GACAT,EAAsBc,GAAA,YAAAA,EAAY,SAAU,CAC1C,QAAAX,EACA,MAAAC,EAC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AQE,SAAAJ,GACH,CAEJ,CAEAH,EAAoB,YAAc","names":["icon_dual_color_exports","__export","namespace_exports","__toCommonJS","namespace_exports","__export","IconDualColorBottom","IconDualColorRoot","IconDualColorTop","import_factory","React","React","injectPropsToChildren","children","options","targets","props","keyPrefix","asChild","cloned","child","index","_a","_b","displayName","shouldInject","childProps","__spreadProps","__spreadValues","useEnhancedChildren","children","targets","props","asChild","keyPrefix","injectPropsToChildren","import_jsx_runtime","IconDualColorRoot","_a","_b","children","size","disabled","asChild","props","__objRest","enhancedChildrenWithInjectProps","useEnhancedChildren","__spreadProps","__spreadValues","React","React","import_pulso_design_tokens","React","import_jsx_runtime","ThemeContext","useTheme","mappedTheme","context","ThemeContext","currentTheme","__spreadValues","import_jsx_runtime","Icon","_a","_b","symbol","size","color","props","__objRest","theme","useTheme","resolvedFontSizes","__spreadProps","__spreadValues","import_jsx_runtime","IconDualColorTop","_a","_b","children","color","size","disabled","props","__objRest","Icon","__spreadProps","__spreadValues","import_jsx_runtime","IconDualColorBottom","_a","_b","children","color","size","disabled","props","__objRest","Icon","__spreadProps","__spreadValues"]}