@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
1 lines • 2.01 kB
Source Map (JSON)
{"version":3,"file":"use-breakpoint-value.cjs","names":["useSystem","useBreakpoint"],"sources":["../../../../src/hooks/use-breakpoint/use-breakpoint-value.ts"],"sourcesContent":["import type { Breakpoint, ResponsiveObject, System } from \"../../core\"\nimport { useMemo } from \"react\"\nimport { useSystem } from \"../../core\"\nimport { useBreakpoint } from \"./use-breakpoint\"\n\n/**\n * `useBreakpointValue` is a custom hook that returns the value of the current breakpoint from the provided object.\n * This hook monitors changes in the window size and returns the appropriate value.\n *\n * @see https://yamada-ui.com/docs/hooks/use-breakpoint-value\n */\nexport const useBreakpointValue = <Y>(\n values: ResponsiveObject<Y, false>,\n): Y => {\n const system = useSystem()\n const breakpoint = useBreakpoint()\n\n return useMemo(\n () => getBreakpointValue<Y>(values)(system, breakpoint),\n [values, system, breakpoint],\n )\n}\n\nexport const getBreakpointValue =\n <Y>(values: ResponsiveObject<Y, false> = {}) =>\n (system: System, breakpoint: Breakpoint): Y => {\n const breakpoints = system.breakpoints.keys\n\n if (!breakpoints.length) {\n console.warn(\"getBreakpointValue: `breakpoints` is undefined.\")\n }\n\n const currentIndex = breakpoints.indexOf(breakpoint)\n\n for (let i = currentIndex; 0 < i; i--) {\n const nextBreakpoint = breakpoints[i]\n\n if (nextBreakpoint && values.hasOwnProperty(nextBreakpoint)) {\n return values[nextBreakpoint] as Y\n }\n }\n\n return values.base as Y\n }\n"],"mappings":";;;;;;;;;;;;;AAWA,MAAa,sBACX,WACM;CACN,MAAM,SAASA,mCAAW;CAC1B,MAAM,aAAaC,sCAAe;AAElC,iCACQ,mBAAsB,OAAO,CAAC,QAAQ,WAAW,EACvD;EAAC;EAAQ;EAAQ;EAAW,CAC7B;;AAGH,MAAa,sBACP,SAAqC,EAAE,MAC1C,QAAgB,eAA8B;CAC7C,MAAM,cAAc,OAAO,YAAY;AAEvC,KAAI,CAAC,YAAY,OACf,SAAQ,KAAK,kDAAkD;CAGjE,MAAM,eAAe,YAAY,QAAQ,WAAW;AAEpD,MAAK,IAAI,IAAI,cAAc,IAAI,GAAG,KAAK;EACrC,MAAM,iBAAiB,YAAY;AAEnC,MAAI,kBAAkB,OAAO,eAAe,eAAe,CACzD,QAAO,OAAO;;AAIlB,QAAO,OAAO"}