@douglasneuroinformatics/libui 2.5.2 → 2.6.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/README.md +7 -1
- package/dist/components/ClientTable/ClientTable.d.ts.map +1 -1
- package/dist/components/ClientTable/ClientTable.js +4 -4
- package/dist/components/Drawer/Drawer.d.ts +5 -5
- package/dist/components/Drawer/DrawerContent.d.ts +1 -1
- package/dist/components/Drawer/DrawerDescription.d.ts +1 -1
- package/dist/components/Drawer/DrawerDescription.d.ts.map +1 -1
- package/dist/components/Drawer/DrawerTitle.d.ts +1 -1
- package/dist/components/Drawer/DrawerTitle.d.ts.map +1 -1
- package/dist/components/Form/NumberField/NumberFieldRadio.d.ts +1 -1
- package/dist/components/Form/NumberField/NumberFieldRadio.d.ts.map +1 -1
- package/dist/components/Form/NumberField/NumberFieldRadio.js +7 -4
- package/dist/components/Form/NumberField/NumberFieldSelect.d.ts +1 -1
- package/dist/components/Form/NumberField/NumberFieldSelect.d.ts.map +1 -1
- package/dist/components/Form/NumberField/NumberFieldSelect.js +6 -2
- package/dist/douglasneuroinformatics-libui-2.6.0.tgz +0 -0
- package/dist/i18n.js +1 -1
- package/package.json +60 -59
- package/src/components/Accordion/Accordion.spec.tsx +37 -0
- package/src/components/Accordion/Accordion.stories.tsx +35 -0
- package/src/components/ActionDropdown/ActionDropdown.stories.tsx +17 -0
- package/src/components/AlertDialog/AlertDialog.stories.tsx +35 -0
- package/src/components/ArrowToggle/ArrowToggle.spec.tsx +49 -0
- package/src/components/ArrowToggle/ArrowToggle.stories.tsx +27 -0
- package/src/components/Avatar/Avatar.spec.tsx +26 -0
- package/src/components/Avatar/Avatar.stories.tsx +20 -0
- package/src/components/Badge/Badge.spec.tsx +19 -0
- package/src/components/Badge/Badge.stories.tsx +13 -0
- package/src/components/Breadcrumb/Breadcrumb.stories.tsx +44 -0
- package/src/components/Button/Button.spec.tsx +27 -0
- package/src/components/Button/Button.stories.tsx +63 -0
- package/src/components/Card/Card.spec.tsx +19 -0
- package/src/components/Card/Card.stories.tsx +56 -0
- package/src/components/Checkbox/Checkbox.spec.tsx +28 -0
- package/src/components/Checkbox/Checkbox.stories.tsx +34 -0
- package/src/components/ClientTable/ClientTable.stories.tsx +126 -0
- package/src/components/ClientTable/ClientTable.tsx +5 -7
- package/src/components/Collapsible/Collapsible.stories.tsx +45 -0
- package/src/components/Command/Command.stories.tsx +55 -0
- package/src/components/ContextMenu/ContextMenu.stories.tsx +61 -0
- package/src/components/DatePicker/DatePicker.stories.tsx +15 -0
- package/src/components/Dialog/Dialog.stories.tsx +44 -0
- package/src/components/Drawer/Drawer.stories.tsx +37 -0
- package/src/components/DropdownButton/DropdownButton.stories.tsx +13 -0
- package/src/components/DropdownMenu/DropdownMenu.stories.tsx +78 -0
- package/src/components/ErrorFallback/ErrorFallback.stories.tsx +9 -0
- package/src/components/Form/BooleanField/BooleanField.spec.tsx +35 -0
- package/src/components/Form/BooleanField/BooleanField.stories.tsx +49 -0
- package/src/components/Form/DateField/DateField.spec.tsx +99 -0
- package/src/components/Form/DateField/DateField.stories.tsx +28 -0
- package/src/components/Form/Form.stories.tsx +360 -0
- package/src/components/Form/Form.test.tsx +119 -0
- package/src/components/Form/NumberField/NumberField.stories.tsx +103 -0
- package/src/components/Form/NumberField/NumberFieldRadio.tsx +16 -8
- package/src/components/Form/NumberField/NumberFieldSelect.tsx +10 -6
- package/src/components/Form/SetField/SetField.stories.tsx +63 -0
- package/src/components/Form/StringField/StringField.stories.tsx +94 -0
- package/src/components/Heading/Heading.stories.tsx +37 -0
- package/src/components/HoverCard/HoverCard.stories.tsx +40 -0
- package/src/components/Input/Input.spec.tsx +23 -0
- package/src/components/Input/Input.stories.tsx +9 -0
- package/src/components/Label/Label.spec.tsx +17 -0
- package/src/components/Label/Label.stories.tsx +13 -0
- package/src/components/LanguageToggle/LanguageToggle.stories.tsx +17 -0
- package/src/components/LineGraph/LineGraph.stories.tsx +81 -0
- package/src/components/ListboxDropdown/ListboxDropdown.stories.tsx +44 -0
- package/src/components/MenuBar/MenuBar.stories.tsx +101 -0
- package/src/components/NotificationHub/NotificationHub.stories.tsx +41 -0
- package/src/components/Pagination/Pagination.stories.tsx +41 -0
- package/src/components/Popover/Popover.spec.tsx +24 -0
- package/src/components/Popover/Popover.stories.tsx +72 -0
- package/src/components/Progress/Progress.stories.tsx +24 -0
- package/src/components/RadioGroup/RadioGroup.spec.tsx +42 -0
- package/src/components/RadioGroup/RadioGroup.stories.tsx +35 -0
- package/src/components/Resizable/Resizable.stories.tsx +39 -0
- package/src/components/ScrollArea/ScrollArea.spec.tsx +19 -0
- package/src/components/ScrollArea/ScrollArea.stories.tsx +23 -0
- package/src/components/SearchBar/SearchBar.stories.tsx +11 -0
- package/src/components/Select/Select.stories.tsx +31 -0
- package/src/components/Separator/Separator.spec.tsx +19 -0
- package/src/components/Separator/Separator.stories.tsx +30 -0
- package/src/components/Sheet/Sheet.stories.tsx +49 -0
- package/src/components/Slider/Slider.stories.tsx +9 -0
- package/src/components/Spinner/Spinner.stories.tsx +14 -0
- package/src/components/SpinnerIcon/SpinnerIcon.stories.tsx +9 -0
- package/src/components/Switch/Switch.stories.tsx +21 -0
- package/src/components/Table/Table.stories.tsx +88 -0
- package/src/components/Tabs/Tabs.stories.tsx +70 -0
- package/src/components/TextArea/TextArea.spec.tsx +23 -0
- package/src/components/TextArea/TextArea.stories.tsx +13 -0
- package/src/components/ThemeToggle/ThemeToggle.stories.tsx +9 -0
- package/src/components/Tooltip/Tooltip.stories.tsx +44 -0
- package/src/hooks/useDownload.test.ts +66 -0
- package/src/hooks/useEventCallback.test.tsx +22 -0
- package/src/hooks/useEventListener.test.tsx +120 -0
- package/src/hooks/useInterval.test.ts +58 -0
- package/src/hooks/useIsomorphicLayoutEffect.test.ts +27 -0
- package/src/hooks/useMediaQuery.test.ts +33 -0
- package/src/hooks/useNotificationsStore.test.ts +30 -0
- package/src/hooks/useOnClickOutside.test.ts +59 -0
- package/src/hooks/useSessionStorage.test.ts +186 -0
- package/src/hooks/useTheme.test.ts +74 -0
- package/src/hooks/useWindowSize.test.ts +57 -0
- package/src/i18n.ts +1 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { act, renderHook } from '@testing-library/react';
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { mockMatchMedia, mockStorage } from '../testing/mocks.js';
|
|
5
|
+
import { isBrowser } from '../utils.js';
|
|
6
|
+
import { DEFAULT_THEME, SYS_DARK_MEDIA_QUERY, THEME_ATTRIBUTE, THEME_KEY, useTheme } from './useTheme.js';
|
|
7
|
+
|
|
8
|
+
mockStorage('localStorage');
|
|
9
|
+
|
|
10
|
+
vi.mock('../utils.js', () => ({ isBrowser: vi.fn(() => true) }));
|
|
11
|
+
|
|
12
|
+
describe('useTheme', () => {
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
vi.spyOn(window, 'matchMedia');
|
|
15
|
+
});
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
vi.restoreAllMocks();
|
|
18
|
+
window.localStorage.clear();
|
|
19
|
+
});
|
|
20
|
+
it('should return the default theme if running on the server', () => {
|
|
21
|
+
vi.mocked(isBrowser).mockReturnValue(false);
|
|
22
|
+
const { result } = renderHook(() => useTheme());
|
|
23
|
+
expect(result.current[0]).toBe(DEFAULT_THEME);
|
|
24
|
+
});
|
|
25
|
+
it('should return the saved light theme if it exists', () => {
|
|
26
|
+
window.localStorage.setItem(THEME_KEY, 'light');
|
|
27
|
+
const { result } = renderHook(() => useTheme());
|
|
28
|
+
expect(result.current[0]).toBe('light');
|
|
29
|
+
});
|
|
30
|
+
it('should return the saved dark theme if it exists', () => {
|
|
31
|
+
window.localStorage.setItem(THEME_KEY, 'dark');
|
|
32
|
+
const { result } = renderHook(() => useTheme());
|
|
33
|
+
expect(result.current[0]).toBe('dark');
|
|
34
|
+
});
|
|
35
|
+
it('should return the result of the media query (dark) if there is no saved theme', () => {
|
|
36
|
+
mockMatchMedia((query) => query === SYS_DARK_MEDIA_QUERY);
|
|
37
|
+
const { result } = renderHook(() => useTheme());
|
|
38
|
+
expect(result.current[0]).toBe('dark');
|
|
39
|
+
});
|
|
40
|
+
it('should return the result of the media query (light) if there is no saved theme', () => {
|
|
41
|
+
mockMatchMedia(false);
|
|
42
|
+
const { result } = renderHook(() => useTheme());
|
|
43
|
+
expect(result.current[0]).toBe('light');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should change the theme when updated', async () => {
|
|
47
|
+
window.localStorage.setItem(THEME_KEY, 'light');
|
|
48
|
+
const { result } = renderHook(() => useTheme());
|
|
49
|
+
await act(async () => {
|
|
50
|
+
result.current[1]('dark');
|
|
51
|
+
return Promise.resolve();
|
|
52
|
+
});
|
|
53
|
+
expect(result.current[0]).toBe('dark');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should save the theme to localStorage', async () => {
|
|
57
|
+
window.localStorage.setItem(THEME_KEY, 'light');
|
|
58
|
+
const { result } = renderHook(() => useTheme());
|
|
59
|
+
await act(async () => {
|
|
60
|
+
result.current[1]('dark');
|
|
61
|
+
return Promise.resolve();
|
|
62
|
+
});
|
|
63
|
+
expect(window.localStorage.getItem(THEME_KEY)).toBe('dark');
|
|
64
|
+
});
|
|
65
|
+
it('should print to stderr if there is an unexpected theme mutation', async () => {
|
|
66
|
+
renderHook(() => useTheme());
|
|
67
|
+
vi.spyOn(console, 'error');
|
|
68
|
+
await act(async () => {
|
|
69
|
+
document.documentElement.setAttribute(THEME_ATTRIBUTE, 'INVALID_THEME');
|
|
70
|
+
return Promise.resolve();
|
|
71
|
+
});
|
|
72
|
+
expect(console.error).toHaveBeenLastCalledWith(expect.stringContaining('INVALID_THEME'));
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { act, renderHook } from '@testing-library/react';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { useWindowSize } from './useWindowSize.js';
|
|
5
|
+
|
|
6
|
+
const setupHook = () => renderHook(() => useWindowSize());
|
|
7
|
+
|
|
8
|
+
const windowResize = (dimension: 'height' | 'width', value: number): void => {
|
|
9
|
+
if (dimension === 'width') {
|
|
10
|
+
window.innerWidth = value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (dimension === 'height') {
|
|
14
|
+
window.innerHeight = value;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
window.dispatchEvent(new Event('resize'));
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
describe('useElementSize()', () => {
|
|
21
|
+
it('should initialize', () => {
|
|
22
|
+
const { result } = setupHook();
|
|
23
|
+
const { height, width } = result.current;
|
|
24
|
+
expect(typeof height).toBe('number');
|
|
25
|
+
expect(typeof width).toBe('number');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should return the corresponding height', () => {
|
|
29
|
+
const { result } = setupHook();
|
|
30
|
+
|
|
31
|
+
act(() => {
|
|
32
|
+
windowResize('height', 420);
|
|
33
|
+
});
|
|
34
|
+
expect(result.current.height).toBe(420);
|
|
35
|
+
|
|
36
|
+
act(() => {
|
|
37
|
+
windowResize('height', 2196);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
expect(result.current.height).toBe(2196);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should return the corresponding width', () => {
|
|
44
|
+
const { result } = setupHook();
|
|
45
|
+
act(() => {
|
|
46
|
+
windowResize('width', 420);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
expect(result.current.width).toBe(420);
|
|
50
|
+
|
|
51
|
+
act(() => {
|
|
52
|
+
windowResize('width', 2196);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
expect(result.current.width).toBe(2196);
|
|
56
|
+
});
|
|
57
|
+
});
|
package/src/i18n.ts
CHANGED
|
@@ -22,7 +22,7 @@ export type TranslatedResource<T = EmptyObject> = {
|
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
export function transformTranslations<T extends { [key: string]: any }>(translations: T, locale: string) {
|
|
25
|
-
if (!isPlainObject) {
|
|
25
|
+
if (!isPlainObject(translations)) {
|
|
26
26
|
throw new Error('Invalid format of translations: must be plain object');
|
|
27
27
|
}
|
|
28
28
|
const result: { [key: string]: unknown } = {};
|