@12-apps/ui 1.4.1 → 1.5.1
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/package.json +17 -8
- package/src/button/index.ts +1 -0
- package/src/social-login-button/index.ts +1 -0
- package/src/{social-login-button.tsx → social-login-button/social-login-button.tsx} +5 -5
- package/src/user-avatar/index.ts +1 -0
- package/src/{user-avatar.tsx → user-avatar/user-avatar.tsx} +4 -4
- package/eslint.config.js +0 -77
- package/src/__tests__/data-grid.test.tsx +0 -125
- package/src/__tests__/package-wiring.test.ts +0 -41
- package/src/__tests__/setup.ts +0 -1
- package/src/__tests__/social-login-button.test.tsx +0 -186
- package/src/__tests__/user-avatar.test.tsx +0 -195
- package/src/__tests__/viewport.test.ts +0 -50
- package/src/components/command/__tests__/command.test.tsx +0 -112
- package/src/components/data-display/Alert/Alert.stories.tsx +0 -559
- package/src/components/data-display/Alert/Alert.test.stories.tsx +0 -707
- package/src/components/data-display/AlertDialog/AlertDialog.stories.tsx +0 -362
- package/src/components/data-display/AlertDialog/AlertDialog.test.stories.tsx +0 -753
- package/src/components/data-display/AsyncStateContainer/AsyncStateContainer.stories.tsx +0 -230
- package/src/components/data-display/AsyncStateContainer/AsyncStateContainer.test.stories.tsx +0 -270
- package/src/components/data-display/Avatar/Avatar.stories.tsx +0 -721
- package/src/components/data-display/Avatar/Avatar.test.stories.tsx +0 -822
- package/src/components/data-display/Badge/Badge.stories.tsx +0 -1134
- package/src/components/data-display/Badge/Badge.test.stories.tsx +0 -1194
- package/src/components/data-display/Banner/Banner.stories.tsx +0 -528
- package/src/components/data-display/Banner/Banner.test.stories.tsx +0 -503
- package/src/components/data-display/Carousel/Carousel.stories.tsx +0 -607
- package/src/components/data-display/Carousel/Carousel.test.stories.tsx +0 -691
- package/src/components/data-display/Chart/Chart.stories.tsx +0 -568
- package/src/components/data-display/Chart/Chart.test.stories.tsx +0 -174
- package/src/components/data-display/Chart/SpecChart.stories.tsx +0 -150
- package/src/components/data-display/Chart/SpecChart.test.stories.tsx +0 -56
- package/src/components/data-display/Chart/__tests__/SpecChart.test.tsx +0 -60
- package/src/components/data-display/Chart/__tests__/chart-format.test.ts +0 -43
- package/src/components/data-display/Chart/__tests__/chart-spec.test.ts +0 -119
- package/src/components/data-display/Chip/Chip.stories.tsx +0 -252
- package/src/components/data-display/Chip/Chip.test.stories.tsx +0 -266
- package/src/components/data-display/DataGrid/DataGrid.stories.tsx +0 -515
- package/src/components/data-display/DataGrid/DataGrid.test.stories.tsx +0 -653
- package/src/components/data-display/DataViews/__tests__/DataViewsGrid.test.tsx +0 -271
- package/src/components/data-display/DataViews/__tests__/DataViewsTableBase.test.tsx +0 -134
- package/src/components/data-display/DataViews/__tests__/SaveViewModal.test.tsx +0 -83
- package/src/components/data-display/DataViews/__tests__/data-views-filter.test.ts +0 -115
- package/src/components/data-display/DataViews/__tests__/data-views-preview.test.ts +0 -53
- package/src/components/data-display/DataViews/__tests__/range-pill.test.tsx +0 -114
- package/src/components/data-display/DataViews/base-card.stories.tsx +0 -136
- package/src/components/data-display/DescriptionItem/DescriptionItem.stories.tsx +0 -254
- package/src/components/data-display/EmptyState/EmptyState.stories.tsx +0 -282
- package/src/components/data-display/EmptyState/EmptyState.test.stories.tsx +0 -441
- package/src/components/data-display/ErrorState/ErrorState.stories.tsx +0 -110
- package/src/components/data-display/ErrorState/ErrorState.test.stories.tsx +0 -133
- package/src/components/data-display/HoverCard/HoverCard.stories.tsx +0 -650
- package/src/components/data-display/HoverCard/HoverCard.test.stories.tsx +0 -929
- package/src/components/data-display/InteractiveTooltip/InteractiveTooltip.stories.tsx +0 -411
- package/src/components/data-display/LazyImage/LazyImage.stories.tsx +0 -387
- package/src/components/data-display/Lightbox/Lightbox.stories.tsx +0 -315
- package/src/components/data-display/Lightbox/Lightbox.test.stories.tsx +0 -598
- package/src/components/data-display/LoadingState/LoadingState.stories.tsx +0 -124
- package/src/components/data-display/LoadingState/LoadingState.test.stories.tsx +0 -99
- package/src/components/data-display/MapPreview/MapPreview.stories.tsx +0 -458
- package/src/components/data-display/MapPreview/MapPreview.test.stories.tsx +0 -394
- package/src/components/data-display/Popover/Popover.stories.tsx +0 -295
- package/src/components/data-display/Popover/Popover.test.stories.tsx +0 -1162
- package/src/components/data-display/Progress/Progress.stories.tsx +0 -481
- package/src/components/data-display/Progress/Progress.test.stories.tsx +0 -2070
- package/src/components/data-display/SectionOnboarding/SectionOnboarding.stories.tsx +0 -160
- package/src/components/data-display/SectionOnboarding/SectionOnboarding.test.stories.tsx +0 -190
- package/src/components/data-display/Sheet/Sheet.stories.tsx +0 -883
- package/src/components/data-display/Sheet/Sheet.test.stories.tsx +0 -1101
- package/src/components/data-display/StatCard/StatCard.stories.tsx +0 -167
- package/src/components/data-display/StatCard/StatCard.test.stories.tsx +0 -240
- package/src/components/data-display/Stepper/Stepper.stories.tsx +0 -540
- package/src/components/data-display/Stepper/Stepper.test.stories.tsx +0 -600
- package/src/components/data-display/Table/Table.stories.tsx +0 -803
- package/src/components/data-display/Table/Table.test.stories.tsx +0 -369
- package/src/components/data-display/Timeline/Timeline.stories.tsx +0 -442
- package/src/components/data-display/Timeline/Timeline.test.stories.tsx +0 -930
- package/src/components/data-display/TimingDiagram/TimingDiagram.stories.tsx +0 -475
- package/src/components/data-display/TimingDiagram/TimingDiagram.test.stories.tsx +0 -734
- package/src/components/data-display/Tooltip/Tooltip.stories.tsx +0 -468
- package/src/components/data-display/Tooltip/Tooltip.test.stories.tsx +0 -1154
- package/src/components/feedback/ConfirmAction/ConfirmAction.stories.tsx +0 -146
- package/src/components/feedback/ConfirmAction/ConfirmAction.test.stories.tsx +0 -114
- package/src/components/feedback/ConfirmAction/__tests__/confirm-action.test.tsx +0 -288
- package/src/components/feedback/Dialog/Dialog.stories.tsx +0 -833
- package/src/components/feedback/Dialog/Dialog.test.stories.tsx +0 -955
- package/src/components/feedback/Dialog/__tests__/dialog-content-spacing.test.tsx +0 -66
- package/src/components/feedback/Modal/Modal.stories.tsx +0 -765
- package/src/components/feedback/Modal/Modal.test.stories.tsx +0 -251
- package/src/components/feedback/Sonner/Sonner.stories.tsx +0 -698
- package/src/components/feedback/Sonner/Sonner.test.stories.tsx +0 -896
- package/src/components/feedback/StackedModal/StackedModal.stories.tsx +0 -1783
- package/src/components/feedback/StackedModal/StackedModal.test.stories.tsx +0 -975
- package/src/components/feedback/StackedModal/__tests__/stacked-modal-viewport.test.tsx +0 -104
- package/src/components/feedback/Toast/Toast.stories.tsx +0 -548
- package/src/components/feedback/Toast/Toast.test.stories.tsx +0 -834
- package/src/components/feedback/TutorialOverlay/TutorialOverlay.stories.tsx +0 -691
- package/src/components/feedback/TutorialOverlay/TutorialOverlay.test.stories.tsx +0 -634
- package/src/components/form/AddressAutocomplete/AddressAutocomplete.stories.tsx +0 -665
- package/src/components/form/AddressAutocomplete/AddressAutocomplete.test.stories.tsx +0 -727
- package/src/components/form/Autocomplete/Autocomplete.stories.tsx +0 -715
- package/src/components/form/Autocomplete/Autocomplete.test.stories.tsx +0 -825
- package/src/components/form/Button/Button.stories.tsx +0 -365
- package/src/components/form/Button/Button.test.stories.tsx +0 -607
- package/src/components/form/Calendar/Calendar.stories.tsx +0 -349
- package/src/components/form/Calendar/Calendar.test.stories.tsx +0 -464
- package/src/components/form/CepField/CepField.stories.tsx +0 -138
- package/src/components/form/CepField/CepField.test.stories.tsx +0 -281
- package/src/components/form/Checkbox/Checkbox.stories.tsx +0 -265
- package/src/components/form/Checkbox/Checkbox.test.stories.tsx +0 -181
- package/src/components/form/CodeEditor/CodeEditor.stories.tsx +0 -871
- package/src/components/form/CodeEditor/CodeEditor.test.stories.tsx +0 -574
- package/src/components/form/Command/Command.stories.tsx +0 -580
- package/src/components/form/Command/Command.test.stories.tsx +0 -215
- package/src/components/form/CreatableSelect/CreatableSelect.stories.tsx +0 -112
- package/src/components/form/CreatableSelect/CreatableSelect.test.stories.tsx +0 -134
- package/src/components/form/Form/Form.stories.tsx +0 -687
- package/src/components/form/Form/Form.test.stories.tsx +0 -601
- package/src/components/form/Input/Input.stories.tsx +0 -260
- package/src/components/form/Input/Input.test.stories.tsx +0 -1191
- package/src/components/form/InputOTP/InputOTP.stories.tsx +0 -774
- package/src/components/form/InputOTP/InputOTP.test.stories.tsx +0 -588
- package/src/components/form/Label/Label.stories.tsx +0 -473
- package/src/components/form/Label/Label.test.stories.tsx +0 -909
- package/src/components/form/Menubar/Menubar.stories.tsx +0 -472
- package/src/components/form/Menubar/Menubar.test.stories.tsx +0 -584
- package/src/components/form/PasswordStrength/PasswordStrength.stories.tsx +0 -562
- package/src/components/form/PasswordStrength/PasswordStrength.test.stories.tsx +0 -327
- package/src/components/form/PhoneInput/PhoneInput.stories.tsx +0 -495
- package/src/components/form/PhoneInput/PhoneInput.test.stories.tsx +0 -666
- package/src/components/form/RadioGroup/RadioGroup.stories.tsx +0 -518
- package/src/components/form/RadioGroup/RadioGroup.test.stories.tsx +0 -685
- package/src/components/form/RichTextEditor/RichTextEditor.stories.tsx +0 -261
- package/src/components/form/RichTextEditor/RichTextEditor.test.stories.tsx +0 -491
- package/src/components/form/SearchPalette/SearchPalette.stories.tsx +0 -135
- package/src/components/form/Select/Select.stories.tsx +0 -364
- package/src/components/form/Select/Select.test.stories.tsx +0 -985
- package/src/components/form/Slider/Slider.stories.tsx +0 -418
- package/src/components/form/Slider/Slider.test.stories.tsx +0 -1042
- package/src/components/form/Switch/Switch.stories.tsx +0 -697
- package/src/components/form/Switch/Switch.test.stories.tsx +0 -597
- package/src/components/form/Textarea/Textarea.stories.tsx +0 -473
- package/src/components/form/Textarea/Textarea.test.stories.tsx +0 -702
- package/src/components/form/Toggle/Toggle.stories.tsx +0 -638
- package/src/components/form/Toggle/Toggle.test.stories.tsx +0 -1159
- package/src/components/form/ToggleGroup/ToggleGroup.stories.tsx +0 -617
- package/src/components/form/ToggleGroup/ToggleGroup.test.stories.tsx +0 -918
- package/src/components/form/UploadButton/UploadButton.stories.tsx +0 -367
- package/src/components/form/UploadButton/UploadButton.test.stories.tsx +0 -573
- package/src/components/form/total-form/total-form.test.tsx +0 -214
- package/src/components/layout/Accordion/Accordion.stories.tsx +0 -694
- package/src/components/layout/Accordion/Accordion.test.stories.tsx +0 -1344
- package/src/components/layout/Card/Card.stories.tsx +0 -591
- package/src/components/layout/Card/Card.test.stories.tsx +0 -1134
- package/src/components/layout/CardGrid/__tests__/CardGrid.test.tsx +0 -92
- package/src/components/layout/Collapsible/Collapsible.stories.tsx +0 -180
- package/src/components/layout/Collapsible/Collapsible.test.stories.tsx +0 -308
- package/src/components/layout/Container/Container.stories.tsx +0 -557
- package/src/components/layout/Container/Container.test.stories.tsx +0 -745
- package/src/components/layout/ContentToolbar/ContentToolbar.stories.tsx +0 -129
- package/src/components/layout/ContentToolbar/ContentToolbar.test.stories.tsx +0 -251
- package/src/components/layout/ContentToolbar/__tests__/ColumnsMenu.test.tsx +0 -39
- package/src/components/layout/ContentToolbar/__tests__/MultiSelectDropdown.test.tsx +0 -131
- package/src/components/layout/ContentToolbar/__tests__/SavedViewsMenu.test.tsx +0 -99
- package/src/components/layout/Dashboard/Dashboard.stories.tsx +0 -104
- package/src/components/layout/Dashboard/Dashboard.test.stories.tsx +0 -190
- package/src/components/layout/Drawer/Drawer.stories.tsx +0 -658
- package/src/components/layout/Drawer/Drawer.test.stories.tsx +0 -1343
- package/src/components/layout/Resizable/Resizable.stories.tsx +0 -1039
- package/src/components/layout/Resizable/Resizable.test.stories.tsx +0 -750
- package/src/components/layout/ScrollArea/ScrollArea.stories.tsx +0 -651
- package/src/components/layout/ScrollArea/ScrollArea.test.stories.tsx +0 -619
- package/src/components/layout/Separator/Separator.stories.tsx +0 -563
- package/src/components/layout/Separator/Separator.test.stories.tsx +0 -518
- package/src/components/layout/SettingsLayout/SettingsLayout.stories.tsx +0 -192
- package/src/components/layout/SettingsLayout/SettingsLayout.test.stories.tsx +0 -175
- package/src/components/layout/Sidebar/Sidebar.stories.tsx +0 -609
- package/src/components/layout/Sidebar/Sidebar.test.stories.tsx +0 -1324
- package/src/components/layout/Skeleton/Skeleton.stories.tsx +0 -689
- package/src/components/layout/Skeleton/Skeleton.test.stories.tsx +0 -521
- package/src/components/layout/Spacer/Spacer.stories.tsx +0 -502
- package/src/components/layout/Spacer/Spacer.test.stories.tsx +0 -472
- package/src/components/layout/TableFilter/TableFilter.stories.tsx +0 -82
- package/src/components/layout/TableFilter/TableFilter.test.stories.tsx +0 -87
- package/src/components/navigation/Breadcrumbs/Breadcrumbs.stories.tsx +0 -638
- package/src/components/navigation/Breadcrumbs/Breadcrumbs.test.stories.tsx +0 -1008
- package/src/components/navigation/CommandPalette/CommandPalette.stories.tsx +0 -386
- package/src/components/navigation/CommandPalette/CommandPalette.test.stories.tsx +0 -435
- package/src/components/navigation/ContextMenu/ContextMenu.stories.tsx +0 -614
- package/src/components/navigation/ContextMenu/ContextMenu.test.stories.tsx +0 -845
- package/src/components/navigation/DropdownMenu/DropdownMenu.stories.tsx +0 -578
- package/src/components/navigation/DropdownMenu/DropdownMenu.test.stories.tsx +0 -660
- package/src/components/navigation/NavigationMenu/stories/NavigationMenu.stories.tsx +0 -516
- package/src/components/navigation/NavigationMenu/stories/NavigationMenu.test.stories.tsx +0 -935
- package/src/components/navigation/NavigationMenu/stories/NavigationMenuHorizontal.stories.tsx +0 -501
- package/src/components/navigation/NavigationMenu/stories/NavigationMenuVertical.stories.tsx +0 -453
- package/src/components/navigation/Pagination/Pagination.stories.tsx +0 -602
- package/src/components/navigation/Pagination/Pagination.test.stories.tsx +0 -520
- package/src/components/navigation/Tabs/Tabs.stories.tsx +0 -1004
- package/src/components/navigation/Tabs/Tabs.test.stories.tsx +0 -1225
- package/src/components/typography/Blockquote/Blockquote.stories.tsx +0 -359
- package/src/components/typography/Blockquote/Blockquote.test.stories.tsx +0 -432
- package/src/components/typography/Code/Code.stories.tsx +0 -686
- package/src/components/typography/Code/Code.test.stories.tsx +0 -703
- package/src/components/typography/Heading/Heading.stories.tsx +0 -451
- package/src/components/typography/Heading/Heading.test.stories.tsx +0 -830
- package/src/components/typography/Paragraph/Paragraph.stories.tsx +0 -280
- package/src/components/typography/Paragraph/Paragraph.test.stories.tsx +0 -231
- package/src/components/typography/Text/Text.stories.tsx +0 -359
- package/src/components/typography/Text/Text.test.stories.tsx +0 -762
- package/src/components/utility/AnimatedIcon/AnimatedIcon.stories.tsx +0 -945
- package/src/components/utility/AnimatedIcon/AnimatedIcon.test.stories.tsx +0 -603
- package/src/components/utility/AspectRatio/AspectRatio.stories.tsx +0 -414
- package/src/components/utility/AspectRatio/AspectRatio.test.stories.tsx +0 -859
- package/src/components/utility/InfiniteScroll/InfiniteScroll.stories.tsx +0 -620
- package/src/components/utility/InfiniteScroll/InfiniteScroll.test.stories.tsx +0 -361
- package/src/components/utility/InstallPrompt/InstallPrompt.stories.tsx +0 -118
- package/src/components/utility/InstallPrompt/InstallPrompt.test.stories.tsx +0 -83
- package/src/components/utility/InstallPrompt/__tests__/InstallPrompt.ios.test.tsx +0 -65
- package/src/components/utility/InstallPrompt/__tests__/usePwaInstall.test.tsx +0 -271
- package/src/components/utility/Portal/Portal.stories.tsx +0 -340
- package/src/components/utility/Portal/Portal.test.stories.tsx +0 -2086
- package/src/components/utility/Transition/Transition.stories.tsx +0 -493
- package/src/components/utility/Transition/Transition.test.stories.tsx +0 -854
- package/src/components/utility/VirtualList/VirtualList.stories.tsx +0 -1073
- package/src/components/utility/VirtualList/VirtualList.test.stories.tsx +0 -1085
- package/src/components/utility/WorkflowStep/WorkflowStep.stories.tsx +0 -431
- package/src/components/utility/WorkflowStep/WorkflowStep.test.stories.tsx +0 -364
- /package/src/{button.tsx → button/button.tsx} +0 -0
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `usePwaInstall` / `InstallPrompt` — the machinery that turns an installable
|
|
3
|
-
* site into one that actually asks.
|
|
4
|
-
*
|
|
5
|
-
* The regression this file exists for: a manifest and a service worker satisfy
|
|
6
|
-
* every installability criterion a browser checks, and still produce no prompt
|
|
7
|
-
* of any kind, because nothing in the page captures `beforeinstallprompt`. The
|
|
8
|
-
* `preventDefault` case below guards that hole — without that call the browser
|
|
9
|
-
* reclaims the event and the app can never install itself.
|
|
10
|
-
*
|
|
11
|
-
* The iOS branch lives in `InstallPrompt.ios.test.tsx`, which needs a
|
|
12
|
-
* module-level mock this file must not carry.
|
|
13
|
-
*/
|
|
14
|
-
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
15
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
16
|
-
|
|
17
|
-
import { InstallPrompt } from '../index';
|
|
18
|
-
import {
|
|
19
|
-
isDismissalActive,
|
|
20
|
-
isIosSafariAgent,
|
|
21
|
-
readDismissedAt,
|
|
22
|
-
writeDismissedAt,
|
|
23
|
-
} from '../InstallPrompt.helpers';
|
|
24
|
-
import type { BeforeInstallPromptEvent } from '../InstallPrompt.types';
|
|
25
|
-
import { usePwaInstall } from '../usePwaInstall';
|
|
26
|
-
|
|
27
|
-
const STORAGE_KEY = 'pwa-install-dismissed';
|
|
28
|
-
|
|
29
|
-
// A fixed clock. Deriving expectations from the real `Date.now()` would make
|
|
30
|
-
// them depend on how long the test took to run.
|
|
31
|
-
const NOW = 1_700_000_000_000;
|
|
32
|
-
const DAY = 86_400_000;
|
|
33
|
-
|
|
34
|
-
type MockPromptEvent = BeforeInstallPromptEvent & { prompt: ReturnType<typeof vi.fn> };
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Stands in for the Chromium event: `prompt()` records that it was called and
|
|
38
|
-
* `userChoice` resolves with whatever answer the test wants the user to give.
|
|
39
|
-
*/
|
|
40
|
-
const createPromptEvent = (outcome: 'accepted' | 'dismissed'): MockPromptEvent => {
|
|
41
|
-
const event = new Event('beforeinstallprompt') as MockPromptEvent;
|
|
42
|
-
|
|
43
|
-
Object.assign(event, {
|
|
44
|
-
platforms: ['web'],
|
|
45
|
-
prompt: vi.fn().mockResolvedValue(undefined),
|
|
46
|
-
userChoice: Promise.resolve({ outcome, platform: 'web' }),
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
return event;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
/** Renders the hook's state into the DOM so assertions can read it directly. */
|
|
53
|
-
const HookProbe = ({ dismissForDays }: { dismissForDays?: number }) => {
|
|
54
|
-
const { canInstall, platform, isInstalled } = usePwaInstall({ dismissForDays });
|
|
55
|
-
|
|
56
|
-
return (
|
|
57
|
-
<div>
|
|
58
|
-
<span data-testid="can-install">{String(canInstall)}</span>
|
|
59
|
-
<span data-testid="platform">{platform}</span>
|
|
60
|
-
<span data-testid="is-installed">{String(isInstalled)}</span>
|
|
61
|
-
</div>
|
|
62
|
-
);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const IPHONE_SAFARI =
|
|
66
|
-
'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1';
|
|
67
|
-
const IPADOS_SAFARI =
|
|
68
|
-
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15';
|
|
69
|
-
const CHROME_ON_IOS =
|
|
70
|
-
'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/120.0 Mobile/15E148 Safari/604.1';
|
|
71
|
-
const DESKTOP_CHROME =
|
|
72
|
-
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
|
|
73
|
-
|
|
74
|
-
describe('isIosSafariAgent', () => {
|
|
75
|
-
it('detects Safari on iPhone', () => {
|
|
76
|
-
expect(isIosSafariAgent(IPHONE_SAFARI, 5)).toBe(true);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('detects iPadOS, which reports a Macintosh agent with touch points', () => {
|
|
80
|
-
expect(isIosSafariAgent(IPADOS_SAFARI, 5)).toBe(true);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('rejects desktop Safari, which shares that agent but has no touch points', () => {
|
|
84
|
-
expect(isIosSafariAgent(IPADOS_SAFARI, 0)).toBe(false);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('rejects Chrome on iOS, which cannot add to the home screen at all', () => {
|
|
88
|
-
expect(isIosSafariAgent(CHROME_ON_IOS, 5)).toBe(false);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('rejects desktop Chrome', () => {
|
|
92
|
-
expect(isIosSafariAgent(DESKTOP_CHROME, 0)).toBe(false);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
describe('InstallPrompt dismissal storage', () => {
|
|
97
|
-
afterEach(() => {
|
|
98
|
-
window.localStorage.clear();
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('reports no dismissal when nothing was ever stored', () => {
|
|
102
|
-
expect(readDismissedAt(STORAGE_KEY)).toBeNull();
|
|
103
|
-
expect(isDismissalActive(null, 30, NOW)).toBe(false);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('round-trips a dismissal timestamp', () => {
|
|
107
|
-
writeDismissedAt(STORAGE_KEY, NOW);
|
|
108
|
-
expect(readDismissedAt(STORAGE_KEY)).toBe(NOW);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('ignores a corrupted stored value instead of throwing', () => {
|
|
112
|
-
window.localStorage.setItem(STORAGE_KEY, 'not-a-number');
|
|
113
|
-
expect(readDismissedAt(STORAGE_KEY)).toBeNull();
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('keeps a dismissal active inside the window and expires it after', () => {
|
|
117
|
-
expect(isDismissalActive(NOW, 30, NOW + 29 * DAY)).toBe(true);
|
|
118
|
-
expect(isDismissalActive(NOW, 30, NOW + 31 * DAY)).toBe(false);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('treats dismissForDays of 0 as permanent', () => {
|
|
122
|
-
expect(isDismissalActive(NOW, 0, NOW + 3650 * DAY)).toBe(true);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('treats a future timestamp as active so a wound-back clock cannot re-prompt', () => {
|
|
126
|
-
expect(isDismissalActive(NOW + DAY, 30, NOW)).toBe(true);
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
describe('usePwaInstall', () => {
|
|
131
|
-
afterEach(() => {
|
|
132
|
-
window.localStorage.clear();
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('cannot install before the browser offers a prompt', async () => {
|
|
136
|
-
render(<HookProbe />);
|
|
137
|
-
|
|
138
|
-
await waitFor(() => {
|
|
139
|
-
expect(screen.getByTestId('platform')).toHaveTextContent('unsupported');
|
|
140
|
-
});
|
|
141
|
-
expect(screen.getByTestId('can-install')).toHaveTextContent('false');
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it('becomes installable once beforeinstallprompt fires', async () => {
|
|
145
|
-
render(<HookProbe />);
|
|
146
|
-
fireEvent(window, createPromptEvent('accepted'));
|
|
147
|
-
|
|
148
|
-
await waitFor(() => {
|
|
149
|
-
expect(screen.getByTestId('can-install')).toHaveTextContent('true');
|
|
150
|
-
});
|
|
151
|
-
expect(screen.getByTestId('platform')).toHaveTextContent('prompt');
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('calls preventDefault so the deferred handle survives', async () => {
|
|
155
|
-
render(<HookProbe />);
|
|
156
|
-
|
|
157
|
-
const event = createPromptEvent('accepted');
|
|
158
|
-
const preventDefault = vi.spyOn(event, 'preventDefault');
|
|
159
|
-
fireEvent(window, event);
|
|
160
|
-
|
|
161
|
-
await waitFor(() => {
|
|
162
|
-
expect(preventDefault).toHaveBeenCalled();
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
// `dismissForDays: 0` makes the stored dismissal permanent, so this asserts
|
|
167
|
-
// that the hook consults storage at all without depending on the wall clock.
|
|
168
|
-
// The expiry arithmetic itself is covered above against a fixed clock.
|
|
169
|
-
it('stays suppressed while a dismissal is stored', async () => {
|
|
170
|
-
writeDismissedAt(STORAGE_KEY, NOW);
|
|
171
|
-
|
|
172
|
-
render(<HookProbe dismissForDays={0} />);
|
|
173
|
-
fireEvent(window, createPromptEvent('accepted'));
|
|
174
|
-
|
|
175
|
-
await waitFor(() => {
|
|
176
|
-
expect(screen.getByTestId('platform')).toHaveTextContent('prompt');
|
|
177
|
-
});
|
|
178
|
-
expect(screen.getByTestId('can-install')).toHaveTextContent('false');
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('reports installed and stays suppressed after appinstalled', async () => {
|
|
182
|
-
render(<HookProbe />);
|
|
183
|
-
fireEvent(window, createPromptEvent('accepted'));
|
|
184
|
-
|
|
185
|
-
await waitFor(() => {
|
|
186
|
-
expect(screen.getByTestId('can-install')).toHaveTextContent('true');
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
fireEvent(window, new Event('appinstalled'));
|
|
190
|
-
|
|
191
|
-
await waitFor(() => {
|
|
192
|
-
expect(screen.getByTestId('is-installed')).toHaveTextContent('true');
|
|
193
|
-
});
|
|
194
|
-
expect(screen.getByTestId('can-install')).toHaveTextContent('false');
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
describe('InstallPrompt', () => {
|
|
199
|
-
afterEach(() => {
|
|
200
|
-
window.localStorage.clear();
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
it('renders nothing until the browser offers a prompt', async () => {
|
|
204
|
-
render(<InstallPrompt />);
|
|
205
|
-
|
|
206
|
-
await waitFor(() => {
|
|
207
|
-
expect(screen.queryByTestId('install-prompt')).not.toBeInTheDocument();
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it('appears with an install button once the prompt is captured', async () => {
|
|
212
|
-
render(<InstallPrompt title="Install FutureDrink" />);
|
|
213
|
-
fireEvent(window, createPromptEvent('accepted'));
|
|
214
|
-
|
|
215
|
-
await waitFor(() => {
|
|
216
|
-
expect(screen.getByTestId('install-prompt')).toBeInTheDocument();
|
|
217
|
-
});
|
|
218
|
-
expect(screen.getByTestId('install-prompt-install')).toBeInTheDocument();
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
it('fires the native prompt and reports the accepted outcome', async () => {
|
|
222
|
-
const onInstall = vi.fn();
|
|
223
|
-
|
|
224
|
-
render(<InstallPrompt onInstall={onInstall} />);
|
|
225
|
-
const event = createPromptEvent('accepted');
|
|
226
|
-
fireEvent(window, event);
|
|
227
|
-
|
|
228
|
-
await waitFor(() => {
|
|
229
|
-
expect(screen.getByTestId('install-prompt-install')).toBeInTheDocument();
|
|
230
|
-
});
|
|
231
|
-
fireEvent.click(screen.getByTestId('install-prompt-install'));
|
|
232
|
-
|
|
233
|
-
await waitFor(() => {
|
|
234
|
-
expect(onInstall).toHaveBeenCalledWith('accepted');
|
|
235
|
-
});
|
|
236
|
-
expect(event.prompt).toHaveBeenCalledTimes(1);
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
it('records a dismissal when the user declines the native dialog', async () => {
|
|
240
|
-
render(<InstallPrompt onInstall={vi.fn()} />);
|
|
241
|
-
fireEvent(window, createPromptEvent('dismissed'));
|
|
242
|
-
|
|
243
|
-
await waitFor(() => {
|
|
244
|
-
expect(screen.getByTestId('install-prompt-install')).toBeInTheDocument();
|
|
245
|
-
});
|
|
246
|
-
fireEvent.click(screen.getByTestId('install-prompt-install'));
|
|
247
|
-
|
|
248
|
-
await waitFor(() => {
|
|
249
|
-
expect(screen.queryByTestId('install-prompt')).not.toBeInTheDocument();
|
|
250
|
-
});
|
|
251
|
-
expect(readDismissedAt(STORAGE_KEY)).not.toBeNull();
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it('hides and persists the dismissal when the close button is used', async () => {
|
|
255
|
-
const onDismiss = vi.fn();
|
|
256
|
-
|
|
257
|
-
render(<InstallPrompt onDismiss={onDismiss} />);
|
|
258
|
-
fireEvent(window, createPromptEvent('accepted'));
|
|
259
|
-
|
|
260
|
-
await waitFor(() => {
|
|
261
|
-
expect(screen.getByTestId('install-prompt-dismiss')).toBeInTheDocument();
|
|
262
|
-
});
|
|
263
|
-
fireEvent.click(screen.getByTestId('install-prompt-dismiss'));
|
|
264
|
-
|
|
265
|
-
await waitFor(() => {
|
|
266
|
-
expect(screen.queryByTestId('install-prompt')).not.toBeInTheDocument();
|
|
267
|
-
});
|
|
268
|
-
expect(onDismiss).toHaveBeenCalledTimes(1);
|
|
269
|
-
expect(readDismissedAt(STORAGE_KEY)).not.toBeNull();
|
|
270
|
-
});
|
|
271
|
-
});
|
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
import { Alert,Box, Button, Paper, Typography } from '@mui/material';
|
|
2
|
-
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
3
|
-
import { useState } from 'react';
|
|
4
|
-
|
|
5
|
-
import { Portal } from './Portal';
|
|
6
|
-
|
|
7
|
-
const meta: Meta<typeof Portal> = {
|
|
8
|
-
title: 'Utility/Portal',
|
|
9
|
-
component: Portal,
|
|
10
|
-
tags: ['autodocs', 'component:Portal'],
|
|
11
|
-
parameters: {
|
|
12
|
-
layout: 'centered',
|
|
13
|
-
docs: {
|
|
14
|
-
description: {
|
|
15
|
-
component:
|
|
16
|
-
'Portal component for rendering content outside the normal DOM hierarchy, useful for modals, tooltips, and overlays.',
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export default meta;
|
|
23
|
-
type Story = StoryObj<typeof Portal>;
|
|
24
|
-
|
|
25
|
-
const BasicComponent = () => {
|
|
26
|
-
const [showPortal, setShowPortal] = useState(false);
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<Box>
|
|
30
|
-
<Paper sx={{ p: 3, mb: 2 }}>
|
|
31
|
-
<Typography variant="h6" gutterBottom>
|
|
32
|
-
Component Container
|
|
33
|
-
</Typography>
|
|
34
|
-
<Typography paragraph>This content is in the normal DOM hierarchy.</Typography>
|
|
35
|
-
<Button variant="contained" onClick={() => setShowPortal(!showPortal)}>
|
|
36
|
-
{showPortal ? 'Hide' : 'Show'} Portal Content
|
|
37
|
-
</Button>
|
|
38
|
-
</Paper>
|
|
39
|
-
|
|
40
|
-
{showPortal && (
|
|
41
|
-
<Portal>
|
|
42
|
-
<Box
|
|
43
|
-
sx={{
|
|
44
|
-
position: 'fixed',
|
|
45
|
-
top: 16,
|
|
46
|
-
right: 16,
|
|
47
|
-
zIndex: 9999,
|
|
48
|
-
maxWidth: 300,
|
|
49
|
-
}}
|
|
50
|
-
>
|
|
51
|
-
<Alert severity="info" onClose={() => setShowPortal(false)}>
|
|
52
|
-
<Typography variant="subtitle2">Portal Content</Typography>
|
|
53
|
-
This content is rendered outside the normal DOM hierarchy using a Portal. It's
|
|
54
|
-
positioned fixed at the top-right corner.
|
|
55
|
-
</Alert>
|
|
56
|
-
</Box>
|
|
57
|
-
</Portal>
|
|
58
|
-
)}
|
|
59
|
-
</Box>
|
|
60
|
-
);
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export const Basic: Story = {
|
|
64
|
-
render: () => <BasicComponent />,
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const CustomContainerComponent = () => {
|
|
68
|
-
const [customContainer, setCustomContainer] = useState<HTMLElement | null>(null);
|
|
69
|
-
const [showPortal, setShowPortal] = useState(false);
|
|
70
|
-
|
|
71
|
-
return (
|
|
72
|
-
<Box sx={{ display: 'flex', gap: 3 }}>
|
|
73
|
-
<Paper sx={{ p: 3, flex: 1 }}>
|
|
74
|
-
<Typography variant="h6" gutterBottom>
|
|
75
|
-
Source Container
|
|
76
|
-
</Typography>
|
|
77
|
-
<Typography paragraph>This is where the Portal component is defined.</Typography>
|
|
78
|
-
<Button
|
|
79
|
-
variant="contained"
|
|
80
|
-
onClick={() => setShowPortal(!showPortal)}
|
|
81
|
-
disabled={!customContainer}
|
|
82
|
-
>
|
|
83
|
-
{showPortal ? 'Hide' : 'Show'} Portal
|
|
84
|
-
</Button>
|
|
85
|
-
</Paper>
|
|
86
|
-
|
|
87
|
-
<Paper
|
|
88
|
-
sx={{ p: 3, flex: 1, bgcolor: 'primary.light', position: 'relative' }}
|
|
89
|
-
ref={(el) => setCustomContainer(el)}
|
|
90
|
-
>
|
|
91
|
-
<Typography variant="h6" gutterBottom color="primary.contrastText">
|
|
92
|
-
Target Container
|
|
93
|
-
</Typography>
|
|
94
|
-
<Typography paragraph color="primary.contrastText">
|
|
95
|
-
Portal content will appear here even though it's defined elsewhere.
|
|
96
|
-
</Typography>
|
|
97
|
-
|
|
98
|
-
{showPortal && customContainer && (
|
|
99
|
-
<Portal container={customContainer}>
|
|
100
|
-
<Box
|
|
101
|
-
sx={{
|
|
102
|
-
position: 'absolute',
|
|
103
|
-
bottom: 16,
|
|
104
|
-
right: 16,
|
|
105
|
-
maxWidth: 200,
|
|
106
|
-
}}
|
|
107
|
-
>
|
|
108
|
-
<Alert severity="success">
|
|
109
|
-
<Typography variant="body2">Portaled into custom container!</Typography>
|
|
110
|
-
</Alert>
|
|
111
|
-
</Box>
|
|
112
|
-
</Portal>
|
|
113
|
-
)}
|
|
114
|
-
</Paper>
|
|
115
|
-
</Box>
|
|
116
|
-
);
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export const CustomContainer: Story = {
|
|
120
|
-
render: () => <CustomContainerComponent />,
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const DisabledPortalComponent = () => {
|
|
124
|
-
const [disablePortal, setDisablePortal] = useState(false);
|
|
125
|
-
|
|
126
|
-
return (
|
|
127
|
-
<Box>
|
|
128
|
-
<Paper sx={{ p: 3, mb: 2, position: 'relative' }}>
|
|
129
|
-
<Typography variant="h6" gutterBottom>
|
|
130
|
-
Portal Behavior Test
|
|
131
|
-
</Typography>
|
|
132
|
-
<Typography paragraph>Toggle between portal and normal rendering.</Typography>
|
|
133
|
-
|
|
134
|
-
<Box sx={{ mb: 2 }}>
|
|
135
|
-
<Button
|
|
136
|
-
variant={disablePortal ? 'contained' : 'outlined'}
|
|
137
|
-
onClick={() => setDisablePortal(!disablePortal)}
|
|
138
|
-
>
|
|
139
|
-
{disablePortal ? 'Enable' : 'Disable'} Portal
|
|
140
|
-
</Button>
|
|
141
|
-
</Box>
|
|
142
|
-
|
|
143
|
-
<Portal disablePortal={disablePortal}>
|
|
144
|
-
<Box
|
|
145
|
-
sx={{
|
|
146
|
-
position: disablePortal ? 'static' : 'fixed',
|
|
147
|
-
top: disablePortal ? 'auto' : 100,
|
|
148
|
-
left: disablePortal ? 'auto' : '50%',
|
|
149
|
-
transform: disablePortal ? 'none' : 'translateX(-50%)',
|
|
150
|
-
zIndex: disablePortal ? 'auto' : 9999,
|
|
151
|
-
maxWidth: 300,
|
|
152
|
-
}}
|
|
153
|
-
>
|
|
154
|
-
<Alert severity={disablePortal ? 'warning' : 'info'}>
|
|
155
|
-
<Typography variant="subtitle2">
|
|
156
|
-
{disablePortal ? 'Normal Rendering' : 'Portal Rendering'}
|
|
157
|
-
</Typography>
|
|
158
|
-
{disablePortal
|
|
159
|
-
? 'This content is rendered in the normal DOM hierarchy.'
|
|
160
|
-
: 'This content is portaled to document.body.'}
|
|
161
|
-
</Alert>
|
|
162
|
-
</Box>
|
|
163
|
-
</Portal>
|
|
164
|
-
</Paper>
|
|
165
|
-
</Box>
|
|
166
|
-
);
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
export const DisabledPortal: Story = {
|
|
170
|
-
render: () => <DisabledPortalComponent />,
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
const MultiplePortalsComponent = () => {
|
|
174
|
-
const [activePortals, setActivePortals] = useState<Set<number>>(new Set());
|
|
175
|
-
|
|
176
|
-
const togglePortal = (id: number) => {
|
|
177
|
-
setActivePortals((prev) => {
|
|
178
|
-
const newSet = new Set(prev);
|
|
179
|
-
if (newSet.has(id)) {
|
|
180
|
-
newSet.delete(id);
|
|
181
|
-
} else {
|
|
182
|
-
newSet.add(id);
|
|
183
|
-
}
|
|
184
|
-
return newSet;
|
|
185
|
-
});
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
const portalConfigs = [
|
|
189
|
-
{ id: 1, position: { top: 20, left: 20 }, color: 'error' },
|
|
190
|
-
{ id: 2, position: { top: 20, right: 20 }, color: 'warning' },
|
|
191
|
-
{ id: 3, position: { bottom: 20, left: 20 }, color: 'success' },
|
|
192
|
-
{ id: 4, position: { bottom: 20, right: 20 }, color: 'info' },
|
|
193
|
-
];
|
|
194
|
-
|
|
195
|
-
return (
|
|
196
|
-
<Box>
|
|
197
|
-
<Paper sx={{ p: 3 }}>
|
|
198
|
-
<Typography variant="h6" gutterBottom>
|
|
199
|
-
Multiple Portal Demo
|
|
200
|
-
</Typography>
|
|
201
|
-
<Typography paragraph>Create multiple portals in different screen positions.</Typography>
|
|
202
|
-
|
|
203
|
-
<Box sx={{ display: 'flex', gap: 1, flexWrap: 'wrap' }}>
|
|
204
|
-
{portalConfigs.map(({ id, color }) => (
|
|
205
|
-
<Button
|
|
206
|
-
key={id}
|
|
207
|
-
variant={activePortals.has(id) ? 'contained' : 'outlined'}
|
|
208
|
-
color={color as 'error' | 'warning' | 'success' | 'info'}
|
|
209
|
-
size="small"
|
|
210
|
-
onClick={() => togglePortal(id)}
|
|
211
|
-
>
|
|
212
|
-
Portal {id}
|
|
213
|
-
</Button>
|
|
214
|
-
))}
|
|
215
|
-
</Box>
|
|
216
|
-
</Paper>
|
|
217
|
-
|
|
218
|
-
{portalConfigs.map(
|
|
219
|
-
({ id, position, color }) =>
|
|
220
|
-
activePortals.has(id) && (
|
|
221
|
-
<Portal key={id}>
|
|
222
|
-
<Box
|
|
223
|
-
sx={{
|
|
224
|
-
position: 'fixed',
|
|
225
|
-
...position,
|
|
226
|
-
zIndex: 9999,
|
|
227
|
-
maxWidth: 250,
|
|
228
|
-
}}
|
|
229
|
-
>
|
|
230
|
-
<Alert
|
|
231
|
-
severity={color as 'error' | 'warning' | 'success' | 'info'}
|
|
232
|
-
onClose={() => togglePortal(id)}
|
|
233
|
-
>
|
|
234
|
-
<Typography variant="subtitle2">Portal {id}</Typography>
|
|
235
|
-
This is portal content positioned at{' '}
|
|
236
|
-
{Object.entries(position)
|
|
237
|
-
.map(([key, value]) => `${key}: ${value}px`)
|
|
238
|
-
.join(', ')}
|
|
239
|
-
</Alert>
|
|
240
|
-
</Box>
|
|
241
|
-
</Portal>
|
|
242
|
-
),
|
|
243
|
-
)}
|
|
244
|
-
</Box>
|
|
245
|
-
);
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
export const MultiplePortals: Story = {
|
|
249
|
-
render: () => <MultiplePortalsComponent />,
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
// Required story exports for validation
|
|
253
|
-
export const Default: Story = {
|
|
254
|
-
render: () => <BasicComponent />,
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
export const AllVariants: Story = {
|
|
258
|
-
render: () => (
|
|
259
|
-
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 3 }}>
|
|
260
|
-
<BasicComponent />
|
|
261
|
-
<CustomContainerComponent />
|
|
262
|
-
<DisabledPortalComponent />
|
|
263
|
-
</Box>
|
|
264
|
-
),
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
export const AllSizes: Story = {
|
|
268
|
-
render: () => (
|
|
269
|
-
<Box>
|
|
270
|
-
<Typography variant="h6" gutterBottom>
|
|
271
|
-
Portal Size Variations
|
|
272
|
-
</Typography>
|
|
273
|
-
<Typography paragraph>
|
|
274
|
-
Portal component doesn't have inherent sizes - it renders children as-is. Size is determined
|
|
275
|
-
by the children content.
|
|
276
|
-
</Typography>
|
|
277
|
-
<BasicComponent />
|
|
278
|
-
</Box>
|
|
279
|
-
),
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
export const AllStates: Story = {
|
|
283
|
-
render: () => (
|
|
284
|
-
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 3 }}>
|
|
285
|
-
<DisabledPortalComponent />
|
|
286
|
-
<BasicComponent />
|
|
287
|
-
</Box>
|
|
288
|
-
),
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
export const InteractiveStates: Story = {
|
|
292
|
-
render: () => <MultiplePortalsComponent />,
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
const ResponsivePortalComponent = () => {
|
|
296
|
-
const [showPortal, setShowPortal] = useState(false);
|
|
297
|
-
|
|
298
|
-
return (
|
|
299
|
-
<Box>
|
|
300
|
-
<Paper sx={{ p: 3, mb: 2 }}>
|
|
301
|
-
<Typography variant="h6" gutterBottom>
|
|
302
|
-
Responsive Portal Demo
|
|
303
|
-
</Typography>
|
|
304
|
-
<Typography paragraph>Portal content adapts to different screen sizes.</Typography>
|
|
305
|
-
<Button variant="contained" onClick={() => setShowPortal(!showPortal)}>
|
|
306
|
-
{showPortal ? 'Hide' : 'Show'} Responsive Portal
|
|
307
|
-
</Button>
|
|
308
|
-
</Paper>
|
|
309
|
-
|
|
310
|
-
{showPortal && (
|
|
311
|
-
<Portal>
|
|
312
|
-
<Box
|
|
313
|
-
sx={{
|
|
314
|
-
position: 'fixed',
|
|
315
|
-
top: { xs: 16, sm: 32, md: 48 },
|
|
316
|
-
right: { xs: 16, sm: 32, md: 48 },
|
|
317
|
-
left: { xs: 16, sm: 'auto' },
|
|
318
|
-
zIndex: 9999,
|
|
319
|
-
maxWidth: { xs: 'calc(100% - 32px)', sm: 400, md: 500 },
|
|
320
|
-
}}
|
|
321
|
-
>
|
|
322
|
-
<Alert severity="info" onClose={() => setShowPortal(false)}>
|
|
323
|
-
<Typography variant="subtitle2">Responsive Portal</Typography>
|
|
324
|
-
<Typography variant="body2">This portal adapts to different screen sizes:</Typography>
|
|
325
|
-
<Typography variant="caption" component="ul" sx={{ mt: 1, pl: 2 }}>
|
|
326
|
-
<li>Mobile: Full width with 16px margins</li>
|
|
327
|
-
<li>Tablet: 400px max width, 32px positioning</li>
|
|
328
|
-
<li>Desktop: 500px max width, 48px positioning</li>
|
|
329
|
-
</Typography>
|
|
330
|
-
</Alert>
|
|
331
|
-
</Box>
|
|
332
|
-
</Portal>
|
|
333
|
-
)}
|
|
334
|
-
</Box>
|
|
335
|
-
);
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
export const Responsive: Story = {
|
|
339
|
-
render: () => <ResponsivePortalComponent />,
|
|
340
|
-
};
|