@scheels-softdev/kendoreact-generics 1.2.1

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.
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import { GridFilterCellProps } from "@progress/kendo-react-grid";
3
+ interface DropdownFilterCellProps<T> extends GridFilterCellProps {
4
+ defaultItem?: any;
5
+ data: T[];
6
+ descriptionKeys: (keyof T)[];
7
+ separator?: string;
8
+ }
9
+ export declare function FilterCellDropdown<T>(props: DropdownFilterCellProps<T>): JSX.Element;
10
+ export {};
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Button } from "@progress/kendo-react-buttons";
3
+ import { GenericDropdown } from "./GenericDropdown";
4
+ // Define the DropdownFilterCell component with props of type DropdownFilterCellProps
5
+ export function FilterCellDropdown(props) {
6
+ // Define a function that returns true if a value is not undefined or null, and is different from the default item
7
+ let hasValue = (value) => Boolean(value && value !== props.defaultItem);
8
+ // Define an onChange function that will be called when the ComboBox value changes
9
+ const onChange = (event) => {
10
+ // Update the hasValue variable based on the new value of the ComboBox
11
+ hasValue = hasValue(event.target.value.id);
12
+ // Call the onChange function passed down as a prop, passing a filter object with the new value and operator
13
+ props.onChange({
14
+ value: hasValue ? event.target.value.id : "",
15
+ operator: hasValue ? "eq" : "",
16
+ syntheticEvent: event.syntheticEvent,
17
+ });
18
+ };
19
+ // Define an onClearButtonClick function that will be called when the Clear button is clicked
20
+ const onClearButtonClick = (event) => {
21
+ event.preventDefault();
22
+ // Call the onChange function passed down as a prop, passing a filter object with empty values
23
+ props.onChange({
24
+ value: "",
25
+ operator: "",
26
+ syntheticEvent: event,
27
+ });
28
+ };
29
+ // Render a div containing a GenericDropdownWithSearch component and a Clear button
30
+ return (_jsxs("div", Object.assign({ className: "k-filtercell", "data-testid": "dropdownFilter" }, { children: [_jsx(GenericDropdown, { data: props.data, changeEvent: onChange, selectedId: props.value, textFields: [...props.descriptionKeys], separator: props.separator }), _jsx(Button, { title: "Clear", disabled: !hasValue(props.value), onClick: onClearButtonClick, icon: "filter-clear" })] })));
31
+ }
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ export declare function GenericDropdown<T>({ data, // array of data objects
3
+ selectedId, // id of the selected data object
4
+ changeEvent, // function to call when the selected value changes
5
+ textFields, // array of field names to use for text values
6
+ separator, // optional separator to use for concatenating text values
7
+ disabled, }: {
8
+ data: T[];
9
+ selectedId: number;
10
+ changeEvent: Function;
11
+ textFields: (keyof T)[];
12
+ separator?: string;
13
+ disabled?: boolean;
14
+ }): JSX.Element;
@@ -0,0 +1,70 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { ComboBox } from "@progress/kendo-react-dropdowns";
3
+ import { filterBy } from "@progress/kendo-data-query";
4
+ import { useEffect, useRef, useState } from "react";
5
+ // function to concatenate text values from dataItem using specified fields and separator
6
+ const getTextValue = (dataItem, fields, separator) => {
7
+ let textValue = "";
8
+ fields.forEach((field, index) => (textValue += index > 0 ? (separator ? separator : " ") + dataItem[field] : dataItem[field]));
9
+ return textValue;
10
+ };
11
+ // component that renders a dropdown with a search filter
12
+ export function GenericDropdown({ data, // array of data objects
13
+ selectedId, // id of the selected data object
14
+ changeEvent, // function to call when the selected value changes
15
+ textFields, // array of field names to use for text values
16
+ separator, // optional separator to use for concatenating text values
17
+ disabled, // boolean to disable the dropdown
18
+ }) {
19
+ //redux state
20
+ //local state
21
+ const pageSize = 15;
22
+ const [dataList, setDataList] = useState(data.map((x) => {
23
+ return Object.assign(Object.assign({}, x), { textValue: getTextValue(x, textFields.map((x) => x.toString()), separator) });
24
+ }));
25
+ const [state, setState] = useState({
26
+ skip: 0,
27
+ total: dataList.length,
28
+ subsetData: dataList.slice(0, pageSize),
29
+ });
30
+ //external function variables
31
+ const filteredData = useRef(dataList.slice());
32
+ //function creation
33
+ // function to handle filter changes
34
+ const onFilterChange = (event) => {
35
+ var _a;
36
+ if ((_a = event.filter.value) === null || _a === void 0 ? void 0 : _a.length)
37
+ filteredData.current = filterBy(dataList.slice(), event.filter);
38
+ else
39
+ filteredData.current = dataList;
40
+ const newData = filteredData.current.slice(0, pageSize);
41
+ setState({
42
+ subsetData: newData,
43
+ skip: 0,
44
+ total: filteredData.current.length,
45
+ });
46
+ };
47
+ // function to handle page changes for virtualization
48
+ const pageChange = (event) => {
49
+ const skip = event.page.skip;
50
+ const take = event.page.take;
51
+ const newSubsetData = filteredData.current.slice(skip, skip + take);
52
+ setState(Object.assign(Object.assign({}, state), { subsetData: newSubsetData, skip: skip }));
53
+ };
54
+ //change event listeners
55
+ useEffect(() => {
56
+ setDataList(data.map((x) => {
57
+ return Object.assign(Object.assign({}, x), { textValue: getTextValue(x, textFields.map((x) => x.toString()), separator) });
58
+ }));
59
+ }, [data, textFields, separator]);
60
+ return (_jsx("div", Object.assign({ "data-testid": "dropdown" }, { children: _jsx(ComboBox, { disabled: disabled, style: {
61
+ maxWidth: "var(--app-nav-width)",
62
+ }, data: state.subsetData, textField: "textValue", virtual: {
63
+ // enable virtualization for large datasets
64
+ total: state.total,
65
+ pageSize: pageSize,
66
+ skip: state.skip,
67
+ }, onPageChange: pageChange, filterable: true, onFilterChange: onFilterChange, popupSettings: {
68
+ height: "210px",
69
+ }, onChange: (e) => e.value && changeEvent(e), onBlur: (e) => e.nativeEvent.preventDefault(), value: dataList.find((item) => selectedId === item.id) }) })));
70
+ }
package/PropTypes.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export type CommonProps = {
2
+ isEditing?: boolean;
3
+ id: number;
4
+ };
5
+ export type GridChangeEvent = {
6
+ value: any;
7
+ field?: string;
8
+ dataItem: any;
9
+ };
package/PropTypes.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/README.md ADDED
File without changes
package/Toolbar.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ type CommonProps = {
3
+ id: number;
4
+ isEditing?: boolean;
5
+ };
6
+ export declare function ToolbarButton<T extends CommonProps>({ item, data, setData }: {
7
+ item: T;
8
+ data: T[];
9
+ setData: Function;
10
+ }): JSX.Element;
11
+ export {};
package/Toolbar.js ADDED
@@ -0,0 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export function ToolbarButton({ item, data, setData }) {
3
+ return (_jsx("button", Object.assign({ title: "Add new", className: "k-button k-button-md k-rounded-md k-button-solid k-button-solid-primary", onClick: () => setData([Object.assign(Object.assign({}, item), { isEditing: true, id: 0 }), ...data]) }, { children: "Add Another" })));
4
+ }
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ export declare function CommandCellCheckBox({ checked, functionToRunOnCheck, functionToRunOnUncheck, }: {
3
+ checked: boolean;
4
+ functionToRunOnCheck: Function;
5
+ functionToRunOnUncheck: Function;
6
+ }): JSX.Element;
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Checkbox } from "@progress/kendo-react-inputs";
3
+ export function CommandCellCheckBox({ checked, functionToRunOnCheck, functionToRunOnUncheck, }) {
4
+ const functionToRun = () => {
5
+ if (checked) {
6
+ functionToRunOnUncheck();
7
+ }
8
+ else {
9
+ functionToRunOnCheck();
10
+ }
11
+ };
12
+ return (_jsx("td", Object.assign({ className: "justify-content-center", "data-testid": "checkbox" }, { children: _jsx(Checkbox, { checked: checked, onChange: functionToRun }) })));
13
+ }
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import { CommonProps, GridChangeEvent } from "../PropTypes";
3
+ export declare function CommandCellDate<T extends CommonProps>({ dataItem, chgFn: changeFunction, field, }: {
4
+ dataItem: T;
5
+ chgFn: (e: GridChangeEvent) => void;
6
+ field: keyof T;
7
+ }): JSX.Element;
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { DatePicker } from "@progress/kendo-react-dateinputs";
3
+ import moment from "moment";
4
+ export function CommandCellDate({ dataItem, chgFn: changeFunction, field, }) {
5
+ let valString = "" + dataItem[field];
6
+ let date = moment(valString).format("MM/DD/YY");
7
+ return (_jsx("td", Object.assign({ "data-testid": "date" }, { children: valString === undefined || dataItem.isEditing ? (_jsx(DatePicker, { value: new Date(moment(valString).format("MMMM, DD YYYY")), onChange: (e) => changeFunction({
8
+ field: field.toString(),
9
+ value: moment(e.value),
10
+ dataItem: dataItem,
11
+ }) })) : (date) })));
12
+ }
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { ComboBoxChangeEvent } from "@progress/kendo-react-dropdowns";
3
+ import { CommonProps } from "../PropTypes";
4
+ export declare function CommandCellDropdown<T extends CommonProps>(props: {
5
+ data: T[];
6
+ selectedId: number;
7
+ textFields: (keyof T)[];
8
+ changeEvent: (e: ComboBoxChangeEvent) => void;
9
+ separator?: string;
10
+ checkEditField?: boolean;
11
+ isEditing?: boolean;
12
+ }): JSX.Element;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { GenericDropdown } from "../GenericDropdown";
3
+ // This exports a function component called "CommandCellDropdown"
4
+ // It takes in various props that are used to render a dropdown in a table cell
5
+ export function CommandCellDropdown(props) {
6
+ return (_jsx("td", { children: props.checkEditField && !props.isEditing ? (props.textFields.map((x) => props.data.find((y) => y.id === props.selectedId)[x]).join(props.separator || " ")) : (
7
+ // If "props.checkEditField" is false or "props.isEditing" is true, render the GenericDropdownWithSearch component with the "props" passed to it
8
+ _jsx(GenericDropdown, Object.assign({}, props))) }));
9
+ }
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ export declare function CommandCellPrice({ cost }: {
3
+ cost: number;
4
+ }): JSX.Element;
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export function CommandCellPrice({ cost }) {
3
+ let formattedCost = new Intl.NumberFormat("en", {
4
+ style: "currency",
5
+ currency: "USD",
6
+ minimumSignificantDigits: 2,
7
+ maximumFractionDigits: 3,
8
+ }).format(cost);
9
+ return _jsx("td", Object.assign({ "data-testid": "price" }, { children: formattedCost }));
10
+ }
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { GridCellProps } from "@progress/kendo-react-grid";
3
+ export declare function CommandCellSwitch({ props, changeFunction }: {
4
+ props: GridCellProps;
5
+ changeFunction: Function;
6
+ }): JSX.Element;
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Switch } from "@progress/kendo-react-inputs";
3
+ export function CommandCellSwitch({ props, changeFunction }) {
4
+ return (_jsx("td", Object.assign({ "data-testid": "switch" }, { children: props.dataItem.isEditing ? (_jsx(Switch, { onChange: () => changeFunction(), checked: props.dataItem[props.field] })) : (props.dataItem[props.field].toString()) })));
5
+ }
package/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export { CommandCellCheckBox } from "./commandCell/CommandCellCheckbox";
2
+ export { CommandCellDate } from "./commandCell/CommandCellDate";
3
+ export { CommandCellDropdown } from "./commandCell/CommandCellDropdown";
4
+ export { CommandCellPrice } from "./commandCell/CommandCellPrice";
5
+ export { CommandCellSwitch } from "./commandCell/CommandCellSwitch";
6
+ export { FilterCellDropdown } from "./FilterCellDropdown";
7
+ export { ToolbarButton } from "./Toolbar";
8
+ export { GenericDropdown } from "./GenericDropdown";
9
+ export { GridChangeEvent, CommonProps } from "./PropTypes";
package/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export { CommandCellCheckBox } from "./commandCell/CommandCellCheckbox";
2
+ export { CommandCellDate } from "./commandCell/CommandCellDate";
3
+ export { CommandCellDropdown } from "./commandCell/CommandCellDropdown";
4
+ export { CommandCellPrice } from "./commandCell/CommandCellPrice";
5
+ export { CommandCellSwitch } from "./commandCell/CommandCellSwitch";
6
+ export { FilterCellDropdown } from "./FilterCellDropdown";
7
+ export { ToolbarButton } from "./Toolbar";
8
+ export { GenericDropdown } from "./GenericDropdown";
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@scheels-softdev/kendoreact-generics",
3
+ "version": "1.2.1",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1",
7
+ "clean": "rm -r ./dist && mkdir dist",
8
+ "build": "npm run clean && tsc && cp package.json README.md ./dist"
9
+ },
10
+ "keywords": [
11
+ "kendo"
12
+ ],
13
+ "author": "JaegerEdward98",
14
+ "license": "ISC",
15
+ "dependencies": {
16
+ "@progress/kendo-data-query": "^1.6.0",
17
+ "npmrc": "^1.1.1"
18
+ },
19
+ "devDependencies": {
20
+ "@progress/kendo-react-dateinputs": "^5.12.0",
21
+ "@progress/kendo-react-dropdowns": "^5.12.0",
22
+ "@progress/kendo-react-grid": "^5.12.0",
23
+ "@progress/kendo-react-inputs": "^5.12.0",
24
+ "@types/moment": "^2.13.0",
25
+ "@types/react": "^18.0.28",
26
+ "moment": "^2.29.4",
27
+ "react": "^18.2.0",
28
+ "react-dom": "^18.2.0",
29
+ "typescript": "^4.9.5"
30
+ },
31
+ "description": ""
32
+ }