@bayonai/mui-design 0.2.1 → 1.1.0
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/CHANGELOG.md +50 -0
- package/README.md +108 -7
- package/dist/cjs/actions/ActionMenu.js +36 -0
- package/dist/cjs/actions/DialogActionButtons.js +33 -0
- package/dist/cjs/actions/LoadingIconButton.js +10 -0
- package/dist/cjs/actions/StickyActionFooter.js +27 -0
- package/dist/cjs/actions/StickySubmitButton.js +10 -0
- package/dist/cjs/actions/index.js +18 -0
- package/dist/cjs/client.js +1 -0
- package/dist/cjs/components/BayonFlowVisual.js +6 -6
- package/dist/cjs/components/BayonThemeModeToggle.js +34 -0
- package/dist/cjs/components/panels.js +7 -7
- package/dist/cjs/drawers/BottomDrawer.js +43 -0
- package/dist/cjs/drawers/MobileBottomDrawer.js +102 -0
- package/dist/cjs/drawers/MobileBottomDrawerHeader.js +36 -0
- package/dist/cjs/drawers/ResponsiveDrawer.js +22 -0
- package/dist/cjs/drawers/drawerAppearance.js +10 -0
- package/dist/cjs/drawers/index.js +17 -0
- package/dist/cjs/drawers/useVisualViewportBottomInset.js +33 -0
- package/dist/cjs/feedback/StatusNotice.js +62 -0
- package/dist/cjs/feedback/index.js +7 -0
- package/dist/cjs/links/LinkAddressPreview.js +80 -0
- package/dist/cjs/links/index.js +9 -0
- package/dist/cjs/links/useLinkAddressPreview.js +152 -0
- package/dist/cjs/pending/PendingChangesDialogShell.js +16 -0
- package/dist/cjs/pending/PendingChangesDialogView.js +126 -0
- package/dist/cjs/pending/PendingChangesIndicatorView.js +27 -0
- package/dist/cjs/pending/index.js +9 -0
- package/dist/cjs/pending/types.js +2 -0
- package/dist/cjs/providers/BayonThemeProvider.js +83 -4
- package/dist/cjs/sections/ExpandableSectionToggle.js +32 -0
- package/dist/cjs/sections/index.js +7 -0
- package/dist/cjs/styles/pageStyles.js +17 -17
- package/dist/cjs/swipe/SwipeActionRow.js +123 -0
- package/dist/cjs/swipe/index.js +8 -0
- package/dist/cjs/theme/components.js +60 -0
- package/dist/cjs/theme/createBayonTheme.js +23 -2
- package/dist/cjs/toasts/ActionToast.js +12 -0
- package/dist/cjs/toasts/Toast.js +55 -0
- package/dist/cjs/toasts/index.js +12 -0
- package/dist/cjs/toasts/useUpwardToastDismiss.js +73 -0
- package/dist/cjs/uploads/CameraCaptureDialog.js +187 -0
- package/dist/cjs/uploads/FileRow.js +23 -0
- package/dist/cjs/uploads/FileSwipeActionRow.js +11 -0
- package/dist/cjs/uploads/FileThumbnail.js +104 -0
- package/dist/cjs/uploads/FileUpload.js +98 -0
- package/dist/cjs/uploads/FileViewer.js +151 -0
- package/dist/cjs/uploads/ImageCropDialog.js +215 -0
- package/dist/cjs/uploads/UploadProgressRing.js +32 -0
- package/dist/cjs/uploads/cameraCropPresentation.js +12 -0
- package/dist/cjs/uploads/index.js +20 -0
- package/dist/esm/actions/ActionMenu.js +30 -0
- package/dist/esm/actions/DialogActionButtons.js +24 -0
- package/dist/esm/actions/LoadingIconButton.js +7 -0
- package/dist/esm/actions/StickyActionFooter.js +24 -0
- package/dist/esm/actions/StickySubmitButton.js +7 -0
- package/dist/esm/actions/index.js +7 -0
- package/dist/esm/client.js +1 -0
- package/dist/esm/components/BayonFlowVisual.js +6 -6
- package/dist/esm/components/BayonThemeModeToggle.js +28 -0
- package/dist/esm/components/panels.js +7 -7
- package/dist/esm/drawers/BottomDrawer.js +37 -0
- package/dist/esm/drawers/MobileBottomDrawer.js +95 -0
- package/dist/esm/drawers/MobileBottomDrawerHeader.js +30 -0
- package/dist/esm/drawers/ResponsiveDrawer.js +19 -0
- package/dist/esm/drawers/drawerAppearance.js +7 -0
- package/dist/esm/drawers/index.js +7 -0
- package/dist/esm/drawers/useVisualViewportBottomInset.js +29 -0
- package/dist/esm/feedback/StatusNotice.js +56 -0
- package/dist/esm/feedback/index.js +3 -0
- package/dist/esm/links/LinkAddressPreview.js +74 -0
- package/dist/esm/links/index.js +4 -0
- package/dist/esm/links/useLinkAddressPreview.js +149 -0
- package/dist/esm/pending/PendingChangesDialogShell.js +10 -0
- package/dist/esm/pending/PendingChangesDialogView.js +120 -0
- package/dist/esm/pending/PendingChangesIndicatorView.js +21 -0
- package/dist/esm/pending/index.js +4 -0
- package/dist/esm/pending/types.js +1 -0
- package/dist/esm/providers/BayonThemeProvider.js +83 -5
- package/dist/esm/sections/ExpandableSectionToggle.js +26 -0
- package/dist/esm/sections/index.js +3 -0
- package/dist/esm/styles/pageStyles.js +17 -17
- package/dist/esm/swipe/SwipeActionRow.js +116 -0
- package/dist/esm/swipe/index.js +3 -0
- package/dist/esm/theme/components.js +60 -0
- package/dist/esm/theme/createBayonTheme.js +23 -2
- package/dist/esm/toasts/ActionToast.js +9 -0
- package/dist/esm/toasts/Toast.js +52 -0
- package/dist/esm/toasts/index.js +5 -0
- package/dist/esm/toasts/useUpwardToastDismiss.js +69 -0
- package/dist/esm/uploads/CameraCaptureDialog.js +181 -0
- package/dist/esm/uploads/FileRow.js +17 -0
- package/dist/esm/uploads/FileSwipeActionRow.js +7 -0
- package/dist/esm/uploads/FileThumbnail.js +98 -0
- package/dist/esm/uploads/FileUpload.js +92 -0
- package/dist/esm/uploads/FileViewer.js +145 -0
- package/dist/esm/uploads/ImageCropDialog.js +212 -0
- package/dist/esm/uploads/UploadProgressRing.js +29 -0
- package/dist/esm/uploads/cameraCropPresentation.js +5 -0
- package/dist/esm/uploads/index.js +9 -0
- package/dist/types/actions/ActionMenu.d.ts +24 -0
- package/dist/types/actions/DialogActionButtons.d.ts +22 -0
- package/dist/types/actions/LoadingIconButton.d.ts +11 -0
- package/dist/types/actions/StickyActionFooter.d.ts +14 -0
- package/dist/types/actions/StickySubmitButton.d.ts +10 -0
- package/dist/types/actions/index.d.ts +5 -0
- package/dist/types/client.d.ts +1 -0
- package/dist/types/components/BayonThemeModeToggle.d.ts +6 -0
- package/dist/types/drawers/BottomDrawer.d.ts +16 -0
- package/dist/types/drawers/MobileBottomDrawer.d.ts +20 -0
- package/dist/types/drawers/MobileBottomDrawerHeader.d.ts +11 -0
- package/dist/types/drawers/ResponsiveDrawer.d.ts +25 -0
- package/dist/types/drawers/drawerAppearance.d.ts +8 -0
- package/dist/types/drawers/index.d.ts +6 -0
- package/dist/types/drawers/useVisualViewportBottomInset.d.ts +6 -0
- package/dist/types/feedback/StatusNotice.d.ts +13 -0
- package/dist/types/feedback/index.d.ts +1 -0
- package/dist/types/links/LinkAddressPreview.d.ts +19 -0
- package/dist/types/links/index.d.ts +3 -0
- package/dist/types/links/useLinkAddressPreview.d.ts +24 -0
- package/dist/types/pending/PendingChangesDialogShell.d.ts +2 -0
- package/dist/types/pending/PendingChangesDialogView.d.ts +2 -0
- package/dist/types/pending/PendingChangesIndicatorView.d.ts +10 -0
- package/dist/types/pending/index.d.ts +3 -0
- package/dist/types/pending/types.d.ts +48 -0
- package/dist/types/providers/BayonThemeProvider.d.ts +10 -1
- package/dist/types/sections/ExpandableSectionToggle.d.ts +12 -0
- package/dist/types/sections/index.d.ts +2 -0
- package/dist/types/swipe/SwipeActionRow.d.ts +8 -0
- package/dist/types/swipe/index.d.ts +1 -0
- package/dist/types/toasts/ActionToast.d.ts +11 -0
- package/dist/types/toasts/Toast.d.ts +16 -0
- package/dist/types/toasts/index.d.ts +5 -0
- package/dist/types/toasts/useUpwardToastDismiss.d.ts +15 -0
- package/dist/types/uploads/CameraCaptureDialog.d.ts +22 -0
- package/dist/types/uploads/FileRow.d.ts +10 -0
- package/dist/types/uploads/FileSwipeActionRow.d.ts +1 -0
- package/dist/types/uploads/FileThumbnail.d.ts +5 -0
- package/dist/types/uploads/FileUpload.d.ts +26 -0
- package/dist/types/uploads/FileViewer.d.ts +9 -0
- package/dist/types/uploads/ImageCropDialog.d.ts +26 -0
- package/dist/types/uploads/UploadProgressRing.d.ts +24 -0
- package/dist/types/uploads/cameraCropPresentation.d.ts +2 -0
- package/dist/types/uploads/index.d.ts +10 -0
- package/docs/camera-crop-contract.md +50 -0
- package/docs/uploads-contract.md +40 -0
- package/package.json +70 -8
|
@@ -37,6 +37,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
38
|
};
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.useBayonThemeMode = useBayonThemeMode;
|
|
40
41
|
exports.BayonThemeProvider = BayonThemeProvider;
|
|
41
42
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
42
43
|
const React = __importStar(require("react"));
|
|
@@ -47,6 +48,54 @@ const styles_1 = require("@mui/material/styles");
|
|
|
47
48
|
const createBayonTheme_js_1 = require("../theme/createBayonTheme.js");
|
|
48
49
|
const createBayonEmotionCache_js_1 = require("../utils/createBayonEmotionCache.js");
|
|
49
50
|
const clientSideEmotionCache = (0, createBayonEmotionCache_js_1.createBayonEmotionCache)();
|
|
51
|
+
const defaultStorageKey = 'bayon-theme-mode';
|
|
52
|
+
const themeModeChangeEvent = 'bayon-theme-mode-change';
|
|
53
|
+
const clientModeOverrides = new Map();
|
|
54
|
+
const BayonThemeModeContext = React.createContext(undefined);
|
|
55
|
+
function readStoredMode(storageKey, defaultMode) {
|
|
56
|
+
if (typeof window === 'undefined') {
|
|
57
|
+
return defaultMode;
|
|
58
|
+
}
|
|
59
|
+
const clientOverride = clientModeOverrides.get(storageKey);
|
|
60
|
+
if (clientOverride) {
|
|
61
|
+
return clientOverride;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const storedMode = window.localStorage.getItem(storageKey);
|
|
65
|
+
return storedMode === 'light' || storedMode === 'dark' ? storedMode : defaultMode;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
console.error('[bayon-theme] Failed to read the saved theme mode', { error, storageKey });
|
|
69
|
+
clientModeOverrides.set(storageKey, defaultMode);
|
|
70
|
+
return defaultMode;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function subscribeToStoredMode(storageKey, onStoreChange) {
|
|
74
|
+
const handleStorageChange = (event) => {
|
|
75
|
+
if (event.key === storageKey) {
|
|
76
|
+
clientModeOverrides.delete(storageKey);
|
|
77
|
+
onStoreChange();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const handleLocalChange = (event) => {
|
|
81
|
+
if (event instanceof CustomEvent && event.detail === storageKey) {
|
|
82
|
+
onStoreChange();
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
window.addEventListener('storage', handleStorageChange);
|
|
86
|
+
window.addEventListener(themeModeChangeEvent, handleLocalChange);
|
|
87
|
+
return () => {
|
|
88
|
+
window.removeEventListener('storage', handleStorageChange);
|
|
89
|
+
window.removeEventListener(themeModeChangeEvent, handleLocalChange);
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function useBayonThemeMode() {
|
|
93
|
+
const context = React.useContext(BayonThemeModeContext);
|
|
94
|
+
if (!context) {
|
|
95
|
+
throw new Error('useBayonThemeMode must be used inside BayonThemeProvider.');
|
|
96
|
+
}
|
|
97
|
+
return context;
|
|
98
|
+
}
|
|
50
99
|
class BayonThemeErrorBoundary extends React.Component {
|
|
51
100
|
constructor(props) {
|
|
52
101
|
super(props);
|
|
@@ -71,12 +120,42 @@ class BayonThemeErrorBoundary extends React.Component {
|
|
|
71
120
|
return this.props.children;
|
|
72
121
|
}
|
|
73
122
|
}
|
|
74
|
-
function BayonThemeProvider({ children, emotionCache = clientSideEmotionCache, disableEmotionCacheProvider = false, theme =
|
|
123
|
+
function BayonThemeProvider({ children, emotionCache = clientSideEmotionCache, disableEmotionCacheProvider = false, theme, defaultMode = 'dark', storageKey = defaultStorageKey, enableErrorBoundary = true, }) {
|
|
124
|
+
const subscribe = React.useCallback((onStoreChange) => subscribeToStoredMode(storageKey, onStoreChange), [storageKey]);
|
|
125
|
+
const getSnapshot = React.useCallback(() => readStoredMode(storageKey, defaultMode), [defaultMode, storageKey]);
|
|
126
|
+
const getServerSnapshot = React.useCallback(() => defaultMode, [defaultMode]);
|
|
127
|
+
const mode = React.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
128
|
+
const setMode = React.useCallback((nextMode) => {
|
|
129
|
+
if (typeof window === 'undefined') {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
clientModeOverrides.set(storageKey, nextMode);
|
|
133
|
+
try {
|
|
134
|
+
window.localStorage.setItem(storageKey, nextMode);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
console.error('[bayon-theme] Failed to persist the selected theme mode', {
|
|
138
|
+
error,
|
|
139
|
+
mode: nextMode,
|
|
140
|
+
storageKey,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
window.dispatchEvent(new CustomEvent(themeModeChangeEvent, { detail: storageKey }));
|
|
144
|
+
}, [storageKey]);
|
|
145
|
+
const toggleMode = React.useCallback(() => {
|
|
146
|
+
setMode(mode === 'dark' ? 'light' : 'dark');
|
|
147
|
+
}, [mode, setMode]);
|
|
148
|
+
const activeTheme = React.useMemo(() => theme !== null && theme !== void 0 ? theme : (0, createBayonTheme_js_1.createBayonTheme)({ mode }), [mode, theme]);
|
|
149
|
+
const modeContextValue = React.useMemo(() => ({
|
|
150
|
+
mode,
|
|
151
|
+
setMode,
|
|
152
|
+
toggleMode,
|
|
153
|
+
}), [mode, setMode, toggleMode]);
|
|
75
154
|
React.useEffect(() => {
|
|
76
|
-
document.documentElement.setAttribute('data-theme',
|
|
77
|
-
}, []);
|
|
155
|
+
document.documentElement.setAttribute('data-theme', mode);
|
|
156
|
+
}, [mode]);
|
|
78
157
|
const content = enableErrorBoundary ? ((0, jsx_runtime_1.jsx)(BayonThemeErrorBoundary, { children: children })) : (children);
|
|
79
|
-
const themedContent = ((0, jsx_runtime_1.
|
|
158
|
+
const themedContent = ((0, jsx_runtime_1.jsx)(styles_1.ThemeProvider, { theme: activeTheme, children: (0, jsx_runtime_1.jsxs)(BayonThemeModeContext.Provider, { value: modeContextValue, children: [(0, jsx_runtime_1.jsx)(CssBaseline_1.default, { enableColorScheme: true }), content] }) }));
|
|
80
159
|
if (disableEmotionCacheProvider) {
|
|
81
160
|
return themedContent;
|
|
82
161
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.ExpandableSectionToggle = ExpandableSectionToggle;
|
|
8
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
|
+
const ExpandMore_1 = __importDefault(require("@mui/icons-material/ExpandMore"));
|
|
10
|
+
const material_1 = require("@mui/material");
|
|
11
|
+
function ExpandableSectionToggle({ ariaControls, ariaLabel, children, endAdornment, expanded, onToggle, showExpandIcon = true, sx, }) {
|
|
12
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.ButtonBase, { "aria-controls": ariaControls, "aria-expanded": expanded, "aria-label": ariaLabel, "data-expandable-section-toggle": "true", onClick: onToggle, sx: {
|
|
13
|
+
alignItems: "center",
|
|
14
|
+
borderRadius: 1,
|
|
15
|
+
color: "text.primary",
|
|
16
|
+
display: "flex",
|
|
17
|
+
gap: 1,
|
|
18
|
+
justifyContent: "space-between",
|
|
19
|
+
minWidth: 0,
|
|
20
|
+
px: 0.75,
|
|
21
|
+
py: 0.5,
|
|
22
|
+
textAlign: "left",
|
|
23
|
+
width: "100%",
|
|
24
|
+
"&:hover": { backgroundColor: "action.hover" },
|
|
25
|
+
"&:focus-visible": {
|
|
26
|
+
outline: "2px solid",
|
|
27
|
+
outlineColor: "primary.main",
|
|
28
|
+
outlineOffset: 2,
|
|
29
|
+
},
|
|
30
|
+
...sx,
|
|
31
|
+
}, type: "button", children: [(0, jsx_runtime_1.jsx)(material_1.Box, { sx: { flex: "1 1 auto", minWidth: 0 }, children: children }), (0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", spacing: 0.5, sx: { alignItems: "center", flex: "0 0 auto" }, children: [endAdornment, showExpandIcon ? ((0, jsx_runtime_1.jsx)(ExpandMore_1.default, { "aria-hidden": "true", fontSize: "small", sx: { transform: expanded ? "rotate(180deg)" : "none" } })) : null] })] }));
|
|
32
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ExpandableSectionToggle = void 0;
|
|
5
|
+
// TL-M249: preserve the established MUI presentation under its owning package.
|
|
6
|
+
var ExpandableSectionToggle_js_1 = require("./ExpandableSectionToggle.js");
|
|
7
|
+
Object.defineProperty(exports, "ExpandableSectionToggle", { enumerable: true, get: function () { return ExpandableSectionToggle_js_1.ExpandableSectionToggle; } });
|
|
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.outlineButtonSx = exports.tealButtonSx = exports.mutedTextSx = exports.eyebrowSx = exports.darkCtaSx = exports.darkPanelHoverSx = exports.accentPanelSx = exports.darkPanelSx = exports.heroBodySx = exports.heroTitleSx = exports.heroStackSx = exports.heroContainerSx = exports.gradientHeroSx = exports.pageShellSx = void 0;
|
|
4
4
|
const palette_js_1 = require("../theme/palette.js");
|
|
5
5
|
exports.pageShellSx = {
|
|
6
|
-
bgcolor:
|
|
7
|
-
color:
|
|
6
|
+
bgcolor: 'var(--bayon-bg)',
|
|
7
|
+
color: 'var(--bayon-fg)',
|
|
8
8
|
};
|
|
9
9
|
exports.gradientHeroSx = {
|
|
10
|
-
bgcolor:
|
|
11
|
-
color:
|
|
10
|
+
bgcolor: 'var(--bayon-bg)',
|
|
11
|
+
color: 'var(--bayon-fg)',
|
|
12
12
|
py: { xs: 8, md: 11 },
|
|
13
13
|
position: 'relative',
|
|
14
14
|
overflow: 'hidden',
|
|
@@ -16,7 +16,7 @@ exports.gradientHeroSx = {
|
|
|
16
16
|
content: '""',
|
|
17
17
|
position: 'absolute',
|
|
18
18
|
inset: 0,
|
|
19
|
-
background: 'linear-gradient(120deg,
|
|
19
|
+
background: 'linear-gradient(120deg, var(--bayon-hero-teal), transparent 34%), linear-gradient(55deg, transparent 48%, var(--bayon-hero-yellow), transparent 70%), linear-gradient(150deg, transparent 40%, var(--bayon-hero-coral))',
|
|
20
20
|
pointerEvents: 'none',
|
|
21
21
|
},
|
|
22
22
|
};
|
|
@@ -28,20 +28,20 @@ exports.heroStackSx = {
|
|
|
28
28
|
position: 'relative',
|
|
29
29
|
};
|
|
30
30
|
exports.heroTitleSx = {
|
|
31
|
-
color: '
|
|
31
|
+
color: 'var(--bayon-heading)',
|
|
32
32
|
fontSize: { xs: '2.75rem', md: '4.75rem' },
|
|
33
33
|
lineHeight: 1,
|
|
34
34
|
};
|
|
35
35
|
exports.heroBodySx = {
|
|
36
|
-
color: '
|
|
36
|
+
color: 'var(--bayon-muted-strong)',
|
|
37
37
|
fontSize: { xs: '1.1rem', md: '1.3rem' },
|
|
38
38
|
lineHeight: 1.65,
|
|
39
39
|
};
|
|
40
40
|
exports.darkPanelSx = {
|
|
41
|
-
bgcolor: '
|
|
42
|
-
border: '1px solid
|
|
41
|
+
bgcolor: 'var(--bayon-panel)',
|
|
42
|
+
border: '1px solid var(--bayon-border)',
|
|
43
43
|
borderRadius: 2,
|
|
44
|
-
boxShadow: '
|
|
44
|
+
boxShadow: 'var(--bayon-panel-shadow)',
|
|
45
45
|
};
|
|
46
46
|
exports.accentPanelSx = {
|
|
47
47
|
...exports.darkPanelSx,
|
|
@@ -69,13 +69,13 @@ exports.darkPanelHoverSx = {
|
|
|
69
69
|
'&:hover': {
|
|
70
70
|
transform: 'translateY(-5px)',
|
|
71
71
|
borderColor: 'rgba(45, 212, 191, 0.65)',
|
|
72
|
-
bgcolor: '
|
|
72
|
+
bgcolor: 'var(--bayon-panel-hover)',
|
|
73
73
|
},
|
|
74
74
|
};
|
|
75
75
|
exports.darkCtaSx = {
|
|
76
|
-
bgcolor:
|
|
77
|
-
color:
|
|
78
|
-
border: '1px solid
|
|
76
|
+
bgcolor: 'var(--bayon-panel-solid)',
|
|
77
|
+
color: 'var(--bayon-fg)',
|
|
78
|
+
border: '1px solid var(--bayon-border)',
|
|
79
79
|
borderRadius: 2,
|
|
80
80
|
};
|
|
81
81
|
exports.eyebrowSx = {
|
|
@@ -85,7 +85,7 @@ exports.eyebrowSx = {
|
|
|
85
85
|
textTransform: 'uppercase',
|
|
86
86
|
};
|
|
87
87
|
exports.mutedTextSx = {
|
|
88
|
-
color: '
|
|
88
|
+
color: 'var(--bayon-muted)',
|
|
89
89
|
lineHeight: 1.75,
|
|
90
90
|
};
|
|
91
91
|
exports.tealButtonSx = {
|
|
@@ -94,8 +94,8 @@ exports.tealButtonSx = {
|
|
|
94
94
|
'&:hover': { bgcolor: palette_js_1.bayonAccent.tealLight },
|
|
95
95
|
};
|
|
96
96
|
exports.outlineButtonSx = {
|
|
97
|
-
borderColor: '
|
|
98
|
-
color:
|
|
97
|
+
borderColor: 'var(--bayon-border-strong)',
|
|
98
|
+
color: 'var(--bayon-fg)',
|
|
99
99
|
'&:hover': {
|
|
100
100
|
borderColor: palette_js_1.bayonAccent.teal,
|
|
101
101
|
bgcolor: 'rgba(45, 212, 191, 0.1)',
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.SWIPE_ROW_SWIPE_DELETE_DISTANCE_PX = void 0;
|
|
8
|
+
exports.SwipeActionRow = SwipeActionRow;
|
|
9
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
10
|
+
const DeleteOutlineRounded_1 = __importDefault(require("@mui/icons-material/DeleteOutlineRounded"));
|
|
11
|
+
const material_1 = require("@mui/material");
|
|
12
|
+
const react_1 = require("react");
|
|
13
|
+
exports.SWIPE_ROW_SWIPE_DELETE_DISTANCE_PX = 72;
|
|
14
|
+
const SWIPE_ROW_MAX_SWIPE_DISTANCE_PX = 104;
|
|
15
|
+
const SWIPE_ROW_SWIPE_DIRECTION_DISTANCE_PX = 12;
|
|
16
|
+
function SwipeActionRow({ children, onDelete, canDelete = true, dataComponent = "swipe-action-row", }) {
|
|
17
|
+
const [swipeOffset, setSwipeOffset] = (0, react_1.useState)(0);
|
|
18
|
+
const suppressNextClickRef = (0, react_1.useRef)(false);
|
|
19
|
+
const swipeStartRef = (0, react_1.useRef)(null);
|
|
20
|
+
function resetSwipe() {
|
|
21
|
+
swipeStartRef.current = null;
|
|
22
|
+
setSwipeOffset(0);
|
|
23
|
+
}
|
|
24
|
+
function handleTouchStart(event) {
|
|
25
|
+
resetSwipe();
|
|
26
|
+
if (!canDelete)
|
|
27
|
+
return;
|
|
28
|
+
if (event.touches.length !== 1)
|
|
29
|
+
return;
|
|
30
|
+
const touch = event.touches[0];
|
|
31
|
+
if (!touch)
|
|
32
|
+
return;
|
|
33
|
+
swipeStartRef.current = {
|
|
34
|
+
direction: null,
|
|
35
|
+
identifier: touch.identifier,
|
|
36
|
+
x: touch.clientX,
|
|
37
|
+
y: touch.clientY,
|
|
38
|
+
};
|
|
39
|
+
setSwipeOffset(0);
|
|
40
|
+
}
|
|
41
|
+
function handleTouchMove(event) {
|
|
42
|
+
if (!canDelete || event.touches.length !== 1) {
|
|
43
|
+
resetSwipe();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const swipeStart = swipeStartRef.current;
|
|
47
|
+
const touch = getTouchByIdentifier(event.touches, swipeStart === null || swipeStart === void 0 ? void 0 : swipeStart.identifier);
|
|
48
|
+
if (!swipeStart || !touch || swipeStart.direction === "vertical")
|
|
49
|
+
return;
|
|
50
|
+
const offsetX = touch.clientX - swipeStart.x;
|
|
51
|
+
const offsetY = touch.clientY - swipeStart.y;
|
|
52
|
+
if (!swipeStart.direction) {
|
|
53
|
+
if (Math.abs(offsetX) < SWIPE_ROW_SWIPE_DIRECTION_DISTANCE_PX &&
|
|
54
|
+
Math.abs(offsetY) < SWIPE_ROW_SWIPE_DIRECTION_DISTANCE_PX) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (offsetX > 0 || Math.abs(offsetY) >= Math.abs(offsetX)) {
|
|
58
|
+
swipeStart.direction = "vertical";
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
swipeStart.direction = "horizontal";
|
|
62
|
+
}
|
|
63
|
+
// pan-y leaves vertical scrolling to the browser; only claim a left pull
|
|
64
|
+
// after direction lock so parent sheets do not also dismiss.
|
|
65
|
+
event.nativeEvent.stopImmediatePropagation();
|
|
66
|
+
setSwipeOffset(Math.max(-SWIPE_ROW_MAX_SWIPE_DISTANCE_PX, Math.min(0, offsetX)));
|
|
67
|
+
}
|
|
68
|
+
function handleTouchEnd(event) {
|
|
69
|
+
const swipeStart = swipeStartRef.current;
|
|
70
|
+
const touch = getTouchByIdentifier(event.changedTouches, swipeStart === null || swipeStart === void 0 ? void 0 : swipeStart.identifier);
|
|
71
|
+
if (!swipeStart || !touch || swipeStart.direction !== "horizontal") {
|
|
72
|
+
resetSwipe();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
event.nativeEvent.stopImmediatePropagation();
|
|
76
|
+
const swipeDistance = touch.clientX - swipeStart.x;
|
|
77
|
+
resetSwipe();
|
|
78
|
+
suppressNextClickRef.current = true;
|
|
79
|
+
globalThis.setTimeout(() => {
|
|
80
|
+
suppressNextClickRef.current = false;
|
|
81
|
+
}, 0);
|
|
82
|
+
if (canDelete && swipeDistance <= -exports.SWIPE_ROW_SWIPE_DELETE_DISTANCE_PX) {
|
|
83
|
+
onDelete();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Box, { "data-component": dataComponent, "data-drawer-gesture-exclude": true, onClickCapture: (event) => {
|
|
87
|
+
if (!suppressNextClickRef.current)
|
|
88
|
+
return;
|
|
89
|
+
suppressNextClickRef.current = false;
|
|
90
|
+
event.preventDefault();
|
|
91
|
+
event.stopPropagation();
|
|
92
|
+
}, onTouchCancel: resetSwipe, onTouchEnd: handleTouchEnd, onTouchMove: handleTouchMove, onTouchStart: handleTouchStart, sx: { overflow: "hidden", position: "relative", touchAction: "pan-y" }, children: [(0, jsx_runtime_1.jsx)(material_1.Box, { "aria-hidden": true, "data-component": "swipe-delete-action", sx: {
|
|
93
|
+
alignItems: "center",
|
|
94
|
+
bgcolor: "error.main",
|
|
95
|
+
color: "common.white",
|
|
96
|
+
display: "flex",
|
|
97
|
+
inset: 0,
|
|
98
|
+
justifyContent: "flex-end",
|
|
99
|
+
opacity: swipeOffset === 0 ? 0 : 1,
|
|
100
|
+
px: 2,
|
|
101
|
+
pointerEvents: "none",
|
|
102
|
+
position: "absolute",
|
|
103
|
+
}, children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", spacing: 0.75, sx: { alignItems: "center" }, children: [(0, jsx_runtime_1.jsx)(DeleteOutlineRounded_1.default, { fontSize: "small" }), (0, jsx_runtime_1.jsx)(material_1.Typography, { component: "span", sx: { fontSize: 12, fontWeight: 700 }, children: "Delete" })] }) }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
|
|
104
|
+
bgcolor: "background.paper",
|
|
105
|
+
transform: swipeOffset === 0
|
|
106
|
+
? undefined
|
|
107
|
+
: `translate3d(${swipeOffset}px, 0, 0)`,
|
|
108
|
+
transition: swipeOffset
|
|
109
|
+
? "none"
|
|
110
|
+
: "transform 160ms cubic-bezier(0.2, 0, 0, 1)",
|
|
111
|
+
"@media (prefers-reduced-motion: reduce)": { transition: "none" },
|
|
112
|
+
}, children: children })] }));
|
|
113
|
+
}
|
|
114
|
+
function getTouchByIdentifier(touches, identifier) {
|
|
115
|
+
if (identifier === undefined)
|
|
116
|
+
return undefined;
|
|
117
|
+
for (let index = 0; index < touches.length; index += 1) {
|
|
118
|
+
const touch = touches[index];
|
|
119
|
+
if ((touch === null || touch === void 0 ? void 0 : touch.identifier) === identifier)
|
|
120
|
+
return touch;
|
|
121
|
+
}
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.SWIPE_ROW_SWIPE_DELETE_DISTANCE_PX = exports.SwipeActionRow = void 0;
|
|
5
|
+
// TL-M249: preserve the established MUI presentation under its owning package.
|
|
6
|
+
var SwipeActionRow_js_1 = require("./SwipeActionRow.js");
|
|
7
|
+
Object.defineProperty(exports, "SwipeActionRow", { enumerable: true, get: function () { return SwipeActionRow_js_1.SwipeActionRow; } });
|
|
8
|
+
Object.defineProperty(exports, "SWIPE_ROW_SWIPE_DELETE_DISTANCE_PX", { enumerable: true, get: function () { return SwipeActionRow_js_1.SWIPE_ROW_SWIPE_DELETE_DISTANCE_PX; } });
|
|
@@ -3,6 +3,66 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.bayonComponents = void 0;
|
|
4
4
|
const shadows_js_1 = require("./shadows.js");
|
|
5
5
|
exports.bayonComponents = {
|
|
6
|
+
MuiCssBaseline: {
|
|
7
|
+
styleOverrides: {
|
|
8
|
+
':root, html[data-theme="dark"]': {
|
|
9
|
+
'--bayon-bg': '#0B1020',
|
|
10
|
+
'--bayon-bg-soft': '#111827',
|
|
11
|
+
'--bayon-fg': '#F8FAFC',
|
|
12
|
+
'--bayon-heading': '#FFFFFF',
|
|
13
|
+
'--bayon-muted': 'rgba(248, 250, 252, 0.74)',
|
|
14
|
+
'--bayon-muted-strong': 'rgba(248, 250, 252, 0.82)',
|
|
15
|
+
'--bayon-border': 'rgba(248, 250, 252, 0.14)',
|
|
16
|
+
'--bayon-border-strong': 'rgba(248, 250, 252, 0.28)',
|
|
17
|
+
'--bayon-panel': 'rgba(248, 250, 252, 0.06)',
|
|
18
|
+
'--bayon-panel-hover': 'rgba(248, 250, 252, 0.08)',
|
|
19
|
+
'--bayon-panel-solid': '#111827',
|
|
20
|
+
'--bayon-panel-shadow': '0 28px 80px rgba(2, 6, 23, 0.24)',
|
|
21
|
+
'--bayon-grid-line': 'rgba(248, 250, 252, 0.08)',
|
|
22
|
+
'--bayon-hero-teal': 'rgba(45, 212, 191, 0.2)',
|
|
23
|
+
'--bayon-hero-blue': 'rgba(96, 165, 250, 0.18)',
|
|
24
|
+
'--bayon-hero-yellow': 'rgba(253, 224, 71, 0.14)',
|
|
25
|
+
'--bayon-hero-coral': 'rgba(255, 107, 107, 0.16)',
|
|
26
|
+
'--bayon-link': '#A7F3D0',
|
|
27
|
+
'--bayon-link-hover': '#2DD4BF',
|
|
28
|
+
colorScheme: 'dark',
|
|
29
|
+
},
|
|
30
|
+
'html[data-theme="light"]': {
|
|
31
|
+
'--bayon-bg': '#F7FAFC',
|
|
32
|
+
'--bayon-bg-soft': '#EAF2F7',
|
|
33
|
+
'--bayon-fg': '#10242A',
|
|
34
|
+
'--bayon-heading': '#08181D',
|
|
35
|
+
'--bayon-muted': 'rgba(16, 36, 42, 0.74)',
|
|
36
|
+
'--bayon-muted-strong': 'rgba(16, 36, 42, 0.84)',
|
|
37
|
+
'--bayon-border': 'rgba(15, 51, 61, 0.14)',
|
|
38
|
+
'--bayon-border-strong': 'rgba(15, 51, 61, 0.26)',
|
|
39
|
+
'--bayon-panel': 'rgba(255, 255, 255, 0.74)',
|
|
40
|
+
'--bayon-panel-hover': 'rgba(255, 255, 255, 0.9)',
|
|
41
|
+
'--bayon-panel-solid': '#FFFFFF',
|
|
42
|
+
'--bayon-panel-shadow': '0 18px 52px rgba(20, 63, 74, 0.13)',
|
|
43
|
+
'--bayon-grid-line': 'rgba(15, 51, 61, 0.08)',
|
|
44
|
+
'--bayon-hero-teal': 'rgba(20, 184, 166, 0.18)',
|
|
45
|
+
'--bayon-hero-blue': 'rgba(37, 99, 235, 0.13)',
|
|
46
|
+
'--bayon-hero-yellow': 'rgba(202, 138, 4, 0.12)',
|
|
47
|
+
'--bayon-hero-coral': 'rgba(225, 83, 83, 0.13)',
|
|
48
|
+
'--bayon-link': '#0F766E',
|
|
49
|
+
'--bayon-link-hover': '#0D9488',
|
|
50
|
+
colorScheme: 'light',
|
|
51
|
+
},
|
|
52
|
+
'html, body': {
|
|
53
|
+
backgroundColor: 'var(--bayon-bg)',
|
|
54
|
+
color: 'var(--bayon-fg)',
|
|
55
|
+
},
|
|
56
|
+
'body': {
|
|
57
|
+
transition: 'background-color 180ms ease, color 180ms ease',
|
|
58
|
+
},
|
|
59
|
+
'@media (prefers-reduced-motion: reduce)': {
|
|
60
|
+
body: {
|
|
61
|
+
transition: 'none',
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
6
66
|
MuiButtonBase: {
|
|
7
67
|
defaultProps: {
|
|
8
68
|
disableRipple: true,
|
|
@@ -20,5 +20,26 @@ function createBayonTheme(options = {}) {
|
|
|
20
20
|
};
|
|
21
21
|
return (0, styles_1.responsiveFontSizes)((0, styles_1.createTheme)(baseTheme, overrides));
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
function createLazyBayonTheme(options = {}) {
|
|
24
|
+
let theme;
|
|
25
|
+
const getTheme = () => {
|
|
26
|
+
theme !== null && theme !== void 0 ? theme : (theme = createBayonTheme(options));
|
|
27
|
+
return theme;
|
|
28
|
+
};
|
|
29
|
+
return new Proxy({}, {
|
|
30
|
+
get(_target, prop) {
|
|
31
|
+
return getTheme()[prop];
|
|
32
|
+
},
|
|
33
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
34
|
+
return Object.getOwnPropertyDescriptor(getTheme(), prop);
|
|
35
|
+
},
|
|
36
|
+
has(_target, prop) {
|
|
37
|
+
return prop in getTheme();
|
|
38
|
+
},
|
|
39
|
+
ownKeys() {
|
|
40
|
+
return Reflect.ownKeys(getTheme());
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
exports.bayonTheme = createLazyBayonTheme();
|
|
45
|
+
exports.bayonDarkTheme = createLazyBayonTheme({ mode: 'dark' });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ActionToast = ActionToast;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const material_1 = require("@mui/material");
|
|
7
|
+
const Toast_js_1 = require("./Toast.js");
|
|
8
|
+
// The host owns expiry and action semantics: dismissing a notification must
|
|
9
|
+
// never implicitly commit a deletion or cancel a transaction in this package.
|
|
10
|
+
function ActionToast({ message, actionLabel, actionAriaLabel, onAction, actionDisabled = false, ToastComponent = Toast_js_1.Toast, ...toastProps }) {
|
|
11
|
+
return ((0, jsx_runtime_1.jsx)(ToastComponent, { ...toastProps, children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", sx: { alignItems: "center", gap: 1, justifyContent: "space-between" }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { noWrap: true, sx: { fontSize: 14, fontWeight: 650 }, children: message }), (0, jsx_runtime_1.jsx)(material_1.Button, { "aria-label": actionAriaLabel, disabled: actionDisabled, onClick: onAction, size: "small", sx: { flexShrink: 0, fontWeight: 760, minWidth: 0, px: 1 }, children: actionLabel })] }) }));
|
|
12
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Toast = Toast;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const material_1 = require("@mui/material");
|
|
7
|
+
const useUpwardToastDismiss_js_1 = require("./useUpwardToastDismiss.js");
|
|
8
|
+
function Toast({ ariaLive, mobileTopOffset = 16, mobileBottomOffset = 16, children, contained = false, dataComponent, onDismiss, placement = "bottom-end", role = "status", sx, variant = "standard", }) {
|
|
9
|
+
const topCentered = placement === "top-center";
|
|
10
|
+
const swipeDismiss = (0, useUpwardToastDismiss_js_1.useUpwardToastDismiss)({
|
|
11
|
+
onDismiss,
|
|
12
|
+
transform: topCentered ? "translateX(-50%)" : "",
|
|
13
|
+
});
|
|
14
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Box, { "aria-live": ariaLive, "data-component": dataComponent, "data-presentation": contained ? "workspace-contained" : "viewport", "data-swipe-dismiss": onDismiss ? "up" : undefined, role: role, ...swipeDismiss.pointerHandlers, sx: [
|
|
15
|
+
{
|
|
16
|
+
...(topCentered
|
|
17
|
+
? {
|
|
18
|
+
bottom: { xs: "auto", md: contained ? 24 : "auto" },
|
|
19
|
+
left: "50%",
|
|
20
|
+
maxWidth: { xs: "none", md: 460 },
|
|
21
|
+
position: contained
|
|
22
|
+
? { xs: "fixed", md: "absolute" }
|
|
23
|
+
: "fixed",
|
|
24
|
+
top: { xs: mobileTopOffset, md: contained ? "auto" : 24 },
|
|
25
|
+
transform: "translateX(-50%)",
|
|
26
|
+
width: {
|
|
27
|
+
xs: "calc(100vw - 16px)",
|
|
28
|
+
md: contained ? "calc(100% - 32px)" : "calc(100vw - 32px)",
|
|
29
|
+
},
|
|
30
|
+
zIndex: 1600,
|
|
31
|
+
}
|
|
32
|
+
: {
|
|
33
|
+
bottom: { xs: mobileBottomOffset, md: 24 },
|
|
34
|
+
maxWidth: { xs: "calc(100vw - 32px)", sm: 476 },
|
|
35
|
+
position: "fixed",
|
|
36
|
+
right: { xs: 16, md: 24 },
|
|
37
|
+
zIndex: (theme) => theme.zIndex.snackbar,
|
|
38
|
+
}),
|
|
39
|
+
...(variant === "standard"
|
|
40
|
+
? {
|
|
41
|
+
bgcolor: "background.paper",
|
|
42
|
+
border: 1,
|
|
43
|
+
borderColor: "divider",
|
|
44
|
+
borderRadius: 2,
|
|
45
|
+
boxShadow: 6,
|
|
46
|
+
color: "text.primary",
|
|
47
|
+
px: 1.5,
|
|
48
|
+
py: 1.25,
|
|
49
|
+
}
|
|
50
|
+
: {}),
|
|
51
|
+
},
|
|
52
|
+
...(Array.isArray(sx) ? sx : sx ? [sx] : []),
|
|
53
|
+
...(swipeDismiss.sx ? [swipeDismiss.sx] : []),
|
|
54
|
+
], children: children }));
|
|
55
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.TOAST_UPWARD_DISMISS_DISTANCE_PX = exports.useUpwardToastDismiss = exports.ActionToast = exports.Toast = void 0;
|
|
5
|
+
// TL-M249: preserve the established MUI presentation under its owning package.
|
|
6
|
+
var Toast_js_1 = require("./Toast.js");
|
|
7
|
+
Object.defineProperty(exports, "Toast", { enumerable: true, get: function () { return Toast_js_1.Toast; } });
|
|
8
|
+
var ActionToast_js_1 = require("./ActionToast.js");
|
|
9
|
+
Object.defineProperty(exports, "ActionToast", { enumerable: true, get: function () { return ActionToast_js_1.ActionToast; } });
|
|
10
|
+
var useUpwardToastDismiss_js_1 = require("./useUpwardToastDismiss.js");
|
|
11
|
+
Object.defineProperty(exports, "useUpwardToastDismiss", { enumerable: true, get: function () { return useUpwardToastDismiss_js_1.useUpwardToastDismiss; } });
|
|
12
|
+
Object.defineProperty(exports, "TOAST_UPWARD_DISMISS_DISTANCE_PX", { enumerable: true, get: function () { return useUpwardToastDismiss_js_1.TOAST_UPWARD_DISMISS_DISTANCE_PX; } });
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.TOAST_UPWARD_DISMISS_DISTANCE_PX = void 0;
|
|
5
|
+
exports.useUpwardToastDismiss = useUpwardToastDismiss;
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
exports.TOAST_UPWARD_DISMISS_DISTANCE_PX = 64;
|
|
8
|
+
function useUpwardToastDismiss({ onDismiss, transform, }) {
|
|
9
|
+
const pointerStartYRef = (0, react_1.useRef)(null);
|
|
10
|
+
const [isDragging, setIsDragging] = (0, react_1.useState)(false);
|
|
11
|
+
const [swipeOffsetY, setSwipeOffsetY] = (0, react_1.useState)(0);
|
|
12
|
+
const resetDrag = (0, react_1.useCallback)(() => {
|
|
13
|
+
pointerStartYRef.current = null;
|
|
14
|
+
setIsDragging(false);
|
|
15
|
+
setSwipeOffsetY(0);
|
|
16
|
+
}, []);
|
|
17
|
+
const onPointerDown = (0, react_1.useCallback)((event) => {
|
|
18
|
+
if (!onDismiss || isInteractiveTarget(event.target)) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
pointerStartYRef.current = event.clientY;
|
|
22
|
+
setIsDragging(true);
|
|
23
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
24
|
+
}, [onDismiss]);
|
|
25
|
+
const onPointerMove = (0, react_1.useCallback)((event) => {
|
|
26
|
+
if (!onDismiss || pointerStartYRef.current === null) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
setSwipeOffsetY(Math.min(0, event.clientY - pointerStartYRef.current));
|
|
31
|
+
}, [onDismiss]);
|
|
32
|
+
const onPointerUp = (0, react_1.useCallback)((event) => {
|
|
33
|
+
const pointerStartY = pointerStartYRef.current;
|
|
34
|
+
if (!onDismiss || pointerStartY === null) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const upwardDistance = pointerStartY - event.clientY;
|
|
38
|
+
resetDrag();
|
|
39
|
+
if (upwardDistance >= exports.TOAST_UPWARD_DISMISS_DISTANCE_PX) {
|
|
40
|
+
onDismiss();
|
|
41
|
+
}
|
|
42
|
+
}, [onDismiss, resetDrag]);
|
|
43
|
+
const pointerHandlers = (0, react_1.useMemo)(() => onDismiss
|
|
44
|
+
? {
|
|
45
|
+
onPointerCancel: resetDrag,
|
|
46
|
+
onPointerDown,
|
|
47
|
+
onPointerMove,
|
|
48
|
+
onPointerUp,
|
|
49
|
+
}
|
|
50
|
+
: undefined, [onDismiss, onPointerDown, onPointerMove, onPointerUp, resetDrag]);
|
|
51
|
+
const sx = (0, react_1.useMemo)(() => onDismiss
|
|
52
|
+
? {
|
|
53
|
+
// Product decision: direct manipulation is reserved for the toast
|
|
54
|
+
// surface; nested actions such as Undo retain their normal taps.
|
|
55
|
+
animation: isDragging ? "none" : undefined,
|
|
56
|
+
touchAction: "none",
|
|
57
|
+
transform: `${transform ? `${transform} ` : ""}translateY(${swipeOffsetY}px)`,
|
|
58
|
+
transition: isDragging
|
|
59
|
+
? "none"
|
|
60
|
+
: "transform 160ms cubic-bezier(0.2, 0, 0, 1)",
|
|
61
|
+
userSelect: "none",
|
|
62
|
+
WebkitTouchCallout: "none",
|
|
63
|
+
WebkitUserSelect: "none",
|
|
64
|
+
willChange: isDragging ? "transform" : "auto",
|
|
65
|
+
}
|
|
66
|
+
: undefined, [isDragging, onDismiss, swipeOffsetY, transform]);
|
|
67
|
+
return { pointerHandlers, sx };
|
|
68
|
+
}
|
|
69
|
+
function isInteractiveTarget(target) {
|
|
70
|
+
var _a;
|
|
71
|
+
const element = target;
|
|
72
|
+
return Boolean((_a = element === null || element === void 0 ? void 0 : element.closest) === null || _a === void 0 ? void 0 : _a.call(element, "button, a, input, select, textarea, [role='button']"));
|
|
73
|
+
}
|