@onewelcome/react-lib-components 7.1.0 → 8.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/dist/cjs/DataGrid/DataGrid.cjs.js +1 -1
- package/dist/cjs/DataGrid/DataGrid.cjs.js.map +1 -1
- package/dist/cjs/DataGrid/DataGridBody/DataGridBody.cjs.js +1 -1
- package/dist/cjs/DataGrid/DataGridBody/DataGridBody.cjs.js.map +1 -1
- package/dist/cjs/DataGrid/DataGridBody/DataGridCell/DataGridCell.cjs.js +1 -1
- package/dist/cjs/DataGrid/DataGridBody/DataGridCell/DataGridCell.cjs.js.map +1 -1
- package/dist/cjs/DataGrid/DataGridBody/DataGridRow/DataGridRow.cjs.js +1 -1
- package/dist/cjs/DataGrid/DataGridBody/DataGridRow/DataGridRow.cjs.js.map +1 -1
- package/dist/cjs/DataGrid/DataGridFilters/DataGridSearchbar.cjs.js +2 -0
- package/dist/cjs/DataGrid/DataGridFilters/DataGridSearchbar.cjs.js.map +1 -0
- package/dist/cjs/DataGrid/DataGridFilters/DataGridToolbar.cjs.js +1 -1
- package/dist/cjs/DataGrid/DataGridFilters/DataGridToolbar.cjs.js.map +1 -1
- package/dist/cjs/DataGrid/DataGridFilters/DataGridToolbar.module.scss.cjs.js +1 -1
- package/dist/cjs/DataGrid/DataGridFilters/DataGridToolbarWrapper.cjs.js +2 -0
- package/dist/cjs/DataGrid/DataGridFilters/DataGridToolbarWrapper.cjs.js.map +1 -0
- package/dist/cjs/Form/FileUpload/FileUpload.module.scss.cjs.js +1 -1
- package/dist/cjs/Form/Select/MultiSelect/MultiSelect.cjs.js +1 -1
- package/dist/cjs/Form/Select/MultiSelect/MultiSelect.cjs.js.map +1 -1
- package/dist/cjs/Form/Select/SingleSelect/Select.cjs.js +1 -1
- package/dist/cjs/Form/Select/SingleSelect/Select.cjs.js.map +1 -1
- package/dist/cjs/src/components/DataGrid/DataGrid.d.ts +3 -4
- package/dist/cjs/src/components/DataGrid/DataGridBody/DataGridBody.d.ts +1 -0
- package/dist/cjs/src/components/DataGrid/DataGridBody/DataGridCell/DataGridCell.d.ts +1 -0
- package/dist/cjs/src/components/DataGrid/DataGridBody/DataGridRow/DataGridRow.d.ts +1 -0
- package/dist/cjs/src/components/DataGrid/DataGridFilters/DataGridSearchbar.d.ts +10 -0
- package/dist/cjs/src/components/DataGrid/DataGridFilters/DataGridToolbar.d.ts +3 -4
- package/dist/cjs/src/components/DataGrid/DataGridFilters/DataGridToolbarWrapper.d.ts +7 -0
- package/dist/esm/DataGrid/DataGrid.esm.js +7 -3
- package/dist/esm/DataGrid/DataGrid.esm.js.map +1 -1
- package/dist/esm/DataGrid/DataGridBody/DataGridBody.esm.js +2 -1
- package/dist/esm/DataGrid/DataGridBody/DataGridBody.esm.js.map +1 -1
- package/dist/esm/DataGrid/DataGridBody/DataGridCell/DataGridCell.esm.js +22 -3
- package/dist/esm/DataGrid/DataGridBody/DataGridCell/DataGridCell.esm.js.map +1 -1
- package/dist/esm/DataGrid/DataGridBody/DataGridRow/DataGridRow.esm.js +2 -1
- package/dist/esm/DataGrid/DataGridBody/DataGridRow/DataGridRow.esm.js.map +1 -1
- package/dist/esm/DataGrid/DataGridFilters/DataGridSearchbar.esm.js +43 -0
- package/dist/esm/DataGrid/DataGridFilters/DataGridSearchbar.esm.js.map +1 -0
- package/dist/esm/DataGrid/DataGridFilters/DataGridToolbar.esm.js +4 -5
- package/dist/esm/DataGrid/DataGridFilters/DataGridToolbar.esm.js.map +1 -1
- package/dist/esm/DataGrid/DataGridFilters/DataGridToolbar.module.scss.esm.js +2 -2
- package/dist/esm/DataGrid/DataGridFilters/DataGridToolbarWrapper.esm.js +25 -0
- package/dist/esm/DataGrid/DataGridFilters/DataGridToolbarWrapper.esm.js.map +1 -0
- package/dist/esm/Form/FileUpload/FileUpload.module.scss.esm.js +1 -1
- package/dist/esm/Form/Select/MultiSelect/MultiSelect.esm.js +1 -1
- package/dist/esm/Form/Select/MultiSelect/MultiSelect.esm.js.map +1 -1
- package/dist/esm/Form/Select/SingleSelect/Select.esm.js +1 -1
- package/dist/esm/Form/Select/SingleSelect/Select.esm.js.map +1 -1
- package/dist/esm/src/components/DataGrid/DataGrid.d.ts +3 -4
- package/dist/esm/src/components/DataGrid/DataGridBody/DataGridBody.d.ts +1 -0
- package/dist/esm/src/components/DataGrid/DataGridBody/DataGridCell/DataGridCell.d.ts +1 -0
- package/dist/esm/src/components/DataGrid/DataGridBody/DataGridRow/DataGridRow.d.ts +1 -0
- package/dist/esm/src/components/DataGrid/DataGridFilters/DataGridSearchbar.d.ts +10 -0
- package/dist/esm/src/components/DataGrid/DataGridFilters/DataGridToolbar.d.ts +3 -4
- package/dist/esm/src/components/DataGrid/DataGridFilters/DataGridToolbarWrapper.d.ts +7 -0
- package/package.json +1 -1
- package/src/components/DataGrid/DataGrid.tsx +11 -6
- package/src/components/DataGrid/DataGridBody/DataGridBody.tsx +3 -0
- package/src/components/DataGrid/DataGridBody/DataGridCell/DataGridCell.tsx +34 -2
- package/src/components/DataGrid/DataGridBody/DataGridRow/DataGridRow.tsx +3 -0
- package/src/components/DataGrid/DataGridFilters/DataGridSearchbar.tsx +68 -0
- package/src/components/DataGrid/DataGridFilters/DataGridToolbar.module.scss +6 -1
- package/src/components/DataGrid/DataGridFilters/DataGridToolbar.tsx +13 -22
- package/src/components/DataGrid/DataGridFilters/DataGridToolbarWrapper.tsx +33 -0
- package/src/components/Form/FileUpload/FileUpload.module.scss +1 -2
- package/src/components/Form/Select/MultiSelect/MultiSelect.tsx +1 -3
- package/src/components/Form/Select/SingleSelect/Select.tsx +1 -3
|
@@ -14,7 +14,12 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import React, {
|
|
17
|
+
import React, {
|
|
18
|
+
ForwardRefRenderFunction,
|
|
19
|
+
ComponentPropsWithRef,
|
|
20
|
+
ReactElement,
|
|
21
|
+
Fragment
|
|
22
|
+
} from "react";
|
|
18
23
|
import { Typography } from "../../../Typography/Typography";
|
|
19
24
|
import classes from "./DataGridCell.module.scss";
|
|
20
25
|
|
|
@@ -22,6 +27,7 @@ export interface Props extends ComponentPropsWithRef<"td"> {
|
|
|
22
27
|
children?: ReactElement | string | number;
|
|
23
28
|
isLoading?: boolean;
|
|
24
29
|
spacing?: React.CSSProperties;
|
|
30
|
+
searchValue?: string;
|
|
25
31
|
cellIndex?: number;
|
|
26
32
|
columnLength?: number;
|
|
27
33
|
disableContextMenuColumn?: boolean;
|
|
@@ -33,6 +39,7 @@ const DataGridCellComponent: ForwardRefRenderFunction<HTMLTableCellElement, Prop
|
|
|
33
39
|
className,
|
|
34
40
|
isLoading,
|
|
35
41
|
spacing,
|
|
42
|
+
searchValue,
|
|
36
43
|
cellIndex,
|
|
37
44
|
columnLength,
|
|
38
45
|
disableContextMenuColumn,
|
|
@@ -52,6 +59,31 @@ const DataGridCellComponent: ForwardRefRenderFunction<HTMLTableCellElement, Prop
|
|
|
52
59
|
cellStyle.paddingRight = spacing?.paddingRight;
|
|
53
60
|
}
|
|
54
61
|
|
|
62
|
+
//NOTE: we might want to migrate to Highlight API once it's supported by Firefox
|
|
63
|
+
const renderContent = () => {
|
|
64
|
+
if (typeof children === "string" && searchValue) {
|
|
65
|
+
if (!children.toLowerCase().includes(searchValue.toLowerCase())) {
|
|
66
|
+
return children;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const matchingSequence = new RegExp(searchValue, "i").exec(children);
|
|
70
|
+
|
|
71
|
+
const parts = children.split(matchingSequence?.[0] ?? "");
|
|
72
|
+
return parts.map((part, i) => {
|
|
73
|
+
if (i === parts.length - 1) return <Fragment key={`${part}-${i}`}>{part}</Fragment>;
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<Fragment key={`${part}-${i}`}>
|
|
77
|
+
{part}
|
|
78
|
+
<mark data-testid={`${matchingSequence}-mark`}>{matchingSequence}</mark>
|
|
79
|
+
</Fragment>
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return children;
|
|
85
|
+
};
|
|
86
|
+
|
|
55
87
|
return (
|
|
56
88
|
<td
|
|
57
89
|
{...rest}
|
|
@@ -62,7 +94,7 @@ const DataGridCellComponent: ForwardRefRenderFunction<HTMLTableCellElement, Prop
|
|
|
62
94
|
{isLoading && <div className={classes["loading"]} aria-busy="true" aria-live="polite"></div>}
|
|
63
95
|
{!isLoading && (
|
|
64
96
|
<Typography className={classes["text"]} variant="body" tag="span">
|
|
65
|
-
{
|
|
97
|
+
{renderContent()}
|
|
66
98
|
</Typography>
|
|
67
99
|
)}
|
|
68
100
|
</td>
|
|
@@ -27,6 +27,7 @@ export interface Props extends ComponentPropsWithRef<"tr"> {
|
|
|
27
27
|
headers?: HeaderCell[];
|
|
28
28
|
isLoading?: boolean;
|
|
29
29
|
spacing?: React.CSSProperties;
|
|
30
|
+
searchValue?: string;
|
|
30
31
|
disableContextMenuColumn?: boolean;
|
|
31
32
|
expandableRowProps?: {
|
|
32
33
|
enableExpandableRow: boolean;
|
|
@@ -42,6 +43,7 @@ const DataGridRowComponent: ForwardRefRenderFunction<HTMLTableRowElement, Props>
|
|
|
42
43
|
children,
|
|
43
44
|
className,
|
|
44
45
|
headers,
|
|
46
|
+
searchValue,
|
|
45
47
|
isLoading,
|
|
46
48
|
spacing,
|
|
47
49
|
expandableRowProps,
|
|
@@ -61,6 +63,7 @@ const DataGridRowComponent: ForwardRefRenderFunction<HTMLTableRowElement, Props>
|
|
|
61
63
|
const visibleCells = React.Children.map(children as React.ReactElement[], (child, index) => {
|
|
62
64
|
if (child) {
|
|
63
65
|
const cellWithSpacing = React.cloneElement(child, {
|
|
66
|
+
searchValue,
|
|
64
67
|
spacing: spacing,
|
|
65
68
|
cellIndex: index,
|
|
66
69
|
columnLength: headers?.length,
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 OneWelcome B.V.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import React, { useState, useEffect } from "react";
|
|
18
|
+
import { InputWrapper } from "../../Form/Wrapper/InputWrapper/InputWrapper";
|
|
19
|
+
import { Icon, Icons } from "../../Icon/Icon";
|
|
20
|
+
import classes from "./DataGridToolbar.module.scss";
|
|
21
|
+
import { InputWrapperProps, useDebouncedCallback } from "../../..";
|
|
22
|
+
|
|
23
|
+
export interface DataGridSearchbarProps {
|
|
24
|
+
onSearch: (value: string) => void;
|
|
25
|
+
initialSearchValue?: string;
|
|
26
|
+
debounceTime?: number;
|
|
27
|
+
placeholder?: string;
|
|
28
|
+
inputWrapperProps?: InputWrapperProps;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const DataGridSearchbar = ({
|
|
32
|
+
onSearch,
|
|
33
|
+
initialSearchValue,
|
|
34
|
+
debounceTime,
|
|
35
|
+
inputWrapperProps,
|
|
36
|
+
placeholder
|
|
37
|
+
}: DataGridSearchbarProps) => {
|
|
38
|
+
const [search, setSearch] = useState(initialSearchValue ?? "");
|
|
39
|
+
const debouncedCallback = useDebouncedCallback(onSearch, debounceTime ?? 500);
|
|
40
|
+
const onSearchCallback = debounceTime ? debouncedCallback : onSearch;
|
|
41
|
+
|
|
42
|
+
const onChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
43
|
+
onSearchCallback(event.target.value);
|
|
44
|
+
setSearch(event.target.value);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
initialSearchValue && setSearch(initialSearchValue);
|
|
49
|
+
}, [initialSearchValue]);
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<InputWrapper
|
|
53
|
+
{...inputWrapperProps}
|
|
54
|
+
className={`${classes["searchbar"]} ${inputWrapperProps?.className ?? ""}`}
|
|
55
|
+
label={inputWrapperProps?.label ?? ""}
|
|
56
|
+
onChange={onChange}
|
|
57
|
+
type="search"
|
|
58
|
+
name={inputWrapperProps?.name ?? "searchbar"}
|
|
59
|
+
value={search}
|
|
60
|
+
inputProps={{
|
|
61
|
+
...inputWrapperProps?.inputProps,
|
|
62
|
+
type: "search",
|
|
63
|
+
prefix: <Icon icon={Icons.Search} />,
|
|
64
|
+
placeholder: placeholder ?? "Search items"
|
|
65
|
+
}}
|
|
66
|
+
></InputWrapper>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
@use "../../../mixins.module.scss";
|
|
18
18
|
|
|
19
|
-
.
|
|
19
|
+
.wrapper {
|
|
20
20
|
display: flex;
|
|
21
21
|
align-items: center;
|
|
22
22
|
justify-content: flex-start;
|
|
@@ -25,6 +25,11 @@
|
|
|
25
25
|
width: 100%;
|
|
26
26
|
padding-bottom: 1rem;
|
|
27
27
|
|
|
28
|
+
.searchbar {
|
|
29
|
+
min-width: 7rem;
|
|
30
|
+
flex-basis: 15rem;
|
|
31
|
+
}
|
|
32
|
+
|
|
28
33
|
.actions-wrapper {
|
|
29
34
|
display: flex;
|
|
30
35
|
align-items: center;
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import React, {
|
|
17
|
+
import React, { Fragment, useReducer } from "react";
|
|
18
18
|
import { DataGridFilter } from "./DataGridFilter";
|
|
19
19
|
import classes from "./DataGridToolbar.module.scss";
|
|
20
20
|
import {
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
} from "./DataGridFilters.interfaces";
|
|
27
27
|
import { Typography } from "../../Typography/Typography";
|
|
28
28
|
|
|
29
|
-
export interface DataGridToolbarProps
|
|
29
|
+
export interface DataGridToolbarProps {
|
|
30
30
|
columnsMetadata: DataGridColumnMetadata[];
|
|
31
31
|
filterValues?: Filter[];
|
|
32
32
|
translations?: FiltersTranslations;
|
|
@@ -62,26 +62,19 @@ const filtersReducer = (state: FiltersState, action: FiltersAction): FiltersStat
|
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
-
export const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
onFilterEdit,
|
|
75
|
-
onFilterDelete,
|
|
76
|
-
onFiltersClear,
|
|
77
|
-
...rest
|
|
78
|
-
},
|
|
79
|
-
ref
|
|
80
|
-
) => {
|
|
65
|
+
export const DataGridToolbar = ({
|
|
66
|
+
columnsMetadata,
|
|
67
|
+
filterValues,
|
|
68
|
+
translations,
|
|
69
|
+
onFilterAdd,
|
|
70
|
+
onFilterEdit,
|
|
71
|
+
onFilterDelete,
|
|
72
|
+
onFiltersClear
|
|
73
|
+
}: DataGridToolbarProps) => {
|
|
81
74
|
const [state, dispatch] = useReducer(filtersReducer, { filters: filterValues || [] });
|
|
82
75
|
const { clearButtonCaption = "Clear all filters" } = translations?.toolbar || {};
|
|
83
76
|
return (
|
|
84
|
-
<
|
|
77
|
+
<Fragment>
|
|
85
78
|
{state.filters.map(filter => (
|
|
86
79
|
<DataGridFilter
|
|
87
80
|
mode="EDIT"
|
|
@@ -119,8 +112,6 @@ export const DataGridToolbarComponent: ForwardRefRenderFunction<
|
|
|
119
112
|
</button>
|
|
120
113
|
)}
|
|
121
114
|
</div>
|
|
122
|
-
</
|
|
115
|
+
</Fragment>
|
|
123
116
|
);
|
|
124
117
|
};
|
|
125
|
-
|
|
126
|
-
export const DataGridToolbar = React.forwardRef(DataGridToolbarComponent);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 OneWelcome B.V.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import React, { ComponentPropsWithRef, ForwardRefRenderFunction } from "react";
|
|
18
|
+
import classes from "./DataGridToolbar.module.scss";
|
|
19
|
+
|
|
20
|
+
type Props = ComponentPropsWithRef<"div">;
|
|
21
|
+
|
|
22
|
+
export const DataGridToolbarWrapperComponent: ForwardRefRenderFunction<HTMLDivElement, Props> = (
|
|
23
|
+
{ children, ...rest },
|
|
24
|
+
ref
|
|
25
|
+
) => {
|
|
26
|
+
return (
|
|
27
|
+
<div ref={ref} className={classes["wrapper"]} {...rest}>
|
|
28
|
+
{children}
|
|
29
|
+
</div>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const DataGridToolbarWrapper = React.forwardRef(DataGridToolbarWrapperComponent);
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
.file-dropzone {
|
|
25
25
|
border-radius: var(--input-border-radius);
|
|
26
26
|
background-color: var(--input-background-color);
|
|
27
|
-
padding: 0.25rem 1.25rem;
|
|
28
27
|
position: relative;
|
|
29
28
|
|
|
30
29
|
.file-upload-title {
|
|
@@ -117,7 +116,7 @@
|
|
|
117
116
|
|
|
118
117
|
.file-selector-sub-text {
|
|
119
118
|
color: var(--greyed-out);
|
|
120
|
-
|
|
119
|
+
|
|
121
120
|
&.error {
|
|
122
121
|
color: var(--error);
|
|
123
122
|
display: block;
|
|
@@ -315,9 +315,7 @@ const MultiSelectComponent: ForwardRefRenderFunction<HTMLSelectElement, MultiSel
|
|
|
315
315
|
id={multiSelectId.current}
|
|
316
316
|
ref={containerReference}
|
|
317
317
|
onKeyDown={onArrowNavigation}
|
|
318
|
-
className={`custom-select ${classes.select} ${additionalClasses.join(" ")}
|
|
319
|
-
className ?? ""
|
|
320
|
-
}`}
|
|
318
|
+
className={`custom-select ${classes.select} ${additionalClasses.join(" ")}`}
|
|
321
319
|
>
|
|
322
320
|
<div
|
|
323
321
|
className={`${classes["custom-select"]} ${additionalClasses.join(" ")} `}
|
|
@@ -239,9 +239,7 @@ const SelectComponent: ForwardRefRenderFunction<HTMLSelectElement, SingleSelectP
|
|
|
239
239
|
{...filterProps(rest, /^data-/)}
|
|
240
240
|
ref={containerReference}
|
|
241
241
|
onKeyDown={onArrowNavigation}
|
|
242
|
-
className={`custom-select ${classes.select} ${additionalClasses.join(" ")}
|
|
243
|
-
className ?? ""
|
|
244
|
-
}`}
|
|
242
|
+
className={`custom-select ${classes.select} ${additionalClasses.join(" ")}`}
|
|
245
243
|
>
|
|
246
244
|
{searchVisible && renderSearch()}
|
|
247
245
|
<button
|