@pautena/react-design-system 0.10.1 → 0.11.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/dist/cjs/index.js +4 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/components/containers/index.d.ts +1 -0
- package/dist/cjs/types/components/containers/list-panel/index.d.ts +2 -0
- package/dist/cjs/types/components/containers/list-panel/list-panel-panel.d.ts +5 -0
- package/dist/cjs/types/components/containers/list-panel/list-panel.context.d.ts +4 -0
- package/dist/cjs/types/components/containers/list-panel/list-panel.d.ts +12 -0
- package/dist/cjs/types/components/containers/list-panel/list-panel.mocks.d.ts +4 -0
- package/dist/esm/index.js +4 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/containers/index.d.ts +1 -0
- package/dist/esm/types/components/containers/list-panel/index.d.ts +2 -0
- package/dist/esm/types/components/containers/list-panel/list-panel-panel.d.ts +5 -0
- package/dist/esm/types/components/containers/list-panel/list-panel.context.d.ts +4 -0
- package/dist/esm/types/components/containers/list-panel/list-panel.d.ts +12 -0
- package/dist/esm/types/components/containers/list-panel/list-panel.mocks.d.ts +4 -0
- package/dist/index.d.ts +17 -1
- package/package.json +2 -2
- package/src/components/containers/containers.stories.mdx +1 -0
- package/src/components/containers/index.ts +1 -0
- package/src/components/containers/list-panel/index.ts +2 -0
- package/src/components/containers/list-panel/list-panel-panel.tsx +17 -0
- package/src/components/containers/list-panel/list-panel.context.tsx +5 -0
- package/src/components/containers/list-panel/list-panel.mocks.tsx +117 -0
- package/src/components/containers/list-panel/list-panel.stories.tsx +38 -0
- package/src/components/containers/list-panel/list-panel.test.tsx +65 -0
- package/src/components/containers/list-panel/list-panel.tsx +87 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const ListPanelContext: import("react").Context<string | undefined>;
|
|
3
|
+
export declare const ListPanelContextProvider: import("react").Provider<string | undefined>;
|
|
4
|
+
export declare const useListPanel: () => string | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PropsWithChildren } from "react";
|
|
2
|
+
export interface ListPanelItem {
|
|
3
|
+
id: string;
|
|
4
|
+
text: string;
|
|
5
|
+
tooltip?: string;
|
|
6
|
+
}
|
|
7
|
+
export type ListPanelProps = PropsWithChildren<{
|
|
8
|
+
defaultSelectedItem?: string;
|
|
9
|
+
items: ListPanelItem[];
|
|
10
|
+
onSelectedItemChange?: (id: string) => void;
|
|
11
|
+
}>;
|
|
12
|
+
export declare const ListPanel: ({ items, defaultSelectedItem, children, onSelectedItemChange, }: ListPanelProps) => JSX.Element;
|
package/dist/index.d.ts
CHANGED
|
@@ -347,6 +347,22 @@ interface CenterContainerProps {
|
|
|
347
347
|
}
|
|
348
348
|
declare function CenterContainer({ children, centerVertical, centerHorizontal, sx, }: CenterContainerProps): JSX.Element;
|
|
349
349
|
|
|
350
|
+
interface ListPanelItem {
|
|
351
|
+
id: string;
|
|
352
|
+
text: string;
|
|
353
|
+
tooltip?: string;
|
|
354
|
+
}
|
|
355
|
+
type ListPanelProps = PropsWithChildren<{
|
|
356
|
+
defaultSelectedItem?: string;
|
|
357
|
+
items: ListPanelItem[];
|
|
358
|
+
onSelectedItemChange?: (id: string) => void;
|
|
359
|
+
}>;
|
|
360
|
+
declare const ListPanel: ({ items, defaultSelectedItem, children, onSelectedItemChange, }: ListPanelProps) => JSX.Element;
|
|
361
|
+
|
|
362
|
+
declare const ListPanelContext: React$1.Context<string | undefined>;
|
|
363
|
+
declare const ListPanelContextProvider: React$1.Provider<string | undefined>;
|
|
364
|
+
declare const useListPanel: () => string | undefined;
|
|
365
|
+
|
|
350
366
|
interface DrawerAppBarProps extends AppBarProps {
|
|
351
367
|
title?: string;
|
|
352
368
|
}
|
|
@@ -1050,4 +1066,4 @@ type TabProviderProps = PropsWithChildren<{
|
|
|
1050
1066
|
}>;
|
|
1051
1067
|
declare const TabProvider: ({ children, initialValue }: TabProviderProps) => JSX.Element;
|
|
1052
1068
|
|
|
1053
|
-
export { ArrayFieldType, ArrayGroupField, ArrayInstanceType, Autocomplete, AutocompleteProps, BaseFieldType, BaseValueProps, BasicModelInstance, Board, BoardProps, BootstrapDialog, BootstrapDialogDialogProps, Bullet, BulletProps, BulletVariant, CenterContainer, CenterContainerProps, ConfirmDialog, ConfirmDialogProps, Content, ContentComponent, ContentElement, ContentPlaceholder, ContentPlaceholderProps, ContentProps, DateRangeCalendar, DateRangeCalendarProps, DateRangePicker, DateRangePickerProps, DefaultPlaceholder, DialogAction, Drawer, DrawerAppBar, DrawerAppBarComponent, DrawerAppBarElement, DrawerAppBarProps, DrawerComponent, DrawerContent, DrawerContentComponent, DrawerContentElement, DrawerContentProps, DrawerContext, DrawerContextProps, DrawerElement, DrawerHeader, DrawerItemAvatar, DrawerItemBullet, DrawerItemLabel, DrawerLayout, DrawerLayoutProps, DrawerMain, DrawerMainProps, DrawerNavigation, DrawerNavigationItem, DrawerNavigationItemCollapsable, DrawerNavigationItemLink, DrawerNavigationSection, DrawerProps, DrawerProvider, DrawerProviderProps, DrawerSection, DrawerSectionProps, DrawerSize, DrawerState, DrawerSubheader, DrawerSubheaderProps, DrawerVariant, EditInputType, EditableValueProps, EnhancedRemoteTable, EnhancedRemoteTableProps, EnhancedTable, EnhancedTableHead, ExpandableAlert, ExpandableAlertProps, FieldType, FormDialog, FormDialogProps, GroupField, GroupInstanceType, GroupValueCard, GroupValueCardProps, HeadCell, Header, HeaderAction, HeaderActionVariant, HeaderBreadcrumb, HeaderComponent, HeaderElement, HeaderLayout, HeaderLayoutError, HeaderLayoutProps, HeaderNavigationButton, HeaderPreset, HeaderProps, HeaderTab, IdleRequest, Label, LabelProps, LabelVariant, LoadingArea, LoadingRequest, LoremIpsumPlaceholder, LoremIpsumPlaceholderProps, Markdown, MarkdownProps, Model, ModelField, ModelFieldTypes, ModelForm, ModelFormProps, ModelRouter, ModelRouterProps, Notification, NotificationCenterContext, NotificationCenterProps, NotificationCenterProvider, NotificationCenterProviderProps, NotificationCenterProviderUndefinedError, NotifyWhenValueChangesOptions, ObjectDetails, ObjectDetailsProps, Order, Placeholder, PlaceholderAction, PlaceholderIcon, PlaceholderIconArgs, PlaceholderProps, QueryContainer, QueryContainerError, QueryContainerProps, QueryContainerSuccess, RequestState, Select, SelectProps, SelectSize, SignIn, SignInProps, SingleFieldType, SkeletonCard, SkeletonCardProps, SkeletonGrid, SkeletonGridProps, SuccessRequest, TabCard, TabCardPanel, TabCardPanelProps, TabCardProps, TabContext, TabContextProvider, TabData, TabPanel, TabProvider, TableList, TableListProps, TableRowOption, TextField, TextFieldProps, UndefinedProvider, ValueBoolean, ValueBooleanProps, ValueCard, ValueCardProps, ValueDatetime, ValueDatetimeProps, ValueEditButton, ValueEditButtonProps, ValueEditButtons, ValueEditButtonsProps, ValueItem, ValueItemComponent, ValueItemElement, ValueItemProps, ValueLabel, ValueLabelProps, ValueRating, ValueRatingProps, ValueText, ValueTextProps, bulletClasses, getDrawerItemColors, getFormData, getRandomItem, labelClasses, markdownDefaultOptions, newArrayWithSize, newBreakpointsCounter, newInstanceFromValuesOrZeroValue, useDialog, useDrawer, useEditableValueDisplay, useGetDefaultThemeColor, useNotificationCenter, useNotifyWhenValueChanges, useTab, valueItemClasses };
|
|
1069
|
+
export { ArrayFieldType, ArrayGroupField, ArrayInstanceType, Autocomplete, AutocompleteProps, BaseFieldType, BaseValueProps, BasicModelInstance, Board, BoardProps, BootstrapDialog, BootstrapDialogDialogProps, Bullet, BulletProps, BulletVariant, CenterContainer, CenterContainerProps, ConfirmDialog, ConfirmDialogProps, Content, ContentComponent, ContentElement, ContentPlaceholder, ContentPlaceholderProps, ContentProps, DateRangeCalendar, DateRangeCalendarProps, DateRangePicker, DateRangePickerProps, DefaultPlaceholder, DialogAction, Drawer, DrawerAppBar, DrawerAppBarComponent, DrawerAppBarElement, DrawerAppBarProps, DrawerComponent, DrawerContent, DrawerContentComponent, DrawerContentElement, DrawerContentProps, DrawerContext, DrawerContextProps, DrawerElement, DrawerHeader, DrawerItemAvatar, DrawerItemBullet, DrawerItemLabel, DrawerLayout, DrawerLayoutProps, DrawerMain, DrawerMainProps, DrawerNavigation, DrawerNavigationItem, DrawerNavigationItemCollapsable, DrawerNavigationItemLink, DrawerNavigationSection, DrawerProps, DrawerProvider, DrawerProviderProps, DrawerSection, DrawerSectionProps, DrawerSize, DrawerState, DrawerSubheader, DrawerSubheaderProps, DrawerVariant, EditInputType, EditableValueProps, EnhancedRemoteTable, EnhancedRemoteTableProps, EnhancedTable, EnhancedTableHead, ExpandableAlert, ExpandableAlertProps, FieldType, FormDialog, FormDialogProps, GroupField, GroupInstanceType, GroupValueCard, GroupValueCardProps, HeadCell, Header, HeaderAction, HeaderActionVariant, HeaderBreadcrumb, HeaderComponent, HeaderElement, HeaderLayout, HeaderLayoutError, HeaderLayoutProps, HeaderNavigationButton, HeaderPreset, HeaderProps, HeaderTab, IdleRequest, Label, LabelProps, LabelVariant, ListPanel, ListPanelContext, ListPanelContextProvider, ListPanelItem, ListPanelProps, LoadingArea, LoadingRequest, LoremIpsumPlaceholder, LoremIpsumPlaceholderProps, Markdown, MarkdownProps, Model, ModelField, ModelFieldTypes, ModelForm, ModelFormProps, ModelRouter, ModelRouterProps, Notification, NotificationCenterContext, NotificationCenterProps, NotificationCenterProvider, NotificationCenterProviderProps, NotificationCenterProviderUndefinedError, NotifyWhenValueChangesOptions, ObjectDetails, ObjectDetailsProps, Order, Placeholder, PlaceholderAction, PlaceholderIcon, PlaceholderIconArgs, PlaceholderProps, QueryContainer, QueryContainerError, QueryContainerProps, QueryContainerSuccess, RequestState, Select, SelectProps, SelectSize, SignIn, SignInProps, SingleFieldType, SkeletonCard, SkeletonCardProps, SkeletonGrid, SkeletonGridProps, SuccessRequest, TabCard, TabCardPanel, TabCardPanelProps, TabCardProps, TabContext, TabContextProvider, TabData, TabPanel, TabProvider, TableList, TableListProps, TableRowOption, TextField, TextFieldProps, UndefinedProvider, ValueBoolean, ValueBooleanProps, ValueCard, ValueCardProps, ValueDatetime, ValueDatetimeProps, ValueEditButton, ValueEditButtonProps, ValueEditButtons, ValueEditButtonsProps, ValueItem, ValueItemComponent, ValueItemElement, ValueItemProps, ValueLabel, ValueLabelProps, ValueRating, ValueRatingProps, ValueText, ValueTextProps, bulletClasses, getDrawerItemColors, getFormData, getRandomItem, labelClasses, markdownDefaultOptions, newArrayWithSize, newBreakpointsCounter, newInstanceFromValuesOrZeroValue, useDialog, useDrawer, useEditableValueDisplay, useGetDefaultThemeColor, useListPanel, useNotificationCenter, useNotifyWhenValueChanges, useTab, valueItemClasses };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pautena/react-design-system",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "My custom design system on top of MUI",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
"tslib": "^2.6.0",
|
|
100
100
|
"typescript": "^5.1.6",
|
|
101
101
|
"vite-tsconfig-paths": "^4.2.0",
|
|
102
|
-
"vitest": "^0.
|
|
102
|
+
"vitest": "^0.33.0"
|
|
103
103
|
},
|
|
104
104
|
"peerDependencies": {
|
|
105
105
|
"@emotion/react": "^11.11.1",
|
|
@@ -8,4 +8,5 @@ import LinkTo from '@storybook/addon-links/react';
|
|
|
8
8
|
<ul>
|
|
9
9
|
<li><LinkTo kind="Components/Containers/CenterContainer">CenterContainer</LinkTo></li>
|
|
10
10
|
<li><LinkTo kind="Components/Containers/Content">Content</LinkTo></li>
|
|
11
|
+
<li><LinkTo kind="Components/Containers/ListPanel">ListPanel</LinkTo></li>
|
|
11
12
|
</ul>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PropsWithChildren } from "react";
|
|
2
|
+
import { useListPanel } from "./list-panel.context";
|
|
3
|
+
import React from "react";
|
|
4
|
+
|
|
5
|
+
export type ListPanelPanelProps = PropsWithChildren<{
|
|
6
|
+
ids: string[];
|
|
7
|
+
}>;
|
|
8
|
+
|
|
9
|
+
export const ListPanelPanel = ({ ids, children }: ListPanelPanelProps) => {
|
|
10
|
+
const selectedId = useListPanel();
|
|
11
|
+
|
|
12
|
+
if (selectedId && !ids.includes(selectedId)) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return <>{children}</>;
|
|
17
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Box } from "@mui/material";
|
|
2
|
+
import { ListPanelItem } from "./list-panel";
|
|
3
|
+
import { useListPanel } from "./list-panel.context";
|
|
4
|
+
import React from "react";
|
|
5
|
+
|
|
6
|
+
export const ListPanelDemoContent = () => {
|
|
7
|
+
const selectedId = useListPanel();
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<Box width={1} display="flex" justifyContent="center" alignItems="center" pt={2}>
|
|
11
|
+
Panel content. Selected id: {selectedId}
|
|
12
|
+
</Box>
|
|
13
|
+
);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const mockItemsShort: ListPanelItem[] = [
|
|
17
|
+
{
|
|
18
|
+
id: "all",
|
|
19
|
+
text: "all",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: "inbox",
|
|
23
|
+
text: "Inbox",
|
|
24
|
+
tooltip: "this is the inbox tooltip",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: "sent",
|
|
28
|
+
text: "Sent",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: "drafts",
|
|
32
|
+
text: "Drafts",
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
export const mockItemsLong: ListPanelItem[] = [
|
|
37
|
+
{
|
|
38
|
+
id: "item1",
|
|
39
|
+
text: "Item 1",
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: "item2",
|
|
43
|
+
text: "Item 2",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: "item3",
|
|
47
|
+
text: "Item 3",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: "item4",
|
|
51
|
+
text: "Item 4",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
id: "item5",
|
|
55
|
+
text: "Item 5",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: "item6",
|
|
59
|
+
text: "Item 6",
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
id: "item7",
|
|
63
|
+
text: "Item 7",
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: "item8",
|
|
67
|
+
text: "Item 8",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: "item9",
|
|
71
|
+
text: "Item 9",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: "item10",
|
|
75
|
+
text: "Item 10",
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
id: "item11",
|
|
79
|
+
text: "Item 11",
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
id: "item12",
|
|
83
|
+
text: "Item 12",
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: "item13",
|
|
87
|
+
text: "Item 13",
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
id: "item14",
|
|
91
|
+
text: "Item 14",
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: "item15",
|
|
95
|
+
text: "Item 15",
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
id: "item16",
|
|
99
|
+
text: "Item 16",
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
id: "item17",
|
|
103
|
+
text: "Item 17",
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: "item18",
|
|
107
|
+
text: "Item 18",
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
id: "item19",
|
|
111
|
+
text: "Item 19",
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
id: "item20",
|
|
115
|
+
text: "Item 20",
|
|
116
|
+
},
|
|
117
|
+
];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import { withContainer } from "../../../storybook";
|
|
3
|
+
import { ListPanel } from "./list-panel";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { Box } from "@mui/material";
|
|
6
|
+
import { ListPanelPanel } from "./list-panel-panel";
|
|
7
|
+
import { ListPanelDemoContent, mockItemsLong, mockItemsShort } from "./list-panel.mocks";
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
title: "Components/Containers/ListPanel",
|
|
11
|
+
component: ListPanel,
|
|
12
|
+
decorators: [withContainer({ width: 800, height: 600 })],
|
|
13
|
+
render: (args) => (
|
|
14
|
+
<ListPanel {...args}>
|
|
15
|
+
<ListPanelDemoContent />
|
|
16
|
+
<ListPanelPanel ids={["drafts"]}>
|
|
17
|
+
<Box>Drafts panel</Box>
|
|
18
|
+
</ListPanelPanel>
|
|
19
|
+
</ListPanel>
|
|
20
|
+
),
|
|
21
|
+
parameters: {
|
|
22
|
+
layout: "centered",
|
|
23
|
+
},
|
|
24
|
+
} satisfies Meta<typeof ListPanel>;
|
|
25
|
+
type Story = StoryObj<typeof ListPanel>;
|
|
26
|
+
|
|
27
|
+
export const Short: Story = {
|
|
28
|
+
args: {
|
|
29
|
+
items: mockItemsShort,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const Long: Story = {
|
|
34
|
+
args: {
|
|
35
|
+
items: mockItemsLong,
|
|
36
|
+
defaultSelectedItem: "item3",
|
|
37
|
+
},
|
|
38
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from "~/tests/testing-library";
|
|
2
|
+
import { ListPanel, ListPanelItem } from "./list-panel";
|
|
3
|
+
import { ListPanelDemoContent, mockItemsShort } from "./list-panel.mocks";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { ListPanelPanel } from "./list-panel-panel";
|
|
6
|
+
import { Box } from "@mui/material";
|
|
7
|
+
import { vi } from "vitest";
|
|
8
|
+
|
|
9
|
+
describe("ListPanel", () => {
|
|
10
|
+
const renderComponent = ({
|
|
11
|
+
items,
|
|
12
|
+
defaultSelectedItem,
|
|
13
|
+
}: {
|
|
14
|
+
items: ListPanelItem[];
|
|
15
|
+
defaultSelectedItem?: string;
|
|
16
|
+
}) => {
|
|
17
|
+
const onSelectedItemChange = vi.fn();
|
|
18
|
+
render(
|
|
19
|
+
<ListPanel
|
|
20
|
+
items={items}
|
|
21
|
+
defaultSelectedItem={defaultSelectedItem}
|
|
22
|
+
onSelectedItemChange={onSelectedItemChange}
|
|
23
|
+
>
|
|
24
|
+
<ListPanelDemoContent />
|
|
25
|
+
<ListPanelPanel ids={["drafts"]}>
|
|
26
|
+
<Box>Drafts panel</Box>
|
|
27
|
+
</ListPanelPanel>
|
|
28
|
+
</ListPanel>,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
return { onSelectedItemChange };
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
it("should render a list item for each item", () => {
|
|
35
|
+
renderComponent({ items: mockItemsShort });
|
|
36
|
+
|
|
37
|
+
mockItemsShort.forEach(({ text }) => {
|
|
38
|
+
expect(screen.getByRole("button", { name: text })).toBeVisible();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("should mark as selected the default item", () => {
|
|
43
|
+
renderComponent({ items: mockItemsShort, defaultSelectedItem: "inbox" });
|
|
44
|
+
|
|
45
|
+
expect(screen.getByText(/selected id: inbox/i)).toBeVisible();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("should change the selected item if one is clicked", () => {
|
|
49
|
+
const { onSelectedItemChange } = renderComponent({ items: mockItemsShort });
|
|
50
|
+
|
|
51
|
+
fireEvent.click(screen.getByRole("button", { name: /drafts/i }));
|
|
52
|
+
|
|
53
|
+
expect(screen.getByText(/selected id: drafts/i)).toBeVisible();
|
|
54
|
+
expect(onSelectedItemChange).toHaveBeenCalledTimes(1);
|
|
55
|
+
expect(onSelectedItemChange).toHaveBeenCalledWith("drafts");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("should render the panel if the draft is selected", () => {
|
|
59
|
+
renderComponent({ items: mockItemsShort });
|
|
60
|
+
|
|
61
|
+
fireEvent.click(screen.getByRole("button", { name: /drafts/i }));
|
|
62
|
+
|
|
63
|
+
expect(screen.getByText(/drafts panel/i)).toBeVisible();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Grid, List, ListItemButton, ListItemText, Paper, Tooltip, useTheme } from "@mui/material";
|
|
2
|
+
import React, { PropsWithChildren, useState } from "react";
|
|
3
|
+
import { useGetDefaultThemeColor } from "~/utils";
|
|
4
|
+
import { ListPanelContextProvider } from "./list-panel.context";
|
|
5
|
+
import { grey } from "@mui/material/colors";
|
|
6
|
+
|
|
7
|
+
export interface ListPanelItem {
|
|
8
|
+
id: string;
|
|
9
|
+
text: string;
|
|
10
|
+
tooltip?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type ListPanelProps = PropsWithChildren<{
|
|
14
|
+
defaultSelectedItem?: string;
|
|
15
|
+
items: ListPanelItem[];
|
|
16
|
+
onSelectedItemChange?: (id: string) => void;
|
|
17
|
+
}>;
|
|
18
|
+
|
|
19
|
+
export const ListPanel = ({
|
|
20
|
+
items,
|
|
21
|
+
defaultSelectedItem,
|
|
22
|
+
children,
|
|
23
|
+
onSelectedItemChange = () => null,
|
|
24
|
+
}: ListPanelProps) => {
|
|
25
|
+
const bgColor = useGetDefaultThemeColor();
|
|
26
|
+
const { palette, typography } = useTheme();
|
|
27
|
+
const [selectedItem, setSelectedItem] = useState(defaultSelectedItem);
|
|
28
|
+
|
|
29
|
+
const handleSelectItem = (id: string) => {
|
|
30
|
+
setSelectedItem(id);
|
|
31
|
+
onSelectedItemChange(id);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<ListPanelContextProvider value={selectedItem}>
|
|
36
|
+
<Grid container bgcolor={bgColor} height={1}>
|
|
37
|
+
<Grid item xs={3} pl={1} height={1}>
|
|
38
|
+
<List sx={{ height: 1, overflowY: "auto" }}>
|
|
39
|
+
{items.map(({ id, text, tooltip }) => {
|
|
40
|
+
const selected = id === selectedItem;
|
|
41
|
+
|
|
42
|
+
const contentEl = (
|
|
43
|
+
<ListItemButton
|
|
44
|
+
key={id}
|
|
45
|
+
dense
|
|
46
|
+
selected={selected}
|
|
47
|
+
disableRipple
|
|
48
|
+
onClick={() => handleSelectItem(id)}
|
|
49
|
+
aria-label={text}
|
|
50
|
+
sx={{ backgroundColor: "transparent !important" }}
|
|
51
|
+
>
|
|
52
|
+
<ListItemText
|
|
53
|
+
primary={text}
|
|
54
|
+
primaryTypographyProps={{
|
|
55
|
+
fontWeight: selected ? typography.fontWeightBold : undefined,
|
|
56
|
+
color: selected ? typography.body1.color : grey[600],
|
|
57
|
+
}}
|
|
58
|
+
/>
|
|
59
|
+
</ListItemButton>
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
return tooltip ? (
|
|
63
|
+
<Tooltip key={id} title={tooltip} enterDelay={1500} placement="right">
|
|
64
|
+
{contentEl}
|
|
65
|
+
</Tooltip>
|
|
66
|
+
) : (
|
|
67
|
+
contentEl
|
|
68
|
+
);
|
|
69
|
+
})}
|
|
70
|
+
</List>
|
|
71
|
+
</Grid>
|
|
72
|
+
<Grid item xs={9} pl={2} py={1} pr={1}>
|
|
73
|
+
<Paper
|
|
74
|
+
elevation={0}
|
|
75
|
+
sx={{
|
|
76
|
+
width: 1,
|
|
77
|
+
height: 1,
|
|
78
|
+
backgroundColor: palette.background.paper,
|
|
79
|
+
}}
|
|
80
|
+
>
|
|
81
|
+
{children}
|
|
82
|
+
</Paper>
|
|
83
|
+
</Grid>
|
|
84
|
+
</Grid>
|
|
85
|
+
</ListPanelContextProvider>
|
|
86
|
+
);
|
|
87
|
+
};
|