@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 • 16.8 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/components/switch/index.ts","../../../src/components/switch/switch.tsx","../../../src/utils/tv.ts","../../../src/components/switch/components/switch-label/switch-label.styles.ts","../../../src/components/switch/components/switch-label/index.tsx","../../../src/components/refresh/index.tsx","../../../src/hooks/use-theme.ts","../../../src/components/theme-provider/index.tsx","../../../src/utils/cn.ts","../../../src/components/switch/components/switch-refresh/index.tsx","../../../src/components/switch/components/switch-thumb/index.tsx","../../../src/components/switch/components/switch-thumb/switch-thumb.styles.ts","../../../src/components/switch/components/switch-toggle/index.tsx","../../../src/components/switch/components/switch-toggle/switch-toggle.styles.ts","../../../src/components/switch/switch.styles.ts"],"sourcesContent":["export { Switch } from './switch'\nexport type { SwitchProps } from './switch.types'\n","import { type Scope, createContextScope } from '@radix-ui/react-context'\n\nimport type {\n SwitchContext,\n SwitchProps,\n SwitchScopedProps,\n} from './switch.types'\n\nimport { SwitchLabel } from './components/switch-label'\nimport { SwitchRefresh } from './components/switch-refresh'\nimport { SwitchThumb } from './components/switch-thumb'\nimport { SwitchToggle } from './components/switch-toggle'\nimport { SwitchRootVariants } from './switch.styles'\n\nexport const DISPLAY_NAME = 'Switch'\n\ntype SwitchRootProps = SwitchProps & {\n children: React.ReactNode\n}\n\nconst SwitchRoot = (props: SwitchRootProps) => {\n const {\n disabled = false,\n loading = false,\n children,\n __scopeSwitch,\n ...rest\n } = props as SwitchScopedProps<SwitchRootProps>\n\n return (\n <SwitchProvider\n {...rest}\n disabled={disabled}\n loading={loading}\n scope={__scopeSwitch}\n >\n <div className={SwitchRootVariants()} data-testid=\"switch-root\">\n {children}\n </div>\n </SwitchProvider>\n )\n}\n\nconst [createSwitchContext] = createContextScope(DISPLAY_NAME)\n\nexport const [SwitchProvider, useSwitchContext]: readonly [\n ProviderType<SwitchContext>,\n (consumerName: string, scope: Scope) => SwitchContext,\n] = createSwitchContext<SwitchContext>(DISPLAY_NAME)\n\n/*\n----------------------------------------------------------------\nComposition Export\n----------------------------------------------------------------\n*/\n\nexport const Switch = {\n Root: SwitchRoot,\n Toggle: SwitchToggle,\n Thumb: SwitchThumb,\n Label: SwitchLabel,\n Refresh: SwitchRefresh,\n}\n","import { type VariantProps, createTV } from 'tailwind-variants'\n\nexport const tv = createTV({\n twMerge: true,\n twMergeConfig: {\n extend: {\n classGroups: {\n 'font-size': [\n {\n text: ['threepulse', 'threeandhalfpulse'],\n },\n ],\n 'border-width': [\n {\n border: ['quarterpulse', 'halfpulse'],\n },\n ],\n '--tw-ring-inset': [\n {\n ring: ['none', 'quarterpulse', 'halfpulse'],\n },\n ],\n },\n },\n },\n})\n\nexport type { VariantProps }\n","import { tv } from '~/utils/tv'\n\nexport const SwitchLabelVariants = tv({\n base: `\n text-text-neutral-alternative text-threepulse font-bold font-rdmodern line leading-medium text-nowrap\n `,\n variants: {\n isDisabled: {\n true: 'text-text-neutral-disabled',\n },\n },\n})\n","import type { SwitchScopedProps } from '../../switch.types'\nimport { SwitchLabelVariants } from './switch-label.styles'\n\nimport { DISPLAY_NAME, useSwitchContext } from '../../switch'\n\ntype SwitchLabelProps = {\n children: React.ReactNode\n}\n\nexport const SwitchLabel = (props: SwitchLabelProps) => {\n const { children, __scopeSwitch } =\n props as SwitchScopedProps<SwitchLabelProps>\n\n const { disabled, loading } = useSwitchContext(DISPLAY_NAME, __scopeSwitch)\n\n const isShowLabel = !loading || disabled\n const isDisabled = disabled\n\n return (\n <>\n {isShowLabel && (\n <div>\n <label\n className={SwitchLabelVariants({\n isDisabled,\n })}\n data-testid=\"switch-label\"\n aria-label={children?.toString()}\n >\n {children}\n </label>\n </div>\n )}\n </>\n )\n}\n","import * as React from 'react'\n\nimport { useTheme } from '~/hooks/use-theme'\nimport { cn } from '~/utils/cn'\n\n/**\n * Conjunto de opções de cor disponíveis para o componente Refresh.\n */\nexport type RefreshColor = 'brand' | 'neutral' | 'black' | 'white'\n\n/**\n * Propriedades do componente Refresh.\n */\nexport type RefreshProps = {\n /**\n * Define a cor do ícone de carregamento com base nos tokens do tema.\n * - `brand`: usa a cor primária da marca.\n * - `neutral`: usa um tom neutro de leitura.\n * - `black`: usa a cor padrão para texto.\n * - `white`: usa a cor inversa (geralmente branco).\n *\n * @default \"brand\"\n */\n color?: RefreshColor\n\n /**\n * Texto alternativo para acessibilidade (leitores de tela).\n * É renderizado como `aria-label` e como conteúdo do elemento `<title>` do SVG.\n */\n srText?: string\n}\n\n/**\n * Componente de ícone animado de carregamento, com suporte a temas e acessibilidade.\n */\nexport function Refresh({ color = 'brand', srText }: RefreshProps) {\n const theme = useTheme()\n\n const colorMap = React.useMemo(() => {\n return {\n brand: theme.colorActionFillBrandPrimaryEnabled,\n neutral: theme.colorTextNeutralReadonly,\n black: theme.colorTextNeutralDefault,\n white: theme.colorTextNeutralInverse,\n }\n }, [theme])\n\n const fillColor = colorMap[color]\n\n return (\n <div\n role=\"status\"\n className={cn('grid size-8 place-items-center')}\n aria-label={srText}\n >\n <svg className={cn('size-6 animate-spin fill-none')} viewBox=\"0 0 24 24\">\n <path\n fillRule=\"evenodd\"\n clipRule=\"evenodd\"\n d=\"M0 12c0 6.627 5.373 12 12 12s12-5.373 12-12S18.627 0 12 0v2c5.523 0 10 4.477 10 10s-4.477 10-10 10S2 17.523 2 12H0z\"\n fill={fillColor}\n />\n <title>{srText}</title>\n </svg>\n </div>\n )\n}\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 { type ClassValue, clsx } from 'clsx'\nimport { twMerge } from 'tailwind-merge'\n\nexport const cn = (...input: ClassValue[]) => twMerge(clsx(...input))\n","import { Refresh } from '~/components/refresh'\nimport { DISPLAY_NAME, useSwitchContext } from '../../switch'\nimport type { SwitchScopedProps } from '../../switch.types'\n\ntype SwitchRefreshProps = {}\n\nexport const SwitchRefresh = (props: SwitchRefreshProps) => {\n const { __scopeSwitch } = props as SwitchScopedProps<SwitchRefreshProps>\n\n const { disabled, loading } = useSwitchContext(DISPLAY_NAME, __scopeSwitch)\n\n const isShowLoading = loading && !disabled\n return (\n <>\n {isShowLoading && (\n <div data-testid=\"switch-refresh\">\n <Refresh color=\"neutral\" />\n </div>\n )}\n </>\n )\n}\n","import * as Switch from '@radix-ui/react-switch'\nimport { SwitchThumbVariants } from './switch-thumb.styles'\n\nexport const SwitchThumb = () => {\n return (\n <Switch.Thumb\n className={SwitchThumbVariants()}\n data-testid=\"switch-thumb\"\n />\n )\n}\n","import { tv } from '~/utils/tv'\n\nexport const SwitchThumbVariants = tv({\n base: `\n flex w-extrasmall h-extrasmall bg-[white] rounded-pill data-[state=checked]:translate-x-[16px] transition-transform\n `,\n variants: {},\n})\n","import { forwardRef } from 'react'\n\nimport * as Switch from '@radix-ui/react-switch'\nimport { DISPLAY_NAME, useSwitchContext } from '../../switch'\n\nimport type { SwitchScopedProps } from '../../switch.types'\n\nimport { SwitchToggleVariants } from './switch-toggle.styles'\n\ntype SwitchToggleProps = Switch.SwitchProps & {\n children: React.ReactNode\n}\n\nexport const SwitchToggle = forwardRef<\n React.ElementRef<typeof Switch.Root>,\n SwitchToggleProps\n>((props, ref) => {\n const { children, __scopeSwitch } =\n props as SwitchScopedProps<SwitchToggleProps>\n const {\n disabled: isDisabled,\n loading: isLoading,\n defaultChecked,\n checked,\n ...rest\n } = useSwitchContext(DISPLAY_NAME, __scopeSwitch)\n return (\n <Switch.Root\n {...rest}\n ref={ref}\n defaultChecked={defaultChecked}\n checked={checked}\n data-testid=\"switch-toggle\"\n disabled={isDisabled || isLoading}\n className={SwitchToggleVariants({\n isDisabled,\n isLoading,\n })}\n >\n {children}\n </Switch.Root>\n )\n})\n\nSwitchToggle.displayName = 'SwitchToggle'\n","import { tv } from '~/utils/tv'\n\nexport const SwitchToggleVariants = tv({\n base: `\n flex w-mediumlarge min-w-mediumlarge h-small rounded-mediumcontainer p-halfpulse focus-visible:outline outline-2 outline-offset-2\n `,\n variants: {\n isDisabled: {\n true: '',\n },\n isLoading: {\n true: '',\n },\n },\n compoundVariants: [\n {\n isDisabled: true,\n className: `\n bg-text-neutral-disabled cursor-not-allowed\n `,\n },\n {\n // @TODO: Change all tokens from backgroundColor when token is available\n isDisabled: false,\n isLoading: false,\n className: `\n data-[state=unchecked]:bg-[#9E9E9E]\n data-[state=checked]:bg-action-text-onbrand\n data-[state=unchecked]:active:bg-[#6B6B6B]\n data-[state=checked]:active:bg-action-text-onbrand-pressed\n data-[state=unchecked]:hover:bg-[#828282]\n data-[state=checked]:hover:bg-action-text-onbrand-hovered\n\n `,\n },\n {\n isDisabled: false,\n isLoading: true,\n className: `\n data-[state=unchecked]:bg-[#6B6B6B]\n data-[state=checked]:bg-action-text-onbrand-pressed\n `,\n },\n ],\n})\n","import { tv } from '~/utils/tv'\n\nexport const SwitchRootVariants = tv({\n base: `\n flex flex-row gap-twopulse p-twopulse items-center\n `,\n variants: {},\n})\n"],"mappings":"+jCAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,YAAAE,IAAA,eAAAC,GAAAH,ICAA,IAAAI,EAA+C,mCCA/C,IAAAC,EAA4C,6BAE/BC,KAAK,YAAS,CACzB,QAAS,GACT,cAAe,CACb,OAAQ,CACN,YAAa,CACX,YAAa,CACX,CACE,KAAM,CAAC,aAAc,mBAAmB,CAC1C,CACF,EACA,eAAgB,CACd,CACE,OAAQ,CAAC,eAAgB,WAAW,CACtC,CACF,EACA,kBAAmB,CACjB,CACE,KAAM,CAAC,OAAQ,eAAgB,WAAW,CAC5C,CACF,CACF,CACF,CACF,CACF,CAAC,ECvBM,IAAMC,EAAsBC,EAAG,CACpC,KAAM;AAAA;AAAA,IAGN,SAAU,CACR,WAAY,CACV,KAAM,4BACR,CACF,CACF,CAAC,ECQG,IAAAC,EAAA,6BAVSC,EAAeC,GAA4B,CACtD,GAAM,CAAE,SAAAC,EAAU,cAAAC,CAAc,EAC9BF,EAEI,CAAE,SAAAG,EAAU,QAAAC,CAAQ,EAAIC,EAAiBC,EAAcJ,CAAa,EAK1E,SACE,mBACG,UALe,CAACE,GAAWD,OAM1B,OAAC,OACC,mBAAC,SACC,UAAWI,EAAoB,CAC7B,WAROJ,CAST,CAAC,EACD,cAAY,eACZ,aAAYF,GAAA,YAA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AAMiB,EAAqBC,EAAG,CACnC,KAAM;AAAA;AAAA,IAGN,SAAU,CAAC,CACb,CAAC,Eb6BK,IAAAC,EAAA,6BAtBOC,EAAe,SAMtBC,GAAcC,GAA2B,CAC7C,IAMIC,EAAAD,EALF,UAAAE,EAAW,GACX,QAAAC,EAAU,GACV,SAAAC,EACA,cAAAC,CAzBJ,EA2BMJ,EADCK,EAAAC,EACDN,EADC,CAJH,WACA,UACA,WACA,kBAIF,SACE,OAACO,GAAAC,EAAAC,EAAA,GACKJ,GADL,CAEC,SAAUJ,EACV,QAASC,EACT,MAAOE,EAEP,mBAAC,OAAI,UAAWM,EAAmB,EAAG,cAAY,cAC/C,SAAAP,EACH,GACF,CAEJ,EAEM,CAACQ,EAAmB,KAAI,sBAAmBd,CAAY,EAEhD,CAACU,GAAgBK,CAAgB,EAG1CD,GAAmCd,CAAY,EAQtCgB,EAAS,CACpB,KAAMf,GACN,OAAQgB,EACR,MAAOC,EACP,MAAOC,EACP,QAASC,CACX","names":["switch_exports","__export","Switch","__toCommonJS","import_react_context","import_tailwind_variants","tv","SwitchLabelVariants","tv","import_jsx_runtime","SwitchLabel","props","children","__scopeSwitch","disabled","loading","useSwitchContext","DISPLAY_NAME","SwitchLabelVariants","React","React","import_pulso_design_tokens","React","import_jsx_runtime","ThemeContext","useTheme","mappedTheme","context","ThemeContext","currentTheme","__spreadValues","import_clsx","import_tailwind_merge","cn","input","import_jsx_runtime","Refresh","color","srText","theme","useTheme","fillColor","cn","import_jsx_runtime","SwitchRefresh","props","__scopeSwitch","disabled","loading","useSwitchContext","DISPLAY_NAME","Refresh","Switch","SwitchThumbVariants","tv","import_jsx_runtime","SwitchThumb","SwitchThumbVariants","import_react","Switch","SwitchToggleVariants","tv","import_jsx_runtime","SwitchToggle","props","ref","children","__scopeSwitch","_a","useSwitchContext","DISPLAY_NAME","isDisabled","isLoading","defaultChecked","checked","rest","__objRest","__spreadProps","__spreadValues","SwitchToggleVariants","SwitchRootVariants","tv","import_jsx_runtime","DISPLAY_NAME","SwitchRoot","props","_a","disabled","loading","children","__scopeSwitch","rest","__objRest","SwitchProvider","__spreadProps","__spreadValues","SwitchRootVariants","createSwitchContext","useSwitchContext","Switch","SwitchToggle","SwitchThumb","SwitchLabel","SwitchRefresh"]}