UNPKG

@yamada-ui/react

Version:

React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion

37 lines (35 loc) 1.54 kB
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs'); const require_system_provider = require('../../core/system/system-provider.cjs'); const require_use_breakpoint = require('./use-breakpoint.cjs'); let react = require("react"); react = require_rolldown_runtime.__toESM(react); //#region src/hooks/use-breakpoint/use-breakpoint-value.ts /** * `useBreakpointValue` is a custom hook that returns the value of the current breakpoint from the provided object. * This hook monitors changes in the window size and returns the appropriate value. * * @see https://yamada-ui.com/docs/hooks/use-breakpoint-value */ const useBreakpointValue = (values) => { const system = require_system_provider.useSystem(); const breakpoint = require_use_breakpoint.useBreakpoint(); return (0, react.useMemo)(() => getBreakpointValue(values)(system, breakpoint), [ values, system, breakpoint ]); }; const getBreakpointValue = (values = {}) => (system, breakpoint) => { const breakpoints = system.breakpoints.keys; if (!breakpoints.length) console.warn("getBreakpointValue: `breakpoints` is undefined."); const currentIndex = breakpoints.indexOf(breakpoint); for (let i = currentIndex; 0 < i; i--) { const nextBreakpoint = breakpoints[i]; if (nextBreakpoint && values.hasOwnProperty(nextBreakpoint)) return values[nextBreakpoint]; } return values.base; }; //#endregion exports.getBreakpointValue = getBreakpointValue; exports.useBreakpointValue = useBreakpointValue; //# sourceMappingURL=use-breakpoint-value.cjs.map