@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 • 15.4 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/hooks/use-theme.ts","../../../src/components/theme-provider/theme-provider.tsx","../../../src/components/refresh/utils/get-refresh-color.ts","../../../src/components/refresh/refresh.tsx","../../../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 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 {\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 { useContext } from 'react'\n\nimport { ThemeContext } from '~/components/theme-provider/theme-provider'\n\nexport function useTheme() {\n const { currentTheme } = useContext(ThemeContext)\n\n const themes = {\n rdsaudesistemas: RDSAUDESISTEMAS_TOKENS,\n drogasil: DROGASIL_TOKENS,\n raia: RAIA_TOKENS,\n subscription: SUBSCRIPTION_TOKENS,\n prime: PRIME_TOKENS,\n }\n\n return {\n ...themes[currentTheme],\n ...GLOBALS_TOKENS,\n }\n}\n","import { createContext, useEffect } from 'react'\n\nimport type { Themes } from '@raiadrogasil/pulso-design-tokens'\n\ntype TThemeContextData = {\n currentTheme: Themes\n}\n\ninterface IThemeProviderProps {\n children: React.ReactNode\n theme: Themes\n}\n\nexport const ThemeContext = createContext({} as TThemeContextData)\n\nexport function ThemeProvider({ children, theme }: IThemeProviderProps) {\n useEffect(() => {\n if (theme && document) {\n document?.documentElement?.classList?.add(theme)\n }\n\n return () => {\n document?.documentElement?.classList?.remove(theme)\n }\n }, [theme])\n\n return (\n <ThemeContext.Provider\n value={{\n currentTheme: theme,\n }}\n >\n {children}\n </ThemeContext.Provider>\n )\n}\n","import { useTheme } from '~/hooks/use-theme'\n\nimport type { TRefreshColor } from '../refresh.types'\n\nexport function getRefreshColor(color: TRefreshColor) {\n const theme = useTheme()\n\n const colors = {\n brand: theme.colorActionFillBrandPrimaryEnabled,\n neutral: theme.colorTextNeutralReadonly,\n black: theme.colorTextNeutralDefault,\n white: theme.colorTextNeutralInverse,\n } as Record<TRefreshColor, string>\n\n return colors[color]\n}\n","import type { TRefreshProps } from './refresh.types'\n\nimport { getRefreshColor } from './utils/get-refresh-color'\n\nexport function Refresh({ color = 'brand', srText }: TRefreshProps) {\n return (\n <div\n role=\"status\"\n className=\"grid size-eightpulse place-items-center\"\n aria-label={srText}\n >\n <svg className=\"size-sixpulse animate-spin fill-none\" viewBox=\"0 0 24 24\">\n <path\n fillRule=\"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 clipRule=\"evenodd\"\n fill={getRefreshColor(color)}\n />\n\n <title>{srText}</title>\n </svg>\n </div>\n )\n}\n\nexport type { TRefreshProps }\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":"yjCAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,YAAAE,IAAA,eAAAC,GAAAH,ICAA,IAAAI,EAA+C,mCCA/C,IAAAC,EAA4C,6BAE/BC,KAAK,YAAS,CACzB,cAAe,CACb,OAAQ,CACN,YAAa,CACX,YAAa,CACX,CACE,KAAM,CAAC,aAAc,mBAAmB,CAC1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AvBJ,EAyBMN,EADCO,EAAAC,EACDR,EADC,CAJH,WACA,UACA,iBACA,YAGF,SACE,OAAQ,OAAPS,EAAAC,EAAA,GACKH,GADL,CAEC,IAAKV,EACL,eAAgBQ,EAChB,QAASC,EACT,cAAY,gBACZ,SAAUH,GAAcC,EACxB,UAAWO,EAAqB,CAC9B,WAAAR,EACA,UAAAC,CACF,CAAC,EAEA,SAAAN,GACH,CAEJ,CAAC,EAEDH,EAAa,YAAc,eE1CpB,IAAMiB,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","import_pulso_design_tokens","import_react","import_react","import_jsx_runtime","ThemeContext","useTheme","currentTheme","ThemeContext","__spreadValues","getRefreshColor","color","theme","useTheme","import_jsx_runtime","Refresh","color","srText","getRefreshColor","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"]}