@jpmorganchase/mosaic-components 0.1.0-beta.71 → 0.1.0-beta.73
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 +8 -5
- package/.turbo/turbo-build.log +0 -4
- package/CHANGELOG.md +0 -686
- package/src/Accordion/__tests__/index.test.tsx +0 -82
- package/src/Accordion/index.tsx +0 -88
- package/src/Accordion/styles.css.ts +0 -16
- package/src/AudioPlayer/__tests__/index.test.tsx +0 -19
- package/src/AudioPlayer/index.tsx +0 -163
- package/src/AudioPlayer/styles.css.ts +0 -65
- package/src/BrowserOnly.tsx +0 -17
- package/src/Button.tsx +0 -25
- package/src/Callout/__tests__/index.test.tsx +0 -102
- package/src/Callout/index.tsx +0 -62
- package/src/Callout/styles.css.ts +0 -77
- package/src/Card/index.tsx +0 -35
- package/src/Card/styles.css.ts +0 -23
- package/src/Cards.tsx +0 -25
- package/src/ComponentExample/index.tsx +0 -23
- package/src/ComponentExample/styles.css.ts +0 -25
- package/src/DataTable.tsx +0 -114
- package/src/EditionFilterView/__tests__/index.test.tsx +0 -49
- package/src/EditionFilterView/index.tsx +0 -108
- package/src/EditionFilterView/styles.css.ts +0 -8
- package/src/EditionTileLink/index.tsx +0 -90
- package/src/EditionTileLink/styles.css.ts +0 -95
- package/src/Feature/Feature.tsx +0 -92
- package/src/Feature/FeatureActions/index.tsx +0 -34
- package/src/Feature/FeatureActions/styles.css.ts +0 -15
- package/src/Feature/FeatureContent/index.tsx +0 -30
- package/src/Feature/FeatureContent/styles.css.ts +0 -13
- package/src/Feature/FeatureEyebrow/index.tsx +0 -19
- package/src/Feature/FeatureEyebrow/styles.css.ts +0 -11
- package/src/Feature/FeatureTitle/index.tsx +0 -18
- package/src/Feature/FeatureTitle/styles.css.ts +0 -9
- package/src/Feature/index.tsx +0 -10
- package/src/Feature/styles.css.ts +0 -58
- package/src/Features/index.tsx +0 -33
- package/src/Features/styles.css.ts +0 -10
- package/src/FilterToolbar/ContentArea/index.tsx +0 -12
- package/src/FilterToolbar/ContentArea/styles.css.ts +0 -16
- package/src/FilterToolbar/FilterDropdown/__tests__/index.test.tsx +0 -22
- package/src/FilterToolbar/FilterDropdown/index.tsx +0 -62
- package/src/FilterToolbar/FilterDropdown/styles.css.ts +0 -16
- package/src/FilterToolbar/PillGroup/__tests__/index.test.tsx +0 -26
- package/src/FilterToolbar/PillGroup/index.tsx +0 -36
- package/src/FilterToolbar/PillGroup/styles.css.ts +0 -17
- package/src/FilterToolbar/Search/__tests__/index.test.tsx +0 -34
- package/src/FilterToolbar/Search/index.tsx +0 -33
- package/src/FilterToolbar/Search/styles.css.ts +0 -9
- package/src/FilterToolbar/SortDropdown/__tests__/index.test.tsx +0 -22
- package/src/FilterToolbar/SortDropdown/defaultSort.js +0 -8
- package/src/FilterToolbar/SortDropdown/index.tsx +0 -53
- package/src/FilterToolbar/SortDropdown/styles.css.ts +0 -15
- package/src/FilterToolbar/Toolbar.tsx +0 -38
- package/src/FilterToolbar/ToolbarProvider.tsx +0 -94
- package/src/FilterToolbar/__tests__/Toolbar.test.tsx +0 -127
- package/src/FilterToolbar/__tests__/ToolbarProvider.test.tsx +0 -85
- package/src/FilterToolbar/index.tsx +0 -9
- package/src/FilterToolbar/styles.css.ts +0 -19
- package/src/FilterView/ContentArea/index.tsx +0 -24
- package/src/FilterView/ContentArea/styles.css.ts +0 -16
- package/src/FilterView/FilterView.tsx +0 -205
- package/src/FilterView/FilterViewProvider.tsx +0 -23
- package/src/FilterView/NoResults/index.tsx +0 -19
- package/src/FilterView/NoResults/styles.css.ts +0 -13
- package/src/FilterView/Pagination/index.tsx +0 -40
- package/src/FilterView/Pagination/styles.css.ts +0 -40
- package/src/FilterView/Pagination/usePagination.ts +0 -31
- package/src/FilterView/ResultCount/index.tsx +0 -23
- package/src/FilterView/ResultCount/styles.css.ts +0 -11
- package/src/FilterView/__tests__/index.test.tsx +0 -109
- package/src/FilterView/index.tsx +0 -5
- package/src/FilterView/useResultCount.tsx +0 -8
- package/src/FormattedContent.tsx +0 -75
- package/src/Grid/index.tsx +0 -29
- package/src/Grid/styles.css.ts +0 -13
- package/src/GridBase/index.tsx +0 -60
- package/src/GridBase/styles.css.ts +0 -19
- package/src/HelpLinks/index.tsx +0 -80
- package/src/HelpLinks/styles.css.ts +0 -32
- package/src/Hero/__tests__/index.test.tsx +0 -19
- package/src/Hero/index.tsx +0 -172
- package/src/Hero/styles.css.ts +0 -111
- package/src/Icon/index.tsx +0 -50
- package/src/ImageProvider.ts +0 -9
- package/src/Impact/index.tsx +0 -36
- package/src/Impact/styles.css.ts +0 -72
- package/src/Impacts.tsx +0 -25
- package/src/IsomorphicSuspense.tsx +0 -9
- package/src/Label/__tests__/index.test.tsx +0 -27
- package/src/Label/index.tsx +0 -42
- package/src/Label/styles.css.ts +0 -14
- package/src/Link/index.tsx +0 -83
- package/src/Link/styles.css.ts +0 -15
- package/src/LinkBase/index.tsx +0 -32
- package/src/LinkButton.css.ts +0 -19
- package/src/LinkButton.tsx +0 -22
- package/src/LinkProvider.ts +0 -9
- package/src/LinkText/index.tsx +0 -121
- package/src/LinkText/styles.css.ts +0 -30
- package/src/Links/index.tsx +0 -18
- package/src/Links/styles.css.ts +0 -13
- package/src/List/ListItem.tsx +0 -31
- package/src/List/OrderedList.tsx +0 -22
- package/src/List/UnorderedList.tsx +0 -35
- package/src/List/index.tsx +0 -3
- package/src/Markdown/AnchorHeading/__tests__/index.test.tsx +0 -56
- package/src/Markdown/AnchorHeading/index.css.ts +0 -64
- package/src/Markdown/AnchorHeading/index.tsx +0 -97
- package/src/Markdown/BlockQuote/index.css.ts +0 -6
- package/src/Markdown/BlockQuote/index.tsx +0 -21
- package/src/Markdown/Heading.tsx +0 -39
- package/src/Markdown/InlineCode.tsx +0 -10
- package/src/Markdown/Link.tsx +0 -11
- package/src/Markdown/Pre/index.css.ts +0 -35
- package/src/Markdown/Pre/index.tsx +0 -155
- package/src/Markdown/Table.tsx +0 -11
- package/src/Markdown/Tbody.tsx +0 -9
- package/src/Markdown/Td.tsx +0 -9
- package/src/Markdown/Th.tsx +0 -9
- package/src/Markdown/Thead.tsx +0 -9
- package/src/Markdown/ThematicBreak/index.css.ts +0 -5
- package/src/Markdown/ThematicBreak/index.tsx +0 -10
- package/src/Markdown/Tr.tsx +0 -9
- package/src/Markdown/__tests__/Heading.test.tsx +0 -56
- package/src/Markdown/index.tsx +0 -210
- package/src/Markdown/markdownElements.tsx +0 -52
- package/src/Markdown/withMarkdownSpacing/index.tsx +0 -33
- package/src/Markdown/withMarkdownSpacing/styles.css.ts +0 -7
- package/src/PageFilterView/index.tsx +0 -86
- package/src/PageFilterView/styles.css.ts +0 -8
- package/src/ReactLive/index.tsx +0 -71
- package/src/ReactLive/styles.css.ts +0 -28
- package/src/SecondaryNavbar/index.tsx +0 -55
- package/src/SecondaryNavbar/styles.css.ts +0 -27
- package/src/SectionHeading/__tests__/index.test.tsx +0 -20
- package/src/SectionHeading/index.tsx +0 -33
- package/src/SectionHeading/styles.css.ts +0 -15
- package/src/StickyHeader/index.tsx +0 -52
- package/src/StickyHeader/styles.css.ts +0 -17
- package/src/Story/index.tsx +0 -70
- package/src/Story/styles.css.ts +0 -37
- package/src/Tabs/index.tsx +0 -65
- package/src/Tabs/styles.css.ts +0 -7
- package/src/TabsBase/TabsBase.tsx +0 -89
- package/src/TabsBase/TabsButton.tsx +0 -30
- package/src/TabsBase/TabsLink.tsx +0 -30
- package/src/TabsBase/TabsMenuButton.tsx +0 -41
- package/src/TabsBase/index.ts +0 -4
- package/src/TabsBase/styles.css.ts +0 -64
- package/src/TabsBase/tabsMenuButton.css.ts +0 -25
- package/src/Tag/__tests__/index.test.tsx +0 -58
- package/src/Tag/index.tsx +0 -62
- package/src/Tag/styles.css.ts +0 -48
- package/src/ThemeProvider.tsx +0 -37
- package/src/TileBase/TileBase.tsx +0 -159
- package/src/TileBase/TileStateProvider.tsx +0 -52
- package/src/TileBase/index.ts +0 -2
- package/src/TileBase/styles.css.ts +0 -15
- package/src/TileButton/index.tsx +0 -68
- package/src/TileContent/index.tsx +0 -155
- package/src/TileContent/styles.css.ts +0 -229
- package/src/TileContentLabel/index.tsx +0 -74
- package/src/TileContentLabel/styles.css.ts +0 -22
- package/src/TileLink/index.tsx +0 -83
- package/src/TileLink/styles.css.ts +0 -9
- package/src/Tiles.tsx +0 -17
- package/src/Typography/Typography.tsx +0 -22
- package/src/Typography/index.tsx +0 -54
- package/src/Typography/withStyledTypography.tsx +0 -25
- package/src/VideoPlayer/__tests__/index.test.tsx +0 -13
- package/src/VideoPlayer/index.tsx +0 -179
- package/src/VideoPlayer/styles.css.ts +0 -87
- package/src/ViewStack/View.tsx +0 -19
- package/src/ViewStack/ViewStack.tsx +0 -50
- package/src/ViewStack/__tests__/index.test.tsx +0 -86
- package/src/ViewStack/index.tsx +0 -2
- package/src/__tests__/Button.test.tsx +0 -13
- package/src/__tests__/LinkButton.test.tsx +0 -16
- package/src/__tests__/ReactLive.test.tsx +0 -21
- package/src/canUseDOM.ts +0 -5
- package/src/common/types/index.ts +0 -52
- package/src/index.tsx +0 -59
- package/src/styles.ts +0 -45
- package/src/useBreakpoint.ts +0 -28
- package/src/useLockBodyScroll.ts +0 -16
- package/src/useOutsideClick.ts +0 -25
- package/src/useSize.ts +0 -32
- package/src/useSpacing.ts +0 -17
- package/src/utils/hasProtocol.ts +0 -1
- package/src/utils/index.ts +0 -1
- package/tsconfig.json +0 -8
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { fireEvent, render, waitFor } from '@testing-library/react';
|
|
3
|
-
|
|
4
|
-
import { ToolbarProvider } from '../../ToolbarProvider';
|
|
5
|
-
import { FilterSortDropdown } from '../index';
|
|
6
|
-
|
|
7
|
-
test('renders a sort dropdown', async () => {
|
|
8
|
-
// arrange
|
|
9
|
-
const source = ['Sort 1', 'Sort 2', 'Sort 3'];
|
|
10
|
-
const { getAllByRole, getByText } = render(
|
|
11
|
-
<ToolbarProvider initialState={{ sort: 'Sort 1' }}>
|
|
12
|
-
<FilterSortDropdown source={source} />
|
|
13
|
-
</ToolbarProvider>
|
|
14
|
-
);
|
|
15
|
-
// assert
|
|
16
|
-
expect(getAllByRole('option').length).toEqual(1);
|
|
17
|
-
// action
|
|
18
|
-
const dropdownButton = getByText('Sort 1');
|
|
19
|
-
fireEvent.click(dropdownButton);
|
|
20
|
-
// assert
|
|
21
|
-
await waitFor(() => expect(getAllByRole('option').length).toEqual(4));
|
|
22
|
-
});
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import classnames from 'clsx';
|
|
3
|
-
import { Dropdown, DropdownButton, DropdownProps, SelectionChangeHandler } from '@salt-ds/lab';
|
|
4
|
-
import { Icon } from '../../Icon';
|
|
5
|
-
import styles from './styles.css';
|
|
6
|
-
import { useToolbarDispatch, useToolbarState } from '../ToolbarProvider';
|
|
7
|
-
import { itemToLabel as defaultItemToLabel, source as defaultSource } from './defaultSort';
|
|
8
|
-
|
|
9
|
-
type PartialDropdownProps = Omit<DropdownProps<string, 'default'>, 'source'>;
|
|
10
|
-
|
|
11
|
-
export interface FilterSortDropdownProps extends PartialDropdownProps {
|
|
12
|
-
/** Callback to translate the selected list item to a Button label */
|
|
13
|
-
labelButton?: (selectedItem: string | undefined) => string;
|
|
14
|
-
/** Dropdown list source */
|
|
15
|
-
source?: string[];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function FilterSortDropdown({
|
|
19
|
-
className,
|
|
20
|
-
itemToString = defaultItemToLabel,
|
|
21
|
-
labelButton,
|
|
22
|
-
source = defaultSource,
|
|
23
|
-
...rest
|
|
24
|
-
}: FilterSortDropdownProps) {
|
|
25
|
-
const dispatch = useToolbarDispatch();
|
|
26
|
-
const { sort = source[0] } = useToolbarState();
|
|
27
|
-
const [, setIsOpen] = useState(false);
|
|
28
|
-
|
|
29
|
-
const handleSelect: SelectionChangeHandler<string, 'default'> = (_e, selectedItem) => {
|
|
30
|
-
if (selectedItem) {
|
|
31
|
-
dispatch({ type: 'setSort', value: selectedItem });
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
return (
|
|
36
|
-
<Dropdown
|
|
37
|
-
className={classnames(className, styles.root)}
|
|
38
|
-
itemToString={itemToString}
|
|
39
|
-
onOpenChange={setIsOpen}
|
|
40
|
-
onSelectionChange={handleSelect}
|
|
41
|
-
selected={sort}
|
|
42
|
-
source={source}
|
|
43
|
-
triggerComponent={
|
|
44
|
-
<span className={styles.triggerRoot}>
|
|
45
|
-
<Icon name="swap" />
|
|
46
|
-
<DropdownButton label={labelButton ? labelButton(sort) : sort} />
|
|
47
|
-
</span>
|
|
48
|
-
}
|
|
49
|
-
width={150}
|
|
50
|
-
{...rest}
|
|
51
|
-
/>
|
|
52
|
-
);
|
|
53
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { style, globalStyle } from '@vanilla-extract/css';
|
|
2
|
-
const triggerRoot = style({ display: 'inline-flex', alignItems: 'center' });
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
root: style({
|
|
6
|
-
display: 'flex !important',
|
|
7
|
-
alignSelf: 'stretch',
|
|
8
|
-
alignItems: 'center'
|
|
9
|
-
}),
|
|
10
|
-
triggerRoot
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
globalStyle(`${triggerRoot} svg.saltIcon`, {
|
|
14
|
-
vars: { '--saltIcon-size-multiplier': '1.2!important' }
|
|
15
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import classnames from 'clsx';
|
|
3
|
-
|
|
4
|
-
import { ToolbarProvider, ToolbarProviderProps } from './ToolbarProvider';
|
|
5
|
-
import { FilterToolbarContentArea } from './ContentArea';
|
|
6
|
-
import { FilterDropdown } from './FilterDropdown';
|
|
7
|
-
import { FilterPillGroup } from './PillGroup';
|
|
8
|
-
import { FilterSearch } from './Search';
|
|
9
|
-
import { FilterSortDropdown } from './SortDropdown';
|
|
10
|
-
import styles from './styles.css';
|
|
11
|
-
|
|
12
|
-
interface ToolbarComposition {
|
|
13
|
-
ContentArea: typeof FilterToolbarContentArea;
|
|
14
|
-
FilterDropdown: typeof FilterDropdown;
|
|
15
|
-
PillGroup: typeof FilterPillGroup;
|
|
16
|
-
Search: typeof FilterSearch;
|
|
17
|
-
SortDropdown: typeof FilterSortDropdown;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface FilterToolbarProps extends ToolbarProviderProps {
|
|
21
|
-
/** Additional class name for root class override */
|
|
22
|
-
className?: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const FilterToolbar: React.FC<React.PropsWithChildren<FilterToolbarProps>> &
|
|
26
|
-
ToolbarComposition = function Toolbar({ children, className, ...rest }) {
|
|
27
|
-
return (
|
|
28
|
-
<ToolbarProvider {...rest}>
|
|
29
|
-
<div className={classnames(styles.root, className)}>{children}</div>
|
|
30
|
-
</ToolbarProvider>
|
|
31
|
-
);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
FilterToolbar.ContentArea = FilterToolbarContentArea;
|
|
35
|
-
FilterToolbar.FilterDropdown = FilterDropdown;
|
|
36
|
-
FilterToolbar.PillGroup = FilterPillGroup;
|
|
37
|
-
FilterToolbar.SortDropdown = FilterSortDropdown;
|
|
38
|
-
FilterToolbar.Search = FilterSearch;
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { Context } from 'react';
|
|
3
|
-
|
|
4
|
-
type Action =
|
|
5
|
-
| { type: 'addFilter'; value: string }
|
|
6
|
-
| { type: 'removeFilter'; value: string }
|
|
7
|
-
| { type: 'setFilters'; value: string[] }
|
|
8
|
-
| { type: 'setSort'; value: string };
|
|
9
|
-
type Dispatch = (action: Action) => void | undefined;
|
|
10
|
-
export type State = { filters?: string[]; sort?: string; hasStateChanged?: boolean };
|
|
11
|
-
export type OnStateChangeCallback = (state: State | undefined) => void;
|
|
12
|
-
|
|
13
|
-
export interface ToolbarProviderProps {
|
|
14
|
-
/** Children of the Toolbar */
|
|
15
|
-
children: React.ReactNode;
|
|
16
|
-
/** Initial filter/sort state of the view */
|
|
17
|
-
initialState?: State;
|
|
18
|
-
/** Callback called when the filter/sort state changes */
|
|
19
|
-
onStateChange?: OnStateChangeCallback;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const ToolbarStateContext: Context<State | undefined> = React.createContext<State | undefined>(
|
|
23
|
-
undefined
|
|
24
|
-
);
|
|
25
|
-
const ToolbarDispatchContext: Context<Dispatch | undefined> = React.createContext<
|
|
26
|
-
Dispatch | undefined
|
|
27
|
-
>(undefined);
|
|
28
|
-
|
|
29
|
-
function toolbarReducer(state: State, action: Action): State {
|
|
30
|
-
const { filters } = state;
|
|
31
|
-
switch (action.type) {
|
|
32
|
-
case 'setFilters': {
|
|
33
|
-
return { ...state, filters: action.value, hasStateChanged: true };
|
|
34
|
-
}
|
|
35
|
-
case 'addFilter': {
|
|
36
|
-
if (filters && filters.indexOf(action.value) === -1) {
|
|
37
|
-
return { ...state, filters: [...filters, action.value], hasStateChanged: true };
|
|
38
|
-
}
|
|
39
|
-
return state;
|
|
40
|
-
}
|
|
41
|
-
case 'removeFilter': {
|
|
42
|
-
const newFilters = filters && filters.filter(value => value !== action.value);
|
|
43
|
-
return { ...state, filters: newFilters, hasStateChanged: true };
|
|
44
|
-
}
|
|
45
|
-
case 'setSort': {
|
|
46
|
-
return { ...state, sort: action.value, hasStateChanged: true };
|
|
47
|
-
}
|
|
48
|
-
default: {
|
|
49
|
-
throw new Error(`Unhandled action type: ${action}`);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const ToolbarProvider = ({ children, initialState = {}, onStateChange }: ToolbarProviderProps) => {
|
|
55
|
-
const previousStateRef = React.useRef<State>();
|
|
56
|
-
const nextStateRef = React.useRef<State>();
|
|
57
|
-
const [state, dispatch] = React.useReducer(toolbarReducer, initialState);
|
|
58
|
-
React.useEffect(() => {
|
|
59
|
-
if (
|
|
60
|
-
onStateChange &&
|
|
61
|
-
previousStateRef.current &&
|
|
62
|
-
previousStateRef.current !== nextStateRef.current
|
|
63
|
-
) {
|
|
64
|
-
onStateChange(nextStateRef.current);
|
|
65
|
-
}
|
|
66
|
-
previousStateRef.current = nextStateRef.current;
|
|
67
|
-
});
|
|
68
|
-
if (state) {
|
|
69
|
-
nextStateRef.current = state;
|
|
70
|
-
}
|
|
71
|
-
return (
|
|
72
|
-
<ToolbarStateContext.Provider value={state}>
|
|
73
|
-
<ToolbarDispatchContext.Provider value={dispatch}>{children}</ToolbarDispatchContext.Provider>
|
|
74
|
-
</ToolbarStateContext.Provider>
|
|
75
|
-
);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
function useToolbarState(): State {
|
|
79
|
-
const context = React.useContext(ToolbarStateContext);
|
|
80
|
-
if (context === undefined) {
|
|
81
|
-
throw new Error('useToolbarState must be used within a ToolbarProvider');
|
|
82
|
-
}
|
|
83
|
-
return context;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function useToolbarDispatch(): Dispatch {
|
|
87
|
-
const context = React.useContext(ToolbarDispatchContext);
|
|
88
|
-
if (context === undefined) {
|
|
89
|
-
throw new Error('useToolbarDispatch must be used within a ToolbarProvider');
|
|
90
|
-
}
|
|
91
|
-
return context;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export { ToolbarProvider, useToolbarState, useToolbarDispatch };
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render, screen, within } from '@testing-library/react';
|
|
3
|
-
import userEvent from '@testing-library/user-event';
|
|
4
|
-
import { FilterToolbar } from '../Toolbar';
|
|
5
|
-
|
|
6
|
-
function renderToolbar(initialState, onStateChange) {
|
|
7
|
-
return render(
|
|
8
|
-
<FilterToolbar initialState={initialState} onStateChange={onStateChange}>
|
|
9
|
-
<label>Another component</label>
|
|
10
|
-
<FilterToolbar.PillGroup />
|
|
11
|
-
<FilterToolbar.SortDropdown
|
|
12
|
-
ListProps={{ 'data-mosaic-testid': 'sort-dropdown' }}
|
|
13
|
-
itemToString={item => `Item ${item}`}
|
|
14
|
-
source={['Sort 1', 'Sort 2', 'Sort 3']}
|
|
15
|
-
/>
|
|
16
|
-
<FilterToolbar.FilterDropdown
|
|
17
|
-
ListProps={{ 'data-mosaic-testid': 'filter-dropdown' }}
|
|
18
|
-
itemToString={item => `Item ${item}`}
|
|
19
|
-
source={['Filter 1', 'Filter 2', 'Filter 3']}
|
|
20
|
-
/>
|
|
21
|
-
</FilterToolbar>
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
test('updates the toolbar sort state', async () => {
|
|
26
|
-
// arrange
|
|
27
|
-
const handleStateChangeMock = jest.fn();
|
|
28
|
-
const { getByText } = renderToolbar({ filters: [], sort: 'Sort 3' }, handleStateChangeMock);
|
|
29
|
-
const dropdownSortButton = getByText('Sort 3');
|
|
30
|
-
// action
|
|
31
|
-
await userEvent.click(dropdownSortButton);
|
|
32
|
-
// assert
|
|
33
|
-
expect(within(screen.getByTestId('sort-dropdown')).getAllByRole('option').length).toEqual(3);
|
|
34
|
-
const sort2 = within(screen.getByTestId('sort-dropdown')).getByText('Item Sort 2');
|
|
35
|
-
// action
|
|
36
|
-
await userEvent.click(sort2);
|
|
37
|
-
// assert
|
|
38
|
-
expect(handleStateChangeMock).toHaveBeenLastCalledWith({
|
|
39
|
-
filters: [],
|
|
40
|
-
sort: 'Sort 2',
|
|
41
|
-
hasStateChanged: true
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('updates the toolbar filter state', async () => {
|
|
46
|
-
// arrange
|
|
47
|
-
const handleStateChangeMock = jest.fn();
|
|
48
|
-
const { getByText } = renderToolbar({ filters: [], sort: 'Sort 3' }, handleStateChangeMock);
|
|
49
|
-
// action
|
|
50
|
-
const dropdownFilterButton = getByText('All');
|
|
51
|
-
await userEvent.click(dropdownFilterButton);
|
|
52
|
-
// assert
|
|
53
|
-
expect(within(screen.getByTestId('filter-dropdown')).getAllByRole('option').length).toEqual(4);
|
|
54
|
-
// action
|
|
55
|
-
const option2 = within(screen.getByTestId('filter-dropdown')).getByText('Item Filter 2');
|
|
56
|
-
await userEvent.click(option2);
|
|
57
|
-
// assert
|
|
58
|
-
expect(handleStateChangeMock).toHaveBeenCalledWith({
|
|
59
|
-
filters: ['Filter 2'],
|
|
60
|
-
sort: 'Sort 3',
|
|
61
|
-
hasStateChanged: true
|
|
62
|
-
});
|
|
63
|
-
// action
|
|
64
|
-
const option3 = within(screen.getByTestId('filter-dropdown')).getByText('Item Filter 3');
|
|
65
|
-
await userEvent.click(option3);
|
|
66
|
-
// assert
|
|
67
|
-
expect(handleStateChangeMock).toHaveBeenLastCalledWith({
|
|
68
|
-
filters: ['Filter 2', 'Filter 3'],
|
|
69
|
-
sort: 'Sort 3',
|
|
70
|
-
hasStateChanged: true
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('remove a filter with the dropdown', async () => {
|
|
75
|
-
// arrange
|
|
76
|
-
const handleStateChangeMock = jest.fn();
|
|
77
|
-
const { getByText } = renderToolbar(
|
|
78
|
-
{ filters: ['Filter 2', 'Filter 3'], sort: 'Sort 3' },
|
|
79
|
-
handleStateChangeMock
|
|
80
|
-
);
|
|
81
|
-
// action
|
|
82
|
-
const dropdownFilterButton = getByText('2 Items Selected');
|
|
83
|
-
await userEvent.click(dropdownFilterButton);
|
|
84
|
-
const option2 = within(screen.getByTestId('filter-dropdown')).getByText('Item Filter 2');
|
|
85
|
-
await userEvent.click(option2);
|
|
86
|
-
// assert
|
|
87
|
-
expect(handleStateChangeMock).toHaveBeenCalledWith({
|
|
88
|
-
filters: ['Filter 3'],
|
|
89
|
-
sort: 'Sort 3',
|
|
90
|
-
hasStateChanged: true
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('clears all filters', async () => {
|
|
95
|
-
// arrange
|
|
96
|
-
const handleStateChangeMock = jest.fn();
|
|
97
|
-
const { getByText } = renderToolbar(
|
|
98
|
-
{ filters: ['Filter 2', 'Filter 3'], sort: 'Sort 3' },
|
|
99
|
-
handleStateChangeMock
|
|
100
|
-
);
|
|
101
|
-
// action
|
|
102
|
-
const dropdownFilterButton = getByText('2 Items Selected');
|
|
103
|
-
await userEvent.click(dropdownFilterButton);
|
|
104
|
-
const clearAllOption = within(screen.getByTestId('filter-dropdown')).getByText('Item Clear all');
|
|
105
|
-
await userEvent.click(clearAllOption);
|
|
106
|
-
// assert
|
|
107
|
-
expect(handleStateChangeMock).toHaveBeenCalledWith({
|
|
108
|
-
filters: [],
|
|
109
|
-
sort: 'Sort 3',
|
|
110
|
-
hasStateChanged: true
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('remove a filter with the pills', async () => {
|
|
115
|
-
// arrange
|
|
116
|
-
const handleStateChangeMock = jest.fn();
|
|
117
|
-
renderToolbar({ filters: ['Filter 2', 'Filter 3'], sort: 'Sort 3' }, handleStateChangeMock);
|
|
118
|
-
// action
|
|
119
|
-
const pills = screen.getAllByTestId('pill');
|
|
120
|
-
await userEvent.click(pills[0]);
|
|
121
|
-
// assert
|
|
122
|
-
expect(handleStateChangeMock).toHaveBeenCalledWith({
|
|
123
|
-
filters: ['Filter 3'],
|
|
124
|
-
sort: 'Sort 3',
|
|
125
|
-
hasStateChanged: true
|
|
126
|
-
});
|
|
127
|
-
});
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import React, { useEffect } from 'react';
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
3
|
-
|
|
4
|
-
import { useToolbarState, useToolbarDispatch, ToolbarProvider } from '../ToolbarProvider';
|
|
5
|
-
|
|
6
|
-
function TestUseToolbarDispatch({ action }) {
|
|
7
|
-
const dispatch = useToolbarDispatch();
|
|
8
|
-
useEffect(() => {
|
|
9
|
-
dispatch(action);
|
|
10
|
-
});
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function TestUseToolbarState({ validate }) {
|
|
15
|
-
const state = useToolbarState();
|
|
16
|
-
validate(state);
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
test('can add filters', async () => {
|
|
21
|
-
const props = {
|
|
22
|
-
handleStateChange: state => {
|
|
23
|
-
expect(state).toEqual({ filters: ['Filter 3'], sort: undefined });
|
|
24
|
-
},
|
|
25
|
-
initialState: { filters: [], sort: undefined }
|
|
26
|
-
};
|
|
27
|
-
render(
|
|
28
|
-
<ToolbarProvider {...props}>
|
|
29
|
-
<TestUseToolbarDispatch action={{ type: 'addFilter', value: 'Filter 3' }} />
|
|
30
|
-
</ToolbarProvider>
|
|
31
|
-
);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test('can set filters', async () => {
|
|
35
|
-
const props = {
|
|
36
|
-
handleStateChange: state => {
|
|
37
|
-
expect(state).toEqual({ filters: ['Filter 3'], sort: undefined });
|
|
38
|
-
},
|
|
39
|
-
initialState: { filters: [], sort: undefined }
|
|
40
|
-
};
|
|
41
|
-
render(
|
|
42
|
-
<ToolbarProvider {...props}>
|
|
43
|
-
<TestUseToolbarDispatch action={{ type: 'setFilters', value: 'Filter 3' }} />
|
|
44
|
-
</ToolbarProvider>
|
|
45
|
-
);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('can remove filters', async () => {
|
|
49
|
-
const props = {
|
|
50
|
-
handleStateChange: state => {
|
|
51
|
-
expect(state).toEqual({ filters: ['Filter 1'], sort: undefined });
|
|
52
|
-
},
|
|
53
|
-
initialState: { filters: ['Filter 1', 'Filter 3'], sort: undefined }
|
|
54
|
-
};
|
|
55
|
-
render(
|
|
56
|
-
<ToolbarProvider {...props}>
|
|
57
|
-
<TestUseToolbarDispatch action={{ type: 'removeFilter', value: 'Filter 3' }} />
|
|
58
|
-
</ToolbarProvider>
|
|
59
|
-
);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('can set sort', async () => {
|
|
63
|
-
const props = {
|
|
64
|
-
handleStateChange: state => {
|
|
65
|
-
expect(state).toEqual({ filters: undefined, sort: 'Sort 1' });
|
|
66
|
-
},
|
|
67
|
-
initialState: { filters: undefined, sort: undefined }
|
|
68
|
-
};
|
|
69
|
-
render(
|
|
70
|
-
<ToolbarProvider {...props}>
|
|
71
|
-
<TestUseToolbarDispatch action={{ type: 'setSort', value: 'Sort 1' }} />
|
|
72
|
-
</ToolbarProvider>
|
|
73
|
-
);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test('can read the state', async () => {
|
|
77
|
-
const validate = state => {
|
|
78
|
-
expect(state).toEqual({ filters: ['Filter 1'], sort: 'Sort 1' });
|
|
79
|
-
};
|
|
80
|
-
render(
|
|
81
|
-
<ToolbarProvider initialState={{ filters: ['Filter 1'], sort: 'Sort 1' }}>
|
|
82
|
-
<TestUseToolbarState validate={validate} />
|
|
83
|
-
</ToolbarProvider>
|
|
84
|
-
);
|
|
85
|
-
});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './FilterDropdown';
|
|
2
|
-
export * from './PillGroup';
|
|
3
|
-
export * from './SortDropdown';
|
|
4
|
-
export * from './ToolbarProvider';
|
|
5
|
-
export * from './ContentArea';
|
|
6
|
-
export * from './Toolbar';
|
|
7
|
-
export * from './PillGroup';
|
|
8
|
-
export * from './Search';
|
|
9
|
-
export * from './SortDropdown';
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { style } from '@vanilla-extract/css';
|
|
2
|
-
import { caption, responsiveSprinkles, neutralBorder } from '@jpmorganchase/mosaic-theme';
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
root: style([
|
|
6
|
-
{
|
|
7
|
-
display: 'flex',
|
|
8
|
-
flexWrap: 'nowrap',
|
|
9
|
-
justifyContent: 'flex-end',
|
|
10
|
-
alignItems: 'center'
|
|
11
|
-
},
|
|
12
|
-
caption({ variant: 'caption2' }),
|
|
13
|
-
responsiveSprinkles({
|
|
14
|
-
columnGap: ['x2', 'x2', 'x2', 'x2'],
|
|
15
|
-
paddingX: ['x2', 'x2', 'x2', 'x2']
|
|
16
|
-
}),
|
|
17
|
-
neutralBorder({ variant: 'low', borderBottomWidth: 'thin' })
|
|
18
|
-
])
|
|
19
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import classnames from 'clsx';
|
|
3
|
-
|
|
4
|
-
import { Grid, GridItemSize } from '../../Grid';
|
|
5
|
-
import styles from './styles.css';
|
|
6
|
-
|
|
7
|
-
export interface FilterViewContentAreaProps {
|
|
8
|
-
/** Additional class name for root class override */
|
|
9
|
-
className?: string;
|
|
10
|
-
/** Tile size */
|
|
11
|
-
size?: GridItemSize;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const FilterViewContentArea: React.FC<
|
|
15
|
-
React.PropsWithChildren<FilterViewContentAreaProps>
|
|
16
|
-
> = ({ children, className, size = 'small', ...rest }) => (
|
|
17
|
-
<Grid
|
|
18
|
-
className={classnames(className, styles.root, { [styles.gutter]: size !== 'fullWidth' })}
|
|
19
|
-
size={size}
|
|
20
|
-
{...rest}
|
|
21
|
-
>
|
|
22
|
-
{children}
|
|
23
|
-
</Grid>
|
|
24
|
-
);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { style } from '@vanilla-extract/css';
|
|
2
|
-
import { responsiveSprinkles } from '@jpmorganchase/mosaic-theme';
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
root: style([
|
|
6
|
-
responsiveSprinkles({
|
|
7
|
-
paddingTop: ['x8', 'x8', 'x8', 'x8']
|
|
8
|
-
})
|
|
9
|
-
]),
|
|
10
|
-
gutter: style([
|
|
11
|
-
responsiveSprinkles({
|
|
12
|
-
marginLeft: ['gutter', 'gutter', 'gutter', 'gutter'],
|
|
13
|
-
marginRight: ['gutter', 'gutter', 'gutter', 'gutter']
|
|
14
|
-
})
|
|
15
|
-
])
|
|
16
|
-
};
|