@opengovsg/oui 0.0.28 → 0.0.30
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/badge/badge.cjs +4 -4
- package/dist/cjs/badge/use-badge.cjs +6 -6
- package/dist/cjs/banner/banner.cjs +4 -4
- package/dist/cjs/button/button.cjs +4 -4
- package/dist/cjs/calendar/calendar-bottom-content.cjs +3 -3
- package/dist/cjs/calendar/calendar-header.cjs +2 -2
- package/dist/cjs/calendar/calendar-month-day-selector.cjs +4 -4
- package/dist/cjs/calendar/calendar.cjs +4 -4
- package/dist/cjs/calendar/hooks/use-calendar-selectors.cjs +4 -4
- package/dist/cjs/calendar/utils.cjs +3 -3
- package/dist/cjs/checkbox/checkbox.cjs +1 -1
- package/dist/cjs/combo-box/combo-box-fuzzy.cjs +6 -6
- package/dist/cjs/combo-box/combo-box-item.cjs +2 -2
- package/dist/cjs/combo-box/combo-box.cjs +5 -5
- package/dist/cjs/date-field/date-field.cjs +4 -4
- package/dist/cjs/date-picker/date-picker.cjs +7 -6
- package/dist/cjs/date-range-picker/date-range-picker.cjs +8 -8
- package/dist/cjs/field/field.cjs +2 -2
- package/dist/cjs/file-dropzone/file-dropzone.cjs +23 -19
- package/dist/cjs/file-dropzone/file-info.cjs +6 -5
- package/dist/cjs/file-dropzone/utils.cjs +4 -4
- package/dist/cjs/govt-banner/govt-banner.cjs +3 -3
- package/dist/cjs/hooks/use-callback-ref.cjs +4 -4
- package/dist/cjs/hooks/use-controllable-state.cjs +2 -2
- package/dist/cjs/hooks/use-draggable.cjs +8 -8
- package/dist/cjs/hooks/use-scroll-position.cjs +53 -0
- package/dist/cjs/index.cjs +38 -19
- package/dist/cjs/input/input.cjs +2 -2
- package/dist/cjs/menu/menu.cjs +8 -8
- package/dist/cjs/modal/modal-body.cjs +2 -2
- package/dist/cjs/modal/modal-content.cjs +4 -4
- package/dist/cjs/modal/modal-footer.cjs +2 -2
- package/dist/cjs/modal/modal-header.cjs +2 -2
- package/dist/cjs/modal/modal.cjs +3 -3
- package/dist/cjs/navbar/index.cjs +25 -0
- package/dist/cjs/navbar/navbar-brand.cjs +28 -0
- package/dist/cjs/navbar/navbar-content.cjs +33 -0
- package/dist/cjs/navbar/navbar-context.cjs +14 -0
- package/dist/cjs/navbar/navbar-item.cjs +29 -0
- package/dist/cjs/navbar/navbar-menu/i18n.cjs +23 -0
- package/dist/cjs/navbar/navbar-menu/item.cjs +44 -0
- package/dist/cjs/navbar/navbar-menu/menu.cjs +62 -0
- package/dist/cjs/navbar/navbar-menu/toggle.cjs +95 -0
- package/dist/cjs/navbar/navbar.cjs +50 -0
- package/dist/cjs/navbar/use-navbar.cjs +126 -0
- package/dist/cjs/node_modules/.pnpm/@react-aria_overlays@3.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@react-aria/overlays/dist/Overlay.cjs +55 -0
- package/dist/cjs/node_modules/.pnpm/@react-aria_overlays@3.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@react-aria/overlays/dist/PortalProvider.cjs +23 -0
- package/dist/cjs/node_modules/.pnpm/@react-aria_overlays@3.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@react-aria/overlays/dist/usePreventScroll.cjs +208 -0
- package/dist/cjs/node_modules/.pnpm/@react-aria_ssr@3.9.10_react@19.2.3/node_modules/@react-aria/ssr/dist/SSRProvider.cjs +104 -0
- package/dist/cjs/node_modules/.pnpm/lucide-react@0.475.0_react@19.2.3/node_modules/lucide-react/dist/esm/Icon.cjs +4 -4
- package/dist/cjs/node_modules/.pnpm/lucide-react@0.475.0_react@19.2.3/node_modules/lucide-react/dist/esm/createLucideIcon.cjs +3 -3
- package/dist/cjs/number-field/number-field.cjs +2 -2
- package/dist/cjs/pagination/hooks/use-pagination.cjs +7 -7
- package/dist/cjs/pagination/pagination.cjs +6 -6
- package/dist/cjs/pagination/use-pagination-item.cjs +3 -3
- package/dist/cjs/pagination/use-pagination.cjs +8 -8
- package/dist/cjs/range-calendar/range-calendar.cjs +7 -7
- package/dist/cjs/ripple/use-ripple.cjs +4 -4
- package/dist/cjs/select/select.cjs +5 -5
- package/dist/cjs/spinner/use-spinner.cjs +3 -3
- package/dist/cjs/system/react-utils/children.cjs +26 -0
- package/dist/cjs/system/react-utils/context.cjs +3 -3
- package/dist/cjs/system/react-utils/refs.cjs +3 -3
- package/dist/cjs/system/utils.cjs +2 -2
- package/dist/cjs/tabs/tabs.cjs +2 -2
- package/dist/cjs/tag-field/tag-field-item.cjs +2 -2
- package/dist/cjs/tag-field/tag-field-list.cjs +4 -4
- package/dist/cjs/tag-field/tag-field-root.cjs +14 -14
- package/dist/cjs/tag-field/tag-field-state-context.cjs +2 -2
- package/dist/cjs/tag-field/tag-field-tag-list.cjs +3 -3
- package/dist/cjs/tag-field/tag-field-trigger.cjs +2 -2
- package/dist/cjs/tag-field/tag-field.cjs +4 -4
- package/dist/cjs/tag-field/use-tag-field-state.cjs +6 -6
- package/dist/cjs/tag-field/use-tag-field.cjs +4 -4
- package/dist/cjs/text-area/text-area.cjs +2 -2
- package/dist/cjs/text-area-field/text-area-field.cjs +1 -1
- package/dist/cjs/text-field/text-field.cjs +1 -1
- package/dist/cjs/toast/toast.cjs +1 -1
- package/dist/cjs/toggle/toggle.cjs +3 -3
- package/dist/esm/banner/banner.js +1 -1
- package/dist/esm/button/button.js +1 -1
- package/dist/esm/calendar/calendar-month-day-selector.js +2 -2
- package/dist/esm/checkbox/checkbox.js +1 -1
- package/dist/esm/combo-box/combo-box.js +2 -2
- package/dist/esm/date-field/date-field.js +1 -1
- package/dist/esm/date-picker/date-picker.js +5 -4
- package/dist/esm/date-range-picker/date-range-picker.js +5 -5
- package/dist/esm/file-dropzone/file-dropzone.js +13 -9
- package/dist/esm/file-dropzone/file-info.js +3 -2
- package/dist/esm/file-dropzone/utils.js +4 -4
- package/dist/esm/hooks/use-scroll-position.js +51 -0
- package/dist/esm/index.js +17 -8
- package/dist/esm/menu/menu.js +2 -2
- package/dist/esm/modal/modal-content.js +1 -1
- package/dist/esm/navbar/index.js +10 -0
- package/dist/esm/navbar/navbar-brand.js +26 -0
- package/dist/esm/navbar/navbar-content.js +31 -0
- package/dist/esm/navbar/navbar-context.js +11 -0
- package/dist/esm/navbar/navbar-item.js +27 -0
- package/dist/esm/navbar/navbar-menu/i18n.js +21 -0
- package/dist/esm/navbar/navbar-menu/item.js +42 -0
- package/dist/esm/navbar/navbar-menu/menu.js +60 -0
- package/dist/esm/navbar/navbar-menu/toggle.js +93 -0
- package/dist/esm/navbar/navbar.js +48 -0
- package/dist/esm/navbar/use-navbar.js +124 -0
- package/dist/esm/node_modules/.pnpm/@react-aria_overlays@3.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@react-aria/overlays/dist/Overlay.js +52 -0
- package/dist/esm/node_modules/.pnpm/@react-aria_overlays@3.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@react-aria/overlays/dist/PortalProvider.js +20 -0
- package/dist/esm/node_modules/.pnpm/@react-aria_overlays@3.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@react-aria/overlays/dist/usePreventScroll.js +206 -0
- package/dist/esm/node_modules/.pnpm/@react-aria_ssr@3.9.10_react@19.2.3/node_modules/@react-aria/ssr/dist/SSRProvider.js +102 -0
- package/dist/esm/number-field/number-field.js +2 -2
- package/dist/esm/pagination/use-pagination-item.js +1 -1
- package/dist/esm/range-calendar/range-calendar.js +1 -1
- package/dist/esm/select/select.js +3 -3
- package/dist/esm/system/react-utils/children.js +23 -0
- package/dist/esm/tag-field/tag-field.js +2 -2
- package/dist/esm/text-area-field/text-area-field.js +1 -1
- package/dist/esm/text-field/text-field.js +1 -1
- package/dist/esm/toast/toast.js +1 -1
- package/dist/types/calendar/calendar.d.ts.map +1 -1
- package/dist/types/date-field/date-field.d.ts.map +1 -1
- package/dist/types/file-dropzone/file-dropzone.d.ts +8 -2
- package/dist/types/file-dropzone/file-dropzone.d.ts.map +1 -1
- package/dist/types/file-dropzone/file-info.d.ts.map +1 -1
- package/dist/types/file-dropzone/types.d.ts +1 -0
- package/dist/types/file-dropzone/types.d.ts.map +1 -1
- package/dist/types/file-dropzone/utils.d.ts +2 -1
- package/dist/types/file-dropzone/utils.d.ts.map +1 -1
- package/dist/types/hooks/use-scroll-position.d.ts +29 -0
- package/dist/types/hooks/use-scroll-position.d.ts.map +1 -0
- package/dist/types/index.d.mts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/menu/menu.d.ts.map +1 -1
- package/dist/types/navbar/index.d.ts +17 -0
- package/dist/types/navbar/index.d.ts.map +1 -0
- package/dist/types/navbar/navbar-brand.d.ts +6 -0
- package/dist/types/navbar/navbar-brand.d.ts.map +1 -0
- package/dist/types/navbar/navbar-content.d.ts +14 -0
- package/dist/types/navbar/navbar-content.d.ts.map +1 -0
- package/dist/types/navbar/navbar-context.d.ts +182 -0
- package/dist/types/navbar/navbar-context.d.ts.map +1 -0
- package/dist/types/navbar/navbar-item.d.ts +11 -0
- package/dist/types/navbar/navbar-item.d.ts.map +1 -0
- package/dist/types/navbar/navbar-menu/i18n.d.ts +3 -0
- package/dist/types/navbar/navbar-menu/i18n.d.ts.map +1 -0
- package/dist/types/navbar/navbar-menu/item.d.ts +16 -0
- package/dist/types/navbar/navbar-menu/item.d.ts.map +1 -0
- package/dist/types/navbar/navbar-menu/menu.d.ts +11 -0
- package/dist/types/navbar/navbar-menu/menu.d.ts.map +1 -0
- package/dist/types/navbar/navbar-menu/toggle.d.ts +12 -0
- package/dist/types/navbar/navbar-menu/toggle.d.ts.map +1 -0
- package/dist/types/navbar/navbar.d.ts +6 -0
- package/dist/types/navbar/navbar.d.ts.map +1 -0
- package/dist/types/navbar/use-navbar.d.ts +163 -0
- package/dist/types/navbar/use-navbar.d.ts.map +1 -0
- package/dist/types/range-calendar/range-calendar.d.ts.map +1 -1
- package/dist/types/system/react-utils/children.d.ts +10 -0
- package/dist/types/system/react-utils/children.d.ts.map +1 -0
- package/dist/types/system/react-utils/index.d.ts +5 -3
- package/dist/types/system/react-utils/index.d.ts.map +1 -1
- package/dist/types/system/utils.d.ts.map +1 -1
- package/dist/types/tabs/tabs.d.ts.map +1 -1
- package/dist/types/tag-field/tag-field-item.d.ts.map +1 -1
- package/dist/types/tag-field/tag-field-list.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -7,13 +7,13 @@ import { useField, useId } from 'react-aria';
|
|
|
7
7
|
import { Provider, LabelContext, GroupContext, TextContext, FieldErrorContext, Group } from 'react-aria-components';
|
|
8
8
|
import { useDropzone } from 'react-dropzone';
|
|
9
9
|
import { fileDropzoneStyles, dataAttr } from '@opengovsg/oui-theme';
|
|
10
|
+
import { Label, Description, FieldError } from '../field/field.js';
|
|
11
|
+
import { useControllableState } from '../hooks/use-controllable-state.js';
|
|
10
12
|
import { mapPropsVariants } from '../system/utils.js';
|
|
11
13
|
import { FileDropzoneStyleContext, FileDropzoneStateContext, useFileDropzoneStateContext, useFileDropzoneStyleContext } from './contexts.js';
|
|
12
14
|
import { FileInfo } from './file-info.js';
|
|
13
15
|
import { formatErrorMessage, formatBytes } from './utils.js';
|
|
14
|
-
import { useControllableState } from '../hooks/use-controllable-state.js';
|
|
15
16
|
import Upload from '../node_modules/.pnpm/lucide-react@0.475.0_react@19.2.3/node_modules/lucide-react/dist/esm/icons/upload.js';
|
|
16
|
-
import { Label, Description, FieldError } from '../field/field.js';
|
|
17
17
|
|
|
18
18
|
const FileDropzone = (originalProps) => {
|
|
19
19
|
const [props, variantProps] = mapPropsVariants(
|
|
@@ -23,6 +23,7 @@ const FileDropzone = (originalProps) => {
|
|
|
23
23
|
const {
|
|
24
24
|
name,
|
|
25
25
|
allowedMimeTypes = [],
|
|
26
|
+
fileSizeBase = "binary",
|
|
26
27
|
maxFileSize = Number.POSITIVE_INFINITY,
|
|
27
28
|
minFileSize = 0,
|
|
28
29
|
showFileSizeText = true,
|
|
@@ -67,9 +68,10 @@ const FileDropzone = (originalProps) => {
|
|
|
67
68
|
(error) => formatErrorMessage(error, {
|
|
68
69
|
maxFileSize,
|
|
69
70
|
minFileSize,
|
|
70
|
-
maxFiles
|
|
71
|
+
maxFiles,
|
|
72
|
+
fileSizeBase
|
|
71
73
|
}),
|
|
72
|
-
[maxFileSize, maxFiles, minFileSize]
|
|
74
|
+
[fileSizeBase, maxFileSize, maxFiles, minFileSize]
|
|
73
75
|
);
|
|
74
76
|
const onDrop = useCallback(
|
|
75
77
|
(acceptedFiles, fileRejections) => {
|
|
@@ -127,19 +129,20 @@ const FileDropzone = (originalProps) => {
|
|
|
127
129
|
const shouldShow = showFileSizeText && (notDefaultMaxFileSize || notDefaultMinFileSize);
|
|
128
130
|
if (!shouldShow) return null;
|
|
129
131
|
if (notDefaultMaxFileSize && notDefaultMinFileSize) {
|
|
130
|
-
return `File size must be between ${formatBytes(minFileSize, 2)} and ${formatBytes(
|
|
132
|
+
return `File size must be between ${formatBytes(minFileSize, 2, fileSizeBase)} and ${formatBytes(
|
|
131
133
|
maxFileSize,
|
|
132
|
-
2
|
|
134
|
+
2,
|
|
135
|
+
fileSizeBase
|
|
133
136
|
)}`;
|
|
134
137
|
}
|
|
135
138
|
if (notDefaultMaxFileSize) {
|
|
136
|
-
return `Maximum file size: ${formatBytes(maxFileSize, 2)}`;
|
|
139
|
+
return `Maximum file size: ${formatBytes(maxFileSize, 2, fileSizeBase)}`;
|
|
137
140
|
}
|
|
138
141
|
if (notDefaultMinFileSize) {
|
|
139
|
-
return `Minimum file size: ${formatBytes(minFileSize, 2)}`;
|
|
142
|
+
return `Minimum file size: ${formatBytes(minFileSize, 2, fileSizeBase)}`;
|
|
140
143
|
}
|
|
141
144
|
return null;
|
|
142
|
-
}, [maxFileSize, minFileSize, showFileSizeText]);
|
|
145
|
+
}, [maxFileSize, minFileSize, showFileSizeText, fileSizeBase]);
|
|
143
146
|
const triggerFileSelector = useCallback(() => {
|
|
144
147
|
if (isDisabled || isReadOnly) return;
|
|
145
148
|
dropzoneState.inputRef.current?.click();
|
|
@@ -185,6 +188,7 @@ const FileDropzone = (originalProps) => {
|
|
|
185
188
|
{
|
|
186
189
|
isDisabled,
|
|
187
190
|
isReadOnly,
|
|
191
|
+
fileSizeBase,
|
|
188
192
|
maxFiles,
|
|
189
193
|
maxFileSize,
|
|
190
194
|
showDropzone,
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
4
4
|
import { useState, useEffect } from 'react';
|
|
5
5
|
import { fileInfoDropzoneStyles, cn } from '@opengovsg/oui-theme';
|
|
6
|
+
import { Button } from '../button/button.js';
|
|
6
7
|
import { useFileDropzoneStateContext, useFileDropzoneStyleContext } from './contexts.js';
|
|
7
8
|
import { formatBytes } from './utils.js';
|
|
8
9
|
import Trash2 from '../node_modules/.pnpm/lucide-react@0.475.0_react@19.2.3/node_modules/lucide-react/dist/esm/icons/trash-2.js';
|
|
9
|
-
import { Button } from '../button/button.js';
|
|
10
10
|
|
|
11
11
|
const FileInfo = ({ file, imagePreview, classNames }) => {
|
|
12
12
|
const {
|
|
@@ -17,7 +17,8 @@ const FileInfo = ({ file, imagePreview, classNames }) => {
|
|
|
17
17
|
isReadOnly
|
|
18
18
|
} = useFileDropzoneStateContext();
|
|
19
19
|
const { size, variant, itemClassNames } = useFileDropzoneStyleContext();
|
|
20
|
-
const
|
|
20
|
+
const { fileSizeBase } = useFileDropzoneStateContext();
|
|
21
|
+
const readableFileSize = formatBytes(file.size, 2, fileSizeBase);
|
|
21
22
|
const styles = fileInfoDropzoneStyles({
|
|
22
23
|
size,
|
|
23
24
|
variant,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { ErrorCode } from 'react-dropzone';
|
|
3
3
|
|
|
4
|
-
const formatBytes = (bytes, decimals = 2, size) => {
|
|
5
|
-
const k = 1e3;
|
|
4
|
+
const formatBytes = (bytes, decimals = 2, base = "binary", size) => {
|
|
5
|
+
const k = base === "binary" ? 1024 : 1e3;
|
|
6
6
|
const dm = decimals < 0 ? 0 : decimals;
|
|
7
7
|
const sizes = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
8
8
|
if (bytes === 0 || bytes === void 0)
|
|
@@ -14,9 +14,9 @@ const formatErrorMessage = (error, config) => {
|
|
|
14
14
|
const { maxFileSize, minFileSize, maxFiles } = config;
|
|
15
15
|
switch (error.code) {
|
|
16
16
|
case ErrorCode.FileTooLarge:
|
|
17
|
-
return `You have exceeded the size limit, please upload a file below ${formatBytes(maxFileSize, 2)}`;
|
|
17
|
+
return `You have exceeded the size limit, please upload a file below ${formatBytes(maxFileSize, 2, config.fileSizeBase)}`;
|
|
18
18
|
case ErrorCode.FileTooSmall:
|
|
19
|
-
return `Please upload a file above ${formatBytes(minFileSize, 2)}`;
|
|
19
|
+
return `Please upload a file above ${formatBytes(minFileSize, 2, config.fileSizeBase)}`;
|
|
20
20
|
case ErrorCode.TooManyFiles:
|
|
21
21
|
return `Maximum number of files allowed is ${maxFiles}.`;
|
|
22
22
|
default: {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { useRef, useCallback, useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
const isBrowser = typeof window !== "undefined";
|
|
5
|
+
function getScrollPosition(element) {
|
|
6
|
+
if (!isBrowser) return { x: 0, y: 0 };
|
|
7
|
+
if (!element) {
|
|
8
|
+
return { x: window.scrollX, y: window.scrollY };
|
|
9
|
+
}
|
|
10
|
+
return { x: element.scrollLeft, y: element.scrollTop };
|
|
11
|
+
}
|
|
12
|
+
const useScrollPosition = (props) => {
|
|
13
|
+
const { elementRef, delay = 30, callback, isEnabled } = props;
|
|
14
|
+
const position = useRef(
|
|
15
|
+
isEnabled ? getScrollPosition(elementRef?.current) : { x: 0, y: 0 }
|
|
16
|
+
);
|
|
17
|
+
const throttleTimeout = useRef(null);
|
|
18
|
+
const handler = useCallback(() => {
|
|
19
|
+
const currPos = getScrollPosition(elementRef?.current);
|
|
20
|
+
if (typeof callback === "function") {
|
|
21
|
+
callback({ prevPos: position.current, currPos });
|
|
22
|
+
}
|
|
23
|
+
position.current = currPos;
|
|
24
|
+
throttleTimeout.current = null;
|
|
25
|
+
}, [callback, elementRef]);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!isEnabled) return;
|
|
28
|
+
const handleScroll = () => {
|
|
29
|
+
if (delay) {
|
|
30
|
+
if (throttleTimeout.current) {
|
|
31
|
+
clearTimeout(throttleTimeout.current);
|
|
32
|
+
}
|
|
33
|
+
throttleTimeout.current = setTimeout(handler, delay);
|
|
34
|
+
} else {
|
|
35
|
+
handler();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const target = elementRef?.current || window;
|
|
39
|
+
target.addEventListener("scroll", handleScroll);
|
|
40
|
+
return () => {
|
|
41
|
+
target.removeEventListener("scroll", handleScroll);
|
|
42
|
+
if (throttleTimeout.current) {
|
|
43
|
+
clearTimeout(throttleTimeout.current);
|
|
44
|
+
throttleTimeout.current = null;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}, [elementRef?.current, delay, handler, isEnabled]);
|
|
48
|
+
return position.current;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export { useScrollPosition };
|
package/dist/esm/index.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
export { Toggle } from './toggle/toggle.js';
|
|
3
|
-
export { Input } from './input/input.js';
|
|
4
|
-
export { TextField } from './text-field/text-field.js';
|
|
5
|
-
export { TextArea } from './text-area/text-area.js';
|
|
6
|
-
export { TextAreaField } from './text-area-field/text-area-field.js';
|
|
7
|
-
export { Toaster } from './toast/toast.js';
|
|
8
2
|
export { useControllableState } from './hooks/use-controllable-state.js';
|
|
9
3
|
export { useDraggable } from './hooks/use-draggable.js';
|
|
10
4
|
export { Button } from './button/button.js';
|
|
@@ -13,8 +7,13 @@ export { Ripple } from './ripple/ripple.js';
|
|
|
13
7
|
export { useRipple } from './ripple/use-ripple.js';
|
|
14
8
|
export { Spinner } from './spinner/spinner.js';
|
|
15
9
|
export { useSpinner } from './spinner/use-spinner.js';
|
|
10
|
+
export { Toggle } from './toggle/toggle.js';
|
|
16
11
|
export { SkipNavLink } from './skip-nav-link/skip-nav-link.js';
|
|
12
|
+
export { Input } from './input/input.js';
|
|
13
|
+
export { TextField } from './text-field/text-field.js';
|
|
17
14
|
export { Description, FieldError, FieldErrorIcon, FieldGroup, Label } from './field/field.js';
|
|
15
|
+
export { TextArea } from './text-area/text-area.js';
|
|
16
|
+
export { TextAreaField } from './text-area-field/text-area-field.js';
|
|
18
17
|
export { ComboBox, ComboBoxEmptyState } from './combo-box/combo-box.js';
|
|
19
18
|
export { ComboBoxFuzzy } from './combo-box/combo-box-fuzzy.js';
|
|
20
19
|
export { ComboBoxItem } from './combo-box/combo-box-item.js';
|
|
@@ -26,10 +25,10 @@ export { Select } from './select/select.js';
|
|
|
26
25
|
export { SelectItem } from './select/select-item.js';
|
|
27
26
|
export { SelectVariantContext, useSelectVariantContext } from './select/select-variant-context.js';
|
|
28
27
|
export { Badge } from './badge/badge.js';
|
|
29
|
-
export { CalendarDate } from '@internationalized/date';
|
|
30
28
|
export { Calendar, CalendarStateWrapper } from './calendar/calendar.js';
|
|
31
29
|
export { CalendarStyleContext, useCalendarStyleContext } from './calendar/calendar-style-context.js';
|
|
32
30
|
export { getEraFormat, useGenerateLocalizedMonths, useGenerateLocalizedYears, useLocalizedMonthYear } from './calendar/utils.js';
|
|
31
|
+
export { CalendarDate } from '@internationalized/date';
|
|
33
32
|
export { RangeCalendar, RangeCalendarCell, RangeCalendarStateWrapper } from './range-calendar/range-calendar.js';
|
|
34
33
|
export { Menu, MenuItem, MenuSection, MenuSeparator, MenuTrigger, MenuVariantContext, SubmenuTrigger, useMenuVariantContext } from './menu/menu.js';
|
|
35
34
|
export { Popover } from './popover/popover.js';
|
|
@@ -39,10 +38,10 @@ export { DatePicker } from './date-picker/date-picker.js';
|
|
|
39
38
|
export { DateRangePicker } from './date-range-picker/date-range-picker.js';
|
|
40
39
|
export { Checkbox, CheckboxGroup } from './checkbox/checkbox.js';
|
|
41
40
|
export { CheckboxGroupStyleContext, useCheckboxGroupStyleContext } from './checkbox/checkbox-group-style-context.js';
|
|
42
|
-
export { PaginationItemType } from './pagination/hooks/use-pagination.js';
|
|
43
41
|
export { Pagination } from './pagination/pagination.js';
|
|
44
42
|
export { PaginationCursor } from './pagination/pagination-cursor.js';
|
|
45
43
|
export { PaginationItem } from './pagination/pagination-item.js';
|
|
44
|
+
export { PaginationItemType } from './pagination/hooks/use-pagination.js';
|
|
46
45
|
export { CURSOR_TRANSITION_TIMEOUT, usePagination } from './pagination/use-pagination.js';
|
|
47
46
|
export { FileDropzone } from './file-dropzone/file-dropzone.js';
|
|
48
47
|
export { FileInfo } from './file-dropzone/file-info.js';
|
|
@@ -54,4 +53,14 @@ export { ModalFooter } from './modal/modal-footer.js';
|
|
|
54
53
|
export { ModalBody } from './modal/modal-body.js';
|
|
55
54
|
export { ModalHeader } from './modal/modal-header.js';
|
|
56
55
|
export { ModalVariantContext, useModalVariantContext } from './modal/modal-variant-context.js';
|
|
56
|
+
export { Toaster } from './toast/toast.js';
|
|
57
|
+
export { Navbar } from './navbar/navbar.js';
|
|
58
|
+
export { NavbarBrand } from './navbar/navbar-brand.js';
|
|
59
|
+
export { NavbarContent } from './navbar/navbar-content.js';
|
|
60
|
+
export { NavbarMenu } from './navbar/navbar-menu/menu.js';
|
|
61
|
+
export { NavbarMenuItem } from './navbar/navbar-menu/item.js';
|
|
62
|
+
export { NavbarMenuToggle } from './navbar/navbar-menu/toggle.js';
|
|
63
|
+
export { NavbarItem } from './navbar/navbar-item.js';
|
|
64
|
+
export { useNavbar } from './navbar/use-navbar.js';
|
|
65
|
+
export { NavbarProvider, useNavbarContext } from './navbar/navbar-context.js';
|
|
57
66
|
export { toast } from 'sonner';
|
package/dist/esm/menu/menu.js
CHANGED
|
@@ -4,11 +4,11 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
|
4
4
|
import { forwardRef, useMemo, useCallback } from 'react';
|
|
5
5
|
import { useContextProps, MenuItem as MenuItem$1, composeRenderProps, Provider, Menu as Menu$1, MenuSection as MenuSection$1, Header, Collection, MenuTrigger as MenuTrigger$1, SubmenuTrigger as SubmenuTrigger$1, Separator } from 'react-aria-components';
|
|
6
6
|
import { listBoxItemStyles, menuItemStyles, menuStyles, menuSectionStyles, menuDividerStyles } from '@opengovsg/oui-theme';
|
|
7
|
+
import { Popover } from '../popover/popover.js';
|
|
7
8
|
import { forwardRefGeneric, mapPropsVariants } from '../system/utils.js';
|
|
9
|
+
import { createContext } from '../system/react-utils/context.js';
|
|
8
10
|
import Check from '../node_modules/.pnpm/lucide-react@0.475.0_react@19.2.3/node_modules/lucide-react/dist/esm/icons/check.js';
|
|
9
11
|
import ChevronRight from '../node_modules/.pnpm/lucide-react@0.475.0_react@19.2.3/node_modules/lucide-react/dist/esm/icons/chevron-right.js';
|
|
10
|
-
import { createContext } from '../system/react-utils/context.js';
|
|
11
|
-
import { Popover } from '../popover/popover.js';
|
|
12
12
|
|
|
13
13
|
const [MenuVariantContext, useMenuVariantContext] = createContext({
|
|
14
14
|
name: "MenuVariantContext",
|
|
@@ -5,10 +5,10 @@ import { useContext, isValidElement } from 'react';
|
|
|
5
5
|
import { useMessageFormatter } from 'react-aria';
|
|
6
6
|
import { Dialog } from 'react-aria-components';
|
|
7
7
|
import { cn } from '@opengovsg/oui-theme';
|
|
8
|
+
import { Button } from '../button/button.js';
|
|
8
9
|
import { i18nStrings } from './i18n.js';
|
|
9
10
|
import { ModalVariantContext } from './modal-variant-context.js';
|
|
10
11
|
import X from '../node_modules/.pnpm/lucide-react@0.475.0_react@19.2.3/node_modules/lucide-react/dist/esm/icons/x.js';
|
|
11
|
-
import { Button } from '../button/button.js';
|
|
12
12
|
|
|
13
13
|
function ModalContent({
|
|
14
14
|
closeButtonContent: closeButtonContentProp,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
export { Navbar } from './navbar.js';
|
|
3
|
+
export { NavbarBrand } from './navbar-brand.js';
|
|
4
|
+
export { NavbarContent } from './navbar-content.js';
|
|
5
|
+
export { NavbarMenu } from './navbar-menu/menu.js';
|
|
6
|
+
export { NavbarMenuItem } from './navbar-menu/item.js';
|
|
7
|
+
export { NavbarMenuToggle } from './navbar-menu/toggle.js';
|
|
8
|
+
export { NavbarItem } from './navbar-item.js';
|
|
9
|
+
export { useNavbar } from './use-navbar.js';
|
|
10
|
+
export { NavbarProvider, useNavbarContext } from './navbar-context.js';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
import { cn } from '@opengovsg/oui-theme';
|
|
5
|
+
import { forwardRef } from '../system/utils.js';
|
|
6
|
+
import { useNavbarContext } from './navbar-context.js';
|
|
7
|
+
import { useDomRef } from '../system/react-utils/refs.js';
|
|
8
|
+
|
|
9
|
+
const NavbarBrand = forwardRef((props, ref) => {
|
|
10
|
+
const { as, className, children, ...otherProps } = props;
|
|
11
|
+
const Component = as || "div";
|
|
12
|
+
const domRef = useDomRef(ref);
|
|
13
|
+
const { slots, classNames } = useNavbarContext();
|
|
14
|
+
return /* @__PURE__ */ jsx(
|
|
15
|
+
Component,
|
|
16
|
+
{
|
|
17
|
+
ref: domRef,
|
|
18
|
+
className: slots.brand?.({ className: cn(classNames?.brand, className) }),
|
|
19
|
+
...otherProps,
|
|
20
|
+
children
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
NavbarBrand.displayName = "NavbarBrand";
|
|
25
|
+
|
|
26
|
+
export { NavbarBrand };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
import { cn } from '@opengovsg/oui-theme';
|
|
5
|
+
import { forwardRef } from '../system/utils.js';
|
|
6
|
+
import { useNavbarContext } from './navbar-context.js';
|
|
7
|
+
import { useDomRef } from '../system/react-utils/refs.js';
|
|
8
|
+
|
|
9
|
+
const NavbarContent = forwardRef(
|
|
10
|
+
(props, ref) => {
|
|
11
|
+
const { as, className, children, justify = "start", ...otherProps } = props;
|
|
12
|
+
const Component = as || "div";
|
|
13
|
+
const domRef = useDomRef(ref);
|
|
14
|
+
const { slots, classNames } = useNavbarContext();
|
|
15
|
+
return /* @__PURE__ */ jsx(
|
|
16
|
+
Component,
|
|
17
|
+
{
|
|
18
|
+
ref: domRef,
|
|
19
|
+
className: slots.content?.({
|
|
20
|
+
className: cn(classNames?.content, className)
|
|
21
|
+
}),
|
|
22
|
+
"data-justify": justify,
|
|
23
|
+
...otherProps,
|
|
24
|
+
children
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
NavbarContent.displayName = "NavbarContent";
|
|
30
|
+
|
|
31
|
+
export { NavbarContent };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
import { createContext } from '../system/react-utils/context.js';
|
|
4
|
+
|
|
5
|
+
const [NavbarProvider, useNavbarContext] = createContext({
|
|
6
|
+
name: "NavbarContext",
|
|
7
|
+
strict: true,
|
|
8
|
+
errorMessage: "useNavbarContext: `context` is undefined. Seems you forgot to wrap component within <Navbar />"
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export { NavbarProvider, useNavbarContext };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
import { dataAttr, cn } from '@opengovsg/oui-theme';
|
|
5
|
+
import { forwardRef } from '../system/utils.js';
|
|
6
|
+
import { useNavbarContext } from './navbar-context.js';
|
|
7
|
+
import { useDomRef } from '../system/react-utils/refs.js';
|
|
8
|
+
|
|
9
|
+
const NavbarItem = forwardRef((props, ref) => {
|
|
10
|
+
const { as, className, children, isActive, ...otherProps } = props;
|
|
11
|
+
const Component = as || "div";
|
|
12
|
+
const domRef = useDomRef(ref);
|
|
13
|
+
const { slots, classNames } = useNavbarContext();
|
|
14
|
+
return /* @__PURE__ */ jsx(
|
|
15
|
+
Component,
|
|
16
|
+
{
|
|
17
|
+
ref: domRef,
|
|
18
|
+
className: slots.item({ className: cn(classNames?.item, className) }),
|
|
19
|
+
"data-active": dataAttr(isActive),
|
|
20
|
+
...otherProps,
|
|
21
|
+
children
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
NavbarItem.displayName = "NavbarItem";
|
|
26
|
+
|
|
27
|
+
export { NavbarItem };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const i18nStrings = {
|
|
3
|
+
"en-SG": {
|
|
4
|
+
openMenu: "Open navigation menu",
|
|
5
|
+
closeMenu: "Close navigation menu"
|
|
6
|
+
},
|
|
7
|
+
"zh-SG": {
|
|
8
|
+
openMenu: "\u6253\u5F00\u5BFC\u822A\u83DC\u5355",
|
|
9
|
+
closeMenu: "\u5173\u95ED\u5BFC\u822A\u83DC\u5355"
|
|
10
|
+
},
|
|
11
|
+
"ms-SG": {
|
|
12
|
+
openMenu: "Buka menu navigasi",
|
|
13
|
+
closeMenu: "Tutup menu navigasi"
|
|
14
|
+
},
|
|
15
|
+
"ta-SG": {
|
|
16
|
+
openMenu: "\u0BA8\u0BC7\u0BB5\u0BBF\u0B95\u0BC7\u0BB7\u0BA9\u0BCD \u0BAE\u0BC6\u0BA9\u0BC1\u0BB5\u0BC8\u0BA4\u0BCD \u0BA4\u0BBF\u0BB1",
|
|
17
|
+
closeMenu: "\u0BA8\u0BC7\u0BB5\u0BBF\u0B95\u0BC7\u0BB7\u0BA9\u0BCD \u0BAE\u0BC6\u0BA9\u0BC1\u0BB5\u0BC8 \u0BAE\u0BC2\u0B9F\u0BC1"
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { i18nStrings };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
import { useRenderProps, composeRenderProps } from 'react-aria-components';
|
|
5
|
+
import { navbarMenuItemStyles, cn, dataAttr } from '@opengovsg/oui-theme';
|
|
6
|
+
import { forwardRef } from '../../system/utils.js';
|
|
7
|
+
import { useNavbarContext } from '../navbar-context.js';
|
|
8
|
+
import { useDomRef } from '../../system/react-utils/refs.js';
|
|
9
|
+
|
|
10
|
+
const NavbarMenuItem = forwardRef(
|
|
11
|
+
(props, ref) => {
|
|
12
|
+
const { className, children, isActive, ...otherProps } = props;
|
|
13
|
+
const domRef = useDomRef(ref);
|
|
14
|
+
const { isMenuOpen, classNames } = useNavbarContext();
|
|
15
|
+
const renderProps = useRenderProps({
|
|
16
|
+
className: composeRenderProps(
|
|
17
|
+
className,
|
|
18
|
+
(className2, renderProps2) => navbarMenuItemStyles({
|
|
19
|
+
className: cn(classNames?.menuItem, className2),
|
|
20
|
+
...renderProps2
|
|
21
|
+
})
|
|
22
|
+
),
|
|
23
|
+
values: {
|
|
24
|
+
isActive: !!isActive
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return /* @__PURE__ */ jsx(
|
|
28
|
+
"li",
|
|
29
|
+
{
|
|
30
|
+
ref: domRef,
|
|
31
|
+
className: renderProps.className,
|
|
32
|
+
"data-active": dataAttr(isActive),
|
|
33
|
+
"data-open": dataAttr(isMenuOpen),
|
|
34
|
+
...otherProps,
|
|
35
|
+
children
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
NavbarMenuItem.displayName = "NavbarMenuItem";
|
|
41
|
+
|
|
42
|
+
export { NavbarMenuItem };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
import { Overlay as $337b884510726a0d$export$c6fdb837b070b4ff } from '../../node_modules/.pnpm/@react-aria_overlays@3.30.0_react-dom@19.2.3_react@19.2.3__react@19.2.3/node_modules/@react-aria/overlays/dist/Overlay.js';
|
|
5
|
+
import { chain } from 'react-aria';
|
|
6
|
+
import { dataAttr, cn } from '@opengovsg/oui-theme';
|
|
7
|
+
import { forwardRef } from '../../system/utils.js';
|
|
8
|
+
import { useNavbarContext } from '../navbar-context.js';
|
|
9
|
+
import { useDomRef } from '../../system/react-utils/refs.js';
|
|
10
|
+
|
|
11
|
+
const NavbarMenu = forwardRef(
|
|
12
|
+
({ className, children, portalContainer, style, onKeyDown, ...props }, ref) => {
|
|
13
|
+
const domRef = useDomRef(ref);
|
|
14
|
+
const {
|
|
15
|
+
slots,
|
|
16
|
+
isMenuOpen,
|
|
17
|
+
menuTopOffsetPx,
|
|
18
|
+
classNames,
|
|
19
|
+
setIsMenuOpen,
|
|
20
|
+
domRef: parentRef,
|
|
21
|
+
menuRef
|
|
22
|
+
} = useNavbarContext();
|
|
23
|
+
const handleKeyDown = (e) => {
|
|
24
|
+
if (e.key === "Escape") {
|
|
25
|
+
e.stopPropagation();
|
|
26
|
+
setIsMenuOpen(false);
|
|
27
|
+
menuRef.current?.focus();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
if (!isMenuOpen) return null;
|
|
31
|
+
return /* @__PURE__ */ jsx(
|
|
32
|
+
$337b884510726a0d$export$c6fdb837b070b4ff,
|
|
33
|
+
{
|
|
34
|
+
disableFocusManagement: true,
|
|
35
|
+
portalContainer: portalContainer ?? parentRef.current ?? void 0,
|
|
36
|
+
children: /* @__PURE__ */ jsx(
|
|
37
|
+
"ul",
|
|
38
|
+
{
|
|
39
|
+
ref: domRef,
|
|
40
|
+
className: slots.menu?.({
|
|
41
|
+
className: cn(classNames?.menu, className)
|
|
42
|
+
}),
|
|
43
|
+
"data-open": dataAttr(isMenuOpen),
|
|
44
|
+
style: {
|
|
45
|
+
...style,
|
|
46
|
+
// @ts-expect-error due to not having any type declaration for CSS variables in React style prop
|
|
47
|
+
"--menu-offset": menuTopOffsetPx
|
|
48
|
+
},
|
|
49
|
+
onKeyDown: chain(handleKeyDown, onKeyDown),
|
|
50
|
+
...props,
|
|
51
|
+
children
|
|
52
|
+
}
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
NavbarMenu.displayName = "NavbarMenu";
|
|
59
|
+
|
|
60
|
+
export { NavbarMenu };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
|
+
import { useMessageFormatter, chain } from 'react-aria';
|
|
6
|
+
import { ToggleButton } from 'react-aria-components';
|
|
7
|
+
import { buttonStyles, cn, dataAttr } from '@opengovsg/oui-theme';
|
|
8
|
+
import { useNavbarContext } from '../navbar-context.js';
|
|
9
|
+
import { i18nStrings } from './i18n.js';
|
|
10
|
+
|
|
11
|
+
const NavbarMenuToggle = ({
|
|
12
|
+
icon,
|
|
13
|
+
className,
|
|
14
|
+
onChange,
|
|
15
|
+
classNames,
|
|
16
|
+
size = "sm",
|
|
17
|
+
radius,
|
|
18
|
+
isIconOnly = true,
|
|
19
|
+
...props
|
|
20
|
+
}) => {
|
|
21
|
+
const {
|
|
22
|
+
slots,
|
|
23
|
+
classNames: contextClassNames,
|
|
24
|
+
isMenuOpen,
|
|
25
|
+
setIsMenuOpen,
|
|
26
|
+
menuRef,
|
|
27
|
+
position,
|
|
28
|
+
menuTopOffset
|
|
29
|
+
} = useNavbarContext();
|
|
30
|
+
const shouldScrollToTop = (isMenuOpen2) => {
|
|
31
|
+
if (!isMenuOpen2 || position === "sticky" || typeof window === "undefined") {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
window.scrollTo({ top: menuTopOffset, behavior: "instant" });
|
|
35
|
+
};
|
|
36
|
+
const formatMessage = useMessageFormatter(i18nStrings);
|
|
37
|
+
const toggleStyles = useMemo(() => {
|
|
38
|
+
return buttonStyles({
|
|
39
|
+
variant: "unstyled",
|
|
40
|
+
size,
|
|
41
|
+
radius,
|
|
42
|
+
isIconOnly,
|
|
43
|
+
className: slots.toggle({
|
|
44
|
+
className: cn(
|
|
45
|
+
contextClassNames?.toggle,
|
|
46
|
+
className ?? classNames?.toggle
|
|
47
|
+
)
|
|
48
|
+
})
|
|
49
|
+
});
|
|
50
|
+
}, [
|
|
51
|
+
className,
|
|
52
|
+
classNames?.toggle,
|
|
53
|
+
contextClassNames?.toggle,
|
|
54
|
+
isIconOnly,
|
|
55
|
+
radius,
|
|
56
|
+
size,
|
|
57
|
+
slots
|
|
58
|
+
]);
|
|
59
|
+
const child = useMemo(() => {
|
|
60
|
+
if (typeof icon === "function") {
|
|
61
|
+
return icon(isMenuOpen ?? false);
|
|
62
|
+
}
|
|
63
|
+
return icon || /* @__PURE__ */ jsx(
|
|
64
|
+
"span",
|
|
65
|
+
{
|
|
66
|
+
className: slots.toggleIcon({
|
|
67
|
+
class: cn(contextClassNames?.toggleIcon, classNames?.toggleIcon)
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
}, [
|
|
72
|
+
icon,
|
|
73
|
+
slots,
|
|
74
|
+
classNames?.toggleIcon,
|
|
75
|
+
contextClassNames?.toggleIcon,
|
|
76
|
+
isMenuOpen
|
|
77
|
+
]);
|
|
78
|
+
return /* @__PURE__ */ jsx(
|
|
79
|
+
ToggleButton,
|
|
80
|
+
{
|
|
81
|
+
"aria-label": isMenuOpen ? formatMessage("closeMenu") : formatMessage("openMenu"),
|
|
82
|
+
ref: menuRef,
|
|
83
|
+
"data-open": dataAttr(isMenuOpen),
|
|
84
|
+
className: toggleStyles,
|
|
85
|
+
isSelected: isMenuOpen,
|
|
86
|
+
onChange: chain(onChange, shouldScrollToTop, setIsMenuOpen),
|
|
87
|
+
...props,
|
|
88
|
+
children: child
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export { NavbarMenuToggle };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
4
|
+
import { LazyMotion, domAnimation, m } from 'motion/react';
|
|
5
|
+
import { FocusScope, mergeProps } from 'react-aria';
|
|
6
|
+
import { pickChildren } from '../system/react-utils/children.js';
|
|
7
|
+
import { forwardRef } from '../system/utils.js';
|
|
8
|
+
import { NavbarProvider } from './navbar-context.js';
|
|
9
|
+
import { NavbarMenu } from './navbar-menu/menu.js';
|
|
10
|
+
import { useNavbar } from './use-navbar.js';
|
|
11
|
+
|
|
12
|
+
const showOnScrollUpVariants = {
|
|
13
|
+
visible: {
|
|
14
|
+
y: 0,
|
|
15
|
+
transition: {
|
|
16
|
+
ease: [0, 0, 0.2, 1]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
hidden: {
|
|
20
|
+
y: "-100%",
|
|
21
|
+
transition: {
|
|
22
|
+
ease: [0, 0, 0.2, 1]
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const Navbar = forwardRef((props, ref) => {
|
|
27
|
+
const { children, ...otherProps } = props;
|
|
28
|
+
const context = useNavbar({ ...otherProps, ref });
|
|
29
|
+
const Component = context.Component;
|
|
30
|
+
const [childrenWithoutMenu, menu] = pickChildren(children, NavbarMenu);
|
|
31
|
+
const content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
32
|
+
/* @__PURE__ */ jsx("header", { ...context.getWrapperProps(), children: childrenWithoutMenu }),
|
|
33
|
+
menu
|
|
34
|
+
] });
|
|
35
|
+
return /* @__PURE__ */ jsx(NavbarProvider, { value: context, children: /* @__PURE__ */ jsx(FocusScope, { contain: context.isMenuOpen, children: context.shouldShowOnScrollUp ? /* @__PURE__ */ jsx(LazyMotion, { features: domAnimation, children: /* @__PURE__ */ jsx(
|
|
36
|
+
m.nav,
|
|
37
|
+
{
|
|
38
|
+
animate: context.isNavbarHidden ? "hidden" : "visible",
|
|
39
|
+
initial: "visible",
|
|
40
|
+
variants: showOnScrollUpVariants,
|
|
41
|
+
...mergeProps(context.getBaseProps(), context.motionProps),
|
|
42
|
+
children: content
|
|
43
|
+
}
|
|
44
|
+
) }) : /* @__PURE__ */ jsx(Component, { ...context.getBaseProps(), children: content }) }) });
|
|
45
|
+
});
|
|
46
|
+
Navbar.displayName = "Navbar";
|
|
47
|
+
|
|
48
|
+
export { Navbar };
|