@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
1 lines • 1.98 kB
Source Map (JSON)
{"version":3,"file":"index.cjs","names":["useSystem","useBreakpoint","useColorMode","getBreakpointValue","getColorModeValue"],"sources":["../../../../src/hooks/use-value/index.ts"],"sourcesContent":["\"use client\"\n\nimport type {\n Breakpoint,\n ColorMode,\n ColorModeArray,\n ResponsiveObject,\n System,\n} from \"../../core\"\nimport { useMemo } from \"react\"\nimport { getColorModeValue, useColorMode, useSystem } from \"../../core\"\nimport { isArray, isObject } from \"../../utils\"\nimport { getBreakpointValue, useBreakpoint } from \"../use-breakpoint\"\n\n/**\n * `useValue` is a custom hook that combines `useBreakpointValue` and `useColorModeValue`.\n *\n * @see https://yamada-ui.com/docs/hooks/use-value\n */\nexport const useValue = <Y>(\n value: ColorModeArray<Y, false> | ResponsiveObject<Y, false> | Y,\n): Y => {\n const system = useSystem()\n const breakpoint = useBreakpoint()\n const { colorMode } = useColorMode()\n\n return useMemo(() => {\n return getValue(value)(system, colorMode, breakpoint)\n }, [value, system, colorMode, breakpoint])\n}\n\nexport const getValue =\n <Y>(value: ColorModeArray<Y, false> | ResponsiveObject<Y, false> | Y) =>\n (system: System, colorMode: ColorMode, breakpoint: Breakpoint): Y => {\n if (isObject<ResponsiveObject<Y, false>>(value)) {\n return getBreakpointValue(value)(system, breakpoint)\n } else if (isArray<ColorModeArray<Y, false>>(value)) {\n const [light, dark] = value\n\n return getColorModeValue(light, dark)(colorMode)\n } else {\n return value\n }\n }\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,MAAa,YACX,UACM;CACN,MAAM,SAASA,mCAAW;CAC1B,MAAM,aAAaC,sCAAe;CAClC,MAAM,EAAE,cAAcC,0CAAc;AAEpC,iCAAqB;AACnB,SAAO,SAAS,MAAM,CAAC,QAAQ,WAAW,WAAW;IACpD;EAAC;EAAO;EAAQ;EAAW;EAAW,CAAC;;AAG5C,MAAa,YACP,WACH,QAAgB,WAAsB,eAA8B;AACnE,qDAAyC,MAAM,CAC7C,QAAOC,gDAAmB,MAAM,CAAC,QAAQ,WAAW;yDACT,MAAM,EAAE;EACnD,MAAM,CAAC,OAAO,QAAQ;AAEtB,SAAOC,+CAAkB,OAAO,KAAK,CAAC,UAAU;OAEhD,QAAO"}