@oliasoft-open-source/react-ui-library 1.0.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/.eslintignore +2 -0
- package/.eslintrc.js +125 -0
- package/.gitlab-ci.yml +45 -0
- package/.husky/pre-commit +4 -0
- package/.prettierignore +3 -0
- package/.prettierrc +4 -0
- package/.storybook/main.js +36 -0
- package/.storybook/preview.js +40 -0
- package/.storybook/storybook.less +8 -0
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/babel.config.js +31 -0
- package/index.js +76 -0
- package/jest.config.js +9 -0
- package/package.json +136 -0
- package/src/components/accordion/accordion.jsx +132 -0
- package/src/components/accordion/accordion.module.less +66 -0
- package/src/components/accordion/accordion.stories.jsx +171 -0
- package/src/components/accordion/chevron/chevron.jsx +12 -0
- package/src/components/accordion/chevron/chevron.module.less +12 -0
- package/src/components/accordion/helpers/accordion-with-default-toggle.jsx +106 -0
- package/src/components/accordion/helpers/accordion-with-default-toggle.module.less +24 -0
- package/src/components/actions/actions.jsx +129 -0
- package/src/components/actions/actions.module.less +44 -0
- package/src/components/actions/actions.shape.js +32 -0
- package/src/components/actions/actions.stories.jsx +79 -0
- package/src/components/badge/badge.jsx +58 -0
- package/src/components/badge/badge.module.less +55 -0
- package/src/components/badge/badge.stories.jsx +31 -0
- package/src/components/breadcrumb/breadcrumb.jsx +49 -0
- package/src/components/breadcrumb/breadcrumb.module.less +39 -0
- package/src/components/breadcrumb/breadcrumb.stories.jsx +45 -0
- package/src/components/breadcrumb/link.jsx +31 -0
- package/src/components/button/button.jsx +156 -0
- package/src/components/button/button.module.less +300 -0
- package/src/components/button/button.stories.jsx +74 -0
- package/src/components/button-group/button-group.jsx +140 -0
- package/src/components/button-group/button-group.module.less +24 -0
- package/src/components/button-group/button-group.stories-data.jsx +67 -0
- package/src/components/button-group/button-group.stories.jsx +63 -0
- package/src/components/buttons-and-links.stories.mdx +55 -0
- package/src/components/card/card.jsx +51 -0
- package/src/components/card/card.module.less +48 -0
- package/src/components/card/card.stories.jsx +39 -0
- package/src/components/check-box/check-box.jsx +92 -0
- package/src/components/check-box/check-box.module.less +101 -0
- package/src/components/check-box/check-box.stories.jsx +27 -0
- package/src/components/color/color.stories-data.jsx +71 -0
- package/src/components/color/color.stories.mdx +37 -0
- package/src/components/dialog/dialog.jsx +64 -0
- package/src/components/dialog/dialog.module.less +76 -0
- package/src/components/divider/divider.jsx +40 -0
- package/src/components/divider/divider.module.less +28 -0
- package/src/components/divider/divider.stories.jsx +50 -0
- package/src/components/drawer/drawer-tabs.jsx +43 -0
- package/src/components/drawer/drawer.jsx +150 -0
- package/src/components/drawer/drawer.module.less +167 -0
- package/src/components/drawer/drawer.stories.jsx +156 -0
- package/src/components/empty/empty.jsx +52 -0
- package/src/components/empty/empty.module.less +17 -0
- package/src/components/empty/empty.stories.jsx +26 -0
- package/src/components/file-input/file-input.jsx +101 -0
- package/src/components/file-input/file-input.module.less +3 -0
- package/src/components/file-input/file-input.stories.jsx +109 -0
- package/src/components/form/field.jsx +96 -0
- package/src/components/form/field.stories.jsx +101 -0
- package/src/components/form/form.module.less +30 -0
- package/src/components/form/form.stories.jsx +191 -0
- package/src/components/heading/heading.jsx +105 -0
- package/src/components/heading/heading.module.less +59 -0
- package/src/components/heading/heading.stories.jsx +60 -0
- package/src/components/icon/deprecated-icon.jsx +97 -0
- package/src/components/icon/icon.jsx +71 -0
- package/src/components/icon/icon.module.less +33 -0
- package/src/components/icon/icon.stories.jsx +37 -0
- package/src/components/icon/icons.example.module.less +4 -0
- package/src/components/input/input.jsx +167 -0
- package/src/components/input/input.module.less +94 -0
- package/src/components/input/input.stories.jsx +28 -0
- package/src/components/input-group/input-group-addon/input-group-addon.jsx +36 -0
- package/src/components/input-group/input-group-addon/input-group-addon.module.less +31 -0
- package/src/components/input-group/input-group.jsx +51 -0
- package/src/components/input-group/input-group.module.less +10 -0
- package/src/components/input-group/input-group.stories.jsx +77 -0
- package/src/components/input-validation.stories.mdx +61 -0
- package/src/components/inputs.stories.mdx +201 -0
- package/src/components/label/label.jsx +115 -0
- package/src/components/label/label.module.less +43 -0
- package/src/components/label/label.stories.jsx +60 -0
- package/src/components/layout/column/column.jsx +85 -0
- package/src/components/layout/column/styles.js +45 -0
- package/src/components/layout/column.stories.jsx +60 -0
- package/src/components/layout/examples/afe.stories.jsx +180 -0
- package/src/components/layout/examples/blowout.stories.jsx +68 -0
- package/src/components/layout/examples/casing-loads.stories.jsx +297 -0
- package/src/components/layout/examples/formation.stories.jsx +110 -0
- package/src/components/layout/examples/projects.stories.jsx +108 -0
- package/src/components/layout/examples/reservoirs.stories.jsx +211 -0
- package/src/components/layout/examples/site.stories.jsx +263 -0
- package/src/components/layout/flex/flex.jsx +48 -0
- package/src/components/layout/flex/flex.stories.jsx +54 -0
- package/src/components/layout/form-row/form-row.jsx +15 -0
- package/src/components/layout/form-row/form-row.module.less +11 -0
- package/src/components/layout/grid/grid.jsx +62 -0
- package/src/components/layout/grid/grid.stories.jsx +65 -0
- package/src/components/layout/page/page.jsx +42 -0
- package/src/components/layout/page/page.module.less +27 -0
- package/src/components/layout/page.stories.jsx +93 -0
- package/src/components/layout/placeholder.jsx +2 -0
- package/src/components/layout/print-header/print-header.jsx +22 -0
- package/src/components/layout/print-header/print-header.module.less +9 -0
- package/src/components/layout/row/row.jsx +75 -0
- package/src/components/layout/row/row.module.less +7 -0
- package/src/components/layout/spacer/spacer.jsx +26 -0
- package/src/components/layout/spacer/spacer.stories.jsx +50 -0
- package/src/components/layout-forms.stories.mdx +104 -0
- package/src/components/layout-general.stories.mdx +215 -0
- package/src/components/list/list-row/item-content.jsx +15 -0
- package/src/components/list/list-row/label.jsx +11 -0
- package/src/components/list/list-row/list-heading.jsx +52 -0
- package/src/components/list/list-row/list-row.jsx +128 -0
- package/src/components/list/list-row/list-subheading.jsx +72 -0
- package/src/components/list/list-row/meta-content.jsx +24 -0
- package/src/components/list/list-row/meta-count.jsx +10 -0
- package/src/components/list/list-row/name.jsx +45 -0
- package/src/components/list/list.jsx +276 -0
- package/src/components/list/list.module.less +256 -0
- package/src/components/list/list.stories-data.jsx +287 -0
- package/src/components/list/list.stories.jsx +458 -0
- package/src/components/list/toggle-narrow.jsx +13 -0
- package/src/components/loader/loader.jsx +63 -0
- package/src/components/loader/loader.module.less +63 -0
- package/src/components/loader/loader.stories.jsx +155 -0
- package/src/components/menu/index.js +7 -0
- package/src/components/menu/layer/divider.jsx +4 -0
- package/src/components/menu/layer/heading.jsx +15 -0
- package/src/components/menu/layer/layer.jsx +82 -0
- package/src/components/menu/layer/option.jsx +77 -0
- package/src/components/menu/layer/path.js +44 -0
- package/src/components/menu/layer/placementOptions.js +6 -0
- package/src/components/menu/layer/section.jsx +66 -0
- package/src/components/menu/menu.jsx +359 -0
- package/src/components/menu/menu.module.less +241 -0
- package/src/components/menu/menu.stories-data.jsx +168 -0
- package/src/components/menu/menu.stories.jsx +126 -0
- package/src/components/menu/menu.test.js +58 -0
- package/src/components/menu/trigger/button.jsx +50 -0
- package/src/components/menu/trigger/component.jsx +14 -0
- package/src/components/menu/trigger/text.jsx +25 -0
- package/src/components/menu/trigger/trigger.jsx +86 -0
- package/src/components/message/dismiss.jsx +26 -0
- package/src/components/message/message.jsx +137 -0
- package/src/components/message/message.module.less +114 -0
- package/src/components/message/message.stories.jsx +84 -0
- package/src/components/modal/modal.jsx +50 -0
- package/src/components/modal/modal.module.less +35 -0
- package/src/components/modal/modal.stories.jsx +159 -0
- package/src/components/option-dropdown/heading.jsx +6 -0
- package/src/components/option-dropdown/layer.jsx +81 -0
- package/src/components/option-dropdown/option-dropdown.jsx +53 -0
- package/src/components/option-dropdown/option-dropdown.module.less +50 -0
- package/src/components/option-dropdown/option-dropdown.stories.jsx +35 -0
- package/src/components/option-dropdown/option.jsx +13 -0
- package/src/components/pagination/pagination.jsx +139 -0
- package/src/components/pagination/pagination.module.less +11 -0
- package/src/components/pagination/pagination.stories.jsx +78 -0
- package/src/components/pagination/pagination.test.js +92 -0
- package/src/components/pagination/pagination.viewdata.js +66 -0
- package/src/components/pop-confirm/content.jsx +25 -0
- package/src/components/pop-confirm/pop-confirm.jsx +61 -0
- package/src/components/pop-confirm/pop-confirm.module.less +18 -0
- package/src/components/pop-confirm/pop-confirm.stories.jsx +53 -0
- package/src/components/popover/popover.jsx +112 -0
- package/src/components/popover/popover.module.less +22 -0
- package/src/components/popover/popover.stories.jsx +59 -0
- package/src/components/portal/portal.jsx +16 -0
- package/src/components/portal/portal.stories.jsx +69 -0
- package/src/components/progress-bar/progress-bar.jsx +64 -0
- package/src/components/progress-bar/progress-bar.module.less +64 -0
- package/src/components/progress-bar/progress-bar.stories.jsx +23 -0
- package/src/components/radio-button/radio-button.jsx +139 -0
- package/src/components/radio-button/radio-button.module.less +135 -0
- package/src/components/radio-button/radio-button.stories.jsx +37 -0
- package/src/components/radio-button/radio-input.jsx +52 -0
- package/src/components/select/custom-select/custom-select.jsx +440 -0
- package/src/components/select/custom-select/custom-select.module.less +123 -0
- package/src/components/select/custom-select/custom-select.reducer.js +157 -0
- package/src/components/select/custom-select/layer/heading.jsx +13 -0
- package/src/components/select/custom-select/layer/layer.jsx +73 -0
- package/src/components/select/custom-select/layer/option.jsx +54 -0
- package/src/components/select/custom-select/layer/placementOptions.js +7 -0
- package/src/components/select/custom-select/layer/section.jsx +35 -0
- package/src/components/select/custom-select/trigger/input.jsx +100 -0
- package/src/components/select/custom-select/trigger/trigger.jsx +155 -0
- package/src/components/select/custom-select/trigger/trigger.module.less +289 -0
- package/src/components/select/native-select/native-select.jsx +198 -0
- package/src/components/select/native-select/native-select.module.less +107 -0
- package/src/components/select/select.input.js +146 -0
- package/src/components/select/select.jsx +207 -0
- package/src/components/select/select.stories-data.jsx +92 -0
- package/src/components/select/select.stories.jsx +135 -0
- package/src/components/select/select.test.js +519 -0
- package/src/components/side-bar/container.module.less +29 -0
- package/src/components/side-bar/link.jsx +83 -0
- package/src/components/side-bar/sections.jsx +23 -0
- package/src/components/side-bar/side-bar.jsx +102 -0
- package/src/components/side-bar/side-bar.module.less +137 -0
- package/src/components/side-bar/side-bar.stories.jsx +101 -0
- package/src/components/slider/rc-slider.less +47 -0
- package/src/components/slider/slider-tooltip.jsx +20 -0
- package/src/components/slider/slider.jsx +233 -0
- package/src/components/slider/slider.module.less +40 -0
- package/src/components/slider/slider.stories.jsx +110 -0
- package/src/components/spinner/spinner.jsx +37 -0
- package/src/components/spinner/spinner.module.less +115 -0
- package/src/components/spinner/spinner.stories.jsx +24 -0
- package/src/components/table/cell/cell.jsx +614 -0
- package/src/components/table/cell/cell.module.less +152 -0
- package/src/components/table/footer/footer.jsx +66 -0
- package/src/components/table/footer/footer.module.less +14 -0
- package/src/components/table/helper.js +64 -0
- package/src/components/table/helper.test.js +166 -0
- package/src/components/table/icon/icon.module.less +31 -0
- package/src/components/table/row/expanded-content-row.jsx +16 -0
- package/src/components/table/row/row.jsx +253 -0
- package/src/components/table/row/row.module.less +62 -0
- package/src/components/table/table-scroll-wrapper.jsx +48 -0
- package/src/components/table/table.jsx +232 -0
- package/src/components/table/table.module.less +145 -0
- package/src/components/table/table.stories-data.jsx +752 -0
- package/src/components/table/table.stories.jsx +814 -0
- package/src/components/table/table.test.js +30 -0
- package/src/components/table/table.variables.less +19 -0
- package/src/components/table/table.viewdata.js +26 -0
- package/src/components/table/title/title.jsx +30 -0
- package/src/components/table/title/title.module.less +9 -0
- package/src/components/tabs/content.jsx +14 -0
- package/src/components/tabs/label.jsx +50 -0
- package/src/components/tabs/tabs.jsx +191 -0
- package/src/components/tabs/tabs.module.less +73 -0
- package/src/components/tabs/tabs.stories.jsx +110 -0
- package/src/components/text/text.jsx +64 -0
- package/src/components/text/text.module.less +45 -0
- package/src/components/text/text.stories.jsx +31 -0
- package/src/components/text-link/text-link.jsx +23 -0
- package/src/components/text-link/text-link.stories.jsx +20 -0
- package/src/components/textarea/textarea.jsx +126 -0
- package/src/components/textarea/textarea.module.less +55 -0
- package/src/components/textarea/textarea.stories.jsx +26 -0
- package/src/components/toaster/toaster.jsx +39 -0
- package/src/components/toaster/toaster.less +17 -0
- package/src/components/toaster/toaster.stories.jsx +116 -0
- package/src/components/toggle/toggle.jsx +65 -0
- package/src/components/toggle/toggle.module.less +139 -0
- package/src/components/toggle/toggle.stories.jsx +26 -0
- package/src/components/tooltip/tooltip-layer.jsx +72 -0
- package/src/components/tooltip/tooltip.jsx +108 -0
- package/src/components/tooltip/tooltip.module.less +28 -0
- package/src/components/tooltip/tooltip.stories.jsx +71 -0
- package/src/components/top-bar/element/element.jsx +72 -0
- package/src/components/top-bar/element/link.jsx +29 -0
- package/src/components/top-bar/title.jsx +24 -0
- package/src/components/top-bar/top-bar.jsx +79 -0
- package/src/components/top-bar/top-bar.module.less +191 -0
- package/src/components/top-bar/top-bar.stories.jsx +137 -0
- package/src/components/top-bar/warning.jsx +6 -0
- package/src/components/tree/tree-item.jsx +79 -0
- package/src/components/tree/tree-placeholder.jsx +6 -0
- package/src/components/tree/tree.jsx +129 -0
- package/src/components/tree/tree.module.less +33 -0
- package/src/components/tree/tree.stories-data.jsx +89 -0
- package/src/components/tree/tree.stories.jsx +106 -0
- package/src/docs/components/page/page.jsx +16 -0
- package/src/docs/config/config.js +1 -0
- package/src/docs/html/favicon.png +0 -0
- package/src/docs/html/index.html +11 -0
- package/src/docs/navigation/footer/footer.jsx +48 -0
- package/src/docs/navigation/header/header.jsx +39 -0
- package/src/docs/navigation/header/header.module.less +32 -0
- package/src/docs/navigation/routes/routes.jsx +16 -0
- package/src/docs/start.jsx +12 -0
- package/src/docs/views/main/main.jsx +209 -0
- package/src/docs/views/main/main.module.less +14 -0
- package/src/docs/views/not-found/not-found.jsx +5 -0
- package/src/helpers/disabled-context.js +8 -0
- package/src/helpers/styles.js +68 -0
- package/src/helpers/text.js +6 -0
- package/src/helpers/types.js +5 -0
- package/src/hooks/index.js +3 -0
- package/src/hooks/use-focus.js +11 -0
- package/src/hooks/use-keyboard-event.js +16 -0
- package/src/hooks/use-window-width.js +20 -0
- package/src/images/icons/icon-drop.png +0 -0
- package/src/images/icons/icon-share.png +0 -0
- package/src/images/icons/icons8-junction.svg +4 -0
- package/src/images/logo.png +0 -0
- package/src/images/logo.svg +13 -0
- package/src/images/oliasoft-logo.svg +1 -0
- package/src/style/colors.less +26 -0
- package/src/style/external.less +10 -0
- package/src/style/fonts/lato/Lato-Bold.woff2 +0 -0
- package/src/style/fonts/lato/Lato-BoldItalic.woff2 +0 -0
- package/src/style/fonts/lato/Lato-Italic.woff2 +0 -0
- package/src/style/fonts/lato/Lato-Regular.woff2 +0 -0
- package/src/style/fonts.less +27 -0
- package/src/style/global.less +51 -0
- package/src/style/mixins.less +67 -0
- package/src/style/reset/reset.less +34 -0
- package/src/style/shared.less +25 -0
- package/src/style/theme.dark.less +37 -0
- package/src/style/theme.default.less +74 -0
- package/src/style/variables.less +49 -0
- package/webpack/webpack.common.js +39 -0
- package/webpack/webpack.common.rules.js +102 -0
- package/webpack/webpack.dev.js +22 -0
- package/webpack/webpack.prod.js +23 -0
- package/webpack/webpack.resolve.js +22 -0
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
import React, { useReducer, useState } from 'react';
|
|
2
|
+
import produce from 'immer';
|
|
3
|
+
import { FaPlus, FaTrash } from 'react-icons/fa';
|
|
4
|
+
import { List, ListHeading, ListSubheading, Flex } from '../../..';
|
|
5
|
+
import * as storyData from './list.stories-data';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
title: 'Basic/List',
|
|
9
|
+
component: List,
|
|
10
|
+
args: {
|
|
11
|
+
list: storyData.list,
|
|
12
|
+
noHeader: true,
|
|
13
|
+
},
|
|
14
|
+
parameters: {
|
|
15
|
+
layout: 'fullscreen',
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const Template = (args) => {
|
|
20
|
+
return (
|
|
21
|
+
<List
|
|
22
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
23
|
+
{...args}
|
|
24
|
+
/>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const Default = Template.bind({});
|
|
29
|
+
|
|
30
|
+
export const Actions = Template.bind({});
|
|
31
|
+
Actions.args = { list: storyData.listActions };
|
|
32
|
+
|
|
33
|
+
export const Menus = Template.bind({});
|
|
34
|
+
Menus.args = { list: storyData.listSubmenus };
|
|
35
|
+
|
|
36
|
+
export const Details = Template.bind({});
|
|
37
|
+
Details.args = { list: storyData.listDetails };
|
|
38
|
+
|
|
39
|
+
export const Expanding = Template.bind({});
|
|
40
|
+
Expanding.args = { list: storyData.listExpanding, expanding: true };
|
|
41
|
+
|
|
42
|
+
export const Header = Template.bind({});
|
|
43
|
+
Header.args = { list: storyData.listHeader, noHeader: false };
|
|
44
|
+
|
|
45
|
+
export const Badges = Template.bind({});
|
|
46
|
+
Badges.args = { list: storyData.listBadges };
|
|
47
|
+
|
|
48
|
+
export const Nested = Template.bind({});
|
|
49
|
+
Nested.args = { list: storyData.listNested };
|
|
50
|
+
|
|
51
|
+
export const InvalidItems = Template.bind({});
|
|
52
|
+
InvalidItems.args = { list: storyData.listInvalid };
|
|
53
|
+
|
|
54
|
+
export const Bordered = Template.bind({});
|
|
55
|
+
Bordered.args = { bordered: true };
|
|
56
|
+
|
|
57
|
+
export const IconWithTooltip = Template.bind({});
|
|
58
|
+
IconWithTooltip.args = { list: storyData.listIconTooltip };
|
|
59
|
+
|
|
60
|
+
export const Metacount = Template.bind({});
|
|
61
|
+
Metacount.args = { list: storyData.listCounts };
|
|
62
|
+
|
|
63
|
+
export const StickyHeader = Template.bind({});
|
|
64
|
+
StickyHeader.args = {
|
|
65
|
+
list: storyData.listLong,
|
|
66
|
+
noHeader: false,
|
|
67
|
+
stickyHeader: true,
|
|
68
|
+
};
|
|
69
|
+
StickyHeader.parameters = {
|
|
70
|
+
docs: {
|
|
71
|
+
inlineStories: false,
|
|
72
|
+
iframeHeight: 200,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const Scrollable = Template.bind({});
|
|
77
|
+
Scrollable.args = {
|
|
78
|
+
list: storyData.listLong,
|
|
79
|
+
scrollDetails: {
|
|
80
|
+
scrollable: true,
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
Scrollable.parameters = {
|
|
84
|
+
docs: {
|
|
85
|
+
description: {
|
|
86
|
+
story:
|
|
87
|
+
'Adds an internal scrollbar to the `List`, which will fill its parent height unless a `height` is set. The scrollbar can be toggled using `hideScrollbar`.',
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
Scrollable.decorators = [
|
|
92
|
+
(story) => <div style={{ height: 200, overflow: 'hidden' }}>{story()}</div>,
|
|
93
|
+
];
|
|
94
|
+
|
|
95
|
+
// TODO: Fix this story in Docs (works in Canvas)
|
|
96
|
+
export const InfiniteScroll = Template.bind({});
|
|
97
|
+
InfiniteScroll.args = {
|
|
98
|
+
list: storyData.listLong,
|
|
99
|
+
scrollDetails: {
|
|
100
|
+
scrollable: true,
|
|
101
|
+
infiniteScroll: true,
|
|
102
|
+
limit: 10,
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
InfiniteScroll.decorators = [
|
|
106
|
+
(story) => <div style={{ height: 200, overflow: 'auto' }}>{story()}</div>,
|
|
107
|
+
];
|
|
108
|
+
|
|
109
|
+
export const ScrollToActiveItem = () => {
|
|
110
|
+
const reducer = (state, action) => {
|
|
111
|
+
switch (action.type) {
|
|
112
|
+
case 'headingClicked': {
|
|
113
|
+
const { headingKey } = action.payload;
|
|
114
|
+
return produce(state, (draft) => {
|
|
115
|
+
const heading = draft[headingKey];
|
|
116
|
+
heading.expanded = !heading.expanded;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
case 'itemClicked': {
|
|
120
|
+
const { headingKey, itemIndex } = action.payload;
|
|
121
|
+
return produce(state, (draft) => {
|
|
122
|
+
Object.keys(draft).forEach((key) => {
|
|
123
|
+
draft[key].items.forEach((item, i) => {
|
|
124
|
+
item.active = key === headingKey && i === itemIndex;
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
case 'addClicked': {
|
|
130
|
+
const { headingKey } = action.payload;
|
|
131
|
+
return produce(state, (draft) => {
|
|
132
|
+
const heading = draft[headingKey];
|
|
133
|
+
heading.expanded = true;
|
|
134
|
+
heading.items.push({
|
|
135
|
+
name: `${heading.label} #${heading.items.length + 1}`,
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
case 'deleteClicked': {
|
|
140
|
+
const { headingKey, itemIndex } = action.payload;
|
|
141
|
+
return produce(state, (draft) => {
|
|
142
|
+
let { items } = draft[headingKey];
|
|
143
|
+
delete items[itemIndex];
|
|
144
|
+
draft[headingKey].items = items.filter((i) => i); //remove empty slots
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
default:
|
|
148
|
+
return state;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
const initialState = () => ({
|
|
152
|
+
mammals: {
|
|
153
|
+
draggable: true,
|
|
154
|
+
name: 'Mammals',
|
|
155
|
+
key: 'mammals',
|
|
156
|
+
label: 'Mammals',
|
|
157
|
+
expanded: true,
|
|
158
|
+
items: [
|
|
159
|
+
{ name: 'Click item to scroll', type: 'Heading' },
|
|
160
|
+
{ name: 'Mammal #1', active: true },
|
|
161
|
+
{ name: 'Mammal #2' },
|
|
162
|
+
{ name: 'Mammal #3' },
|
|
163
|
+
{ name: 'Mammal #4' },
|
|
164
|
+
{ name: 'Mammal #5' },
|
|
165
|
+
{ name: 'Mammal #6' },
|
|
166
|
+
{ name: 'Mammal #7' },
|
|
167
|
+
{ name: 'Mammal #8' },
|
|
168
|
+
{ name: 'Mammal #9' },
|
|
169
|
+
{ name: 'Mammal #10' },
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
amphibians: {
|
|
173
|
+
name: 'Amphibians (sticky header)',
|
|
174
|
+
key: 'amphibians',
|
|
175
|
+
label: 'Amphibians',
|
|
176
|
+
expanded: true,
|
|
177
|
+
items: [
|
|
178
|
+
{ name: 'Click item to scroll', type: 'Heading' },
|
|
179
|
+
{ name: 'Amphibian #1', active: true },
|
|
180
|
+
{ name: 'Amphibian #2' },
|
|
181
|
+
{ name: 'Amphibian #3' },
|
|
182
|
+
{ name: 'Amphibian #4' },
|
|
183
|
+
{ name: 'Amphibian #5' },
|
|
184
|
+
{ name: 'Amphibian #6' },
|
|
185
|
+
{ name: 'Amphibian #7' },
|
|
186
|
+
{ name: 'Amphibian #8' },
|
|
187
|
+
{ name: 'Amphibian #9' },
|
|
188
|
+
{ name: 'Amphibian #10' },
|
|
189
|
+
],
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
const [state, dispatch] = useReducer(reducer, {}, () => initialState());
|
|
193
|
+
const [triggerScroll, setTriggerScroll] = useState(false);
|
|
194
|
+
const onClickItem = (headingKey, itemIndex) => {
|
|
195
|
+
setTriggerScroll(true);
|
|
196
|
+
dispatch({
|
|
197
|
+
type: 'itemClicked',
|
|
198
|
+
payload: { headingKey, itemIndex },
|
|
199
|
+
});
|
|
200
|
+
// will execute after stack is cleared
|
|
201
|
+
setTimeout(() => setTriggerScroll(false), 0);
|
|
202
|
+
};
|
|
203
|
+
const onAddItem = (headingKey) => {
|
|
204
|
+
dispatch({ type: 'addClicked', payload: { headingKey } });
|
|
205
|
+
};
|
|
206
|
+
const onDeleteItem = (headingKey, itemIndex) =>
|
|
207
|
+
dispatch({
|
|
208
|
+
type: 'deleteClicked',
|
|
209
|
+
payload: { headingKey, itemIndex },
|
|
210
|
+
});
|
|
211
|
+
const { mammals, amphibians } = state;
|
|
212
|
+
const hydrateList = (list) => ({
|
|
213
|
+
...list,
|
|
214
|
+
actions: [
|
|
215
|
+
{
|
|
216
|
+
label: 'Add',
|
|
217
|
+
primary: true,
|
|
218
|
+
icon: <FaPlus />,
|
|
219
|
+
onClick: () => onAddItem(list.key),
|
|
220
|
+
},
|
|
221
|
+
],
|
|
222
|
+
items: list.items.map((item, itemIndex) => {
|
|
223
|
+
if (item.type == 'Heading') {
|
|
224
|
+
return {
|
|
225
|
+
...item,
|
|
226
|
+
id: itemIndex,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
return {
|
|
230
|
+
...item,
|
|
231
|
+
id: itemIndex,
|
|
232
|
+
onClick: () => onClickItem(list.key, itemIndex),
|
|
233
|
+
actions: [
|
|
234
|
+
{
|
|
235
|
+
label: 'Delete',
|
|
236
|
+
icon: <FaTrash />,
|
|
237
|
+
onClick: () => onDeleteItem(list.key, itemIndex),
|
|
238
|
+
},
|
|
239
|
+
],
|
|
240
|
+
};
|
|
241
|
+
}),
|
|
242
|
+
});
|
|
243
|
+
const height = 300;
|
|
244
|
+
return (
|
|
245
|
+
<Flex gap>
|
|
246
|
+
<List
|
|
247
|
+
list={hydrateList(mammals)}
|
|
248
|
+
bordered
|
|
249
|
+
height={height}
|
|
250
|
+
scrollDetails={{
|
|
251
|
+
scrollable: true,
|
|
252
|
+
hideScrollbar: false,
|
|
253
|
+
triggerScrollToActiveItem: triggerScroll,
|
|
254
|
+
}}
|
|
255
|
+
/>
|
|
256
|
+
<List
|
|
257
|
+
list={hydrateList(amphibians)}
|
|
258
|
+
bordered
|
|
259
|
+
stickyHeader
|
|
260
|
+
height={height}
|
|
261
|
+
scrollDetails={{
|
|
262
|
+
scrollable: true,
|
|
263
|
+
hideScrollbar: false,
|
|
264
|
+
triggerScrollToActiveItem: triggerScroll,
|
|
265
|
+
}}
|
|
266
|
+
/>
|
|
267
|
+
</Flex>
|
|
268
|
+
);
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
export const HeadingsManaged = () => {
|
|
272
|
+
const reducer = (state, action) => {
|
|
273
|
+
switch (action.type) {
|
|
274
|
+
case 'headingClicked': {
|
|
275
|
+
const { headingKey } = action.payload;
|
|
276
|
+
return produce(state, (draft) => {
|
|
277
|
+
const heading = draft[headingKey];
|
|
278
|
+
heading.expanded = !heading.expanded;
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
case 'itemClicked': {
|
|
282
|
+
const { headingKey, itemIndex } = action.payload;
|
|
283
|
+
return produce(state, (draft) => {
|
|
284
|
+
Object.keys(draft).forEach((key) => {
|
|
285
|
+
draft[key].items.forEach((item, i) => {
|
|
286
|
+
item.active = key === headingKey && i === itemIndex;
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
case 'addClicked': {
|
|
292
|
+
const { headingKey } = action.payload;
|
|
293
|
+
return produce(state, (draft) => {
|
|
294
|
+
const heading = draft[headingKey];
|
|
295
|
+
heading.expanded = true;
|
|
296
|
+
heading.items.push({
|
|
297
|
+
name: `${heading.label} #${heading.items.length + 1}`,
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
case 'deleteClicked': {
|
|
302
|
+
const { headingKey, itemIndex } = action.payload;
|
|
303
|
+
return produce(state, (draft) => {
|
|
304
|
+
let { items } = draft[headingKey];
|
|
305
|
+
delete items[itemIndex];
|
|
306
|
+
draft[headingKey].items = items.filter((i) => i); //remove empty slots
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
default:
|
|
310
|
+
return state;
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
const initialState = () => ({
|
|
314
|
+
mammals: {
|
|
315
|
+
key: 'mammals',
|
|
316
|
+
label: 'Mammals',
|
|
317
|
+
expanded: true,
|
|
318
|
+
items: [{ name: 'Aardvark', active: true }, { name: 'Kangaroo' }],
|
|
319
|
+
},
|
|
320
|
+
amphibians: {
|
|
321
|
+
key: 'amphibians',
|
|
322
|
+
label: 'Amphibians',
|
|
323
|
+
expanded: true,
|
|
324
|
+
items: [{ name: 'Frog' }],
|
|
325
|
+
},
|
|
326
|
+
});
|
|
327
|
+
const [state, dispatch] = useReducer(reducer, {}, () => initialState());
|
|
328
|
+
const onClickHeading = (headingKey) =>
|
|
329
|
+
dispatch({ type: 'headingClicked', payload: { headingKey } });
|
|
330
|
+
const onClickItem = (headingKey, itemIndex) =>
|
|
331
|
+
dispatch({
|
|
332
|
+
type: 'itemClicked',
|
|
333
|
+
payload: { headingKey, itemIndex },
|
|
334
|
+
});
|
|
335
|
+
const onAddItem = (headingKey) =>
|
|
336
|
+
dispatch({ type: 'addClicked', payload: { headingKey } });
|
|
337
|
+
const onDeleteItem = (headingKey, itemIndex) =>
|
|
338
|
+
dispatch({
|
|
339
|
+
type: 'deleteClicked',
|
|
340
|
+
payload: { headingKey, itemIndex },
|
|
341
|
+
});
|
|
342
|
+
const { mammals, amphibians } = state;
|
|
343
|
+
const hydrateHeading = (list) => ({
|
|
344
|
+
name: list.label,
|
|
345
|
+
metaCount: list.items.length,
|
|
346
|
+
expanded: list.expanded,
|
|
347
|
+
onClick: () => onClickHeading(list.key),
|
|
348
|
+
actions: [
|
|
349
|
+
{
|
|
350
|
+
label: 'Add',
|
|
351
|
+
primary: true,
|
|
352
|
+
icon: <FaPlus />,
|
|
353
|
+
onClick: () => onAddItem(list.key),
|
|
354
|
+
},
|
|
355
|
+
],
|
|
356
|
+
});
|
|
357
|
+
const hydrateList = (list) => ({
|
|
358
|
+
...list,
|
|
359
|
+
items: list.items.map((item, itemIndex) => ({
|
|
360
|
+
...item,
|
|
361
|
+
id: itemIndex,
|
|
362
|
+
onClick: () => onClickItem(list.key, itemIndex),
|
|
363
|
+
actions: [
|
|
364
|
+
{
|
|
365
|
+
label: 'Delete',
|
|
366
|
+
icon: <FaTrash />,
|
|
367
|
+
onClick: () => onDeleteItem(list.key, itemIndex),
|
|
368
|
+
},
|
|
369
|
+
],
|
|
370
|
+
})),
|
|
371
|
+
});
|
|
372
|
+
return (
|
|
373
|
+
<>
|
|
374
|
+
<ListHeading name="Animals" />
|
|
375
|
+
<ListSubheading item={hydrateHeading(mammals)} />
|
|
376
|
+
{mammals.expanded && <List noHeader list={hydrateList(mammals)} />}
|
|
377
|
+
<ListSubheading item={hydrateHeading(amphibians)} />
|
|
378
|
+
{amphibians.expanded && <List noHeader list={hydrateList(amphibians)} />}
|
|
379
|
+
</>
|
|
380
|
+
);
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
export const ManagedDragAndDrop = () => {
|
|
384
|
+
const arraymove = (arr, from, to) => {
|
|
385
|
+
if (isNaN(from) || isNaN(to) || from === to) {
|
|
386
|
+
return arr;
|
|
387
|
+
}
|
|
388
|
+
const copy = [...arr];
|
|
389
|
+
copy.splice(to, 0, copy.splice(from, 1)[0]);
|
|
390
|
+
return copy;
|
|
391
|
+
};
|
|
392
|
+
const beautifulDnD = {
|
|
393
|
+
name: 'List Name',
|
|
394
|
+
draggable: true,
|
|
395
|
+
items: [
|
|
396
|
+
{
|
|
397
|
+
id: 1,
|
|
398
|
+
name: 'element 1',
|
|
399
|
+
actions: [
|
|
400
|
+
{
|
|
401
|
+
label: 'Delete',
|
|
402
|
+
icon: <FaTrash />,
|
|
403
|
+
onClick: () => {},
|
|
404
|
+
},
|
|
405
|
+
],
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
id: 2,
|
|
409
|
+
name: 'element 2',
|
|
410
|
+
actions: [
|
|
411
|
+
{
|
|
412
|
+
label: 'Delete',
|
|
413
|
+
icon: <FaTrash />,
|
|
414
|
+
onClick: () => {},
|
|
415
|
+
},
|
|
416
|
+
],
|
|
417
|
+
},
|
|
418
|
+
{
|
|
419
|
+
id: 3,
|
|
420
|
+
name: 'element 3',
|
|
421
|
+
},
|
|
422
|
+
{
|
|
423
|
+
id: 4,
|
|
424
|
+
name: 'element 4',
|
|
425
|
+
actions: [
|
|
426
|
+
{
|
|
427
|
+
label: 'Delete',
|
|
428
|
+
icon: <FaTrash />,
|
|
429
|
+
onClick: () => {},
|
|
430
|
+
},
|
|
431
|
+
],
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
id: 5,
|
|
435
|
+
name: 'element 5',
|
|
436
|
+
actions: [
|
|
437
|
+
{
|
|
438
|
+
label: 'Delete',
|
|
439
|
+
icon: <FaTrash />,
|
|
440
|
+
onClick: () => {},
|
|
441
|
+
},
|
|
442
|
+
],
|
|
443
|
+
},
|
|
444
|
+
],
|
|
445
|
+
};
|
|
446
|
+
const [reorderedItems, setReorderedItems] = useState(beautifulDnD.items);
|
|
447
|
+
const onListReorder = (reorderData) => {
|
|
448
|
+
const { to, from } = reorderData;
|
|
449
|
+
setReorderedItems(arraymove(reorderedItems, from, to));
|
|
450
|
+
};
|
|
451
|
+
return (
|
|
452
|
+
<List
|
|
453
|
+
list={{ ...beautifulDnD, items: reorderedItems }}
|
|
454
|
+
draggable
|
|
455
|
+
onListReorder={onListReorder}
|
|
456
|
+
/>
|
|
457
|
+
);
|
|
458
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FaChevronLeft } from 'react-icons/fa';
|
|
3
|
+
import { Icon } from '../icon/icon';
|
|
4
|
+
import styles from './list.module.less';
|
|
5
|
+
|
|
6
|
+
export const ToggleNarrow = ({ toggleNarrow, onClickToggleNarrow }) => {
|
|
7
|
+
return toggleNarrow ? (
|
|
8
|
+
// eslint-disable-next-line jsx-a11y/anchor-is-valid
|
|
9
|
+
<a className={styles.toggleNarrow} onClick={onClickToggleNarrow}>
|
|
10
|
+
<Icon icon={<FaChevronLeft />} />
|
|
11
|
+
</a>
|
|
12
|
+
) : null;
|
|
13
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import cx from 'classnames';
|
|
4
|
+
import styles from './loader.module.less';
|
|
5
|
+
|
|
6
|
+
export const Loader = ({
|
|
7
|
+
width,
|
|
8
|
+
height,
|
|
9
|
+
text,
|
|
10
|
+
details,
|
|
11
|
+
fullViewPortSize,
|
|
12
|
+
cover,
|
|
13
|
+
children,
|
|
14
|
+
theme,
|
|
15
|
+
}) => {
|
|
16
|
+
const color = theme === 'dark' ? 'white' : 'inherit';
|
|
17
|
+
|
|
18
|
+
const background =
|
|
19
|
+
theme === 'white'
|
|
20
|
+
? 'var(--color-background-raised)'
|
|
21
|
+
: theme === 'light'
|
|
22
|
+
? 'var(--color-background)'
|
|
23
|
+
: 'black';
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<div
|
|
27
|
+
className={cx(styles.loader, cover ? styles.cover : '', {
|
|
28
|
+
[styles.fullViewPortSize]: fullViewPortSize,
|
|
29
|
+
})}
|
|
30
|
+
style={{ width, height }}
|
|
31
|
+
>
|
|
32
|
+
<div className={styles.dimmer} style={{ background, color }}>
|
|
33
|
+
<div className={styles.content}>
|
|
34
|
+
{children}
|
|
35
|
+
{text !== '' && <div className={styles.text}>{text}</div>}
|
|
36
|
+
{details !== '' && <div className={styles.details}>{details}</div>}
|
|
37
|
+
</div>
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
Loader.defaultProps = {
|
|
44
|
+
fullViewPortSize: false,
|
|
45
|
+
cover: false,
|
|
46
|
+
width: null,
|
|
47
|
+
height: null,
|
|
48
|
+
text: '',
|
|
49
|
+
details: '',
|
|
50
|
+
children: null,
|
|
51
|
+
theme: 'dark',
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
Loader.propTypes = {
|
|
55
|
+
fullViewPortSize: PropTypes.bool,
|
|
56
|
+
cover: PropTypes.bool,
|
|
57
|
+
width: PropTypes.string,
|
|
58
|
+
height: PropTypes.string,
|
|
59
|
+
text: PropTypes.string,
|
|
60
|
+
details: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
|
61
|
+
children: PropTypes.node,
|
|
62
|
+
theme: PropTypes.string,
|
|
63
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
@import '../../style/variables.less';
|
|
2
|
+
|
|
3
|
+
.loader {
|
|
4
|
+
width: 100%;
|
|
5
|
+
height: 100%;
|
|
6
|
+
position: relative;
|
|
7
|
+
border-radius: inherit;
|
|
8
|
+
|
|
9
|
+
&.fullViewPortSize {
|
|
10
|
+
position: absolute;
|
|
11
|
+
top: 0;
|
|
12
|
+
left: 0;
|
|
13
|
+
width: 100vw;
|
|
14
|
+
height: 100vh;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
&.cover {
|
|
18
|
+
position: absolute;
|
|
19
|
+
top: 0;
|
|
20
|
+
left: 0;
|
|
21
|
+
bottom: 0;
|
|
22
|
+
right: 0;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.dimmer {
|
|
27
|
+
position: absolute;
|
|
28
|
+
top: 0;
|
|
29
|
+
left: 0;
|
|
30
|
+
width: 100%;
|
|
31
|
+
height: 100%;
|
|
32
|
+
text-align: center;
|
|
33
|
+
vertical-align: middle;
|
|
34
|
+
padding: 1em;
|
|
35
|
+
opacity: 0;
|
|
36
|
+
line-height: 1;
|
|
37
|
+
animation-fill-mode: both;
|
|
38
|
+
animation-duration: 0.5s;
|
|
39
|
+
transition: background-color 0.5s linear;
|
|
40
|
+
flex-direction: column;
|
|
41
|
+
align-items: center;
|
|
42
|
+
justify-content: center;
|
|
43
|
+
user-select: none;
|
|
44
|
+
will-change: opacity;
|
|
45
|
+
z-index: @zindex_dimmer;
|
|
46
|
+
display: flex;
|
|
47
|
+
opacity: 0.95;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.content {
|
|
51
|
+
display: flex;
|
|
52
|
+
flex-direction: column;
|
|
53
|
+
align-items: center;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.text {
|
|
57
|
+
margin-top: 12px;
|
|
58
|
+
opacity: 0.6;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.details {
|
|
62
|
+
margin-top: 8px;
|
|
63
|
+
}
|