@darajs/ui-components 0.4.8
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/LICENSE +201 -0
- package/dist/accordion/accordion-item.d.ts +24 -0
- package/dist/accordion/accordion-item.d.ts.map +1 -0
- package/dist/accordion/accordion-item.js +92 -0
- package/dist/accordion/accordion-item.js.map +1 -0
- package/dist/accordion/accordion.d.ts +32 -0
- package/dist/accordion/accordion.d.ts.map +1 -0
- package/dist/accordion/accordion.js +87 -0
- package/dist/accordion/accordion.js.map +1 -0
- package/dist/badge/badge.d.ts +20 -0
- package/dist/badge/badge.d.ts.map +1 -0
- package/dist/badge/badge.js +42 -0
- package/dist/badge/badge.js.map +1 -0
- package/dist/button/button.d.ts +35 -0
- package/dist/button/button.d.ts.map +1 -0
- package/dist/button/button.js +169 -0
- package/dist/button/button.js.map +1 -0
- package/dist/button-bar/button-bar.d.ts +19 -0
- package/dist/button-bar/button-bar.d.ts.map +1 -0
- package/dist/button-bar/button-bar.js +124 -0
- package/dist/button-bar/button-bar.js.map +1 -0
- package/dist/carousel/carousel.d.ts +23 -0
- package/dist/carousel/carousel.d.ts.map +1 -0
- package/dist/carousel/carousel.js +178 -0
- package/dist/carousel/carousel.js.map +1 -0
- package/dist/chat/chat.d.ts +28 -0
- package/dist/chat/chat.d.ts.map +1 -0
- package/dist/chat/chat.js +182 -0
- package/dist/chat/chat.js.map +1 -0
- package/dist/chat/message.d.ts +28 -0
- package/dist/chat/message.d.ts.map +1 -0
- package/dist/chat/message.js +220 -0
- package/dist/chat/message.js.map +1 -0
- package/dist/checkbox/checkbox-group.d.ts +35 -0
- package/dist/checkbox/checkbox-group.d.ts.map +1 -0
- package/dist/checkbox/checkbox-group.js +116 -0
- package/dist/checkbox/checkbox-group.js.map +1 -0
- package/dist/checkbox/checkbox.d.ts +27 -0
- package/dist/checkbox/checkbox.d.ts.map +1 -0
- package/dist/checkbox/checkbox.js +164 -0
- package/dist/checkbox/checkbox.js.map +1 -0
- package/dist/checkbox/tri-state-checkbox.d.ts +22 -0
- package/dist/checkbox/tri-state-checkbox.d.ts.map +1 -0
- package/dist/checkbox/tri-state-checkbox.js +87 -0
- package/dist/checkbox/tri-state-checkbox.js.map +1 -0
- package/dist/code-viewer/code-viewer.d.ts +31 -0
- package/dist/code-viewer/code-viewer.d.ts.map +1 -0
- package/dist/code-viewer/code-viewer.js +115 -0
- package/dist/code-viewer/code-viewer.js.map +1 -0
- package/dist/combo-box/combo-box.d.ts +39 -0
- package/dist/combo-box/combo-box.d.ts.map +1 -0
- package/dist/combo-box/combo-box.js +176 -0
- package/dist/combo-box/combo-box.js.map +1 -0
- package/dist/component-select-list/component-select-list.d.ts +27 -0
- package/dist/component-select-list/component-select-list.d.ts.map +1 -0
- package/dist/component-select-list/component-select-list.js +131 -0
- package/dist/component-select-list/component-select-list.js.map +1 -0
- package/dist/constants.d.ts +33 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +47 -0
- package/dist/constants.js.map +1 -0
- package/dist/context-menu/context-menu.d.ts +24 -0
- package/dist/context-menu/context-menu.d.ts.map +1 -0
- package/dist/context-menu/context-menu.js +116 -0
- package/dist/context-menu/context-menu.js.map +1 -0
- package/dist/datepicker/datepicker-select.d.ts +48 -0
- package/dist/datepicker/datepicker-select.d.ts.map +1 -0
- package/dist/datepicker/datepicker-select.js +219 -0
- package/dist/datepicker/datepicker-select.js.map +1 -0
- package/dist/datepicker/datepicker.d.ts +56 -0
- package/dist/datepicker/datepicker.d.ts.map +1 -0
- package/dist/datepicker/datepicker.js +669 -0
- package/dist/datepicker/datepicker.js.map +1 -0
- package/dist/dropzone/dropzone.d.ts +21 -0
- package/dist/dropzone/dropzone.d.ts.map +1 -0
- package/dist/dropzone/dropzone.js +80 -0
- package/dist/dropzone/dropzone.js.map +1 -0
- package/dist/error-boundary/error-boundary.d.ts +33 -0
- package/dist/error-boundary/error-boundary.d.ts.map +1 -0
- package/dist/error-boundary/error-boundary.js +72 -0
- package/dist/error-boundary/error-boundary.js.map +1 -0
- package/dist/filter/categorical-filter.d.ts +26 -0
- package/dist/filter/categorical-filter.d.ts.map +1 -0
- package/dist/filter/categorical-filter.js +153 -0
- package/dist/filter/categorical-filter.js.map +1 -0
- package/dist/filter/datetime-filter.d.ts +28 -0
- package/dist/filter/datetime-filter.d.ts.map +1 -0
- package/dist/filter/datetime-filter.js +174 -0
- package/dist/filter/datetime-filter.js.map +1 -0
- package/dist/filter/numeric-filter.d.ts +24 -0
- package/dist/filter/numeric-filter.d.ts.map +1 -0
- package/dist/filter/numeric-filter.js +148 -0
- package/dist/filter/numeric-filter.js.map +1 -0
- package/dist/hierarchy-selector/hierarchy-selector.d.ts +31 -0
- package/dist/hierarchy-selector/hierarchy-selector.d.ts.map +1 -0
- package/dist/hierarchy-selector/hierarchy-selector.js +65 -0
- package/dist/hierarchy-selector/hierarchy-selector.js.map +1 -0
- package/dist/hierarchy-selector/node/branch.d.ts +47 -0
- package/dist/hierarchy-selector/node/branch.d.ts.map +1 -0
- package/dist/hierarchy-selector/node/branch.js +132 -0
- package/dist/hierarchy-selector/node/branch.js.map +1 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -0
- package/dist/input/input.d.ts +44 -0
- package/dist/input/input.d.ts.map +1 -0
- package/dist/input/input.js +91 -0
- package/dist/input/input.js.map +1 -0
- package/dist/jest-setup.d.ts +18 -0
- package/dist/jest-setup.d.ts.map +1 -0
- package/dist/jest-setup.js +18 -0
- package/dist/jest-setup.js.map +1 -0
- package/dist/markdown/markdown.d.ts +18 -0
- package/dist/markdown/markdown.d.ts.map +1 -0
- package/dist/markdown/markdown.js +356 -0
- package/dist/markdown/markdown.js.map +1 -0
- package/dist/modal/modal.d.ts +37 -0
- package/dist/modal/modal.d.ts.map +1 -0
- package/dist/modal/modal.js +121 -0
- package/dist/modal/modal.js.map +1 -0
- package/dist/multiselect/multiselect.d.ts +31 -0
- package/dist/multiselect/multiselect.d.ts.map +1 -0
- package/dist/multiselect/multiselect.js +231 -0
- package/dist/multiselect/multiselect.js.map +1 -0
- package/dist/numeric-input/input-stepper.d.ts +33 -0
- package/dist/numeric-input/input-stepper.d.ts.map +1 -0
- package/dist/numeric-input/input-stepper.js +54 -0
- package/dist/numeric-input/input-stepper.js.map +1 -0
- package/dist/numeric-input/numeric-input.d.ts +42 -0
- package/dist/numeric-input/numeric-input.d.ts.map +1 -0
- package/dist/numeric-input/numeric-input.js +234 -0
- package/dist/numeric-input/numeric-input.js.map +1 -0
- package/dist/progress-bar/progress-bar.d.ts +23 -0
- package/dist/progress-bar/progress-bar.d.ts.map +1 -0
- package/dist/progress-bar/progress-bar.js +90 -0
- package/dist/progress-bar/progress-bar.js.map +1 -0
- package/dist/radio/radio-group.d.ts +19 -0
- package/dist/radio/radio-group.d.ts.map +1 -0
- package/dist/radio/radio-group.js +160 -0
- package/dist/radio/radio-group.js.map +1 -0
- package/dist/search-bar/search-bar.d.ts +34 -0
- package/dist/search-bar/search-bar.d.ts.map +1 -0
- package/dist/search-bar/search-bar.js +39 -0
- package/dist/search-bar/search-bar.js.map +1 -0
- package/dist/sectioned-list/sectioned-list.d.ts +29 -0
- package/dist/sectioned-list/sectioned-list.d.ts.map +1 -0
- package/dist/sectioned-list/sectioned-list.js +205 -0
- package/dist/sectioned-list/sectioned-list.js.map +1 -0
- package/dist/select/select.d.ts +54 -0
- package/dist/select/select.d.ts.map +1 -0
- package/dist/select/select.js +143 -0
- package/dist/select/select.js.map +1 -0
- package/dist/shared/chevron-button.d.ts +13 -0
- package/dist/shared/chevron-button.d.ts.map +1 -0
- package/dist/shared/chevron-button.js +35 -0
- package/dist/shared/chevron-button.js.map +1 -0
- package/dist/shared/dropdown-list.d.ts +34 -0
- package/dist/shared/dropdown-list.d.ts.map +1 -0
- package/dist/shared/dropdown-list.js +33 -0
- package/dist/shared/dropdown-list.js.map +1 -0
- package/dist/shared/list-item.d.ts +35 -0
- package/dist/shared/list-item.d.ts.map +1 -0
- package/dist/shared/list-item.js +69 -0
- package/dist/shared/list-item.js.map +1 -0
- package/dist/slider/slider-inputs.d.ts +36 -0
- package/dist/slider/slider-inputs.d.ts.map +1 -0
- package/dist/slider/slider-inputs.js +88 -0
- package/dist/slider/slider-inputs.js.map +1 -0
- package/dist/slider/slider.d.ts +53 -0
- package/dist/slider/slider.d.ts.map +1 -0
- package/dist/slider/slider.js +273 -0
- package/dist/slider/slider.js.map +1 -0
- package/dist/spinner/spinner.d.ts +19 -0
- package/dist/spinner/spinner.d.ts.map +1 -0
- package/dist/spinner/spinner.js +144 -0
- package/dist/spinner/spinner.js.map +1 -0
- package/dist/switch/sun-icon.d.ts +3 -0
- package/dist/switch/sun-icon.d.ts.map +1 -0
- package/dist/switch/sun-icon.js +24 -0
- package/dist/switch/sun-icon.js.map +1 -0
- package/dist/switch/switch.d.ts +16 -0
- package/dist/switch/switch.d.ts.map +1 -0
- package/dist/switch/switch.js +92 -0
- package/dist/switch/switch.js.map +1 -0
- package/dist/table/cells/action-cell.d.ts +34 -0
- package/dist/table/cells/action-cell.d.ts.map +1 -0
- package/dist/table/cells/action-cell.js +68 -0
- package/dist/table/cells/action-cell.js.map +1 -0
- package/dist/table/cells/datetime-cell.d.ts +12 -0
- package/dist/table/cells/datetime-cell.d.ts.map +1 -0
- package/dist/table/cells/datetime-cell.js +36 -0
- package/dist/table/cells/datetime-cell.js.map +1 -0
- package/dist/table/cells/edit-cell-utils.d.ts +32 -0
- package/dist/table/cells/edit-cell-utils.d.ts.map +1 -0
- package/dist/table/cells/edit-cell-utils.js +2 -0
- package/dist/table/cells/edit-cell-utils.js.map +1 -0
- package/dist/table/cells/edit-input-cell.d.ts +10 -0
- package/dist/table/cells/edit-input-cell.d.ts.map +1 -0
- package/dist/table/cells/edit-input-cell.js +61 -0
- package/dist/table/cells/edit-input-cell.js.map +1 -0
- package/dist/table/cells/edit-select-cell.d.ts +12 -0
- package/dist/table/cells/edit-select-cell.d.ts.map +1 -0
- package/dist/table/cells/edit-select-cell.js +55 -0
- package/dist/table/cells/edit-select-cell.js.map +1 -0
- package/dist/table/filters.d.ts +46 -0
- package/dist/table/filters.d.ts.map +1 -0
- package/dist/table/filters.js +226 -0
- package/dist/table/filters.js.map +1 -0
- package/dist/table/headers/select-header.d.ts +14 -0
- package/dist/table/headers/select-header.d.ts.map +1 -0
- package/dist/table/headers/select-header.js +41 -0
- package/dist/table/headers/select-header.js.map +1 -0
- package/dist/table/options-menu.d.ts +25 -0
- package/dist/table/options-menu.d.ts.map +1 -0
- package/dist/table/options-menu.js +123 -0
- package/dist/table/options-menu.js.map +1 -0
- package/dist/table/render-row.d.ts +25 -0
- package/dist/table/render-row.d.ts.map +1 -0
- package/dist/table/render-row.js +163 -0
- package/dist/table/render-row.js.map +1 -0
- package/dist/table/table.d.ts +95 -0
- package/dist/table/table.d.ts.map +1 -0
- package/dist/table/table.js +422 -0
- package/dist/table/table.js.map +1 -0
- package/dist/table/types.d.ts +30 -0
- package/dist/table/types.d.ts.map +1 -0
- package/dist/table/types.js +2 -0
- package/dist/table/types.js.map +1 -0
- package/dist/tabs/tabs.d.ts +22 -0
- package/dist/tabs/tabs.d.ts.map +1 -0
- package/dist/tabs/tabs.js +91 -0
- package/dist/tabs/tabs.js.map +1 -0
- package/dist/textarea/textarea.d.ts +47 -0
- package/dist/textarea/textarea.d.ts.map +1 -0
- package/dist/textarea/textarea.js +121 -0
- package/dist/textarea/textarea.js.map +1 -0
- package/dist/tooltip/tooltip.d.ts +48 -0
- package/dist/tooltip/tooltip.d.ts.map +1 -0
- package/dist/tooltip/tooltip.js +116 -0
- package/dist/tooltip/tooltip.js.map +1 -0
- package/dist/types.d.ts +94 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/chevron.d.ts +34 -0
- package/dist/utils/chevron.d.ts.map +1 -0
- package/dist/utils/chevron.js +38 -0
- package/dist/utils/chevron.js.map +1 -0
- package/dist/utils/index.d.ts +22 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +22 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/label.d.ts +3 -0
- package/dist/utils/label.d.ts.map +1 -0
- package/dist/utils/label.js +24 -0
- package/dist/utils/label.js.map +1 -0
- package/dist/utils/list-styles.d.ts +8 -0
- package/dist/utils/list-styles.d.ts.map +1 -0
- package/dist/utils/list-styles.js +43 -0
- package/dist/utils/list-styles.js.map +1 -0
- package/dist/utils/match-width-to-reference.d.ts +24 -0
- package/dist/utils/match-width-to-reference.d.ts.map +1 -0
- package/dist/utils/match-width-to-reference.js +30 -0
- package/dist/utils/match-width-to-reference.js.map +1 -0
- package/dist/utils/syncKbdHighlightIdx.d.ts +23 -0
- package/dist/utils/syncKbdHighlightIdx.d.ts.map +1 -0
- package/dist/utils/syncKbdHighlightIdx.js +41 -0
- package/dist/utils/syncKbdHighlightIdx.js.map +1 -0
- package/dist/utils/use-infinite-loader.d.ts +32 -0
- package/dist/utils/use-infinite-loader.d.ts.map +1 -0
- package/dist/utils/use-infinite-loader.js +119 -0
- package/dist/utils/use-infinite-loader.js.map +1 -0
- package/dist/utils/use-on-click-outside.d.ts +3 -0
- package/dist/utils/use-on-click-outside.d.ts.map +1 -0
- package/dist/utils/use-on-click-outside.js +36 -0
- package/dist/utils/use-on-click-outside.js.map +1 -0
- package/package.json +106 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright 2023 Impulse Innovations Limited
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
import { faFilter } from '@fortawesome/free-solid-svg-icons';
|
|
19
|
+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
20
|
+
import { isAfter, isBefore, isEqual, isWithinInterval, parseISO } from 'date-fns';
|
|
21
|
+
import { transparentize } from 'polished';
|
|
22
|
+
import { useMemo, useRef, useState } from 'react';
|
|
23
|
+
import styled from '@darajs/styled-components';
|
|
24
|
+
import { FilterWrapper, StyledSearchBar } from '../filter/categorical-filter';
|
|
25
|
+
import Tooltip from '../tooltip/tooltip';
|
|
26
|
+
const FilterIcon = styled(FontAwesomeIcon) `
|
|
27
|
+
cursor: pointer;
|
|
28
|
+
color: ${(props) => (props.$hasFilter ? props.theme.colors.primary : props.theme.colors.grey3)};
|
|
29
|
+
`;
|
|
30
|
+
export const HeaderIconWrapper = styled.div `
|
|
31
|
+
display: flex;
|
|
32
|
+
align-items: center;
|
|
33
|
+
justify-content: center;
|
|
34
|
+
|
|
35
|
+
width: 1.5rem;
|
|
36
|
+
height: 1.5rem;
|
|
37
|
+
|
|
38
|
+
border-radius: 0.25rem;
|
|
39
|
+
|
|
40
|
+
:hover {
|
|
41
|
+
background-color: ${(props) => transparentize(0.9, props.theme.colors.primaryHover)};
|
|
42
|
+
|
|
43
|
+
svg {
|
|
44
|
+
color: ${(props) => (props.hasFilter ? props.theme.colors.primary : props.theme.colors.grey3)};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
:active {
|
|
49
|
+
background-color: ${(props) => transparentize(0.8, props.theme.colors.primaryDown)};
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
var NumericOperator;
|
|
53
|
+
(function (NumericOperator) {
|
|
54
|
+
NumericOperator["BT"] = "Between";
|
|
55
|
+
NumericOperator["EQ"] = "Equal to";
|
|
56
|
+
NumericOperator["GT"] = "Greater than";
|
|
57
|
+
NumericOperator["LT"] = "Less than";
|
|
58
|
+
NumericOperator["NE"] = "Not equal to";
|
|
59
|
+
})(NumericOperator || (NumericOperator = {}));
|
|
60
|
+
var DateOperator;
|
|
61
|
+
(function (DateOperator) {
|
|
62
|
+
DateOperator["BT"] = "Between";
|
|
63
|
+
DateOperator["EQ"] = "On date";
|
|
64
|
+
DateOperator["GT"] = "After";
|
|
65
|
+
DateOperator["LT"] = "Before";
|
|
66
|
+
})(DateOperator || (DateOperator = {}));
|
|
67
|
+
/**
|
|
68
|
+
* Check whether a given operator is supported
|
|
69
|
+
* @param op potential operator
|
|
70
|
+
*/
|
|
71
|
+
function isValidOperator(op) {
|
|
72
|
+
return Object.keys(NumericOperator)
|
|
73
|
+
.map((key) => NumericOperator[key])
|
|
74
|
+
.includes(op);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Check whether a given operator is supported for datetime
|
|
78
|
+
* @param op potential operator
|
|
79
|
+
*/
|
|
80
|
+
function isValidDatetimeOperator(op) {
|
|
81
|
+
return Object.keys(DateOperator)
|
|
82
|
+
.map((key) => DateOperator[key])
|
|
83
|
+
.includes(op);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Apply an operator to a given numeric value.
|
|
87
|
+
*
|
|
88
|
+
* @param operator operator to apply
|
|
89
|
+
* @param value value to compare
|
|
90
|
+
* @param filterValue filter value to compare to
|
|
91
|
+
*/
|
|
92
|
+
function applyNumericOperator(operator, value, filterValue) {
|
|
93
|
+
switch (operator) {
|
|
94
|
+
case NumericOperator.EQ:
|
|
95
|
+
return value === filterValue;
|
|
96
|
+
case NumericOperator.GT:
|
|
97
|
+
if (Array.isArray(filterValue)) {
|
|
98
|
+
throw new Error('Cannot use array for GT operator');
|
|
99
|
+
}
|
|
100
|
+
return value > filterValue;
|
|
101
|
+
case NumericOperator.LT:
|
|
102
|
+
if (Array.isArray(filterValue)) {
|
|
103
|
+
throw new Error('Cannot use array for LT operator');
|
|
104
|
+
}
|
|
105
|
+
return value < filterValue;
|
|
106
|
+
case NumericOperator.NE:
|
|
107
|
+
return value !== filterValue;
|
|
108
|
+
case NumericOperator.BT:
|
|
109
|
+
if (Array.isArray(filterValue)) {
|
|
110
|
+
return value <= filterValue[1] && value >= filterValue[0];
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
default:
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Apply an operator to a given datetime value.
|
|
119
|
+
*
|
|
120
|
+
* @param operator operator to apply
|
|
121
|
+
* @param value value to compare
|
|
122
|
+
* @param filterValue filter value to compare to
|
|
123
|
+
*/
|
|
124
|
+
function applyDatetimeOperator(operator, value, filterValue) {
|
|
125
|
+
const parsedValue = parseISO(value);
|
|
126
|
+
if (Array.isArray(filterValue)) {
|
|
127
|
+
if (operator === DateOperator.BT) {
|
|
128
|
+
return isWithinInterval(parsedValue, { end: filterValue[1], start: filterValue[0] });
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
switch (operator) {
|
|
133
|
+
case DateOperator.EQ:
|
|
134
|
+
return isEqual(parsedValue, filterValue);
|
|
135
|
+
case DateOperator.GT:
|
|
136
|
+
return isAfter(parsedValue, filterValue);
|
|
137
|
+
case DateOperator.LT:
|
|
138
|
+
return isBefore(parsedValue, filterValue);
|
|
139
|
+
default:
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Custom numeric filter function
|
|
145
|
+
*
|
|
146
|
+
* @param rows rows to filter
|
|
147
|
+
* @param columnIds IDs of columns
|
|
148
|
+
* @param filterValue filter value provided
|
|
149
|
+
*/
|
|
150
|
+
export function numeric(rows, columnIds, filterValue) {
|
|
151
|
+
const { selected, value } = filterValue;
|
|
152
|
+
const [colId] = columnIds;
|
|
153
|
+
// If operator not supported or there's no value to compare to, return all rows
|
|
154
|
+
if (!isValidOperator(selected) || (!value && value !== 0)) {
|
|
155
|
+
return rows;
|
|
156
|
+
}
|
|
157
|
+
return rows.filter((row) => applyNumericOperator(selected, row.values[colId], value));
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Custom datetime filter function
|
|
161
|
+
*
|
|
162
|
+
* @param rows rows to filter
|
|
163
|
+
* @param columnIds IDs of columns
|
|
164
|
+
* @param filterValue filter value
|
|
165
|
+
*/
|
|
166
|
+
export function datetime(rows, columnIds, filterValue) {
|
|
167
|
+
const { selected, value } = filterValue;
|
|
168
|
+
const [colId] = columnIds;
|
|
169
|
+
// If operator not supported or there's no value to compare to, return all rows
|
|
170
|
+
if (!isValidDatetimeOperator(selected) || !value) {
|
|
171
|
+
return rows;
|
|
172
|
+
}
|
|
173
|
+
return rows.filter((row) => applyDatetimeOperator(selected, row.values[colId], value));
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Custom categorical filter function
|
|
177
|
+
*
|
|
178
|
+
* @param rows rows to filter
|
|
179
|
+
* @param columnIds IDs of columns
|
|
180
|
+
* @param filterItems filter value
|
|
181
|
+
*/
|
|
182
|
+
export function categorical(rows, columnIds, filterItems) {
|
|
183
|
+
const [colId] = columnIds;
|
|
184
|
+
const filteredItems = filterItems.map((item) => item.value);
|
|
185
|
+
// If no categories selected return everything
|
|
186
|
+
if (filteredItems.length === 0) {
|
|
187
|
+
return rows;
|
|
188
|
+
}
|
|
189
|
+
return rows.filter((row) => filteredItems.includes(row.values[colId]));
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Text Filter component
|
|
193
|
+
*/
|
|
194
|
+
export function TextFilter(props) {
|
|
195
|
+
return (_jsx(FilterWrapper, { children: _jsx(StyledSearchBar, { onChange: (val) => props.column.setFilter(val || undefined), placeholder: "Rows containing value...", value: props.column.filterValue || '' }) }));
|
|
196
|
+
}
|
|
197
|
+
export function FilterContainer(props) {
|
|
198
|
+
var _a;
|
|
199
|
+
const [visible, setVisible] = useState(false);
|
|
200
|
+
const show = () => setVisible(true);
|
|
201
|
+
const hide = () => setVisible(false);
|
|
202
|
+
const hasFilter = !(props.col.filterValue === undefined ||
|
|
203
|
+
((_a = props.col.filterValue) === null || _a === void 0 ? void 0 : _a.selected) === 'None' ||
|
|
204
|
+
(Array.isArray(props.col.filterValue) && props.col.filterValue.length === 0));
|
|
205
|
+
const items = useMemo(() => {
|
|
206
|
+
var _a;
|
|
207
|
+
if ((_a = props.col) === null || _a === void 0 ? void 0 : _a.uniqueItems) {
|
|
208
|
+
return props.col.uniqueItems.map((item) => ({ label: item, value: item }));
|
|
209
|
+
}
|
|
210
|
+
}, [props.col]);
|
|
211
|
+
// because the select dropdown lives outside of the component we need to pass a ref so that we can check whether the user is clicking within it or outside
|
|
212
|
+
const portalsRef = useRef([]);
|
|
213
|
+
function onClickOutside(instance, event) {
|
|
214
|
+
const target = event.target;
|
|
215
|
+
// loop through refs if they contain the target then user is clicking within a dropdown
|
|
216
|
+
for (const portal of portalsRef.current) {
|
|
217
|
+
if (portal === null || portal === void 0 ? void 0 : portal.contains(target)) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
// user clicked outside so hide
|
|
222
|
+
hide();
|
|
223
|
+
}
|
|
224
|
+
return (_jsx(Tooltip, { content: props.col.render('Filter', { items, onChange: hide, portalsRef }), hidden: true, interactive: true, onClickOutside: onClickOutside, visible: visible, children: _jsx("span", { children: _jsx(HeaderIconWrapper, { hasFilter: hasFilter, children: _jsx(FilterIcon, { "$hasFilter": hasFilter, icon: faFilter, onClick: show }) }) }) }));
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=filters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filters.js","sourceRoot":"","sources":["../../src/table/filters.tsx"],"names":[],"mappings":";AAAA;;;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AI,MAAA,KAAK,CAAC,GAAG,0CAAE,WAAW,EAAE,CAAC;YACzB,OAAO,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,EAAQ,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QACrF,CAAC;IACL,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IAEhB,0JAA0J;IAC1J,MAAM,UAAU,GAAG,MAAM,CAAqB,EAAE,CAAC,CAAC;IAElD,SAAS,cAAc,CAAC,QAAa,EAAE,KAAY;QAC/C,MAAM,MAAM,GAAG,KAAK,CAAC,MAA0B,CAAC;QAEhD,uFAAuF;QACvF,KAAK,MAAM,MAAM,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;YACtC,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC3B,OAAO;YACX,CAAC;QACL,CAAC;QACD,+BAA+B;QAC/B,IAAI,EAAE,CAAC;IACX,CAAC;IAED,OAAO,CACH,KAAC,OAAO,IACJ,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,EAC1E,MAAM,QACN,WAAW,QACX,cAAc,EAAE,cAAc,EAC9B,OAAO,EAAE,OAAO,YAEhB,yBACI,KAAC,iBAAiB,IAAC,SAAS,EAAE,SAAS,YACnC,KAAC,UAAU,kBAAa,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,GAAI,GACpD,GACjB,GACD,CACb,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface selectHeaderProps {
|
|
2
|
+
/** An action handler, will be called for selecting/unselecting all rows */
|
|
3
|
+
onAction: (actionId: string, input?: any) => void | Promise<void>;
|
|
4
|
+
/** The rows of the table, needed to keep track of them being selected or not */
|
|
5
|
+
rows: any;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A table header with a tri-state checkbox, for bulk selection actions
|
|
9
|
+
*
|
|
10
|
+
* @param {selectHeaderProps} props - the component props
|
|
11
|
+
*/
|
|
12
|
+
declare function SelectHeader(props: selectHeaderProps): JSX.Element;
|
|
13
|
+
export default SelectHeader;
|
|
14
|
+
//# sourceMappingURL=select-header.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select-header.d.ts","sourceRoot":"","sources":["../../../src/table/headers/select-header.tsx"],"names":[],"mappings":"AAmBA,UAAU,iBAAiB;IACvB,2EAA2E;IAC3E,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClE,gFAAgF;IAChF,IAAI,EAAE,GAAG,CAAC;CACb;AAED;;;;GAIG;AACH,iBAAS,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,GAAG,CAAC,OAAO,CAyB3D;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright 2023 Impulse Innovations Limited
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
import TriStateCheckbox, { CheckboxState } from '../../checkbox/tri-state-checkbox';
|
|
19
|
+
import { Action } from '../cells/action-cell';
|
|
20
|
+
/**
|
|
21
|
+
* A table header with a tri-state checkbox, for bulk selection actions
|
|
22
|
+
*
|
|
23
|
+
* @param {selectHeaderProps} props - the component props
|
|
24
|
+
*/
|
|
25
|
+
function SelectHeader(props) {
|
|
26
|
+
const allValues = props.rows.map((r) => r.original.selected);
|
|
27
|
+
const countSelected = allValues.filter(Boolean).length;
|
|
28
|
+
const allSelected = countSelected > 0 && countSelected === allValues.length;
|
|
29
|
+
const noneSelected = countSelected === 0;
|
|
30
|
+
const onChange = (state) => {
|
|
31
|
+
if (state === CheckboxState.UNCHECKED) {
|
|
32
|
+
props.onAction(Action.UNSELECT_ALL);
|
|
33
|
+
}
|
|
34
|
+
else if (state === CheckboxState.CHECKED) {
|
|
35
|
+
props.onAction(Action.SELECT_ALL, props.rows.map((r) => r.original));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
return (_jsx(TriStateCheckbox, { allSelected: allSelected, noneSelected: noneSelected, onChange: onChange, style: { display: 'flex', justifyContent: 'center' } }));
|
|
39
|
+
}
|
|
40
|
+
export default SelectHeader;
|
|
41
|
+
//# sourceMappingURL=select-header.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select-header.js","sourceRoot":"","sources":["../../../src/table/headers/select-header.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,gBAAgB,EAAE,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AACpF,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAS9C;;;;GAIG;AACH,SAAS,YAAY,CAAC,KAAwB;IAC1C,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAClE,MAAM,aAAa,GAAG,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;IAEvD,MAAM,WAAW,GAAG,aAAa,GAAG,CAAC,IAAI,aAAa,KAAK,SAAS,CAAC,MAAM,CAAC;IAC5E,MAAM,YAAY,GAAG,aAAa,KAAK,CAAC,CAAC;IAEzC,MAAM,QAAQ,GAAG,CAAC,KAAoB,EAAQ,EAAE;QAC5C,IAAI,KAAK,KAAK,aAAa,CAAC,SAAS,EAAE,CAAC;YACpC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QACxC,CAAC;aAAM,IAAI,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,CAAC;YACzC,KAAK,CAAC,QAAQ,CACV,MAAM,CAAC,UAAU,EACjB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CACzC,CAAC;QACN,CAAC;IACL,CAAC,CAAC;IACF,OAAO,CACH,KAAC,gBAAgB,IACb,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,GACtD,CACL,CAAC;AACN,CAAC;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { FunctionComponent } from 'react';
|
|
2
|
+
import { ColumnInstance, Filters } from 'react-table';
|
|
3
|
+
interface OptionsMenuProps {
|
|
4
|
+
/** all columns from the table component */
|
|
5
|
+
allColumns: ColumnInstance<any>[];
|
|
6
|
+
/** Optional flag to enable column hiding */
|
|
7
|
+
allowColumnHiding?: boolean;
|
|
8
|
+
/** count of currently visible columns */
|
|
9
|
+
numVisibleColumns: number;
|
|
10
|
+
/** column resizing reset function callback from useTable */
|
|
11
|
+
resetResizing: () => void;
|
|
12
|
+
/** filter setter from useTable */
|
|
13
|
+
setAllFilters: (updater: Filters<any> | ((filters: Filters<any>) => Filters<any>)) => void;
|
|
14
|
+
/** Pass through of the style prop to the table options Dropdown */
|
|
15
|
+
style: React.CSSProperties;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The OptionsMenu component adds a sectioned list menu to the Table component.
|
|
19
|
+
* It inherits the ability to reset column widths and filters from react-table's useTable hook
|
|
20
|
+
*
|
|
21
|
+
* @param props - the component props
|
|
22
|
+
*/
|
|
23
|
+
declare const OptionsMenu: FunctionComponent<OptionsMenuProps>;
|
|
24
|
+
export default OptionsMenu;
|
|
25
|
+
//# sourceMappingURL=options-menu.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options-menu.d.ts","sourceRoot":"","sources":["../../src/table/options-menu.tsx"],"names":[],"mappings":"AA4BA,OAAO,EAAE,iBAAiB,EAAkC,MAAM,OAAO,CAAC;AAE1E,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AA6BtD,UAAU,gBAAgB;IACtB,2CAA2C;IAC3C,UAAU,EAAE,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;IAClC,4CAA4C;IAC5C,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,yCAAyC;IACzC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,4DAA4D;IAC5D,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,kCAAkC;IAClC,aAAa,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC;IAC3F,mEAAmE;IACnE,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC;CAC9B;AAED;;;;;GAKG;AACH,QAAA,MAAM,WAAW,EAAE,iBAAiB,CAAC,gBAAgB,CA6GpD,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright 2023 Impulse Innovations Limited
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
import { autoUpdate, flip, shift, useClick, useDismiss, useFloating, useInteractions, useRole, } from '@floating-ui/react';
|
|
19
|
+
import { faEllipsisV } from '@fortawesome/free-solid-svg-icons';
|
|
20
|
+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
21
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
22
|
+
import ReactDOM from 'react-dom';
|
|
23
|
+
import styled from '@darajs/styled-components';
|
|
24
|
+
import SectionedList from '../sectioned-list/sectioned-list';
|
|
25
|
+
import { List } from '../utils';
|
|
26
|
+
const HeaderOptionsIcon = styled(FontAwesomeIcon) `
|
|
27
|
+
cursor: pointer;
|
|
28
|
+
align-items: center;
|
|
29
|
+
color: ${(props) => props.theme.colors.grey5};
|
|
30
|
+
`;
|
|
31
|
+
const HeaderOptions = styled.div `
|
|
32
|
+
display: flex;
|
|
33
|
+
align-items: center;
|
|
34
|
+
justify-content: center;
|
|
35
|
+
|
|
36
|
+
width: 12px;
|
|
37
|
+
|
|
38
|
+
background-color: ${(props) => props.theme.colors.grey3};
|
|
39
|
+
`;
|
|
40
|
+
const OptionsDropdownList = styled(List) `
|
|
41
|
+
background-color: ${(props) => props.theme.colors.background};
|
|
42
|
+
box-shadow: ${(props) => props.theme.shadow.light};
|
|
43
|
+
`;
|
|
44
|
+
/**
|
|
45
|
+
* The OptionsMenu component adds a sectioned list menu to the Table component.
|
|
46
|
+
* It inherits the ability to reset column widths and filters from react-table's useTable hook
|
|
47
|
+
*
|
|
48
|
+
* @param props - the component props
|
|
49
|
+
*/
|
|
50
|
+
const OptionsMenu = ({ allColumns, allowColumnHiding, numVisibleColumns, resetResizing, setAllFilters, style, }) => {
|
|
51
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
52
|
+
const toggleOptions = useCallback(() => {
|
|
53
|
+
setIsOpen((prev) => !prev);
|
|
54
|
+
}, []);
|
|
55
|
+
const onOptionSelect = useCallback((option) => {
|
|
56
|
+
option.onClick();
|
|
57
|
+
setIsOpen(false);
|
|
58
|
+
}, []);
|
|
59
|
+
const { refs, floatingStyles, context } = useFloating({
|
|
60
|
+
open: isOpen,
|
|
61
|
+
onOpenChange: setIsOpen,
|
|
62
|
+
placement: 'left-end',
|
|
63
|
+
middleware: [flip(), shift()],
|
|
64
|
+
whileElementsMounted: isOpen ? autoUpdate : undefined,
|
|
65
|
+
});
|
|
66
|
+
const interactions = useInteractions([
|
|
67
|
+
useClick(context, { event: 'mousedown' }),
|
|
68
|
+
useDismiss(context, { outsidePress: true, outsidePressEvent: 'mousedown' }),
|
|
69
|
+
useRole(context, { role: 'menu' }),
|
|
70
|
+
]);
|
|
71
|
+
const resetFunctions = useMemo(() => {
|
|
72
|
+
const functions = {
|
|
73
|
+
items: [
|
|
74
|
+
{
|
|
75
|
+
label: 'Reset Column Widths',
|
|
76
|
+
onClick: resetResizing,
|
|
77
|
+
value: 'resetResizing',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
label: 'Reset Filters',
|
|
81
|
+
onClick: () => setAllFilters([]),
|
|
82
|
+
value: 'resetFilters',
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
label: 'Reset',
|
|
86
|
+
};
|
|
87
|
+
if (allowColumnHiding) {
|
|
88
|
+
functions.items.push({
|
|
89
|
+
label: 'Show All Columns',
|
|
90
|
+
onClick: () => {
|
|
91
|
+
allColumns.forEach((column) => {
|
|
92
|
+
if (!column.isVisible) {
|
|
93
|
+
column.toggleHidden();
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
value: 'showAllColumns',
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return functions;
|
|
101
|
+
}, [resetResizing, setAllFilters, allColumns, allowColumnHiding]);
|
|
102
|
+
const columnToggles = useMemo(() => {
|
|
103
|
+
return {
|
|
104
|
+
items: allColumns
|
|
105
|
+
.filter((column) => typeof column.Header === 'string')
|
|
106
|
+
.map((column) => ({
|
|
107
|
+
label: `${column.isVisible ? 'Hide' : 'Show'} ${String(column.Header)}`,
|
|
108
|
+
onClick: () =>
|
|
109
|
+
/* Don't allow last visible column to be hidden */
|
|
110
|
+
!(column.isVisible && numVisibleColumns === 1) ? column.toggleHidden() : null,
|
|
111
|
+
value: `${column.isVisible ? 'hide' : 'show'}${String(column.Header)}`,
|
|
112
|
+
})),
|
|
113
|
+
label: 'Columns',
|
|
114
|
+
};
|
|
115
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
116
|
+
}, [allColumns, allowColumnHiding, numVisibleColumns]);
|
|
117
|
+
return (_jsxs(HeaderOptions, { ref: refs.setReference, children: [_jsx(HeaderOptionsIcon, { icon: faEllipsisV, onClick: toggleOptions }), ReactDOM.createPortal(_jsx(OptionsDropdownList, Object.assign({}, interactions.getFloatingProps({
|
|
118
|
+
ref: refs.setFloating,
|
|
119
|
+
style: Object.assign(Object.assign(Object.assign({}, floatingStyles), { maxHeight: 800, minWidth: 150, zIndex: 9999 }), style),
|
|
120
|
+
}), { isOpen: isOpen, children: _jsx(SectionedList, { items: allowColumnHiding ? [resetFunctions, columnToggles] : [resetFunctions], onSelect: onOptionSelect }, isOpen ? 'open' : 'closed') })), document.body)] }));
|
|
121
|
+
};
|
|
122
|
+
export default OptionsMenu;
|
|
123
|
+
//# sourceMappingURL=options-menu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options-menu.js","sourceRoot":"","sources":["../../src/table/options-menu.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EACH,UAAU,EACV,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,UAAU,EACV,WAAW,EACX,eAAe,EACf,OAAO,GACV,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAqB,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC1E,OAAO,QAAQ,MAAM,WAAW,CAAC;AAGjC,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAE/C,OAAO,aAA8B,MAAM,kCAAkC,CAAC;AAE9E,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC,MAAM,iBAAiB,GAAG,MAAM,CAAC,eAAe,CAAC,CAAA;;;aAGpC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK;CAC/C,CAAC;AAEF,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;wBAOR,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK;CAC1D,CAAC;AAEF,MAAM,mBAAmB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;wBAChB,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,MA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|
+
import { HeaderGroup } from 'react-table';
|
|
3
|
+
import { TableColumn } from './types';
|
|
4
|
+
export declare const ROW_HEIGHT: number;
|
|
5
|
+
export declare const shouldForwardProp: (prop: any) => boolean;
|
|
6
|
+
type Props = {
|
|
7
|
+
data: {
|
|
8
|
+
backgroundColor: string;
|
|
9
|
+
currentEditCell: [number, string | number];
|
|
10
|
+
getItem: (index: number) => any;
|
|
11
|
+
headerGroups: Array<HeaderGroup<object>>;
|
|
12
|
+
mappedColumns: Array<TableColumn>;
|
|
13
|
+
onClickRow: (row: any) => void | Promise<void>;
|
|
14
|
+
prepareRow: (row: any) => void;
|
|
15
|
+
rows: Array<any>;
|
|
16
|
+
throttledClickRow: (row: any) => void | Promise<void>;
|
|
17
|
+
totalColumnsWidth: number;
|
|
18
|
+
width: number;
|
|
19
|
+
};
|
|
20
|
+
index: number;
|
|
21
|
+
style: React.CSSProperties;
|
|
22
|
+
};
|
|
23
|
+
declare const RenderRow: React.MemoExoticComponent<({ data: { width, currentEditCell, headerGroups, rows, prepareRow, getItem, totalColumnsWidth, onClickRow, throttledClickRow, backgroundColor, mappedColumns, }, index, style: renderRowStyle, }: Props) => JSX.Element>;
|
|
24
|
+
export default RenderRow;
|
|
25
|
+
//# sourceMappingURL=render-row.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-row.d.ts","sourceRoot":"","sources":["../../src/table/render-row.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAK1C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAStC,eAAO,MAAM,UAAU,QAA6B,CAAC;AAGrD,eAAO,MAAM,iBAAiB,SAAU,GAAG,KAAG,OAAqD,CAAC;AAkGpG,KAAK,KAAK,GAAG;IACT,IAAI,EAAE;QACF,eAAe,EAAE,MAAM,CAAC;QACxB,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;QAC3C,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,GAAG,CAAC;QAChC,YAAY,EAAE,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;QACzC,aAAa,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;QAClC,UAAU,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/C,UAAU,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC;QAC/B,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;QACjB,iBAAiB,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QACtD,iBAAiB,EAAE,MAAM,CAAC;QAC1B,KAAK,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC;CAC9B,CAAC;AAEF,QAAA,MAAM,SAAS,8NAiBR,KAAK,KAAG,GAAG,CAAC,OAAO,CAsGzB,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { createElement as _createElement } from "react";
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { transparentize } from 'polished';
|
|
15
|
+
import * as React from 'react';
|
|
16
|
+
import { areEqual } from 'react-window';
|
|
17
|
+
import styled from '@darajs/styled-components';
|
|
18
|
+
// Get the row height from the font size of the root element to respect rem units
|
|
19
|
+
const { fontSize } = window.getComputedStyle(document.documentElement);
|
|
20
|
+
export const ROW_HEIGHT = parseFloat(fontSize) * 2.5;
|
|
21
|
+
// Prevents the isSorted or onClickRow prop being added to the dom element
|
|
22
|
+
export const shouldForwardProp = (prop) => !['isSorted', 'onClickRow'].includes(prop);
|
|
23
|
+
const Row = styled.div.withConfig({ shouldForwardProp }) `
|
|
24
|
+
cursor: ${(props) => (props.onClickRow ? 'pointer' : 'default')};
|
|
25
|
+
display: flex;
|
|
26
|
+
|
|
27
|
+
:hover {
|
|
28
|
+
div {
|
|
29
|
+
background-color: ${(props) => props.theme.colors.grey1};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
:active,
|
|
34
|
+
:focus {
|
|
35
|
+
div {
|
|
36
|
+
background-color: ${(props) => props.theme.colors.grey2};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
const RowPlaceholder = styled(Row) `
|
|
41
|
+
position: absolute;
|
|
42
|
+
left: 0;
|
|
43
|
+
|
|
44
|
+
display: flex;
|
|
45
|
+
align-items: center;
|
|
46
|
+
justify-content: center;
|
|
47
|
+
`;
|
|
48
|
+
const CellPlaceholder = styled.div `
|
|
49
|
+
min-width: 80px;
|
|
50
|
+
height: 0.7rem;
|
|
51
|
+
margin: 0.5rem;
|
|
52
|
+
|
|
53
|
+
background: ${(props) => `linear-gradient(to right, ${props.theme.colors.grey2}, ${transparentize(0.2, props.theme.colors.grey3)}, ${props.theme.colors.grey2});`};
|
|
54
|
+
background-size: 50%;
|
|
55
|
+
border-radius: 0.5rem;
|
|
56
|
+
|
|
57
|
+
animation-name: ani-horizontal;
|
|
58
|
+
animation-duration: 3.5s;
|
|
59
|
+
animation-timing-function: linear;
|
|
60
|
+
animation-iteration-count: infinite;
|
|
61
|
+
|
|
62
|
+
@keyframes ani-horizontal {
|
|
63
|
+
0% {
|
|
64
|
+
background-position: -100% 0;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
100% {
|
|
68
|
+
background-position: 100% 0;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
`;
|
|
72
|
+
const Cell = styled.div `
|
|
73
|
+
display: flex !important;
|
|
74
|
+
align-items: center;
|
|
75
|
+
|
|
76
|
+
min-width: 80px;
|
|
77
|
+
height: ${() => `${ROW_HEIGHT}px`};
|
|
78
|
+
|
|
79
|
+
color: ${(props) => props.theme.colors.grey6};
|
|
80
|
+
|
|
81
|
+
background-color: ${(props) => props.theme.colors.blue1};
|
|
82
|
+
border-bottom: 1px solid ${(props) => props.theme.colors.grey3};
|
|
83
|
+
|
|
84
|
+
:last-child {
|
|
85
|
+
border-right: 0;
|
|
86
|
+
}
|
|
87
|
+
`;
|
|
88
|
+
const CellContent = styled.span `
|
|
89
|
+
overflow: hidden;
|
|
90
|
+
|
|
91
|
+
width: 100%;
|
|
92
|
+
padding: 0 1rem;
|
|
93
|
+
|
|
94
|
+
text-overflow: ellipsis;
|
|
95
|
+
white-space: nowrap;
|
|
96
|
+
`;
|
|
97
|
+
/**
|
|
98
|
+
* Checks if the previous and next props are equal while also
|
|
99
|
+
* forcing a re-render if any column in any headerGroup is being resized
|
|
100
|
+
*
|
|
101
|
+
* @param {any} prevProps - The previous props.
|
|
102
|
+
* @param {any} nextProps - The next props.
|
|
103
|
+
* @returns {boolean} - Whether the props are equal.
|
|
104
|
+
*/
|
|
105
|
+
const arePropsEqual = (prevProps, nextProps) => {
|
|
106
|
+
var _a;
|
|
107
|
+
return areEqual(prevProps, nextProps) &&
|
|
108
|
+
!(((_a = nextProps.data) === null || _a === void 0 ? void 0 : _a.headerGroups) || []).some((headerGroup) => ((headerGroup === null || headerGroup === void 0 ? void 0 : headerGroup.headers) || []).some((header) => header.isResizing));
|
|
109
|
+
};
|
|
110
|
+
const RenderRow = React.memo(({ data: { width, currentEditCell, headerGroups, rows, prepareRow, getItem, totalColumnsWidth, onClickRow, throttledClickRow, backgroundColor, mappedColumns, }, index, style: renderRowStyle, }) => {
|
|
111
|
+
let row = rows[index];
|
|
112
|
+
if (getItem) {
|
|
113
|
+
const value = getItem(index);
|
|
114
|
+
// attempting to render a row which there's no data yet, make sure loading state is used
|
|
115
|
+
if (!value) {
|
|
116
|
+
row = null;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
row.original = value;
|
|
120
|
+
row.values = value;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (!row) {
|
|
124
|
+
return (_jsx("div", { children: headerGroups.map((headerGroup, gidx) => (_jsx(RowPlaceholder, { style: {
|
|
125
|
+
height: ROW_HEIGHT,
|
|
126
|
+
top: (index + 1) * ROW_HEIGHT,
|
|
127
|
+
width: totalColumnsWidth > width ? totalColumnsWidth : '100%',
|
|
128
|
+
}, children: headerGroup === null || headerGroup === void 0 ? void 0 : headerGroup.headers.map((col, cidx) => {
|
|
129
|
+
const headerProps = col.getHeaderProps();
|
|
130
|
+
// If width calc has messed up then use the raw width from the column
|
|
131
|
+
const headerWidth = headerProps.style.width === 'NaNpx' ?
|
|
132
|
+
mappedColumns[cidx].width
|
|
133
|
+
: headerProps.style.width;
|
|
134
|
+
return (_jsx(CellPlaceholder, { style: {
|
|
135
|
+
maxWidth: col.maxWidth,
|
|
136
|
+
width: headerWidth,
|
|
137
|
+
} }, `col-${index}-${cidx}`));
|
|
138
|
+
}) }, `row-${gidx}`))) }));
|
|
139
|
+
}
|
|
140
|
+
prepareRow(row);
|
|
141
|
+
const onClick = () => {
|
|
142
|
+
if (onClickRow) {
|
|
143
|
+
throttledClickRow(row.original);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
const _a = row.getRowProps({ style: renderRowStyle }), { style: rowStyle } = _a, restRow = __rest(_a, ["style"]);
|
|
147
|
+
return (_createElement(Row, Object.assign({}, restRow, { key: `row-${index}`, onClick: onClick, onClickRow: onClickRow, style: Object.assign(Object.assign({}, rowStyle), { top: (index + 1) * ROW_HEIGHT, width: totalColumnsWidth > width ? totalColumnsWidth : '100%' }) }), row.cells.map((cell, colIdx) => {
|
|
148
|
+
var _a;
|
|
149
|
+
const cellProps = cell.getCellProps();
|
|
150
|
+
return (_createElement(Cell, Object.assign({}, cellProps, { key: `cell-${index}-${colIdx}`, style: Object.assign(Object.assign({}, cellProps.style), { backgroundColor, justifyContent: mappedColumns[colIdx].align, maxWidth: (_a = cell.column) === null || _a === void 0 ? void 0 : _a.maxWidth, width:
|
|
151
|
+
// If width calc has messed up then use the raw width from the column
|
|
152
|
+
cellProps.style.width === 'NaNpx' ?
|
|
153
|
+
mappedColumns[colIdx].width
|
|
154
|
+
: cellProps.style.width }) }),
|
|
155
|
+
_jsx(CellContent, { children: cell.render('Cell', {
|
|
156
|
+
colIdx,
|
|
157
|
+
currentEditCell,
|
|
158
|
+
rowIdx: index,
|
|
159
|
+
}) })));
|
|
160
|
+
})));
|
|
161
|
+
}, arePropsEqual);
|
|
162
|
+
export default RenderRow;
|
|
163
|
+
//# sourceMappingURL=render-row.js.map
|