@equinor/eds-core-react 0.35.1 → 0.36.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/eds-core-react.cjs +5582 -4353
- package/dist/esm/components/Accordion/Accordion.js +21 -23
- package/dist/esm/components/Accordion/Accordion.tokens.js +65 -23
- package/dist/esm/components/Accordion/AccordionHeader.js +74 -62
- package/dist/esm/components/Accordion/AccordionHeaderActions.js +22 -20
- package/dist/esm/components/Accordion/AccordionHeaderTitle.js +22 -20
- package/dist/esm/components/Accordion/AccordionItem.js +28 -35
- package/dist/esm/components/Accordion/AccordionPanel.js +27 -26
- package/dist/esm/components/Accordion/index.js +1 -1
- package/dist/esm/components/Autocomplete/Autocomplete.js +451 -329
- package/dist/esm/components/Autocomplete/Autocomplete.tokens.js +33 -17
- package/dist/esm/components/Autocomplete/Option.js +35 -32
- package/dist/esm/components/Avatar/Avatar.js +19 -26
- package/dist/esm/components/Avatar/Avatar.tokens.js +1 -1
- package/dist/esm/components/Banner/Banner.js +26 -27
- package/dist/esm/components/Banner/Banner.tokens.js +47 -18
- package/dist/esm/components/Banner/BannerActions.js +18 -19
- package/dist/esm/components/Banner/BannerIcon.js +26 -25
- package/dist/esm/components/Banner/BannerMessage.js +13 -14
- package/dist/esm/components/Banner/index.js +1 -1
- package/dist/esm/components/Breadcrumbs/Breadcrumb.js +30 -32
- package/dist/esm/components/Breadcrumbs/Breadcrumbs.js +46 -53
- package/dist/esm/components/Breadcrumbs/Breadcrumbs.tokens.js +20 -5
- package/dist/esm/components/Breadcrumbs/index.js +1 -1
- package/dist/esm/components/Button/Button.js +46 -46
- package/dist/esm/components/Button/ButtonGroup/ButtonGroup.js +22 -22
- package/dist/esm/components/Button/ButtonGroup/ButtonGroup.tokens.js +8 -2
- package/dist/esm/components/Button/InnerFullWidth.js +8 -10
- package/dist/esm/components/Button/ToggleButton/ToggleButton.js +23 -33
- package/dist/esm/components/Button/index.js +1 -1
- package/dist/esm/components/Button/tokens/button.js +62 -31
- package/dist/esm/components/Button/tokens/contained.js +38 -14
- package/dist/esm/components/Button/tokens/contained_icon.js +13 -10
- package/dist/esm/components/Button/tokens/ghost.js +36 -13
- package/dist/esm/components/Button/tokens/icon.js +46 -20
- package/dist/esm/components/Button/tokens/index.js +1 -1
- package/dist/esm/components/Button/tokens/outlined.js +42 -15
- package/dist/esm/components/Card/Card.js +24 -27
- package/dist/esm/components/Card/Card.tokens.js +32 -11
- package/dist/esm/components/Card/CardActions.js +22 -23
- package/dist/esm/components/Card/CardContent.js +12 -12
- package/dist/esm/components/Card/CardHeader.js +15 -13
- package/dist/esm/components/Card/CardHeaderTitle.js +12 -12
- package/dist/esm/components/Card/CardMedia.js +20 -20
- package/dist/esm/components/Card/index.js +1 -1
- package/dist/esm/components/Checkbox/Checkbox.js +20 -21
- package/dist/esm/components/Checkbox/Checkbox.tokens.js +41 -16
- package/dist/esm/components/Checkbox/Input.js +75 -84
- package/dist/esm/components/Chip/Chip.js +61 -64
- package/dist/esm/components/Chip/Chip.tokens.js +68 -26
- package/dist/esm/components/Chip/Icon.js +13 -11
- package/dist/esm/components/Dialog/Dialog.js +34 -35
- package/dist/esm/components/Dialog/Dialog.tokens.js +32 -10
- package/dist/esm/components/Dialog/DialogActions.js +13 -14
- package/dist/esm/components/Dialog/DialogContent.js +19 -20
- package/dist/esm/components/Dialog/DialogHeader.js +16 -15
- package/dist/esm/components/Dialog/DialogTitle.js +13 -14
- package/dist/esm/components/Dialog/index.js +1 -1
- package/dist/esm/components/Divider/Divider.js +24 -25
- package/dist/esm/components/Divider/Divider.tokens.js +24 -10
- package/dist/esm/components/EdsProvider/eds.context.js +18 -26
- package/dist/esm/components/Icon/Icon.js +75 -78
- package/dist/esm/components/Icon/index.js +1 -1
- package/dist/esm/components/Icon/library.js +9 -8
- package/dist/esm/components/Input/Input.js +93 -92
- package/dist/esm/components/Input/Input.tokens.js +56 -40
- package/dist/esm/components/InputWrapper/HelperText/HelperText.js +24 -28
- package/dist/esm/components/InputWrapper/HelperText/HelperText.token.js +11 -7
- package/dist/esm/components/InputWrapper/InputWrapper.js +34 -35
- package/dist/esm/components/InputWrapper/InputWrapper.tokens.js +56 -40
- package/dist/esm/components/Label/Label.js +16 -20
- package/dist/esm/components/Label/Label.tokens.js +11 -7
- package/dist/esm/components/List/List.js +17 -19
- package/dist/esm/components/List/List.tokens.js +6 -2
- package/dist/esm/components/List/ListItem.js +7 -8
- package/dist/esm/components/List/index.js +1 -1
- package/dist/esm/components/Menu/Menu.context.js +35 -42
- package/dist/esm/components/Menu/Menu.js +111 -108
- package/dist/esm/components/Menu/Menu.tokens.js +57 -24
- package/dist/esm/components/Menu/MenuItem.js +59 -61
- package/dist/esm/components/Menu/MenuList.js +52 -55
- package/dist/esm/components/Menu/MenuSection.js +9 -9
- package/dist/esm/components/Menu/index.js +1 -1
- package/dist/esm/components/Pagination/Pagination.js +70 -75
- package/dist/esm/components/Pagination/Pagination.tokens.js +18 -5
- package/dist/esm/components/Pagination/PaginationItem.js +18 -19
- package/dist/esm/components/Pagination/paginationControl.js +18 -22
- package/dist/esm/components/Paper/Paper.js +15 -18
- package/dist/esm/components/Paper/Paper.tokens.js +12 -4
- package/dist/esm/components/Popover/Popover.js +98 -87
- package/dist/esm/components/Popover/Popover.tokens.js +37 -11
- package/dist/esm/components/Popover/PopoverActions.js +15 -14
- package/dist/esm/components/Popover/PopoverContent.js +15 -14
- package/dist/esm/components/Popover/PopoverHeader.js +16 -15
- package/dist/esm/components/Popover/PopoverTitle.js +15 -14
- package/dist/esm/components/Popover/index.js +1 -1
- package/dist/esm/components/Progress/Circular/CircularProgress.js +33 -42
- package/dist/esm/components/Progress/Circular/CircularProgress.tokens.js +24 -8
- package/dist/esm/components/Progress/Dots/DotProgress.js +20 -23
- package/dist/esm/components/Progress/Dots/DotProgress.tokens.js +20 -8
- package/dist/esm/components/Progress/Linear/LinearProgress.js +25 -31
- package/dist/esm/components/Progress/Linear/LinearProgress.tokens.js +13 -4
- package/dist/esm/components/Progress/Star/StarProgress.js +23 -27
- package/dist/esm/components/Progress/Star/StarProgress.tokens.js +10 -2
- package/dist/esm/components/Progress/index.js +1 -1
- package/dist/esm/components/Radio/Radio.js +71 -83
- package/dist/esm/components/Radio/Radio.tokens.js +41 -16
- package/dist/esm/components/Scrim/Scrim.js +20 -23
- package/dist/esm/components/Scrim/Scrim.tokens.js +11 -3
- package/dist/esm/components/Search/Search.js +24 -31
- package/dist/esm/components/Select/NativeSelect.js +45 -44
- package/dist/esm/components/Select/NativeSelect.tokens.js +15 -10
- package/dist/esm/components/SideBar/SideBar.context.js +27 -33
- package/dist/esm/components/SideBar/SideBar.js +42 -40
- package/dist/esm/components/SideBar/SideBar.tokens.js +49 -20
- package/dist/esm/components/SideBar/SideBarAccordion/index.js +98 -90
- package/dist/esm/components/SideBar/SideBarAccordionItem/index.js +46 -33
- package/dist/esm/components/SideBar/SideBarButton/index.js +61 -45
- package/dist/esm/components/SideBar/SideBarContent.js +13 -13
- package/dist/esm/components/SideBar/SideBarFooter.js +13 -13
- package/dist/esm/components/SideBar/SideBarToggle.js +40 -26
- package/dist/esm/components/SideBar/SidebarLink/index.js +87 -48
- package/dist/esm/components/SideBar/index.js +1 -1
- package/dist/esm/components/SideSheet/SideSheet.js +27 -27
- package/dist/esm/components/SideSheet/SideSheet.tokens.js +29 -12
- package/dist/esm/components/Slider/MinMax.js +10 -6
- package/dist/esm/components/Slider/Output.js +15 -18
- package/dist/esm/components/Slider/Slider.js +157 -188
- package/dist/esm/components/Slider/Slider.tokens.js +67 -19
- package/dist/esm/components/Slider/SliderInput.js +37 -34
- package/dist/esm/components/Snackbar/Snackbar.js +39 -45
- package/dist/esm/components/Snackbar/Snackbar.tokens.js +45 -17
- package/dist/esm/components/Snackbar/SnackbarAction.js +15 -14
- package/dist/esm/components/Snackbar/index.js +1 -1
- package/dist/esm/components/Switch/Switch.js +37 -42
- package/dist/esm/components/Switch/Switch.styles.js +17 -20
- package/dist/esm/components/Switch/Switch.tokens.js +66 -21
- package/dist/esm/components/Switch/SwitchDefault.js +38 -36
- package/dist/esm/components/Switch/SwitchSmall.js +38 -33
- package/dist/esm/components/Table/Body.js +8 -9
- package/dist/esm/components/Table/Caption.js +12 -14
- package/dist/esm/components/Table/Cell.js +15 -14
- package/dist/esm/components/Table/DataCell/DataCell.js +27 -26
- package/dist/esm/components/Table/DataCell/DataCell.tokens.js +79 -38
- package/dist/esm/components/Table/Head/Head.js +10 -11
- package/dist/esm/components/Table/Head/Head.tokens.js +15 -4
- package/dist/esm/components/Table/HeaderCell/HeaderCell.js +37 -33
- package/dist/esm/components/Table/HeaderCell/HeaderCell.tokens.js +65 -28
- package/dist/esm/components/Table/Inner.context.js +2 -2
- package/dist/esm/components/Table/Row/Row.js +12 -16
- package/dist/esm/components/Table/Row/Row.tokens.js +13 -4
- package/dist/esm/components/Table/Table.js +8 -9
- package/dist/esm/components/Table/index.js +1 -1
- package/dist/esm/components/TableOfContents/LinkItem.js +11 -11
- package/dist/esm/components/TableOfContents/TableOfContents.js +25 -26
- package/dist/esm/components/TableOfContents/TableOfContents.tokens.js +46 -21
- package/dist/esm/components/TableOfContents/index.js +1 -1
- package/dist/esm/components/Tabs/Tab.js +30 -29
- package/dist/esm/components/Tabs/TabList.js +50 -62
- package/dist/esm/components/Tabs/TabPanel.js +19 -18
- package/dist/esm/components/Tabs/TabPanels.js +16 -17
- package/dist/esm/components/Tabs/Tabs.context.js +3 -5
- package/dist/esm/components/Tabs/Tabs.js +37 -53
- package/dist/esm/components/Tabs/Tabs.tokens.js +56 -21
- package/dist/esm/components/Tabs/index.js +1 -1
- package/dist/esm/components/TextField/TextField.js +64 -59
- package/dist/esm/components/Textarea/Textarea.js +38 -38
- package/dist/esm/components/Tooltip/Tooltip.js +79 -81
- package/dist/esm/components/Tooltip/Tooltip.tokens.js +33 -13
- package/dist/esm/components/TopBar/Actions.js +9 -11
- package/dist/esm/components/TopBar/CustomContent.js +9 -11
- package/dist/esm/components/TopBar/Header.js +9 -11
- package/dist/esm/components/TopBar/TopBar.js +24 -25
- package/dist/esm/components/TopBar/TopBar.tokens.js +10 -4
- package/dist/esm/components/TopBar/index.js +1 -1
- package/dist/esm/components/Typography/Typography.js +42 -54
- package/dist/esm/components/Typography/Typography.tokens.js +50 -23
- package/dist/esm/node_modules/.pnpm/ramda@0.29.1/node_modules/ramda/es/internal/_isPlaceholder.js +1 -3
- package/dist/types/components/Accordion/Accordion.types.d.ts +1 -1
- package/dist/types/components/Autocomplete/Autocomplete.d.ts +13 -0
- package/dist/types/components/Autocomplete/Option.d.ts +1 -0
- package/dist/types/components/Slider/Slider.d.ts +11 -3
- package/package.json +6 -7
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
|
-
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
3
1
|
import { forwardRef, useMemo, Children, cloneElement, useEffect, isValidElement } from 'react';
|
|
4
2
|
import styled from 'styled-components';
|
|
5
3
|
import { useMenu } from './Menu.context.js';
|
|
@@ -9,8 +7,7 @@ import { menu } from './Menu.tokens.js';
|
|
|
9
7
|
import { spacingsTemplate } from '@equinor/eds-utils';
|
|
10
8
|
import { jsx } from 'react/jsx-runtime';
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
var List = styled.div.withConfig({
|
|
10
|
+
const List = styled.div.withConfig({
|
|
14
11
|
displayName: "MenuList__List",
|
|
15
12
|
componentId: "sc-104rzof-0"
|
|
16
13
|
})(["position:relative;list-style:none;display:flex;flex-direction:column;margin:0;", " li:first-child{z-index:3;}"], spacingsTemplate(menu.spacings));
|
|
@@ -22,49 +19,47 @@ function closeMenuOnClick(item) {
|
|
|
22
19
|
if ( /*#__PURE__*/isValidElement(item) && item.type === MenuItem && item.props.closeMenuOnClick !== false) return true;
|
|
23
20
|
return false;
|
|
24
21
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
22
|
+
const MenuList = /*#__PURE__*/forwardRef(function MenuList({
|
|
23
|
+
addCloseMenuOnClickIndex,
|
|
24
|
+
children,
|
|
25
|
+
...rest
|
|
26
|
+
}, ref) {
|
|
27
|
+
const {
|
|
28
|
+
focusedIndex,
|
|
29
|
+
setFocusedIndex,
|
|
30
|
+
initialFocus
|
|
31
|
+
} = useMenu();
|
|
32
|
+
let index = -1;
|
|
33
|
+
const focusableIndexs = useMemo(() => [], []);
|
|
34
|
+
const updatedChildren = useMemo(() => Children.map(children, child => {
|
|
35
|
+
if (!child) return child;
|
|
36
|
+
if (child.type === MenuSection) {
|
|
37
|
+
index++;
|
|
38
|
+
const menuSectionIndex = index;
|
|
39
|
+
const updatedGrandChildren = Children.map(child.props.children, grandChild => {
|
|
41
40
|
index++;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
index
|
|
45
|
-
if (isIndexable(grandChild)) focusableIndexs.push(index);
|
|
46
|
-
return /*#__PURE__*/cloneElement(grandChild, {
|
|
47
|
-
index: index
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
return /*#__PURE__*/cloneElement(child, {
|
|
51
|
-
index: menuSectionIndex
|
|
52
|
-
}, updatedGrandChildren);
|
|
53
|
-
} else {
|
|
54
|
-
index++;
|
|
55
|
-
if (isIndexable(child)) focusableIndexs.push(index);
|
|
56
|
-
if (closeMenuOnClick(child)) {
|
|
57
|
-
addCloseMenuOnClickIndex(index);
|
|
58
|
-
}
|
|
59
|
-
return /*#__PURE__*/cloneElement(child, {
|
|
60
|
-
index: index
|
|
41
|
+
if (isIndexable(grandChild)) focusableIndexs.push(index);
|
|
42
|
+
return /*#__PURE__*/cloneElement(grandChild, {
|
|
43
|
+
index
|
|
61
44
|
});
|
|
45
|
+
});
|
|
46
|
+
return /*#__PURE__*/cloneElement(child, {
|
|
47
|
+
index: menuSectionIndex
|
|
48
|
+
}, updatedGrandChildren);
|
|
49
|
+
} else {
|
|
50
|
+
index++;
|
|
51
|
+
if (isIndexable(child)) focusableIndexs.push(index);
|
|
52
|
+
if (closeMenuOnClick(child)) {
|
|
53
|
+
addCloseMenuOnClickIndex(index);
|
|
62
54
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
55
|
+
return /*#__PURE__*/cloneElement(child, {
|
|
56
|
+
index
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}), [children, focusableIndexs, index, addCloseMenuOnClickIndex]);
|
|
60
|
+
const firstFocusIndex = focusableIndexs[0];
|
|
61
|
+
const lastFocusIndex = focusableIndexs[focusableIndexs.length - 1];
|
|
62
|
+
useEffect(() => {
|
|
68
63
|
if (initialFocus === 'first') {
|
|
69
64
|
setFocusedIndex(firstFocusIndex);
|
|
70
65
|
}
|
|
@@ -73,15 +68,17 @@ var MenuList = /*#__PURE__*/forwardRef(function MenuList(_ref, ref) {
|
|
|
73
68
|
}
|
|
74
69
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
75
70
|
}, [initialFocus, firstFocusIndex, lastFocusIndex]);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
71
|
+
const handleMenuItemChange = (direction, fallbackIndex) => {
|
|
72
|
+
const i = direction === 'down' ? 1 : -1;
|
|
73
|
+
const currentFocus = focusableIndexs.indexOf(focusedIndex);
|
|
74
|
+
const nextMenuItem = focusableIndexs[currentFocus + i];
|
|
75
|
+
const nextFocusedIndex = typeof nextMenuItem === 'undefined' ? fallbackIndex : nextMenuItem;
|
|
81
76
|
setFocusedIndex(nextFocusedIndex);
|
|
82
77
|
};
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
const handleKeyPress = event => {
|
|
79
|
+
const {
|
|
80
|
+
key
|
|
81
|
+
} = event;
|
|
85
82
|
event.stopPropagation();
|
|
86
83
|
if (key === 'ArrowDown') {
|
|
87
84
|
event.preventDefault();
|
|
@@ -92,13 +89,13 @@ var MenuList = /*#__PURE__*/forwardRef(function MenuList(_ref, ref) {
|
|
|
92
89
|
handleMenuItemChange('up', lastFocusIndex);
|
|
93
90
|
}
|
|
94
91
|
};
|
|
95
|
-
return /*#__PURE__*/jsx(List,
|
|
92
|
+
return /*#__PURE__*/jsx(List, {
|
|
96
93
|
onKeyDown: handleKeyPress,
|
|
97
|
-
role: "menu"
|
|
98
|
-
|
|
94
|
+
role: "menu",
|
|
95
|
+
...rest,
|
|
99
96
|
ref: ref,
|
|
100
97
|
children: updatedChildren
|
|
101
|
-
})
|
|
98
|
+
});
|
|
102
99
|
});
|
|
103
100
|
|
|
104
101
|
// MenuList.displayName = 'EdsMenuList'
|
|
@@ -6,18 +6,18 @@ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
|
6
6
|
import { Divider } from '../Divider/Divider.js';
|
|
7
7
|
import { Typography } from '../Typography/Typography.js';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
}).withConfig({
|
|
9
|
+
const Header = styled.div.attrs(() => ({
|
|
10
|
+
tabIndex: 0
|
|
11
|
+
})).withConfig({
|
|
14
12
|
displayName: "MenuSection__Header",
|
|
15
13
|
componentId: "sc-gfcbvg-0"
|
|
16
14
|
})(["", " &:focus{outline:none;}"], spacingsTemplate(menu.entities.title.spacings));
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
const MenuSection = /*#__PURE__*/memo(function MenuSection(props) {
|
|
16
|
+
const {
|
|
17
|
+
children,
|
|
18
|
+
title,
|
|
19
|
+
index
|
|
20
|
+
} = props;
|
|
21
21
|
return /*#__PURE__*/jsxs(Fragment, {
|
|
22
22
|
children: [index !== 0 && /*#__PURE__*/jsx("div", {
|
|
23
23
|
children: /*#__PURE__*/jsx(Divider, {
|
|
@@ -2,7 +2,7 @@ import { Menu as Menu$1 } from './Menu.js';
|
|
|
2
2
|
import { MenuItem } from './MenuItem.js';
|
|
3
3
|
import { MenuSection } from './MenuSection.js';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const Menu = Menu$1;
|
|
6
6
|
Menu.Item = MenuItem;
|
|
7
7
|
Menu.Section = MenuSection;
|
|
8
8
|
Menu.Item.displayName = 'Menu.Item';
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
|
-
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
3
|
-
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
4
1
|
import { forwardRef, useState } from 'react';
|
|
5
2
|
import styled from 'styled-components';
|
|
6
3
|
import { useIsMounted, useIsomorphicLayoutEffect } from '@equinor/eds-utils';
|
|
@@ -13,63 +10,57 @@ import { PaginationControl } from './paginationControl.js';
|
|
|
13
10
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
14
11
|
import { Typography } from '../Typography/Typography.js';
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
more_horizontal: more_horizontal
|
|
13
|
+
const icons = {
|
|
14
|
+
chevron_left,
|
|
15
|
+
chevron_right,
|
|
16
|
+
more_horizontal
|
|
21
17
|
};
|
|
22
18
|
Icon.add(icons);
|
|
23
|
-
|
|
19
|
+
const Navigation = styled.nav.withConfig({
|
|
24
20
|
displayName: "Pagination__Navigation",
|
|
25
21
|
componentId: "sc-13cpp3o-0"
|
|
26
|
-
})(["display:flex;justify-content:space-between;align-items:center;flex-wrap:nowrap;margin-left:", ";"],
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var OrderedList = styled.ol.withConfig({
|
|
22
|
+
})(["display:flex;justify-content:space-between;align-items:center;flex-wrap:nowrap;margin-left:", ";"], ({
|
|
23
|
+
$withItemIndicator
|
|
24
|
+
}) => $withItemIndicator ? pagination.spacings.left : 0);
|
|
25
|
+
const OrderedList = styled.ol.withConfig({
|
|
31
26
|
displayName: "Pagination__OrderedList",
|
|
32
27
|
componentId: "sc-13cpp3o-1"
|
|
33
28
|
})(["list-style:none;margin:0;padding:0;display:grid;grid-gap:", ";grid-auto-flow:column;"], pagination.spacings.left);
|
|
34
|
-
|
|
29
|
+
const ListItem = styled.li.withConfig({
|
|
35
30
|
displayName: "Pagination__ListItem",
|
|
36
31
|
componentId: "sc-13cpp3o-2"
|
|
37
32
|
})(["display:inline-grid;"]);
|
|
38
|
-
|
|
33
|
+
const StyledIcon = styled(Icon).withConfig({
|
|
39
34
|
displayName: "Pagination__StyledIcon",
|
|
40
35
|
componentId: "sc-13cpp3o-3"
|
|
41
36
|
})(["align-self:center;justify-self:center;fill:", ";"], pagination.entities.icon.typography.color);
|
|
42
|
-
|
|
37
|
+
const FlexContainer = styled.div.withConfig({
|
|
43
38
|
displayName: "Pagination__FlexContainer",
|
|
44
39
|
componentId: "sc-13cpp3o-4"
|
|
45
40
|
})(["display:flex;justify-content:space-between;flex-wrap:nowrap;align-items:center;"]);
|
|
46
|
-
|
|
41
|
+
const Text = styled(Typography).withConfig({
|
|
47
42
|
displayName: "Pagination__Text",
|
|
48
43
|
componentId: "sc-13cpp3o-5"
|
|
49
44
|
})(["white-space:nowrap;"]);
|
|
50
45
|
function getAriaLabel(page, selected) {
|
|
51
|
-
return
|
|
46
|
+
return `${selected === page ? 'Current page, ' : 'Go to '}page ${page}`;
|
|
52
47
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
var columns = pages < 5 ? pages + 2 : 7; // Total pages to display on the control + 2: < and >
|
|
48
|
+
const Pagination = /*#__PURE__*/forwardRef(function Pagination({
|
|
49
|
+
totalItems,
|
|
50
|
+
defaultPage = 1,
|
|
51
|
+
withItemIndicator,
|
|
52
|
+
itemsPerPage = 10,
|
|
53
|
+
onChange,
|
|
54
|
+
...rest
|
|
55
|
+
}, ref) {
|
|
56
|
+
const pages = Math.ceil(totalItems / itemsPerPage); // Total page numbers
|
|
57
|
+
const columns = pages < 5 ? pages + 2 : 7; // Total pages to display on the control + 2: < and >
|
|
64
58
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
setActivePage = _useState2[1];
|
|
69
|
-
var currentItemFirst = activePage === 1 ? 1 : activePage * itemsPerPage - itemsPerPage + 1; // First number of range of items at current page
|
|
70
|
-
var currentItemLast = activePage === pages ? totalItems : activePage * itemsPerPage; // Last number of range of items at current page
|
|
59
|
+
const [activePage, setActivePage] = useState(defaultPage);
|
|
60
|
+
const currentItemFirst = activePage === 1 ? 1 : activePage * itemsPerPage - itemsPerPage + 1; // First number of range of items at current page
|
|
61
|
+
const currentItemLast = activePage === pages ? totalItems : activePage * itemsPerPage; // Last number of range of items at current page
|
|
71
62
|
|
|
72
|
-
|
|
63
|
+
const onPageChange = (event, page) => {
|
|
73
64
|
page && setActivePage(page);
|
|
74
65
|
if (event && onChange) {
|
|
75
66
|
// Callback for provided onChange func
|
|
@@ -78,30 +69,31 @@ var Pagination = /*#__PURE__*/forwardRef(function Pagination(_ref2, ref) {
|
|
|
78
69
|
return undefined;
|
|
79
70
|
}
|
|
80
71
|
};
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
useIsomorphicLayoutEffect(
|
|
72
|
+
const isMounted = useIsMounted();
|
|
73
|
+
const items = PaginationControl(pages, activePage);
|
|
74
|
+
useIsomorphicLayoutEffect(() => {
|
|
84
75
|
if (isMounted) {
|
|
85
76
|
setActivePage(1);
|
|
86
|
-
onChange
|
|
77
|
+
onChange?.(null, 1);
|
|
87
78
|
}
|
|
88
79
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
89
80
|
}, [itemsPerPage]);
|
|
90
|
-
|
|
91
|
-
ref
|
|
92
|
-
$withItemIndicator: withItemIndicator
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
81
|
+
const props = {
|
|
82
|
+
ref,
|
|
83
|
+
$withItemIndicator: withItemIndicator,
|
|
84
|
+
...rest
|
|
85
|
+
};
|
|
86
|
+
const pagination = /*#__PURE__*/jsx(Navigation, {
|
|
87
|
+
"aria-label": "pagination",
|
|
88
|
+
...props,
|
|
97
89
|
children: /*#__PURE__*/jsxs(OrderedList, {
|
|
98
90
|
style: {
|
|
99
|
-
gridTemplateColumns:
|
|
91
|
+
gridTemplateColumns: `repeat(${columns}, 48px)`
|
|
100
92
|
},
|
|
101
93
|
children: [/*#__PURE__*/jsx(ListItem, {
|
|
102
94
|
children: /*#__PURE__*/jsx(Button, {
|
|
103
95
|
variant: "ghost_icon",
|
|
104
|
-
onClick: activePage > 1 ?
|
|
96
|
+
onClick: activePage > 1 ? event => {
|
|
105
97
|
onPageChange(event, activePage - 1);
|
|
106
98
|
} : undefined,
|
|
107
99
|
disabled: activePage === 1,
|
|
@@ -110,31 +102,29 @@ var Pagination = /*#__PURE__*/forwardRef(function Pagination(_ref2, ref) {
|
|
|
110
102
|
name: "chevron_left"
|
|
111
103
|
})
|
|
112
104
|
})
|
|
113
|
-
}, "previous"), items.length > 0 ? items.map(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
, {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
, {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}, "ellipsis-".concat(index));
|
|
134
|
-
}) : undefined, /*#__PURE__*/jsx(ListItem, {
|
|
105
|
+
}, "previous"), items.length > 0 ? items.map((page, index) => page !== 'ELLIPSIS' ? /*#__PURE__*/jsx(ListItem
|
|
106
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
107
|
+
, {
|
|
108
|
+
children: /*#__PURE__*/jsx(PaginationItem, {
|
|
109
|
+
"aria-label": getAriaLabel(page, activePage),
|
|
110
|
+
"aria-current": activePage,
|
|
111
|
+
$page: page,
|
|
112
|
+
selected: page === activePage,
|
|
113
|
+
onClick: event => {
|
|
114
|
+
onPageChange(event, page);
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
}, `list-item ${index}`) : /*#__PURE__*/jsx(ListItem
|
|
118
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
119
|
+
, {
|
|
120
|
+
children: /*#__PURE__*/jsx(StyledIcon, {
|
|
121
|
+
name: "more_horizontal",
|
|
122
|
+
"aria-label": "Ellipsis of pages"
|
|
123
|
+
})
|
|
124
|
+
}, `ellipsis-${index}`)) : undefined, /*#__PURE__*/jsx(ListItem, {
|
|
135
125
|
children: /*#__PURE__*/jsx(Button, {
|
|
136
126
|
variant: "ghost_icon",
|
|
137
|
-
onClick: activePage < pages ?
|
|
127
|
+
onClick: activePage < pages ? event => {
|
|
138
128
|
onPageChange(event, activePage + 1);
|
|
139
129
|
} : undefined,
|
|
140
130
|
"aria-label": "Go to next page",
|
|
@@ -145,10 +135,15 @@ var Pagination = /*#__PURE__*/forwardRef(function Pagination(_ref2, ref) {
|
|
|
145
135
|
})
|
|
146
136
|
}, "next")]
|
|
147
137
|
})
|
|
148
|
-
})
|
|
138
|
+
});
|
|
149
139
|
return withItemIndicator ? /*#__PURE__*/jsxs(FlexContainer, {
|
|
150
140
|
children: [/*#__PURE__*/jsx(Text, {
|
|
151
|
-
children: currentItemFirst !== currentItemLast ?
|
|
141
|
+
children: currentItemFirst !== currentItemLast ? `${currentItemFirst}
|
|
142
|
+
${' - '}
|
|
143
|
+
${currentItemLast}
|
|
144
|
+
${' of '}
|
|
145
|
+
${totalItems}
|
|
146
|
+
${' items'}` : `${currentItemFirst} ${' of '} ${totalItems} ${' items'}`
|
|
152
147
|
}), pagination]
|
|
153
148
|
}) : pagination;
|
|
154
149
|
});
|
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
import { tokens } from '@equinor/eds-tokens';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
const {
|
|
4
|
+
colors: {
|
|
5
|
+
interactive: {
|
|
6
|
+
primary__selected_highlight: {
|
|
7
|
+
rgba: selectedColor
|
|
8
|
+
},
|
|
9
|
+
disabled__text: {
|
|
10
|
+
rgba: disabledColor
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
spacings: {
|
|
15
|
+
comfortable: {
|
|
16
|
+
small: spacingSmall
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
} = tokens;
|
|
20
|
+
const pagination = {
|
|
8
21
|
entities: {
|
|
9
22
|
item: {
|
|
10
23
|
states: {
|
|
@@ -1,31 +1,30 @@
|
|
|
1
|
-
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
|
-
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
3
1
|
import { forwardRef } from 'react';
|
|
4
2
|
import { Button } from '../Button/index.js';
|
|
5
3
|
import { pagination } from './Pagination.tokens.js';
|
|
6
4
|
import { jsx } from 'react/jsx-runtime';
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
ref
|
|
16
|
-
$page
|
|
17
|
-
selected
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
6
|
+
const PaginationItem = /*#__PURE__*/forwardRef(function PaginationItem({
|
|
7
|
+
$page,
|
|
8
|
+
selected,
|
|
9
|
+
onClick,
|
|
10
|
+
...rest
|
|
11
|
+
}, ref) {
|
|
12
|
+
const props = {
|
|
13
|
+
ref,
|
|
14
|
+
$page,
|
|
15
|
+
selected,
|
|
16
|
+
...rest
|
|
17
|
+
};
|
|
18
|
+
const background = selected ? pagination.entities.item.states.active.background : null;
|
|
19
|
+
return /*#__PURE__*/jsx(Button, {
|
|
21
20
|
style: {
|
|
22
|
-
background
|
|
21
|
+
background
|
|
23
22
|
},
|
|
24
23
|
variant: "ghost_icon",
|
|
25
|
-
onClick: onClick ? onClick : undefined
|
|
26
|
-
|
|
24
|
+
onClick: onClick ? onClick : undefined,
|
|
25
|
+
...props,
|
|
27
26
|
children: $page
|
|
28
|
-
})
|
|
27
|
+
});
|
|
29
28
|
});
|
|
30
29
|
|
|
31
30
|
export { PaginationItem };
|
|
@@ -1,40 +1,36 @@
|
|
|
1
|
-
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
2
|
-
|
|
3
1
|
function PaginationControl(pages, activePage) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
const siblings = 1; // amount of siblings on left and right side of active page after trunking
|
|
3
|
+
const totalPagesShown = 7; // amount of total pages before we start trunking pages in ellipsis
|
|
4
|
+
const pagesBeforeEllipsis = 5; // total pages shown before ellipsis and trunking begins
|
|
5
|
+
const ELLIPSIS = 'ELLIPSIS';
|
|
8
6
|
|
|
9
7
|
// Range function from https://dev.to/namirsab/comment/2050
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
const range = (start, end) => {
|
|
9
|
+
const length = end - start + 1;
|
|
12
10
|
return Array.from({
|
|
13
|
-
length
|
|
14
|
-
},
|
|
15
|
-
return start + i;
|
|
16
|
-
});
|
|
11
|
+
length
|
|
12
|
+
}, (_, i) => start + i);
|
|
17
13
|
};
|
|
18
|
-
|
|
14
|
+
let pageRange;
|
|
19
15
|
if (pages > 4) {
|
|
20
|
-
|
|
16
|
+
const startPage = Math.max(1, activePage < pagesBeforeEllipsis || pages <= totalPagesShown ? 1 : activePage + siblings + 1 >= pages ? pages - 4 // - 4 to fit total columns /
|
|
21
17
|
: activePage > 4 && pages > totalPagesShown ? activePage - siblings : 1); // the first page after left ellipsis
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
const endOffset = activePage < pagesBeforeEllipsis && pages > totalPagesShown ? pagesBeforeEllipsis : activePage < pagesBeforeEllipsis && pages <= totalPagesShown ? pages : activePage + siblings + 1 < pages - 1 ? activePage + siblings : activePage + siblings + 1 === pages - 1 ? pages : pages;
|
|
20
|
+
const endPage = Math.min(pages, endOffset); // the last page before right ellipsis
|
|
25
21
|
pageRange = range(startPage, endPage); // range in between ellipsis(es). Ex: range(4, 6) = 1 ... ( 4 5 6 ) ... 10
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
const hiddenLeft = startPage > 2 && pages > totalPagesShown; // Has hidden pages on left side
|
|
24
|
+
const hiddenRight = pages - endPage > 1 && pages > totalPagesShown; // Has hidden pages on right side
|
|
29
25
|
|
|
30
26
|
if (hiddenLeft && !hiddenRight) {
|
|
31
|
-
pageRange = [1, ELLIPSIS]
|
|
27
|
+
pageRange = [1, ELLIPSIS, ...pageRange];
|
|
32
28
|
} else if (!hiddenLeft && hiddenRight) {
|
|
33
|
-
pageRange = [
|
|
29
|
+
pageRange = [...pageRange, ELLIPSIS, pages];
|
|
34
30
|
} else if (hiddenLeft && hiddenRight) {
|
|
35
|
-
pageRange = [1, ELLIPSIS
|
|
31
|
+
pageRange = [1, ELLIPSIS, ...pageRange, ELLIPSIS, pages];
|
|
36
32
|
}
|
|
37
|
-
return
|
|
33
|
+
return [...pageRange];
|
|
38
34
|
}
|
|
39
35
|
return range(1, pages);
|
|
40
36
|
}
|
|
@@ -1,29 +1,26 @@
|
|
|
1
|
-
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
|
-
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
3
1
|
import { forwardRef } from 'react';
|
|
4
2
|
import styled from 'styled-components';
|
|
5
3
|
import { paper, elevation } from './Paper.tokens.js';
|
|
6
4
|
import { jsx } from 'react/jsx-runtime';
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
var StyledPaper = styled.div.withConfig({
|
|
6
|
+
const StyledPaper = styled.div.withConfig({
|
|
10
7
|
displayName: "Paper__StyledPaper",
|
|
11
8
|
componentId: "sc-6ncnv9-0"
|
|
12
|
-
})(["background:", ";box-shadow:", ";"], paper.background,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
rest
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
9
|
+
})(["background:", ";box-shadow:", ";"], paper.background, ({
|
|
10
|
+
$elevation
|
|
11
|
+
}) => $elevation);
|
|
12
|
+
const Paper = /*#__PURE__*/forwardRef(function Paper({
|
|
13
|
+
elevation: elevation$1 = 'none',
|
|
14
|
+
...rest
|
|
15
|
+
}, ref) {
|
|
16
|
+
const props = {
|
|
17
|
+
...rest,
|
|
18
|
+
$elevation: elevation[elevation$1] ?? 'none'
|
|
19
|
+
};
|
|
20
|
+
return /*#__PURE__*/jsx(StyledPaper, {
|
|
21
|
+
...props,
|
|
25
22
|
ref: ref
|
|
26
|
-
})
|
|
23
|
+
});
|
|
27
24
|
});
|
|
28
25
|
|
|
29
26
|
export { Paper };
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { tokens } from '@equinor/eds-tokens';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
const {
|
|
4
|
+
elevation,
|
|
5
|
+
colors: {
|
|
6
|
+
ui: {
|
|
7
|
+
background__default: {
|
|
8
|
+
rgba: background
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
} = tokens;
|
|
13
|
+
const paper = {
|
|
14
|
+
background
|
|
7
15
|
};
|
|
8
16
|
|
|
9
17
|
export { elevation, paper };
|