@yamada-ui/react 2.3.4-dev-20261124000514 → 2.3.4-dev-20261124055019
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/picture/picture.cjs +3 -3
- package/dist/cjs/components/picture/picture.cjs.map +1 -1
- package/dist/cjs/core/constant.cjs +2 -0
- package/dist/cjs/core/constant.cjs.map +1 -1
- package/dist/cjs/core/index.cjs +2 -1
- package/dist/cjs/core/system/breakpoint.cjs +2 -1
- package/dist/cjs/core/system/breakpoint.cjs.map +1 -1
- package/dist/cjs/hooks/use-breakpoint/use-breakpoint-effect.cjs +10 -2
- package/dist/cjs/hooks/use-breakpoint/use-breakpoint-effect.cjs.map +1 -1
- package/dist/cjs/hooks/use-breakpoint/use-breakpoint-state.cjs.map +1 -1
- package/dist/cjs/hooks/use-breakpoint/use-breakpoint-value.cjs +6 -2
- package/dist/cjs/hooks/use-breakpoint/use-breakpoint-value.cjs.map +1 -1
- package/dist/cjs/hooks/use-breakpoint/use-breakpoint.cjs +2 -1
- package/dist/cjs/hooks/use-breakpoint/use-breakpoint.cjs.map +1 -1
- package/dist/cjs/hooks/use-breakpoint/use-update-breakpoint-effect.cjs +10 -2
- package/dist/cjs/hooks/use-breakpoint/use-update-breakpoint-effect.cjs.map +1 -1
- package/dist/cjs/index.cjs +3 -1
- package/dist/esm/components/picture/picture.js +3 -3
- package/dist/esm/components/picture/picture.js.map +1 -1
- package/dist/esm/core/constant.js +2 -1
- package/dist/esm/core/constant.js.map +1 -1
- package/dist/esm/core/index.js +2 -2
- package/dist/esm/core/system/breakpoint.js +2 -1
- package/dist/esm/core/system/breakpoint.js.map +1 -1
- package/dist/esm/hooks/use-breakpoint/use-breakpoint-effect.js +10 -2
- package/dist/esm/hooks/use-breakpoint/use-breakpoint-effect.js.map +1 -1
- package/dist/esm/hooks/use-breakpoint/use-breakpoint-state.js.map +1 -1
- package/dist/esm/hooks/use-breakpoint/use-breakpoint-value.js +6 -2
- package/dist/esm/hooks/use-breakpoint/use-breakpoint-value.js.map +1 -1
- package/dist/esm/hooks/use-breakpoint/use-breakpoint.js +2 -1
- package/dist/esm/hooks/use-breakpoint/use-breakpoint.js.map +1 -1
- package/dist/esm/hooks/use-breakpoint/use-update-breakpoint-effect.js +10 -2
- package/dist/esm/hooks/use-breakpoint/use-update-breakpoint-effect.js.map +1 -1
- package/dist/esm/index.js +3 -2
- package/dist/types/components/accordion/accordion.style.d.ts +1 -1
- package/dist/types/components/alert/alert.style.d.ts +1 -1
- package/dist/types/components/autocomplete/autocomplete.style.d.ts +1 -1
- package/dist/types/components/breadcrumb/breadcrumb.style.d.ts +1 -1
- package/dist/types/components/bubble/bubble.style.d.ts +1 -1
- package/dist/types/components/calendar/calendar.style.d.ts +2 -2
- package/dist/types/components/carousel/carousel.style.d.ts +2 -2
- package/dist/types/components/checkbox-card/checkbox-card.d.ts +3 -3
- package/dist/types/components/checkbox-card/checkbox-card.style.d.ts +1 -1
- package/dist/types/components/color-picker/color-picker.style.d.ts +1 -1
- package/dist/types/components/data-list/data-list.style.d.ts +1 -1
- package/dist/types/components/date-picker/date-picker.style.d.ts +1 -1
- package/dist/types/components/dropzone/dropzone.d.ts +1 -1
- package/dist/types/components/dropzone/dropzone.style.d.ts +1 -1
- package/dist/types/components/editable/editable.d.ts +1 -1
- package/dist/types/components/editable/editable.style.d.ts +1 -1
- package/dist/types/components/empty-state/empty-state.style.d.ts +2 -2
- package/dist/types/components/flip/flip.d.ts +1 -1
- package/dist/types/components/flip/flip.style.d.ts +1 -1
- package/dist/types/components/form/form.style.d.ts +1 -1
- package/dist/types/components/list/list.style.d.ts +2 -2
- package/dist/types/components/marquee/marquee.style.d.ts +1 -1
- package/dist/types/components/menu/menu.style.d.ts +2 -2
- package/dist/types/components/native-accordion/native-accordion.style.d.ts +2 -2
- package/dist/types/components/native-select/native-select.style.d.ts +1 -1
- package/dist/types/components/notice/notice.style.d.ts +1 -1
- package/dist/types/components/number-input/number-input.style.d.ts +1 -1
- package/dist/types/components/pagination/pagination.style.d.ts +1 -1
- package/dist/types/components/password-input/password-input.style.d.ts +1 -1
- package/dist/types/components/pin-input/pin-input.style.d.ts +1 -1
- package/dist/types/components/radio-card/radio-card.d.ts +3 -3
- package/dist/types/components/radio-card/radio-card.style.d.ts +1 -1
- package/dist/types/components/rating/rating.style.d.ts +2 -2
- package/dist/types/components/reorder/reorder.style.d.ts +1 -1
- package/dist/types/components/resizable/resizable.style.d.ts +2 -2
- package/dist/types/components/segmented-control/segmented-control.style.d.ts +2 -2
- package/dist/types/components/select/select.style.d.ts +1 -1
- package/dist/types/components/steps/steps.style.d.ts +1 -1
- package/dist/types/components/timeline/timeline.d.ts +1 -1
- package/dist/types/components/timeline/timeline.style.d.ts +1 -1
- package/dist/types/components/tree/tree.style.d.ts +1 -1
- package/dist/types/core/constant.d.ts +2 -1
- package/dist/types/core/index.d.ts +2 -2
- package/dist/types/hooks/use-breakpoint/use-breakpoint-effect.d.ts +2 -2
- package/dist/types/hooks/use-breakpoint/use-breakpoint-state.d.ts +2 -1
- package/dist/types/hooks/use-breakpoint/use-breakpoint-value.d.ts +2 -2
- package/dist/types/hooks/use-breakpoint/use-update-breakpoint-effect.d.ts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/package.json +1 -1
|
@@ -22,13 +22,13 @@ const createQuery = (minW, maxW) => {
|
|
|
22
22
|
const Picture = ({ children, enableSorting = true, sources: sourcesProp = [], pictureProps, ...rest }) => {
|
|
23
23
|
const system = require_system_provider.useSystem();
|
|
24
24
|
const { queriesObj } = system.breakpoints;
|
|
25
|
-
const { direction
|
|
25
|
+
const { direction, identifier = "@media screen" } = system.config.breakpoint ?? {};
|
|
26
26
|
const searchValue = identifier === "@media screen" ? "@media screen and " : `${identifier} `;
|
|
27
27
|
const compareSources = (0, react.useCallback)((a, b) => {
|
|
28
|
-
const k = direction === "
|
|
28
|
+
const k = direction === "up" ? "minW" : "maxW";
|
|
29
29
|
if ((0, require_utils_index.utils_exports.isUndefined)(a[k]) && !(0, require_utils_index.utils_exports.isUndefined)(b[k])) return -1;
|
|
30
30
|
if (!(0, require_utils_index.utils_exports.isUndefined)(a[k]) && (0, require_utils_index.utils_exports.isUndefined)(b[k])) return 1;
|
|
31
|
-
return direction === "
|
|
31
|
+
return direction === "up" ? Number(b.minW) - Number(a.minW) : Number(a.maxW) - Number(b.maxW);
|
|
32
32
|
}, [direction]);
|
|
33
33
|
const sources = (0, react.useMemo)(() => {
|
|
34
34
|
const computedSources = sourcesProp.map(({ maxW, media, minW, ...rest }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"picture.cjs","names":["useSystem","useCallback","useMemo","tokenToValue","styled","Image"],"sources":["../../../../src/components/picture/picture.tsx"],"sourcesContent":["import type { FC } from \"react\"\nimport type { HTMLStyledProps, ThemeTokens } from \"../../core\"\nimport type { AnyString } from \"../../utils\"\nimport type { ImageProps } from \"../image\"\nimport { useCallback, useMemo } from \"react\"\nimport { styled, tokenToValue, useSystem } from \"../../core\"\nimport { getPx, isUndefined } from \"../../utils\"\nimport { Image } from \"../image\"\n\nconst createQuery = (\n minW: number | string | undefined,\n maxW: number | string | undefined,\n) => {\n let media = \"\"\n\n if (minW) {\n media = `(min-width: ${minW}px)`\n\n if (maxW) media += ` and (max-width: ${maxW}px)`\n } else {\n media = `(max-width: ${maxW}px)`\n }\n\n return media\n}\n\nexport interface PictureSource extends SourceProps {\n /**\n * The maximum width for the source.\n *\n * If media is set, media takes precedence.\n */\n maxW?: AnyString | number | ThemeTokens[\"sizes\"]\n /**\n * The minimum width for the source.\n *\n * If media is set, media takes precedence.\n */\n minW?: AnyString | number | ThemeTokens[\"sizes\"]\n /**\n * The source set for the source element.\n */\n srcSet?: string\n}\n\nexport interface PictureProps extends ImageProps {\n /**\n * If `true`, the sources will be sorted by the `minW` and `maxW` properties.\n *\n * @default true\n */\n enableSorting?: boolean\n /**\n * The sources for the picture element.\n */\n sources?: PictureSource[]\n /**\n * The props for the picture element.\n */\n pictureProps?: HTMLStyledProps<\"picture\">\n}\n\n/**\n * `Picture` is a component that uses the `picture` element to provide alternative images for different display or device scenarios.\n *\n * @see https://yamada-ui.com/docs/components/picture\n */\nexport const Picture: FC<PictureProps> = ({\n children,\n enableSorting = true,\n sources: sourcesProp = [],\n pictureProps,\n ...rest\n}) => {\n const system = useSystem()\n const { queriesObj } = system.breakpoints\n const { direction
|
|
1
|
+
{"version":3,"file":"picture.cjs","names":["useSystem","useCallback","useMemo","tokenToValue","styled","Image"],"sources":["../../../../src/components/picture/picture.tsx"],"sourcesContent":["import type { FC } from \"react\"\nimport type { HTMLStyledProps, ThemeTokens } from \"../../core\"\nimport type { AnyString } from \"../../utils\"\nimport type { ImageProps } from \"../image\"\nimport { useCallback, useMemo } from \"react\"\nimport { styled, tokenToValue, useSystem } from \"../../core\"\nimport { getPx, isUndefined } from \"../../utils\"\nimport { Image } from \"../image\"\n\nconst createQuery = (\n minW: number | string | undefined,\n maxW: number | string | undefined,\n) => {\n let media = \"\"\n\n if (minW) {\n media = `(min-width: ${minW}px)`\n\n if (maxW) media += ` and (max-width: ${maxW}px)`\n } else {\n media = `(max-width: ${maxW}px)`\n }\n\n return media\n}\n\nexport interface PictureSource extends SourceProps {\n /**\n * The maximum width for the source.\n *\n * If media is set, media takes precedence.\n */\n maxW?: AnyString | number | ThemeTokens[\"sizes\"]\n /**\n * The minimum width for the source.\n *\n * If media is set, media takes precedence.\n */\n minW?: AnyString | number | ThemeTokens[\"sizes\"]\n /**\n * The source set for the source element.\n */\n srcSet?: string\n}\n\nexport interface PictureProps extends ImageProps {\n /**\n * If `true`, the sources will be sorted by the `minW` and `maxW` properties.\n *\n * @default true\n */\n enableSorting?: boolean\n /**\n * The sources for the picture element.\n */\n sources?: PictureSource[]\n /**\n * The props for the picture element.\n */\n pictureProps?: HTMLStyledProps<\"picture\">\n}\n\n/**\n * `Picture` is a component that uses the `picture` element to provide alternative images for different display or device scenarios.\n *\n * @see https://yamada-ui.com/docs/components/picture\n */\nexport const Picture: FC<PictureProps> = ({\n children,\n enableSorting = true,\n sources: sourcesProp = [],\n pictureProps,\n ...rest\n}) => {\n const system = useSystem()\n const { queriesObj } = system.breakpoints\n const { direction, identifier = \"@media screen\" } =\n system.config.breakpoint ?? {}\n const searchValue =\n identifier === \"@media screen\" ? \"@media screen and \" : `${identifier} `\n\n const compareSources = useCallback(\n (a: PictureSource, b: PictureSource) => {\n const k = direction === \"up\" ? \"minW\" : \"maxW\"\n\n if (isUndefined(a[k]) && !isUndefined(b[k])) return -1\n\n if (!isUndefined(a[k]) && isUndefined(b[k])) return 1\n\n return direction === \"up\"\n ? Number(b.minW) - Number(a.minW)\n : Number(a.maxW) - Number(b.maxW)\n },\n [direction],\n )\n\n const sources = useMemo(() => {\n const computedSources = sourcesProp.map(\n ({ maxW, media, minW, ...rest }) => {\n if (!media) {\n if (minW) minW = getPx(tokenToValue(system)(\"sizes\", minW))\n if (maxW) maxW = getPx(tokenToValue(system)(\"sizes\", maxW))\n\n media = createQuery(minW, maxW)\n\n return { ...rest, maxW, media, minW }\n } else {\n const { maxW, minW, query } = queriesObj[media] ?? {}\n\n if (query) media = query.replace(searchValue, \"\")\n\n return { ...rest, maxW, media, minW }\n }\n },\n )\n\n if (enableSorting) return computedSources.sort(compareSources)\n else return computedSources\n }, [\n sourcesProp,\n enableSorting,\n system,\n queriesObj,\n searchValue,\n compareSources,\n ])\n\n const sourceElements = useMemo(\n () =>\n sources.map(({ maxW: _maxW, minW: _minW, ...rest }, index) => (\n <styled.source key={index} {...rest} />\n )),\n [sources],\n )\n\n return (\n <styled.picture {...pictureProps}>\n {children ?? (\n <>\n {sourceElements}\n\n <Image {...rest} />\n </>\n )}\n </styled.picture>\n )\n}\n\nexport interface SourceProps extends HTMLStyledProps<\"source\"> {\n /**\n * The media query for the source.\n */\n media?: AnyString | ThemeTokens[\"breakpoints\"]\n}\n\nexport const Source: FC<SourceProps> = ({ media, ...rest }) => {\n const { breakpoints, config } = useSystem()\n const { queriesObj } = breakpoints\n const { identifier = \"@media screen\" } = config.breakpoint ?? {}\n const searchValue =\n identifier === \"@media screen\" ? \"@media screen and \" : `${identifier} `\n\n const { query } = media ? (queriesObj[media] ?? {}) : {}\n\n if (query) media = query.replace(searchValue, \"\")\n\n return <styled.source media={media} {...rest} />\n}\n"],"mappings":";;;;;;;;AASA,MAAM,eACJ,MACA,SACG;CACH,IAAI,QAAQ;CAEZ,IAAI,MAAM;EACR,QAAQ,eAAe,KAAK;EAE5B,IAAI,MAAM,SAAS,oBAAoB,KAAK;CAC9C,OACE,QAAQ,eAAe,KAAK;CAG9B,OAAO;AACT;;;;;;AA2CA,MAAa,WAA6B,EACxC,UACA,gBAAgB,MAChB,SAAS,cAAc,CAAC,GACxB,cACA,GAAG,WACC;CACJ,MAAM,SAASA,wBAAAA,UAAU;CACzB,MAAM,EAAE,eAAe,OAAO;CAC9B,MAAM,EAAE,WAAW,aAAa,oBAC9B,OAAO,OAAO,cAAc,CAAC;CAC/B,MAAM,cACJ,eAAe,kBAAkB,uBAAuB,GAAG,WAAW;CAExE,MAAM,kBAAA,GAAiBC,MAAAA,YAAAA,EACpB,GAAkB,MAAqB;EACtC,MAAM,IAAI,cAAc,OAAO,SAAS;EAExC,KAAA,GAAA,oBAAA,cAAI,YAAA,CAAY,EAAE,EAAE,KAAK,EAAA,GAAA,oBAAA,cAAC,YAAA,CAAY,EAAE,EAAE,GAAG,OAAO;EAEpD,IAAI,EAAA,GAAA,oBAAA,cAAC,YAAA,CAAY,EAAE,EAAE,MAAA,GAAA,oBAAA,cAAK,YAAA,CAAY,EAAE,EAAE,GAAG,OAAO;EAEpD,OAAO,cAAc,OACjB,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,IAAI,IAC9B,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,IAAI;CACpC,GACA,CAAC,SAAS,CACZ;CAEA,MAAM,WAAA,GAAUC,MAAAA,QAAAA,OAAc;EAC5B,MAAM,kBAAkB,YA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AU;CAC1C,MAAM,EAAE,eAAe;CACvB,MAAM,EAAE,aAAa,oBAAoB,OAAO,cAAc,CAAC;CAC/D,MAAM,cACJ,eAAe,kBAAkB,uBAAuB,GAAG,WAAW;CAExE,MAAM,EAAE,UAAU,QAAS,WAAW,UAAU,CAAC,IAAK,CAAC;CAEvD,IAAI,OAAO,QAAQ,MAAM,QAAQ,aAAa,EAAE;CAEhD,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAACI,gBAAAA,OAAO,QAAR;EAAsB;EAAO,GAAI;CAAO,CAAA;AACjD"}
|
|
@@ -38,7 +38,9 @@ const DEFAULT_LAYERS = {
|
|
|
38
38
|
order: 0
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
|
+
const DEFAULT_BREAKPOINT_DIRECTION = "down";
|
|
41
42
|
exports.COLOR_MODE_STORAGE_KEY = COLOR_MODE_STORAGE_KEY;
|
|
43
|
+
exports.DEFAULT_BREAKPOINT_DIRECTION = DEFAULT_BREAKPOINT_DIRECTION;
|
|
42
44
|
exports.DEFAULT_DIRECTION = DEFAULT_DIRECTION;
|
|
43
45
|
exports.DEFAULT_LAYERS = DEFAULT_LAYERS;
|
|
44
46
|
exports.DEFAULT_LOCALE = DEFAULT_LOCALE;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constant.cjs","names":[],"sources":["../../../src/core/constant.ts"],"sourcesContent":["import type { LayersConfig } from \"./system\"\n\nexport const COLOR_MODE_STORAGE_KEY = \"color-mode\"\nexport const THEME_SCHEME_STORAGE_KEY = \"theme-scheme\"\n\nexport const DEFAULT_VAR_PREFIX = \"ui\"\nexport const DEFAULT_LOCALE = \"en-US\"\nexport const DEFAULT_DIRECTION = \"ltr\"\nexport const DEFAULT_LAYERS: LayersConfig = {\n size: { name: \"size\", order: 4 },\n variant: { name: \"variant\", order: 5 },\n base: { name: \"base\", order: 3 },\n compounds: { name: \"compounds\", order: 7 },\n global: { name: \"global\", order: 2 },\n props: { name: \"props\", order: 6 },\n reset: { name: \"reset\", order: 1 },\n tokens: { name: \"tokens\", order: 0 },\n}\n"],"mappings":";AAEA,MAAa,yBAAyB;AACtC,MAAa,2BAA2B;AAExC,MAAa,qBAAqB;AAClC,MAAa,iBAAiB;AAC9B,MAAa,oBAAoB;AACjC,MAAa,iBAA+B;CAC1C,MAAM;EAAE,MAAM;EAAQ,OAAO;CAAE;CAC/B,SAAS;EAAE,MAAM;EAAW,OAAO;CAAE;CACrC,MAAM;EAAE,MAAM;EAAQ,OAAO;CAAE;CAC/B,WAAW;EAAE,MAAM;EAAa,OAAO;CAAE;CACzC,QAAQ;EAAE,MAAM;EAAU,OAAO;CAAE;CACnC,OAAO;EAAE,MAAM;EAAS,OAAO;CAAE;CACjC,OAAO;EAAE,MAAM;EAAS,OAAO;CAAE;CACjC,QAAQ;EAAE,MAAM;EAAU,OAAO;CAAE;AACrC"}
|
|
1
|
+
{"version":3,"file":"constant.cjs","names":[],"sources":["../../../src/core/constant.ts"],"sourcesContent":["import type { LayersConfig } from \"./system\"\n\nexport const COLOR_MODE_STORAGE_KEY = \"color-mode\"\nexport const THEME_SCHEME_STORAGE_KEY = \"theme-scheme\"\n\nexport const DEFAULT_VAR_PREFIX = \"ui\"\nexport const DEFAULT_LOCALE = \"en-US\"\nexport const DEFAULT_DIRECTION = \"ltr\"\nexport const DEFAULT_LAYERS: LayersConfig = {\n size: { name: \"size\", order: 4 },\n variant: { name: \"variant\", order: 5 },\n base: { name: \"base\", order: 3 },\n compounds: { name: \"compounds\", order: 7 },\n global: { name: \"global\", order: 2 },\n props: { name: \"props\", order: 6 },\n reset: { name: \"reset\", order: 1 },\n tokens: { name: \"tokens\", order: 0 },\n}\nexport const DEFAULT_BREAKPOINT_DIRECTION = \"down\"\n"],"mappings":";AAEA,MAAa,yBAAyB;AACtC,MAAa,2BAA2B;AAExC,MAAa,qBAAqB;AAClC,MAAa,iBAAiB;AAC9B,MAAa,oBAAoB;AACjC,MAAa,iBAA+B;CAC1C,MAAM;EAAE,MAAM;EAAQ,OAAO;CAAE;CAC/B,SAAS;EAAE,MAAM;EAAW,OAAO;CAAE;CACrC,MAAM;EAAE,MAAM;EAAQ,OAAO;CAAE;CAC/B,WAAW;EAAE,MAAM;EAAa,OAAO;CAAE;CACzC,QAAQ;EAAE,MAAM;EAAU,OAAO;CAAE;CACnC,OAAO;EAAE,MAAM;EAAS,OAAO;CAAE;CACjC,OAAO;EAAE,MAAM;EAAS,OAAO;CAAE;CACjC,QAAQ;EAAE,MAAM;EAAU,OAAO;CAAE;AACrC;AACA,MAAa,+BAA+B"}
|
package/dist/cjs/core/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_breakpoint = require("./system/breakpoint.cjs");
|
|
3
2
|
const require_constant = require("./constant.cjs");
|
|
3
|
+
const require_breakpoint = require("./system/breakpoint.cjs");
|
|
4
4
|
const require_environment_provider = require("./system/environment-provider.cjs");
|
|
5
5
|
const require_storage_manager = require("./system/storage-manager.cjs");
|
|
6
6
|
const require_layer = require("./system/layer.cjs");
|
|
@@ -37,6 +37,7 @@ exports.ColorModeContext = require_color_mode_provider.ColorModeContext;
|
|
|
37
37
|
exports.ColorModeProvider = require_color_mode_provider.ColorModeProvider;
|
|
38
38
|
exports.ColorModeScript = require_storage_script.ColorModeScript;
|
|
39
39
|
exports.ColorSchemeContext = require_styled.ColorSchemeContext;
|
|
40
|
+
exports.DEFAULT_BREAKPOINT_DIRECTION = require_constant.DEFAULT_BREAKPOINT_DIRECTION;
|
|
40
41
|
exports.DEFAULT_DIRECTION = require_constant.DEFAULT_DIRECTION;
|
|
41
42
|
exports.DEFAULT_LAYERS = require_constant.DEFAULT_LAYERS;
|
|
42
43
|
exports.DEFAULT_LOCALE = require_constant.DEFAULT_LOCALE;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const require_utils_index = require("../../utils/index.cjs");
|
|
2
|
+
const require_constant = require("../constant.cjs");
|
|
2
3
|
// src/core/system/breakpoint.ts
|
|
3
4
|
function createQuery(min, max, identifier = "@media screen") {
|
|
4
5
|
const query = [identifier];
|
|
@@ -44,7 +45,7 @@ function transformBreakpoints(breakpoints, config) {
|
|
|
44
45
|
}
|
|
45
46
|
function createBreakpoints(breakpoints = {}, config = {}) {
|
|
46
47
|
config.base ??= "9999px";
|
|
47
|
-
config.direction ??=
|
|
48
|
+
config.direction ??= require_constant.DEFAULT_BREAKPOINT_DIRECTION;
|
|
48
49
|
breakpoints.base = config.direction !== "up" ? config.base : "0px";
|
|
49
50
|
const { queries, queriesObj } = createQueries(transformBreakpoints(breakpoints, config), config);
|
|
50
51
|
const keys = Object.keys(queriesObj);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"breakpoint.cjs","names":[],"sources":["../../../../src/core/system/breakpoint.ts"],"sourcesContent":["import type { Dict } from \"../../utils\"\nimport type {\n Breakpoint,\n BreakpointConfig,\n DefineThemeBreakpointTokens,\n} from \"./index.type\"\nimport { getPx, isObject } from \"../../utils\"\n\ninterface BreakpointQuery {\n breakpoint: Breakpoint\n maxW: number | undefined\n maxWQuery: string | undefined\n minMaxQuery: string | undefined\n minW: number | undefined\n minWQuery: string | undefined\n query: string | undefined\n}\n\nexport interface Breakpoints {\n keys: Breakpoint[]\n queries: BreakpointQuery[]\n queriesObj: { [key: string]: BreakpointQuery }\n getQuery: (key: string) => string | undefined\n isResponsive: (obj: any, strict?: boolean) => boolean\n isResponsiveKey: (key: string) => boolean\n}\n\nfunction createQuery(\n min: number | undefined,\n max: number | undefined,\n identifier = \"@media screen\",\n): string | undefined {\n const query = [identifier]\n\n if (min) query.push(\"and\", `(min-width: ${min}px)`)\n if (max) query.push(\"and\", `(max-width: ${max}px)`)\n\n return query.length > 1\n ? query.join(\" \").replace(/^@container(\\s+\\w*)?\\s+and/, `@container$1`)\n : undefined\n}\n\nfunction createQueries(breakpoints: Dict<number>, config: BreakpointConfig) {\n const { direction, identifier } = config\n const down = direction !== \"up\"\n\n const queryEntries = Object.entries(breakpoints)\n .map(([breakpoint, width], i, entry) => {\n const [, relatedWidth] = entry[i + 1] ?? []\n let minW = down ? relatedWidth : width\n let maxW = down ? width : relatedWidth\n\n if (breakpoint === \"base\")\n if (down) maxW = undefined\n else minW = undefined\n\n if (down) {\n if (minW) minW += 1\n } else {\n if (maxW) maxW -= 1\n }\n\n const maxWQuery = createQuery(undefined, maxW, identifier)\n const minWQuery = createQuery(minW, undefined, identifier)\n const minMaxQuery = createQuery(minW, maxW, identifier)\n const query = down ? maxWQuery : minWQuery\n\n return [\n breakpoint,\n {\n breakpoint: breakpoint as Breakpoint,\n maxW,\n maxWQuery,\n minMaxQuery,\n minW,\n minWQuery,\n query,\n },\n ] as const\n })\n .sort((a, b) =>\n down\n ? (b[1].maxW ?? Infinity) - (a[1].maxW ?? Infinity)\n : (a[1].minW ?? 0) - (b[1].minW ?? 0),\n )\n\n const queries = queryEntries.map(([_, query]) => query)\n const queriesObj = Object.fromEntries(queryEntries)\n\n return { queries, queriesObj }\n}\n\nfunction transformBreakpoints(\n breakpoints: Dict,\n config: BreakpointConfig,\n): Dict {\n return Object.fromEntries(\n Object.entries(breakpoints)\n .map(([name, value]) => [name, getPx(value)] as const)\n .sort((a, b) => {\n if (config.direction !== \"up\") return b[1] - a[1]\n else return a[1] - b[1]\n }),\n )\n}\n\nexport function createBreakpoints(\n breakpoints: DefineThemeBreakpointTokens = {},\n config: BreakpointConfig = {},\n): Breakpoints {\n config.base ??= \"9999px\"\n config.direction ??= \
|
|
1
|
+
{"version":3,"file":"breakpoint.cjs","names":["DEFAULT_BREAKPOINT_DIRECTION"],"sources":["../../../../src/core/system/breakpoint.ts"],"sourcesContent":["import type { Dict } from \"../../utils\"\nimport type {\n Breakpoint,\n BreakpointConfig,\n DefineThemeBreakpointTokens,\n} from \"./index.type\"\nimport { getPx, isObject } from \"../../utils\"\nimport { DEFAULT_BREAKPOINT_DIRECTION } from \"../constant\"\n\ninterface BreakpointQuery {\n breakpoint: Breakpoint\n maxW: number | undefined\n maxWQuery: string | undefined\n minMaxQuery: string | undefined\n minW: number | undefined\n minWQuery: string | undefined\n query: string | undefined\n}\n\nexport interface Breakpoints {\n keys: Breakpoint[]\n queries: BreakpointQuery[]\n queriesObj: { [key: string]: BreakpointQuery }\n getQuery: (key: string) => string | undefined\n isResponsive: (obj: any, strict?: boolean) => boolean\n isResponsiveKey: (key: string) => boolean\n}\n\nfunction createQuery(\n min: number | undefined,\n max: number | undefined,\n identifier = \"@media screen\",\n): string | undefined {\n const query = [identifier]\n\n if (min) query.push(\"and\", `(min-width: ${min}px)`)\n if (max) query.push(\"and\", `(max-width: ${max}px)`)\n\n return query.length > 1\n ? query.join(\" \").replace(/^@container(\\s+\\w*)?\\s+and/, `@container$1`)\n : undefined\n}\n\nfunction createQueries(breakpoints: Dict<number>, config: BreakpointConfig) {\n const { direction, identifier } = config\n const down = direction !== \"up\"\n\n const queryEntries = Object.entries(breakpoints)\n .map(([breakpoint, width], i, entry) => {\n const [, relatedWidth] = entry[i + 1] ?? []\n let minW = down ? relatedWidth : width\n let maxW = down ? width : relatedWidth\n\n if (breakpoint === \"base\")\n if (down) maxW = undefined\n else minW = undefined\n\n if (down) {\n if (minW) minW += 1\n } else {\n if (maxW) maxW -= 1\n }\n\n const maxWQuery = createQuery(undefined, maxW, identifier)\n const minWQuery = createQuery(minW, undefined, identifier)\n const minMaxQuery = createQuery(minW, maxW, identifier)\n const query = down ? maxWQuery : minWQuery\n\n return [\n breakpoint,\n {\n breakpoint: breakpoint as Breakpoint,\n maxW,\n maxWQuery,\n minMaxQuery,\n minW,\n minWQuery,\n query,\n },\n ] as const\n })\n .sort((a, b) =>\n down\n ? (b[1].maxW ?? Infinity) - (a[1].maxW ?? Infinity)\n : (a[1].minW ?? 0) - (b[1].minW ?? 0),\n )\n\n const queries = queryEntries.map(([_, query]) => query)\n const queriesObj = Object.fromEntries(queryEntries)\n\n return { queries, queriesObj }\n}\n\nfunction transformBreakpoints(\n breakpoints: Dict,\n config: BreakpointConfig,\n): Dict {\n return Object.fromEntries(\n Object.entries(breakpoints)\n .map(([name, value]) => [name, getPx(value)] as const)\n .sort((a, b) => {\n if (config.direction !== \"up\") return b[1] - a[1]\n else return a[1] - b[1]\n }),\n )\n}\n\nexport function createBreakpoints(\n breakpoints: DefineThemeBreakpointTokens = {},\n config: BreakpointConfig = {},\n): Breakpoints {\n config.base ??= \"9999px\"\n config.direction ??= DEFAULT_BREAKPOINT_DIRECTION\n\n breakpoints.base = config.direction !== \"up\" ? config.base : \"0px\"\n\n const transformedBreakpoints = transformBreakpoints(breakpoints, config)\n const { queries, queriesObj } = createQueries(transformedBreakpoints, config)\n const keys = Object.keys(queriesObj) as Breakpoint[]\n\n function isResponsive(obj: any, strict = false) {\n if (!isObject(obj)) return false\n\n const providedKeys = Object.keys(obj) as Breakpoint[]\n\n if (!providedKeys.length) return false\n\n if (strict && !providedKeys.includes(\"base\")) return false\n\n return providedKeys.every((key) => keys.includes(key))\n }\n\n function isResponsiveKey(key: string) {\n return key in queriesObj\n }\n\n function getQuery(key: string) {\n return key in queriesObj ? queriesObj[key]?.query : undefined\n }\n\n return {\n getQuery,\n isResponsive,\n isResponsiveKey,\n keys,\n queries,\n queriesObj,\n }\n}\n"],"mappings":";;;AA4BA,SAAS,YACP,KACA,KACA,aAAa,iBACO;CACpB,MAAM,QAAQ,CAAC,UAAU;CAEzB,IAAI,KAAK,MAAM,KAAK,OAAO,eAAe,IAAI,IAAI;CAClD,IAAI,KAAK,MAAM,KAAK,OAAO,eAAe,IAAI,IAAI;CAElD,OAAO,MAAM,SAAS,IAClB,MAAM,KAAK,GAAG,CAAC,CAAC,QAAQ,8BAA8B,cAAc,IACpE,KAAA;AACN;AAEA,SAAS,cAAc,aAA2B,QAA0B;CAC1E,MAAM,EAAE,WAAW,eAAe;CAClC,MAAM,OAAO,cAAc;CAE3B,MAAM,eAAe,OAAO,QAAQ,WAAW,CAAC,CAC7C,KA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AAO;CAG7D,MAAM,EAAE,SAAS,eAAe,cADD,qBAAqB,aAAa,MACE,GAAG,MAAM;CAC5E,MAAM,OAAO,OAAO,KAAK,UAAU;CAEnC,SAAS,aAAa,KAAU,SAAS,OAAO;EAC9C,IAAI,EAAA,GAAA,oBAAA,cAAC,SAAA,CAAS,GAAG,GAAG,OAAO;EAE3B,MAAM,eAAe,OAAO,KAAK,GAAG;EAEpC,IAAI,CAAC,aAAa,QAAQ,OAAO;EAEjC,IAAI,UAAU,CAAC,aAAa,SAAS,MAAM,GAAG,OAAO;EAErD,OAAO,aAAa,OAAO,QAAQ,KAAK,SAAS,GAAG,CAAC;CACvD;CAEA,SAAS,gBAAgB,KAAa;EACpC,OAAO,OAAO;CAChB;CAEA,SAAS,SAAS,KAAa;EAC7B,OAAO,OAAO,aAAa,WAAW,IAAI,EAAE,QAAQ,KAAA;CACtD;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
require("../../core/constant.cjs");
|
|
3
|
+
const require_system_provider = require("../../core/system/system-provider.cjs");
|
|
2
4
|
const require_use_breakpoint = require("./use-breakpoint.cjs");
|
|
3
5
|
let react = require("react");
|
|
4
6
|
// src/hooks/use-breakpoint/use-breakpoint-effect.ts
|
|
@@ -8,10 +10,16 @@ let react = require("react");
|
|
|
8
10
|
* @see https://yamada-ui.com/docs/hooks/use-breakpoint-effect
|
|
9
11
|
*/
|
|
10
12
|
const useBreakpointEffect = (callback, deps) => {
|
|
13
|
+
const { config } = require_system_provider.useSystem();
|
|
11
14
|
const breakpoint = require_use_breakpoint.useBreakpoint();
|
|
15
|
+
const direction = config.breakpoint?.direction ?? "down";
|
|
12
16
|
(0, react.useEffect)(() => {
|
|
13
|
-
callback(breakpoint);
|
|
14
|
-
}, [
|
|
17
|
+
callback(breakpoint, direction);
|
|
18
|
+
}, [
|
|
19
|
+
breakpoint,
|
|
20
|
+
direction,
|
|
21
|
+
...deps
|
|
22
|
+
]);
|
|
15
23
|
};
|
|
16
24
|
exports.useBreakpointEffect = useBreakpointEffect;
|
|
17
25
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-breakpoint-effect.cjs","names":["useBreakpoint"],"sources":["../../../../src/hooks/use-breakpoint/use-breakpoint-effect.ts"],"sourcesContent":["\"use client\"\n\nimport type { DependencyList } from \"react\"\nimport type { Breakpoint } from \"../../core\"\nimport { useEffect } from \"react\"\nimport { useBreakpoint } from \"./use-breakpoint\"\n\n/**\n * `useBreakpointEffect` is a custom hook that executes a specific callback function when the breakpoint changes.\n *\n * @see https://yamada-ui.com/docs/hooks/use-breakpoint-effect\n */\nexport const useBreakpointEffect = (\n callback: (breakpoint: Breakpoint) => void,\n deps: DependencyList,\n) => {\n const breakpoint = useBreakpoint()\n\n useEffect(() => {\n callback(breakpoint)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [breakpoint, ...deps])\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-breakpoint-effect.cjs","names":["useSystem","useBreakpoint"],"sources":["../../../../src/hooks/use-breakpoint/use-breakpoint-effect.ts"],"sourcesContent":["\"use client\"\n\nimport type { DependencyList } from \"react\"\nimport type { Breakpoint, BreakpointDirection } from \"../../core\"\nimport { useEffect } from \"react\"\nimport { DEFAULT_BREAKPOINT_DIRECTION, useSystem } from \"../../core\"\nimport { useBreakpoint } from \"./use-breakpoint\"\n\n/**\n * `useBreakpointEffect` is a custom hook that executes a specific callback function when the breakpoint changes.\n *\n * @see https://yamada-ui.com/docs/hooks/use-breakpoint-effect\n */\nexport const useBreakpointEffect = (\n callback: (breakpoint: Breakpoint, direction: BreakpointDirection) => void,\n deps: DependencyList,\n) => {\n const { config } = useSystem()\n const breakpoint = useBreakpoint()\n const direction = config.breakpoint?.direction ?? DEFAULT_BREAKPOINT_DIRECTION\n\n useEffect(() => {\n callback(breakpoint, direction)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [breakpoint, direction, ...deps])\n}\n"],"mappings":";;;;;;;;;;;AAaA,MAAa,uBACX,UACA,SACG;CACH,MAAM,EAAE,WAAWA,wBAAAA,UAAU;CAC7B,MAAM,aAAaC,uBAAAA,cAAc;CACjC,MAAM,YAAY,OAAO,YAAY,aAAA;CAErC,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,SAAS,YAAY,SAAS;CAEhC,GAAG;EAAC;EAAY;EAAW,GAAG;CAAI,CAAC;AACrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-breakpoint-state.cjs","names":["useBreakpointValue","useState"],"sources":["../../../../src/hooks/use-breakpoint/use-breakpoint-state.ts"],"sourcesContent":["\"use client\"\n\nimport type { ResponsiveObject } from \"../../core\"\nimport { useState } from \"react\"\nimport { useBreakpointValue } from \"./use-breakpoint-value\"\n\n/**\n * `useBreakpointState` is a custom hook that takes a responsive object as an initial state and returns a state corresponding to the current breakpoint.\n *\n * @see https://yamada-ui.com/docs/hooks/use-breakpoint-state\n */\nexport const useBreakpointState = <Y>(\n initialState: ResponsiveObject<Y, false>,\n) => {\n const state = useBreakpointValue(initialState)\n\n return useState(state)\n}\n"],"mappings":";;;;;;;;;AAWA,MAAa,sBACX,
|
|
1
|
+
{"version":3,"file":"use-breakpoint-state.cjs","names":["useBreakpointValue","useState"],"sources":["../../../../src/hooks/use-breakpoint/use-breakpoint-state.ts"],"sourcesContent":["\"use client\"\n\nimport type { BreakpointDirection, ResponsiveObject } from \"../../core\"\nimport { useState } from \"react\"\nimport { useBreakpointValue } from \"./use-breakpoint-value\"\n\n/**\n * `useBreakpointState` is a custom hook that takes a responsive object as an initial state and returns a state corresponding to the current breakpoint.\n *\n * @see https://yamada-ui.com/docs/hooks/use-breakpoint-state\n */\nexport const useBreakpointState = <Y>(\n initialState:\n | ((direction: BreakpointDirection) => ResponsiveObject<Y, false>)\n | ResponsiveObject<Y, false>,\n) => {\n const state = useBreakpointValue(initialState)\n\n return useState(state)\n}\n"],"mappings":";;;;;;;;;AAWA,MAAa,sBACX,iBAGG;CACH,MAAM,QAAQA,6BAAAA,mBAAmB,YAAY;CAE7C,QAAA,GAAOC,MAAAA,SAAAA,CAAS,KAAK;AACvB"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
require("../../core/constant.cjs");
|
|
1
2
|
const require_system_provider = require("../../core/system/system-provider.cjs");
|
|
2
3
|
const require_use_breakpoint = require("./use-breakpoint.cjs");
|
|
3
4
|
let react = require("react");
|
|
5
|
+
let _yamada_ui_utils = require("@yamada-ui/utils");
|
|
4
6
|
// src/hooks/use-breakpoint/use-breakpoint-value.ts
|
|
5
7
|
/**
|
|
6
8
|
* `useBreakpointValue` is a custom hook that returns the value of the current breakpoint from the provided object.
|
|
@@ -11,10 +13,12 @@ let react = require("react");
|
|
|
11
13
|
const useBreakpointValue = (values) => {
|
|
12
14
|
const system = require_system_provider.useSystem();
|
|
13
15
|
const breakpoint = require_use_breakpoint.useBreakpoint();
|
|
14
|
-
|
|
16
|
+
const direction = system.config.breakpoint?.direction ?? "down";
|
|
17
|
+
return (0, react.useMemo)(() => getBreakpointValue((0, _yamada_ui_utils.runIfFn)(values, direction))(system, breakpoint), [
|
|
15
18
|
values,
|
|
16
19
|
system,
|
|
17
|
-
breakpoint
|
|
20
|
+
breakpoint,
|
|
21
|
+
direction
|
|
18
22
|
]);
|
|
19
23
|
};
|
|
20
24
|
const getBreakpointValue = (values = {}) => (system, breakpoint) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-breakpoint-value.cjs","names":["useSystem","useBreakpoint","useMemo"],"sources":["../../../../src/hooks/use-breakpoint/use-breakpoint-value.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"use-breakpoint-value.cjs","names":["useSystem","useBreakpoint","useMemo","runIfFn"],"sources":["../../../../src/hooks/use-breakpoint/use-breakpoint-value.ts"],"sourcesContent":["import type {\n Breakpoint,\n BreakpointDirection,\n ResponsiveObject,\n System,\n} from \"../../core\"\nimport { runIfFn } from \"@yamada-ui/utils\"\nimport { useMemo } from \"react\"\nimport { DEFAULT_BREAKPOINT_DIRECTION, 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:\n | ((direction: BreakpointDirection) => ResponsiveObject<Y, false>)\n | ResponsiveObject<Y, false>,\n): Y => {\n const system = useSystem()\n const breakpoint = useBreakpoint()\n const direction =\n system.config.breakpoint?.direction ?? DEFAULT_BREAKPOINT_DIRECTION\n\n return useMemo(\n () => getBreakpointValue<Y>(runIfFn(values, direction))(system, breakpoint),\n [values, system, breakpoint, direction],\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 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 return values.base as Y\n }\n"],"mappings":";;;;;;;;;;;;AAiBA,MAAa,sBACX,WAGM;CACN,MAAM,SAASA,wBAAAA,UAAU;CACzB,MAAM,aAAaC,uBAAAA,cAAc;CACjC,MAAM,YACJ,OAAO,OAAO,YAAY,aAAA;CAE5B,QAAA,GAAOC,MAAAA,QAAAA,OACC,oBAAA,GAAsBC,iBAAAA,QAAAA,CAAQ,QAAQ,SAAS,CAAC,CAAC,CAAC,QAAQ,UAAU,GAC1E;EAAC;EAAQ;EAAQ;EAAY;CAAS,CACxC;AACF;AAEA,MAAa,sBACP,SAAqC,CAAC,OACzC,QAAgB,eAA8B;CAC7C,MAAM,cAAc,OAAO,YAAY;CAEvC,IAAI,CAAC,YAAY,QACf,QAAQ,KAAK,iDAAiD;CAEhE,MAAM,eAAe,YAAY,QAAQ,UAAU;CAEnD,KAAK,IAAI,IAAI,cAAc,IAAI,GAAG,KAAK;EACrC,MAAM,iBAAiB,YAAY;EAEnC,IAAI,kBAAkB,OAAO,eAAe,cAAc,GACxD,OAAO,OAAO;CAClB;CAEA,OAAO,OAAO;AAChB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
const require_constant = require("../../core/constant.cjs");
|
|
2
3
|
const require_environment_provider = require("../../core/system/environment-provider.cjs");
|
|
3
4
|
const require_system_provider = require("../../core/system/system-provider.cjs");
|
|
4
5
|
const require_utils_index = require("../../utils/index.cjs");
|
|
@@ -14,7 +15,7 @@ const useBreakpoint = () => {
|
|
|
14
15
|
const animationFrameId = (0, react.useRef)(0);
|
|
15
16
|
const { breakpoints, config } = require_system_provider.useSystem();
|
|
16
17
|
const { getWindow } = require_environment_provider.useEnvironment();
|
|
17
|
-
const { containerRef, direction =
|
|
18
|
+
const { containerRef, direction = require_constant.DEFAULT_BREAKPOINT_DIRECTION, identifier = "@media screen" } = config.breakpoint ?? {};
|
|
18
19
|
const hasContainer = !!containerRef;
|
|
19
20
|
const queries = (0, react.useMemo)(() => {
|
|
20
21
|
return breakpoints.queries.map(({ breakpoint, maxW, minMaxQuery, minW }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-breakpoint.cjs","names":["useRef","useSystem","useEnvironment","useMemo","useCallback","useSyncExternalStore"],"sources":["../../../../src/hooks/use-breakpoint/use-breakpoint.ts"],"sourcesContent":["\"use client\"\n\nimport type { Breakpoint } from \"../../core\"\nimport { useCallback, useMemo, useRef, useSyncExternalStore } from \"react\"\nimport {
|
|
1
|
+
{"version":3,"file":"use-breakpoint.cjs","names":["useRef","useSystem","useEnvironment","DEFAULT_BREAKPOINT_DIRECTION","useMemo","useCallback","useSyncExternalStore"],"sources":["../../../../src/hooks/use-breakpoint/use-breakpoint.ts"],"sourcesContent":["\"use client\"\n\nimport type { Breakpoint } from \"../../core\"\nimport { useCallback, useMemo, useRef, useSyncExternalStore } from \"react\"\nimport {\n DEFAULT_BREAKPOINT_DIRECTION,\n useEnvironment,\n useSystem,\n} from \"../../core\"\nimport { createdDom, isUndefined, noop } from \"../../utils\"\n\n/**\n * `useBreakpoint` is a custom hook that returns the current breakpoint.\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\n */\nexport const useBreakpoint = () => {\n const animationFrameId = useRef(0)\n const { breakpoints, config } = useSystem()\n const { getWindow } = useEnvironment()\n const {\n containerRef,\n direction = DEFAULT_BREAKPOINT_DIRECTION,\n identifier = \"@media screen\",\n } = config.breakpoint ?? {}\n const hasContainer = !!containerRef\n\n const queries = useMemo(() => {\n return breakpoints.queries.map(\n ({ breakpoint, maxW, minMaxQuery, minW }) => {\n const searchValue =\n identifier === \"@media screen\"\n ? \"@media screen and \"\n : `${identifier} `\n const query = minMaxQuery?.replace(searchValue, \"\") ?? \"\"\n\n return {\n breakpoint,\n maxW,\n minW,\n query,\n }\n },\n )\n }, [breakpoints, identifier])\n\n const hasQueries = !!queries.length\n\n const getBreakpoint = useCallback(\n (width?: number) => {\n if (isUndefined(width)) {\n const win = getWindow()\n\n if (hasContainer || !hasQueries) return \"base\"\n\n for (const { breakpoint, query } of queries) {\n const mql = win?.matchMedia(query)\n\n if (mql?.matches) return breakpoint\n }\n } else {\n for (const { breakpoint, maxW, minW } of queries)\n if (direction !== \"up\") {\n if ((minW ?? 0) <= width) return breakpoint\n } else {\n if (width <= (maxW ?? Infinity)) return breakpoint\n }\n }\n\n return \"base\"\n },\n [direction, getWindow, hasContainer, hasQueries, queries],\n )\n\n const breakpointRef = useRef<Breakpoint>(getBreakpoint())\n\n const subscribe = useCallback(\n (listener: () => void) => {\n if (!hasContainer || !hasQueries) {\n const observer = queries.map(({ breakpoint, query }): (() => void) => {\n const mql = getWindow()?.matchMedia(query)\n\n const onChange = (e: MediaQueryListEvent) => {\n if (e.matches) breakpointRef.current = breakpoint\n\n listener()\n }\n\n mql?.addEventListener(\"change\", onChange)\n\n return () => {\n mql?.removeEventListener(\"change\", onChange)\n }\n })\n\n return () => {\n observer.forEach((unobserve) => unobserve())\n }\n } else if (createdDom()) {\n const observer = new ResizeObserver(([entry]) => {\n if (!entry) return\n\n cancelAnimationFrame(animationFrameId.current)\n\n const { width } = entry.contentRect\n\n breakpointRef.current = getBreakpoint(width)\n\n animationFrameId.current = requestAnimationFrame(listener)\n })\n\n if (containerRef.current) observer.observe(containerRef.current)\n\n return () => {\n observer.disconnect()\n\n if (process.env.NODE_ENV !== \"test\")\n cancelAnimationFrame(animationFrameId.current)\n }\n } else {\n return noop\n }\n },\n [containerRef, getBreakpoint, getWindow, hasContainer, hasQueries, queries],\n )\n\n const getSnapshot = useCallback(() => {\n return breakpointRef.current\n }, [])\n\n const breakpoint = useSyncExternalStore(subscribe, getSnapshot, getSnapshot)\n\n return breakpoint\n}\n"],"mappings":";;;;;;;;;;;;;AAiBA,MAAa,sBAAsB;CACjC,MAAM,oBAAA,GAAmBA,MAAAA,OAAAA,CAAO,CAAC;CACjC,MAAM,EAAE,aAAa,WAAWC,wBAAAA,UAAU;CAC1C,MAAM,EAAE,cAAcC,6BAAAA,eAAe;CACrC,MAAM,EACJ,cACA,YAAYC,iBAAAA,8BACZ,aAAa,oBACX,OAAO,cAAc,CAAC;CAC1B,MAAM,eAAe,CAAC,CAAC;CAEvB,MAAM,WAAA,GAAUC,MAAAA,QAAAA,OAAc;EAC5B,OAAO,YAAY,QAAQ,KACxB,EAAE,YAAY,MAAM,aAAa,WAAW;GAC3C,MAAM,cACJ,eAAe,kBACX,uBACA,GAAG,WAAW;GAGpB,OAAO;IACL;IACA;IACA;IACA,OANY,aAAa,Q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E7C,MAAM,EAAE,UAAU,MAAM;IAExB,cAAc,UAAU,cAAc,KAAK;IAE3C,iBAAiB,UAAU,sBAAsB,QAAQ;GAC3D,CAAC;GAED,IAAI,aAAa,SAAS,SAAS,QAAQ,aAAa,OAAO;GAE/D,aAAa;IACX,SAAS,WAAW;IAEpB,IAAI,QAAQ,IAAI,aAAa,QAC3B,qBAAqB,iBAAiB,OAAO;GACjD;EACF,OACE,OAAA,oBAAA,cAAO;CAEX,GACA;EAAC;EAAc;EAAe;EAAW;EAAc;EAAY;CAAO,CAC5E;CAEA,MAAM,eAAA,GAAcA,MAAAA,YAAAA,OAAkB;EACpC,OAAO,cAAc;CACvB,GAAG,CAAC,CAAC;CAIL,QAAA,GAFmBC,MAAAA,qBAAAA,CAAqB,WAAW,aAAa,WAEhD;AAClB"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require("../../core/constant.cjs");
|
|
2
|
+
const require_system_provider = require("../../core/system/system-provider.cjs");
|
|
1
3
|
const require_effect = require("../../utils/effect.cjs");
|
|
2
4
|
const require_use_breakpoint = require("./use-breakpoint.cjs");
|
|
3
5
|
// src/hooks/use-breakpoint/use-update-breakpoint-effect.ts
|
|
@@ -7,10 +9,16 @@ const require_use_breakpoint = require("./use-breakpoint.cjs");
|
|
|
7
9
|
* @see https://yamada-ui.com/docs/hooks/use-update-breakpoint-effect
|
|
8
10
|
*/
|
|
9
11
|
const useUpdateBreakpointEffect = (callback, deps) => {
|
|
12
|
+
const { config } = require_system_provider.useSystem();
|
|
10
13
|
const breakpoint = require_use_breakpoint.useBreakpoint();
|
|
14
|
+
const direction = config.breakpoint?.direction ?? "down";
|
|
11
15
|
require_effect.useUpdateEffect(() => {
|
|
12
|
-
callback(breakpoint);
|
|
13
|
-
}, [
|
|
16
|
+
callback(breakpoint, direction);
|
|
17
|
+
}, [
|
|
18
|
+
breakpoint,
|
|
19
|
+
direction,
|
|
20
|
+
...deps
|
|
21
|
+
]);
|
|
14
22
|
};
|
|
15
23
|
exports.useUpdateBreakpointEffect = useUpdateBreakpointEffect;
|
|
16
24
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-update-breakpoint-effect.cjs","names":["useBreakpoint"],"sources":["../../../../src/hooks/use-breakpoint/use-update-breakpoint-effect.ts"],"sourcesContent":["import type { DependencyList } from \"react\"\nimport type { Breakpoint } from \"../../core\"\nimport { useUpdateEffect } from \"../../utils\"\nimport { useBreakpoint } from \"./use-breakpoint\"\n\n/**\n * `useUpdateBreakpointEffect` is a custom hook that skips the side effect on the initial render and executes a specific callback function when the breakpoint changes.\n *\n * @see https://yamada-ui.com/docs/hooks/use-update-breakpoint-effect\n */\nexport const useUpdateBreakpointEffect = (\n callback: (breakpoint: Breakpoint) => void,\n deps: DependencyList,\n) => {\n const breakpoint = useBreakpoint()\n\n useUpdateEffect(() => {\n callback(breakpoint)\n }, [breakpoint, ...deps])\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-update-breakpoint-effect.cjs","names":["useSystem","useBreakpoint"],"sources":["../../../../src/hooks/use-breakpoint/use-update-breakpoint-effect.ts"],"sourcesContent":["import type { DependencyList } from \"react\"\nimport type { Breakpoint, BreakpointDirection } from \"../../core\"\nimport { DEFAULT_BREAKPOINT_DIRECTION, useSystem } from \"../../core\"\nimport { useUpdateEffect } from \"../../utils\"\nimport { useBreakpoint } from \"./use-breakpoint\"\n\n/**\n * `useUpdateBreakpointEffect` is a custom hook that skips the side effect on the initial render and executes a specific callback function when the breakpoint changes.\n *\n * @see https://yamada-ui.com/docs/hooks/use-update-breakpoint-effect\n */\nexport const useUpdateBreakpointEffect = (\n callback: (breakpoint: Breakpoint, direction: BreakpointDirection) => void,\n deps: DependencyList,\n) => {\n const { config } = useSystem()\n const breakpoint = useBreakpoint()\n const direction = config.breakpoint?.direction ?? DEFAULT_BREAKPOINT_DIRECTION\n\n useUpdateEffect(() => {\n callback(breakpoint, direction)\n }, [breakpoint, direction, ...deps])\n}\n"],"mappings":";;;;;;;;;;AAWA,MAAa,6BACX,UACA,SACG;CACH,MAAM,EAAE,WAAWA,wBAAAA,UAAU;CAC7B,MAAM,aAAaC,uBAAAA,cAAc;CACjC,MAAM,YAAY,OAAO,YAAY,aAAA;CAErC,eAAA,sBAAsB;EACpB,SAAS,YAAY,SAAS;CAChC,GAAG;EAAC;EAAY;EAAW,GAAG;CAAI,CAAC;AACrC"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -8,8 +8,8 @@ const require_ref = require("./utils/ref.cjs");
|
|
|
8
8
|
const require_ssr = require("./utils/ssr.cjs");
|
|
9
9
|
const require_store = require("./utils/store.cjs");
|
|
10
10
|
const require_theme_index = require("./theme/index.cjs");
|
|
11
|
-
const require_breakpoint = require("./core/system/breakpoint.cjs");
|
|
12
11
|
const require_constant = require("./core/constant.cjs");
|
|
12
|
+
const require_breakpoint = require("./core/system/breakpoint.cjs");
|
|
13
13
|
const require_environment_provider = require("./core/system/environment-provider.cjs");
|
|
14
14
|
const require_storage_manager = require("./core/system/storage-manager.cjs");
|
|
15
15
|
const require_layer = require("./core/system/layer.cjs");
|
|
@@ -3362,6 +3362,7 @@ var src_exports = /* @__PURE__ */ require_runtime.__exportAll({
|
|
|
3362
3362
|
CupcakeIcon: () => require_cupcake_icon.CupcakeIcon,
|
|
3363
3363
|
CurrencyIcon: () => require_currency_icon.CurrencyIcon,
|
|
3364
3364
|
CylinderIcon: () => require_cylinder_icon.CylinderIcon,
|
|
3365
|
+
DEFAULT_BREAKPOINT_DIRECTION: () => require_constant.DEFAULT_BREAKPOINT_DIRECTION,
|
|
3365
3366
|
DEFAULT_DIRECTION: () => "ltr",
|
|
3366
3367
|
DEFAULT_FIRST_DAY_OF_WEEK: () => require_use_calendar.DEFAULT_FIRST_DAY_OF_WEEK,
|
|
3367
3368
|
DEFAULT_HOLIDAYS: () => require_use_calendar.DEFAULT_HOLIDAYS,
|
|
@@ -6909,6 +6910,7 @@ exports.CupSodaIcon = require_cup_soda_icon.CupSodaIcon;
|
|
|
6909
6910
|
exports.CupcakeIcon = require_cupcake_icon.CupcakeIcon;
|
|
6910
6911
|
exports.CurrencyIcon = require_currency_icon.CurrencyIcon;
|
|
6911
6912
|
exports.CylinderIcon = require_cylinder_icon.CylinderIcon;
|
|
6913
|
+
exports.DEFAULT_BREAKPOINT_DIRECTION = require_constant.DEFAULT_BREAKPOINT_DIRECTION;
|
|
6912
6914
|
exports.DEFAULT_DIRECTION = require_constant.DEFAULT_DIRECTION;
|
|
6913
6915
|
exports.DEFAULT_FIRST_DAY_OF_WEEK = require_use_calendar.DEFAULT_FIRST_DAY_OF_WEEK;
|
|
6914
6916
|
exports.DEFAULT_HOLIDAYS = require_use_calendar.DEFAULT_HOLIDAYS;
|
|
@@ -22,13 +22,13 @@ const createQuery = (minW, maxW) => {
|
|
|
22
22
|
const Picture = ({ children, enableSorting = true, sources: sourcesProp = [], pictureProps, ...rest }) => {
|
|
23
23
|
const system = useSystem();
|
|
24
24
|
const { queriesObj } = system.breakpoints;
|
|
25
|
-
const { direction
|
|
25
|
+
const { direction, identifier = "@media screen" } = system.config.breakpoint ?? {};
|
|
26
26
|
const searchValue = identifier === "@media screen" ? "@media screen and " : `${identifier} `;
|
|
27
27
|
const compareSources = useCallback((a, b) => {
|
|
28
|
-
const k = direction === "
|
|
28
|
+
const k = direction === "up" ? "minW" : "maxW";
|
|
29
29
|
if ((0, utils_exports.isUndefined)(a[k]) && !(0, utils_exports.isUndefined)(b[k])) return -1;
|
|
30
30
|
if (!(0, utils_exports.isUndefined)(a[k]) && (0, utils_exports.isUndefined)(b[k])) return 1;
|
|
31
|
-
return direction === "
|
|
31
|
+
return direction === "up" ? Number(b.minW) - Number(a.minW) : Number(a.maxW) - Number(b.maxW);
|
|
32
32
|
}, [direction]);
|
|
33
33
|
const sources = useMemo(() => {
|
|
34
34
|
const computedSources = sourcesProp.map(({ maxW, media, minW, ...rest }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"picture.js","names":["isUndefined","getPx"],"sources":["../../../../src/components/picture/picture.tsx"],"sourcesContent":["import type { FC } from \"react\"\nimport type { HTMLStyledProps, ThemeTokens } from \"../../core\"\nimport type { AnyString } from \"../../utils\"\nimport type { ImageProps } from \"../image\"\nimport { useCallback, useMemo } from \"react\"\nimport { styled, tokenToValue, useSystem } from \"../../core\"\nimport { getPx, isUndefined } from \"../../utils\"\nimport { Image } from \"../image\"\n\nconst createQuery = (\n minW: number | string | undefined,\n maxW: number | string | undefined,\n) => {\n let media = \"\"\n\n if (minW) {\n media = `(min-width: ${minW}px)`\n\n if (maxW) media += ` and (max-width: ${maxW}px)`\n } else {\n media = `(max-width: ${maxW}px)`\n }\n\n return media\n}\n\nexport interface PictureSource extends SourceProps {\n /**\n * The maximum width for the source.\n *\n * If media is set, media takes precedence.\n */\n maxW?: AnyString | number | ThemeTokens[\"sizes\"]\n /**\n * The minimum width for the source.\n *\n * If media is set, media takes precedence.\n */\n minW?: AnyString | number | ThemeTokens[\"sizes\"]\n /**\n * The source set for the source element.\n */\n srcSet?: string\n}\n\nexport interface PictureProps extends ImageProps {\n /**\n * If `true`, the sources will be sorted by the `minW` and `maxW` properties.\n *\n * @default true\n */\n enableSorting?: boolean\n /**\n * The sources for the picture element.\n */\n sources?: PictureSource[]\n /**\n * The props for the picture element.\n */\n pictureProps?: HTMLStyledProps<\"picture\">\n}\n\n/**\n * `Picture` is a component that uses the `picture` element to provide alternative images for different display or device scenarios.\n *\n * @see https://yamada-ui.com/docs/components/picture\n */\nexport const Picture: FC<PictureProps> = ({\n children,\n enableSorting = true,\n sources: sourcesProp = [],\n pictureProps,\n ...rest\n}) => {\n const system = useSystem()\n const { queriesObj } = system.breakpoints\n const { direction
|
|
1
|
+
{"version":3,"file":"picture.js","names":["isUndefined","getPx"],"sources":["../../../../src/components/picture/picture.tsx"],"sourcesContent":["import type { FC } from \"react\"\nimport type { HTMLStyledProps, ThemeTokens } from \"../../core\"\nimport type { AnyString } from \"../../utils\"\nimport type { ImageProps } from \"../image\"\nimport { useCallback, useMemo } from \"react\"\nimport { styled, tokenToValue, useSystem } from \"../../core\"\nimport { getPx, isUndefined } from \"../../utils\"\nimport { Image } from \"../image\"\n\nconst createQuery = (\n minW: number | string | undefined,\n maxW: number | string | undefined,\n) => {\n let media = \"\"\n\n if (minW) {\n media = `(min-width: ${minW}px)`\n\n if (maxW) media += ` and (max-width: ${maxW}px)`\n } else {\n media = `(max-width: ${maxW}px)`\n }\n\n return media\n}\n\nexport interface PictureSource extends SourceProps {\n /**\n * The maximum width for the source.\n *\n * If media is set, media takes precedence.\n */\n maxW?: AnyString | number | ThemeTokens[\"sizes\"]\n /**\n * The minimum width for the source.\n *\n * If media is set, media takes precedence.\n */\n minW?: AnyString | number | ThemeTokens[\"sizes\"]\n /**\n * The source set for the source element.\n */\n srcSet?: string\n}\n\nexport interface PictureProps extends ImageProps {\n /**\n * If `true`, the sources will be sorted by the `minW` and `maxW` properties.\n *\n * @default true\n */\n enableSorting?: boolean\n /**\n * The sources for the picture element.\n */\n sources?: PictureSource[]\n /**\n * The props for the picture element.\n */\n pictureProps?: HTMLStyledProps<\"picture\">\n}\n\n/**\n * `Picture` is a component that uses the `picture` element to provide alternative images for different display or device scenarios.\n *\n * @see https://yamada-ui.com/docs/components/picture\n */\nexport const Picture: FC<PictureProps> = ({\n children,\n enableSorting = true,\n sources: sourcesProp = [],\n pictureProps,\n ...rest\n}) => {\n const system = useSystem()\n const { queriesObj } = system.breakpoints\n const { direction, identifier = \"@media screen\" } =\n system.config.breakpoint ?? {}\n const searchValue =\n identifier === \"@media screen\" ? \"@media screen and \" : `${identifier} `\n\n const compareSources = useCallback(\n (a: PictureSource, b: PictureSource) => {\n const k = direction === \"up\" ? \"minW\" : \"maxW\"\n\n if (isUndefined(a[k]) && !isUndefined(b[k])) return -1\n\n if (!isUndefined(a[k]) && isUndefined(b[k])) return 1\n\n return direction === \"up\"\n ? Number(b.minW) - Number(a.minW)\n : Number(a.maxW) - Number(b.maxW)\n },\n [direction],\n )\n\n const sources = useMemo(() => {\n const computedSources = sourcesProp.map(\n ({ maxW, media, minW, ...rest }) => {\n if (!media) {\n if (minW) minW = getPx(tokenToValue(system)(\"sizes\", minW))\n if (maxW) maxW = getPx(tokenToValue(system)(\"sizes\", maxW))\n\n media = createQuery(minW, maxW)\n\n return { ...rest, maxW, media, minW }\n } else {\n const { maxW, minW, query } = queriesObj[media] ?? {}\n\n if (query) media = query.replace(searchValue, \"\")\n\n return { ...rest, maxW, media, minW }\n }\n },\n )\n\n if (enableSorting) return computedSources.sort(compareSources)\n else return computedSources\n }, [\n sourcesProp,\n enableSorting,\n system,\n queriesObj,\n searchValue,\n compareSources,\n ])\n\n const sourceElements = useMemo(\n () =>\n sources.map(({ maxW: _maxW, minW: _minW, ...rest }, index) => (\n <styled.source key={index} {...rest} />\n )),\n [sources],\n )\n\n return (\n <styled.picture {...pictureProps}>\n {children ?? (\n <>\n {sourceElements}\n\n <Image {...rest} />\n </>\n )}\n </styled.picture>\n )\n}\n\nexport interface SourceProps extends HTMLStyledProps<\"source\"> {\n /**\n * The media query for the source.\n */\n media?: AnyString | ThemeTokens[\"breakpoints\"]\n}\n\nexport const Source: FC<SourceProps> = ({ media, ...rest }) => {\n const { breakpoints, config } = useSystem()\n const { queriesObj } = breakpoints\n const { identifier = \"@media screen\" } = config.breakpoint ?? {}\n const searchValue =\n identifier === \"@media screen\" ? \"@media screen and \" : `${identifier} `\n\n const { query } = media ? (queriesObj[media] ?? {}) : {}\n\n if (query) media = query.replace(searchValue, \"\")\n\n return <styled.source media={media} {...rest} />\n}\n"],"mappings":";;;;;;;;AASA,MAAM,eACJ,MACA,SACG;CACH,IAAI,QAAQ;CAEZ,IAAI,MAAM;EACR,QAAQ,eAAe,KAAK;EAE5B,IAAI,MAAM,SAAS,oBAAoB,KAAK;CAC9C,OACE,QAAQ,eAAe,KAAK;CAG9B,OAAO;AACT;;;;;;AA2CA,MAAa,WAA6B,EACxC,UACA,gBAAgB,MAChB,SAAS,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,IAAI,eAAe,OAAO,gBAAgB,KAAK,cAAc;OACxD,OAAO;CACd,GAAG;EACD;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,MAAM,iBAAiB,cAEnB,QAAQ,KAAK,EAAE,MAAM,OAAO,MAAM,OAAO,GAAG,QAAQ,UAClD,oBAAC,OAAO,QAAR,EAA2B,GAAI,KAAO,GAAlB,KAAkB,CACvC,GACH,CAAC,OAAO,CACV;CAEA,OACE,oBAAC,OAAO,SAAR;EAAgB,GAAI;EACjB,UAAA,YACC,qBAAA,YAAA,EAAA,UAAA,CACG,gBAED,oBAAC,OAAD,EAAO,GAAI,KAAO,CAAA,CAClB,EAAA,CAAA;CAEU,CAAA;AAEpB;AASA,MAAa,UAA2B,EAAE,OAAO,GAAG,WAAW;CAC7D,MAAM,EAAE,aAAa,WAAW,UAAU;CAC1C,MAAM,EAAE,eAAe;CACvB,MAAM,EAAE,aAAa,oBAAoB,OAAO,cAAc,CAAC;CAC/D,MAAM,cACJ,eAAe,kBAAkB,uBAAuB,GAAG,WAAW;CAExE,MAAM,EAAE,UAAU,QAAS,WAAW,UAAU,CAAC,IAAK,CAAC;CAEvD,IAAI,OAAO,QAAQ,MAAM,QAAQ,aAAa,EAAE;CAEhD,OAAO,oBAAC,OAAO,QAAR;EAAsB;EAAO,GAAI;CAAO,CAAA;AACjD"}
|
|
@@ -38,6 +38,7 @@ const DEFAULT_LAYERS = {
|
|
|
38
38
|
order: 0
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
|
-
|
|
41
|
+
const DEFAULT_BREAKPOINT_DIRECTION = "down";
|
|
42
|
+
export { COLOR_MODE_STORAGE_KEY, DEFAULT_BREAKPOINT_DIRECTION, DEFAULT_DIRECTION, DEFAULT_LAYERS, DEFAULT_LOCALE, DEFAULT_VAR_PREFIX, THEME_SCHEME_STORAGE_KEY };
|
|
42
43
|
|
|
43
44
|
//# sourceMappingURL=constant.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constant.js","names":[],"sources":["../../../src/core/constant.ts"],"sourcesContent":["import type { LayersConfig } from \"./system\"\n\nexport const COLOR_MODE_STORAGE_KEY = \"color-mode\"\nexport const THEME_SCHEME_STORAGE_KEY = \"theme-scheme\"\n\nexport const DEFAULT_VAR_PREFIX = \"ui\"\nexport const DEFAULT_LOCALE = \"en-US\"\nexport const DEFAULT_DIRECTION = \"ltr\"\nexport const DEFAULT_LAYERS: LayersConfig = {\n size: { name: \"size\", order: 4 },\n variant: { name: \"variant\", order: 5 },\n base: { name: \"base\", order: 3 },\n compounds: { name: \"compounds\", order: 7 },\n global: { name: \"global\", order: 2 },\n props: { name: \"props\", order: 6 },\n reset: { name: \"reset\", order: 1 },\n tokens: { name: \"tokens\", order: 0 },\n}\n"],"mappings":";AAEA,MAAa,yBAAyB;AACtC,MAAa,2BAA2B;AAExC,MAAa,qBAAqB;AAClC,MAAa,iBAAiB;AAC9B,MAAa,oBAAoB;AACjC,MAAa,iBAA+B;CAC1C,MAAM;EAAE,MAAM;EAAQ,OAAO;CAAE;CAC/B,SAAS;EAAE,MAAM;EAAW,OAAO;CAAE;CACrC,MAAM;EAAE,MAAM;EAAQ,OAAO;CAAE;CAC/B,WAAW;EAAE,MAAM;EAAa,OAAO;CAAE;CACzC,QAAQ;EAAE,MAAM;EAAU,OAAO;CAAE;CACnC,OAAO;EAAE,MAAM;EAAS,OAAO;CAAE;CACjC,OAAO;EAAE,MAAM;EAAS,OAAO;CAAE;CACjC,QAAQ;EAAE,MAAM;EAAU,OAAO;CAAE;AACrC"}
|
|
1
|
+
{"version":3,"file":"constant.js","names":[],"sources":["../../../src/core/constant.ts"],"sourcesContent":["import type { LayersConfig } from \"./system\"\n\nexport const COLOR_MODE_STORAGE_KEY = \"color-mode\"\nexport const THEME_SCHEME_STORAGE_KEY = \"theme-scheme\"\n\nexport const DEFAULT_VAR_PREFIX = \"ui\"\nexport const DEFAULT_LOCALE = \"en-US\"\nexport const DEFAULT_DIRECTION = \"ltr\"\nexport const DEFAULT_LAYERS: LayersConfig = {\n size: { name: \"size\", order: 4 },\n variant: { name: \"variant\", order: 5 },\n base: { name: \"base\", order: 3 },\n compounds: { name: \"compounds\", order: 7 },\n global: { name: \"global\", order: 2 },\n props: { name: \"props\", order: 6 },\n reset: { name: \"reset\", order: 1 },\n tokens: { name: \"tokens\", order: 0 },\n}\nexport const DEFAULT_BREAKPOINT_DIRECTION = \"down\"\n"],"mappings":";AAEA,MAAa,yBAAyB;AACtC,MAAa,2BAA2B;AAExC,MAAa,qBAAqB;AAClC,MAAa,iBAAiB;AAC9B,MAAa,oBAAoB;AACjC,MAAa,iBAA+B;CAC1C,MAAM;EAAE,MAAM;EAAQ,OAAO;CAAE;CAC/B,SAAS;EAAE,MAAM;EAAW,OAAO;CAAE;CACrC,MAAM;EAAE,MAAM;EAAQ,OAAO;CAAE;CAC/B,WAAW;EAAE,MAAM;EAAa,OAAO;CAAE;CACzC,QAAQ;EAAE,MAAM;EAAU,OAAO;CAAE;CACnC,OAAO;EAAE,MAAM;EAAS,OAAO;CAAE;CACjC,OAAO;EAAE,MAAM;EAAS,OAAO;CAAE;CACjC,QAAQ;EAAE,MAAM;EAAU,OAAO;CAAE;AACrC;AACA,MAAa,+BAA+B"}
|
package/dist/esm/core/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { COLOR_MODE_STORAGE_KEY, DEFAULT_BREAKPOINT_DIRECTION, DEFAULT_DIRECTION, DEFAULT_LAYERS, DEFAULT_LOCALE, DEFAULT_VAR_PREFIX, THEME_SCHEME_STORAGE_KEY } from "./constant.js";
|
|
1
2
|
import { createBreakpoints } from "./system/breakpoint.js";
|
|
2
|
-
import { COLOR_MODE_STORAGE_KEY, DEFAULT_DIRECTION, DEFAULT_LAYERS, DEFAULT_LOCALE, DEFAULT_VAR_PREFIX, THEME_SCHEME_STORAGE_KEY } from "./constant.js";
|
|
3
3
|
import { EnvironmentProvider, defaultEnvironment, useEnvironment } from "./system/environment-provider.js";
|
|
4
4
|
import { createStorageManager } from "./system/storage-manager.js";
|
|
5
5
|
import { createLayers, defaultLayers } from "./system/layer.js";
|
|
@@ -31,4 +31,4 @@ import { chainProps, createShouldForwardProp, cssProps, extractProps, isEqualPro
|
|
|
31
31
|
import { getSlotClassName, mergeSlotCSS, useComponentSlotStyle, useComponentStyle } from "./components/use-component-style.js";
|
|
32
32
|
import { getClassName, getDisplayName } from "./components/utils.js";
|
|
33
33
|
import { createComponent, createSlotComponent } from "./components/create-component.js";
|
|
34
|
-
export { COLOR_MODE_STORAGE_KEY, ColorModeContext, ColorModeProvider, ColorModeScript, ColorSchemeContext, DEFAULT_DIRECTION, DEFAULT_LAYERS, DEFAULT_LOCALE, DEFAULT_VAR_PREFIX, EnvironmentProvider, GlobalStyles, HydrationContext, SystemProvider, THEME_SCHEME_STORAGE_KEY, ThemeProvider, ThemeSchemeScript, animation, animationProperties, aspectRatioProperties, atRuleStyles, attributeProperties, attributeSelectors, attributes, blurProperties, borderProperties, chainProps, colorMix, colorProperties, conditionProperties, conditionSelectors, conditions, createBreakpoints, createComponent, createLayers, createShouldForwardProp, createSlotComponent, createStorageManager, createStyled, createSystem, createVarRules, createVars, css, cssProps, defaultEnvironment, defaultLayers, defaultSystem, defineComponentSlotStyle, defineComponentStyle, defineConfig, defineSemanticTokens, defineStyles, defineTheme, defineThemeSchemes, defineTokens, display, durationProperties, easingProperties, extractProps, focusRingStyle, fontProperties, getCSS, getCSSFunction, getClassName, getColorModeValue, getColorSchemeVar, getCondition, getDisplayName, getPreventTransition, getSlotClassName, getStorageScript, getStyle, getVar, getVarName, gradient, gradientProperties, groupAttributeProperties, groupAttributeSelectors, groupAttributes, injectKeyframes, injectVars, isCSSFunction, isCSSToken, isCSSVar, isColorScheme, isEqualProps, keyframeProperties, keyframes, mergeCSS, mergeProps, mergeSlotCSS, mergeVars, peerAttributeProperties, peerAttributeSelectors, peerAttributes, pseudoClassProperties, pseudoClassSelectors, pseudoClasses, pseudoElementProperties, pseudoElementSelectors, pseudoElements, pseudoStyles, radiusProperties, shadowProperties, shorthandStyles, sizeProperties, spaceProperties, standardStyles, styleProperties, styled, styledStyles, styles, tokenToValue, tokenToVar, transformConditionalValue, transformInterpolation, transforms, useCSS, useColorMode, useColorModeValue, useColorSchemeContext, useComponentSlotStyle, useComponentStyle, useEnvironment, useExtractProps, useHydrationContext, useInjectVarsIntoCss, useInjectVarsIntoProps, useSplitProps, useSystem, useSystemColorMode, useTheme, varAttr, varToValue, variableLengthProperties, vendorProperties, zIndexProperties };
|
|
34
|
+
export { COLOR_MODE_STORAGE_KEY, ColorModeContext, ColorModeProvider, ColorModeScript, ColorSchemeContext, DEFAULT_BREAKPOINT_DIRECTION, DEFAULT_DIRECTION, DEFAULT_LAYERS, DEFAULT_LOCALE, DEFAULT_VAR_PREFIX, EnvironmentProvider, GlobalStyles, HydrationContext, SystemProvider, THEME_SCHEME_STORAGE_KEY, ThemeProvider, ThemeSchemeScript, animation, animationProperties, aspectRatioProperties, atRuleStyles, attributeProperties, attributeSelectors, attributes, blurProperties, borderProperties, chainProps, colorMix, colorProperties, conditionProperties, conditionSelectors, conditions, createBreakpoints, createComponent, createLayers, createShouldForwardProp, createSlotComponent, createStorageManager, createStyled, createSystem, createVarRules, createVars, css, cssProps, defaultEnvironment, defaultLayers, defaultSystem, defineComponentSlotStyle, defineComponentStyle, defineConfig, defineSemanticTokens, defineStyles, defineTheme, defineThemeSchemes, defineTokens, display, durationProperties, easingProperties, extractProps, focusRingStyle, fontProperties, getCSS, getCSSFunction, getClassName, getColorModeValue, getColorSchemeVar, getCondition, getDisplayName, getPreventTransition, getSlotClassName, getStorageScript, getStyle, getVar, getVarName, gradient, gradientProperties, groupAttributeProperties, groupAttributeSelectors, groupAttributes, injectKeyframes, injectVars, isCSSFunction, isCSSToken, isCSSVar, isColorScheme, isEqualProps, keyframeProperties, keyframes, mergeCSS, mergeProps, mergeSlotCSS, mergeVars, peerAttributeProperties, peerAttributeSelectors, peerAttributes, pseudoClassProperties, pseudoClassSelectors, pseudoClasses, pseudoElementProperties, pseudoElementSelectors, pseudoElements, pseudoStyles, radiusProperties, shadowProperties, shorthandStyles, sizeProperties, spaceProperties, standardStyles, styleProperties, styled, styledStyles, styles, tokenToValue, tokenToVar, transformConditionalValue, transformInterpolation, transforms, useCSS, useColorMode, useColorModeValue, useColorSchemeContext, useComponentSlotStyle, useComponentStyle, useEnvironment, useExtractProps, useHydrationContext, useInjectVarsIntoCss, useInjectVarsIntoProps, useSplitProps, useSystem, useSystemColorMode, useTheme, varAttr, varToValue, variableLengthProperties, vendorProperties, zIndexProperties };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { utils_exports } from "../../utils/index.js";
|
|
2
|
+
import { DEFAULT_BREAKPOINT_DIRECTION } from "../constant.js";
|
|
2
3
|
// src/core/system/breakpoint.ts
|
|
3
4
|
function createQuery(min, max, identifier = "@media screen") {
|
|
4
5
|
const query = [identifier];
|
|
@@ -44,7 +45,7 @@ function transformBreakpoints(breakpoints, config) {
|
|
|
44
45
|
}
|
|
45
46
|
function createBreakpoints(breakpoints = {}, config = {}) {
|
|
46
47
|
config.base ??= "9999px";
|
|
47
|
-
config.direction ??=
|
|
48
|
+
config.direction ??= DEFAULT_BREAKPOINT_DIRECTION;
|
|
48
49
|
breakpoints.base = config.direction !== "up" ? config.base : "0px";
|
|
49
50
|
const { queries, queriesObj } = createQueries(transformBreakpoints(breakpoints, config), config);
|
|
50
51
|
const keys = Object.keys(queriesObj);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"breakpoint.js","names":["getPx","isObject"],"sources":["../../../../src/core/system/breakpoint.ts"],"sourcesContent":["import type { Dict } from \"../../utils\"\nimport type {\n Breakpoint,\n BreakpointConfig,\n DefineThemeBreakpointTokens,\n} from \"./index.type\"\nimport { getPx, isObject } from \"../../utils\"\n\ninterface BreakpointQuery {\n breakpoint: Breakpoint\n maxW: number | undefined\n maxWQuery: string | undefined\n minMaxQuery: string | undefined\n minW: number | undefined\n minWQuery: string | undefined\n query: string | undefined\n}\n\nexport interface Breakpoints {\n keys: Breakpoint[]\n queries: BreakpointQuery[]\n queriesObj: { [key: string]: BreakpointQuery }\n getQuery: (key: string) => string | undefined\n isResponsive: (obj: any, strict?: boolean) => boolean\n isResponsiveKey: (key: string) => boolean\n}\n\nfunction createQuery(\n min: number | undefined,\n max: number | undefined,\n identifier = \"@media screen\",\n): string | undefined {\n const query = [identifier]\n\n if (min) query.push(\"and\", `(min-width: ${min}px)`)\n if (max) query.push(\"and\", `(max-width: ${max}px)`)\n\n return query.length > 1\n ? query.join(\" \").replace(/^@container(\\s+\\w*)?\\s+and/, `@container$1`)\n : undefined\n}\n\nfunction createQueries(breakpoints: Dict<number>, config: BreakpointConfig) {\n const { direction, identifier } = config\n const down = direction !== \"up\"\n\n const queryEntries = Object.entries(breakpoints)\n .map(([breakpoint, width], i, entry) => {\n const [, relatedWidth] = entry[i + 1] ?? []\n let minW = down ? relatedWidth : width\n let maxW = down ? width : relatedWidth\n\n if (breakpoint === \"base\")\n if (down) maxW = undefined\n else minW = undefined\n\n if (down) {\n if (minW) minW += 1\n } else {\n if (maxW) maxW -= 1\n }\n\n const maxWQuery = createQuery(undefined, maxW, identifier)\n const minWQuery = createQuery(minW, undefined, identifier)\n const minMaxQuery = createQuery(minW, maxW, identifier)\n const query = down ? maxWQuery : minWQuery\n\n return [\n breakpoint,\n {\n breakpoint: breakpoint as Breakpoint,\n maxW,\n maxWQuery,\n minMaxQuery,\n minW,\n minWQuery,\n query,\n },\n ] as const\n })\n .sort((a, b) =>\n down\n ? (b[1].maxW ?? Infinity) - (a[1].maxW ?? Infinity)\n : (a[1].minW ?? 0) - (b[1].minW ?? 0),\n )\n\n const queries = queryEntries.map(([_, query]) => query)\n const queriesObj = Object.fromEntries(queryEntries)\n\n return { queries, queriesObj }\n}\n\nfunction transformBreakpoints(\n breakpoints: Dict,\n config: BreakpointConfig,\n): Dict {\n return Object.fromEntries(\n Object.entries(breakpoints)\n .map(([name, value]) => [name, getPx(value)] as const)\n .sort((a, b) => {\n if (config.direction !== \"up\") return b[1] - a[1]\n else return a[1] - b[1]\n }),\n )\n}\n\nexport function createBreakpoints(\n breakpoints: DefineThemeBreakpointTokens = {},\n config: BreakpointConfig = {},\n): Breakpoints {\n config.base ??= \"9999px\"\n config.direction ??= \
|
|
1
|
+
{"version":3,"file":"breakpoint.js","names":["getPx","isObject"],"sources":["../../../../src/core/system/breakpoint.ts"],"sourcesContent":["import type { Dict } from \"../../utils\"\nimport type {\n Breakpoint,\n BreakpointConfig,\n DefineThemeBreakpointTokens,\n} from \"./index.type\"\nimport { getPx, isObject } from \"../../utils\"\nimport { DEFAULT_BREAKPOINT_DIRECTION } from \"../constant\"\n\ninterface BreakpointQuery {\n breakpoint: Breakpoint\n maxW: number | undefined\n maxWQuery: string | undefined\n minMaxQuery: string | undefined\n minW: number | undefined\n minWQuery: string | undefined\n query: string | undefined\n}\n\nexport interface Breakpoints {\n keys: Breakpoint[]\n queries: BreakpointQuery[]\n queriesObj: { [key: string]: BreakpointQuery }\n getQuery: (key: string) => string | undefined\n isResponsive: (obj: any, strict?: boolean) => boolean\n isResponsiveKey: (key: string) => boolean\n}\n\nfunction createQuery(\n min: number | undefined,\n max: number | undefined,\n identifier = \"@media screen\",\n): string | undefined {\n const query = [identifier]\n\n if (min) query.push(\"and\", `(min-width: ${min}px)`)\n if (max) query.push(\"and\", `(max-width: ${max}px)`)\n\n return query.length > 1\n ? query.join(\" \").replace(/^@container(\\s+\\w*)?\\s+and/, `@container$1`)\n : undefined\n}\n\nfunction createQueries(breakpoints: Dict<number>, config: BreakpointConfig) {\n const { direction, identifier } = config\n const down = direction !== \"up\"\n\n const queryEntries = Object.entries(breakpoints)\n .map(([breakpoint, width], i, entry) => {\n const [, relatedWidth] = entry[i + 1] ?? []\n let minW = down ? relatedWidth : width\n let maxW = down ? width : relatedWidth\n\n if (breakpoint === \"base\")\n if (down) maxW = undefined\n else minW = undefined\n\n if (down) {\n if (minW) minW += 1\n } else {\n if (maxW) maxW -= 1\n }\n\n const maxWQuery = createQuery(undefined, maxW, identifier)\n const minWQuery = createQuery(minW, undefined, identifier)\n const minMaxQuery = createQuery(minW, maxW, identifier)\n const query = down ? maxWQuery : minWQuery\n\n return [\n breakpoint,\n {\n breakpoint: breakpoint as Breakpoint,\n maxW,\n maxWQuery,\n minMaxQuery,\n minW,\n minWQuery,\n query,\n },\n ] as const\n })\n .sort((a, b) =>\n down\n ? (b[1].maxW ?? Infinity) - (a[1].maxW ?? Infinity)\n : (a[1].minW ?? 0) - (b[1].minW ?? 0),\n )\n\n const queries = queryEntries.map(([_, query]) => query)\n const queriesObj = Object.fromEntries(queryEntries)\n\n return { queries, queriesObj }\n}\n\nfunction transformBreakpoints(\n breakpoints: Dict,\n config: BreakpointConfig,\n): Dict {\n return Object.fromEntries(\n Object.entries(breakpoints)\n .map(([name, value]) => [name, getPx(value)] as const)\n .sort((a, b) => {\n if (config.direction !== \"up\") return b[1] - a[1]\n else return a[1] - b[1]\n }),\n )\n}\n\nexport function createBreakpoints(\n breakpoints: DefineThemeBreakpointTokens = {},\n config: BreakpointConfig = {},\n): Breakpoints {\n config.base ??= \"9999px\"\n config.direction ??= DEFAULT_BREAKPOINT_DIRECTION\n\n breakpoints.base = config.direction !== \"up\" ? config.base : \"0px\"\n\n const transformedBreakpoints = transformBreakpoints(breakpoints, config)\n const { queries, queriesObj } = createQueries(transformedBreakpoints, config)\n const keys = Object.keys(queriesObj) as Breakpoint[]\n\n function isResponsive(obj: any, strict = false) {\n if (!isObject(obj)) return false\n\n const providedKeys = Object.keys(obj) as Breakpoint[]\n\n if (!providedKeys.length) return false\n\n if (strict && !providedKeys.includes(\"base\")) return false\n\n return providedKeys.every((key) => keys.includes(key))\n }\n\n function isResponsiveKey(key: string) {\n return key in queriesObj\n }\n\n function getQuery(key: string) {\n return key in queriesObj ? queriesObj[key]?.query : undefined\n }\n\n return {\n getQuery,\n isResponsive,\n isResponsiveKey,\n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CAAE;AAC/B;AAEA,SAAS,qBACP,aACA,QACM;CACN,OAAO,OAAO,YACZ,OAAO,QAAQ,WAAW,CAAC,CACxB,KAAK,CAAC,MAAM,WAAW,CAAC,OAAA,GAAMA,cAAAA,MAAAA,CAAM,KAAK,CAAC,CAAU,CAAC,CACrD,MAAM,GAAG,MAAM;EACd,IAAI,OAAO,cAAc,MAAM,OAAO,EAAE,KAAK,EAAE;OAC1C,OAAO,EAAE,KAAK,EAAE;CACvB,CAAC,CACL;AACF;AAEA,SAAgB,kBACd,cAA2C,CAAC,GAC5C,SAA2B,CAAC,GACf;CACb,OAAO,SAAS;CAChB,OAAO,cAAc;CAErB,YAAY,OAAO,OAAO,cAAc,OAAO,OAAO,OAAO;CAG7D,MAAM,EAAE,SAAS,eAAe,cADD,qBAAqB,aAAa,MACE,GAAG,MAAM;CAC5E,MAAM,OAAO,OAAO,KAAK,UAAU;CAEnC,SAAS,aAAa,KAAU,SAAS,OAAO;EAC9C,IAAI,EAAA,GAACC,cAAAA,SAAAA,CAAS,GAAG,GAAG,OAAO;EAE3B,MAAM,eAAe,OAAO,KAAK,GAAG;EAEpC,IAAI,CAAC,aAAa,QAAQ,OAAO;EAEjC,IAAI,UAAU,CAAC,aAAa,SAAS,MAAM,GAAG,OAAO;EAErD,OAAO,aAAa,OAAO,QAAQ,KAAK,SAAS,GAAG,CAAC;CACvD;CAEA,SAAS,gBAAgB,KAAa;EACpC,OAAO,OAAO;CAChB;CAEA,SAAS,SAAS,KAAa;EAC7B,OAAO,OAAO,aAAa,WAAW,IAAI,EAAE,QAAQ,KAAA;CACtD;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import "../../core/constant.js";
|
|
3
|
+
import { useSystem } from "../../core/system/system-provider.js";
|
|
2
4
|
import { useBreakpoint } from "./use-breakpoint.js";
|
|
3
5
|
import { useEffect } from "react";
|
|
4
6
|
// src/hooks/use-breakpoint/use-breakpoint-effect.ts
|
|
@@ -8,10 +10,16 @@ import { useEffect } from "react";
|
|
|
8
10
|
* @see https://yamada-ui.com/docs/hooks/use-breakpoint-effect
|
|
9
11
|
*/
|
|
10
12
|
const useBreakpointEffect = (callback, deps) => {
|
|
13
|
+
const { config } = useSystem();
|
|
11
14
|
const breakpoint = useBreakpoint();
|
|
15
|
+
const direction = config.breakpoint?.direction ?? "down";
|
|
12
16
|
useEffect(() => {
|
|
13
|
-
callback(breakpoint);
|
|
14
|
-
}, [
|
|
17
|
+
callback(breakpoint, direction);
|
|
18
|
+
}, [
|
|
19
|
+
breakpoint,
|
|
20
|
+
direction,
|
|
21
|
+
...deps
|
|
22
|
+
]);
|
|
15
23
|
};
|
|
16
24
|
export { useBreakpointEffect };
|
|
17
25
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-breakpoint-effect.js","names":[],"sources":["../../../../src/hooks/use-breakpoint/use-breakpoint-effect.ts"],"sourcesContent":["\"use client\"\n\nimport type { DependencyList } from \"react\"\nimport type { Breakpoint } from \"../../core\"\nimport { useEffect } from \"react\"\nimport { useBreakpoint } from \"./use-breakpoint\"\n\n/**\n * `useBreakpointEffect` is a custom hook that executes a specific callback function when the breakpoint changes.\n *\n * @see https://yamada-ui.com/docs/hooks/use-breakpoint-effect\n */\nexport const useBreakpointEffect = (\n callback: (breakpoint: Breakpoint) => void,\n deps: DependencyList,\n) => {\n const breakpoint = useBreakpoint()\n\n useEffect(() => {\n callback(breakpoint)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [breakpoint, ...deps])\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-breakpoint-effect.js","names":[],"sources":["../../../../src/hooks/use-breakpoint/use-breakpoint-effect.ts"],"sourcesContent":["\"use client\"\n\nimport type { DependencyList } from \"react\"\nimport type { Breakpoint, BreakpointDirection } from \"../../core\"\nimport { useEffect } from \"react\"\nimport { DEFAULT_BREAKPOINT_DIRECTION, useSystem } from \"../../core\"\nimport { useBreakpoint } from \"./use-breakpoint\"\n\n/**\n * `useBreakpointEffect` is a custom hook that executes a specific callback function when the breakpoint changes.\n *\n * @see https://yamada-ui.com/docs/hooks/use-breakpoint-effect\n */\nexport const useBreakpointEffect = (\n callback: (breakpoint: Breakpoint, direction: BreakpointDirection) => void,\n deps: DependencyList,\n) => {\n const { config } = useSystem()\n const breakpoint = useBreakpoint()\n const direction = config.breakpoint?.direction ?? DEFAULT_BREAKPOINT_DIRECTION\n\n useEffect(() => {\n callback(breakpoint, direction)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [breakpoint, direction, ...deps])\n}\n"],"mappings":";;;;;;;;;;;AAaA,MAAa,uBACX,UACA,SACG;CACH,MAAM,EAAE,WAAW,UAAU;CAC7B,MAAM,aAAa,cAAc;CACjC,MAAM,YAAY,OAAO,YAAY,aAAA;CAErC,gBAAgB;EACd,SAAS,YAAY,SAAS;CAEhC,GAAG;EAAC;EAAY;EAAW,GAAG;CAAI,CAAC;AACrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-breakpoint-state.js","names":[],"sources":["../../../../src/hooks/use-breakpoint/use-breakpoint-state.ts"],"sourcesContent":["\"use client\"\n\nimport type { ResponsiveObject } from \"../../core\"\nimport { useState } from \"react\"\nimport { useBreakpointValue } from \"./use-breakpoint-value\"\n\n/**\n * `useBreakpointState` is a custom hook that takes a responsive object as an initial state and returns a state corresponding to the current breakpoint.\n *\n * @see https://yamada-ui.com/docs/hooks/use-breakpoint-state\n */\nexport const useBreakpointState = <Y>(\n initialState: ResponsiveObject<Y, false>,\n) => {\n const state = useBreakpointValue(initialState)\n\n return useState(state)\n}\n"],"mappings":";;;;;;;;;AAWA,MAAa,sBACX,
|
|
1
|
+
{"version":3,"file":"use-breakpoint-state.js","names":[],"sources":["../../../../src/hooks/use-breakpoint/use-breakpoint-state.ts"],"sourcesContent":["\"use client\"\n\nimport type { BreakpointDirection, ResponsiveObject } from \"../../core\"\nimport { useState } from \"react\"\nimport { useBreakpointValue } from \"./use-breakpoint-value\"\n\n/**\n * `useBreakpointState` is a custom hook that takes a responsive object as an initial state and returns a state corresponding to the current breakpoint.\n *\n * @see https://yamada-ui.com/docs/hooks/use-breakpoint-state\n */\nexport const useBreakpointState = <Y>(\n initialState:\n | ((direction: BreakpointDirection) => ResponsiveObject<Y, false>)\n | ResponsiveObject<Y, false>,\n) => {\n const state = useBreakpointValue(initialState)\n\n return useState(state)\n}\n"],"mappings":";;;;;;;;;AAWA,MAAa,sBACX,iBAGG;CACH,MAAM,QAAQ,mBAAmB,YAAY;CAE7C,OAAO,SAAS,KAAK;AACvB"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import "../../core/constant.js";
|
|
1
2
|
import { useSystem } from "../../core/system/system-provider.js";
|
|
2
3
|
import { useBreakpoint } from "./use-breakpoint.js";
|
|
3
4
|
import { useMemo } from "react";
|
|
5
|
+
import { runIfFn } from "@yamada-ui/utils";
|
|
4
6
|
// src/hooks/use-breakpoint/use-breakpoint-value.ts
|
|
5
7
|
/**
|
|
6
8
|
* `useBreakpointValue` is a custom hook that returns the value of the current breakpoint from the provided object.
|
|
@@ -11,10 +13,12 @@ import { useMemo } from "react";
|
|
|
11
13
|
const useBreakpointValue = (values) => {
|
|
12
14
|
const system = useSystem();
|
|
13
15
|
const breakpoint = useBreakpoint();
|
|
14
|
-
|
|
16
|
+
const direction = system.config.breakpoint?.direction ?? "down";
|
|
17
|
+
return useMemo(() => getBreakpointValue(runIfFn(values, direction))(system, breakpoint), [
|
|
15
18
|
values,
|
|
16
19
|
system,
|
|
17
|
-
breakpoint
|
|
20
|
+
breakpoint,
|
|
21
|
+
direction
|
|
18
22
|
]);
|
|
19
23
|
};
|
|
20
24
|
const getBreakpointValue = (values = {}) => (system, breakpoint) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-breakpoint-value.js","names":[],"sources":["../../../../src/hooks/use-breakpoint/use-breakpoint-value.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"use-breakpoint-value.js","names":[],"sources":["../../../../src/hooks/use-breakpoint/use-breakpoint-value.ts"],"sourcesContent":["import type {\n Breakpoint,\n BreakpointDirection,\n ResponsiveObject,\n System,\n} from \"../../core\"\nimport { runIfFn } from \"@yamada-ui/utils\"\nimport { useMemo } from \"react\"\nimport { DEFAULT_BREAKPOINT_DIRECTION, 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:\n | ((direction: BreakpointDirection) => ResponsiveObject<Y, false>)\n | ResponsiveObject<Y, false>,\n): Y => {\n const system = useSystem()\n const breakpoint = useBreakpoint()\n const direction =\n system.config.breakpoint?.direction ?? DEFAULT_BREAKPOINT_DIRECTION\n\n return useMemo(\n () => getBreakpointValue<Y>(runIfFn(values, direction))(system, breakpoint),\n [values, system, breakpoint, direction],\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 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 return values.base as Y\n }\n"],"mappings":";;;;;;;;;;;;AAiBA,MAAa,sBACX,WAGM;CACN,MAAM,SAAS,UAAU;CACzB,MAAM,aAAa,cAAc;CACjC,MAAM,YACJ,OAAO,OAAO,YAAY,aAAA;CAE5B,OAAO,cACC,mBAAsB,QAAQ,QAAQ,SAAS,CAAC,CAAC,CAAC,QAAQ,UAAU,GAC1E;EAAC;EAAQ;EAAQ;EAAY;CAAS,CACxC;AACF;AAEA,MAAa,sBACP,SAAqC,CAAC,OACzC,QAAgB,eAA8B;CAC7C,MAAM,cAAc,OAAO,YAAY;CAEvC,IAAI,CAAC,YAAY,QACf,QAAQ,KAAK,iDAAiD;CAEhE,MAAM,eAAe,YAAY,QAAQ,UAAU;CAEnD,KAAK,IAAI,IAAI,cAAc,IAAI,GAAG,KAAK;EACrC,MAAM,iBAAiB,YAAY;EAEnC,IAAI,kBAAkB,OAAO,eAAe,cAAc,GACxD,OAAO,OAAO;CAClB;CAEA,OAAO,OAAO;AAChB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { DEFAULT_BREAKPOINT_DIRECTION } from "../../core/constant.js";
|
|
2
3
|
import { useEnvironment } from "../../core/system/environment-provider.js";
|
|
3
4
|
import { useSystem } from "../../core/system/system-provider.js";
|
|
4
5
|
import { utils_exports } from "../../utils/index.js";
|
|
@@ -14,7 +15,7 @@ const useBreakpoint = () => {
|
|
|
14
15
|
const animationFrameId = useRef(0);
|
|
15
16
|
const { breakpoints, config } = useSystem();
|
|
16
17
|
const { getWindow } = useEnvironment();
|
|
17
|
-
const { containerRef, direction =
|
|
18
|
+
const { containerRef, direction = DEFAULT_BREAKPOINT_DIRECTION, identifier = "@media screen" } = config.breakpoint ?? {};
|
|
18
19
|
const hasContainer = !!containerRef;
|
|
19
20
|
const queries = useMemo(() => {
|
|
20
21
|
return breakpoints.queries.map(({ breakpoint, maxW, minMaxQuery, minW }) => {
|