react-mkx-toolkit
Advanced tools
Comparing version 1.0.9 to 1.1.1
@@ -19,3 +19,3 @@ "use strict"; | ||
const react_1 = __importDefault(require("react")); | ||
const useRowSelection_1 = require("./useRowSelection"); | ||
const useRowSelection_1 = require("useRowSelection"); | ||
Object.defineProperty(exports, "useRowSelection", { enumerable: true, get: function () { return useRowSelection_1.useRowSelection; } }); | ||
@@ -22,0 +22,0 @@ const Input = (_a) => { |
@@ -5,8 +5,8 @@ "use strict"; | ||
const react_1 = require("react"); | ||
const useRowSelection = (initialSelectedIds, key, data) => { | ||
const useRowSelection = ({ initialSelectedIds, key, data, }) => { | ||
const [selectedIds, setSelectedIds] = (0, react_1.useState)(initialSelectedIds); | ||
const handleSelectRow = (id) => { | ||
const onSelectRow = (id) => { | ||
setSelectedIds((prev) => prev.includes(id) ? prev.filter((i) => i !== id) : [...prev, id]); | ||
}; | ||
const handleSelectAllRow = () => { | ||
const onSelectAllRow = () => { | ||
try { | ||
@@ -21,6 +21,6 @@ if (selectedIds.length === (data === null || data === void 0 ? void 0 : data.length)) { | ||
catch (error) { | ||
console.error("Error occurred in handleSelectAllRow:", error); | ||
console.error("Error occurred in onSelectAllRow:", error); | ||
} | ||
}; | ||
const handleClearSelection = () => { | ||
const onClearSelection = () => { | ||
try { | ||
@@ -30,13 +30,8 @@ setSelectedIds([]); | ||
catch (error) { | ||
console.error("Error occurred in handleClearSelection:", error); | ||
console.error("Error occurred in onClearSelection:", error); | ||
} | ||
}; | ||
return { | ||
selectedIds, | ||
handleSelectRow, | ||
handleSelectAllRow, | ||
handleClearSelection, | ||
}; | ||
return { selectedIds, onSelectRow, onSelectAllRow, onClearSelection }; | ||
}; | ||
exports.useRowSelection = useRowSelection; | ||
//# sourceMappingURL=index.js.map |
@@ -6,1 +6,14 @@ export interface InputProps | ||
} | ||
export interface RowSelectionProps { | ||
selectedIds: Array<string | number>; | ||
onSelectRow: (id: string | number) => void; | ||
onSelectAllRow: () => void; | ||
onClearSelection: () => void; | ||
} | ||
export interface useRowSelectionProps { | ||
initialSelectedIds: Array<string | number>; | ||
key: string; | ||
data: Array<object>; | ||
} |
@@ -0,4 +1,4 @@ | ||
import { InputProps } from "index.d"; | ||
import React, { ChangeEvent } from "react"; | ||
import { InputProps } from "./index.d"; | ||
import { useRowSelection } from "./useRowSelection"; | ||
import { useRowSelection } from "useRowSelection"; | ||
/** | ||
@@ -5,0 +5,0 @@ * Input component. |
{ | ||
"name": "react-mkx-toolkit", | ||
"version": "1.0.9", | ||
"version": "1.1.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -0,1 +1,2 @@ | ||
import { useRowSelectionProps } from "index.d"; | ||
import { useState } from "react"; | ||
@@ -5,16 +6,14 @@ | ||
* Custom hook for managing row selection. | ||
* @param initialSelectedIds - Initial array of selected item ids. | ||
* @param key - The key used to access the id property in each item of the data array. | ||
* @param data - Data object containing items. | ||
* @param props - Props containing initialSelectedIds, key, and data. | ||
* @returns Object containing selectedIds state and selection handling functions. | ||
*/ | ||
const useRowSelection = ( | ||
initialSelectedIds: Array<string | number>, | ||
key: string, | ||
data: any | ||
): { | ||
const useRowSelection = ({ | ||
initialSelectedIds, | ||
key, | ||
data, | ||
}: useRowSelectionProps): { | ||
selectedIds: Array<string | number>; | ||
handleSelectRow: (id: string | number) => void; | ||
handleSelectAllRow: () => void; | ||
handleClearSelection: () => void; | ||
onSelectRow: (id: string | number) => void; | ||
onSelectAllRow: () => void; | ||
onClearSelection: () => void; | ||
} => { | ||
@@ -28,3 +27,3 @@ const [selectedIds, setSelectedIds] = | ||
*/ | ||
const handleSelectRow = (id: string | number): void => { | ||
const onSelectRow = (id: string | number): void => { | ||
setSelectedIds((prev) => | ||
@@ -38,3 +37,3 @@ prev.includes(id) ? prev.filter((i) => i !== id) : [...prev, id] | ||
*/ | ||
const handleSelectAllRow = (): void => { | ||
const onSelectAllRow = (): void => { | ||
try { | ||
@@ -47,3 +46,3 @@ if (selectedIds.length === data?.length) { | ||
} catch (error) { | ||
console.error("Error occurred in handleSelectAllRow:", error); | ||
console.error("Error occurred in onSelectAllRow:", error); | ||
} | ||
@@ -55,18 +54,13 @@ }; | ||
*/ | ||
const handleClearSelection = (): void => { | ||
const onClearSelection = (): void => { | ||
try { | ||
setSelectedIds([]); | ||
} catch (error) { | ||
console.error("Error occurred in handleClearSelection:", error); | ||
console.error("Error occurred in onClearSelection:", error); | ||
} | ||
}; | ||
return { | ||
selectedIds, | ||
handleSelectRow, | ||
handleSelectAllRow, | ||
handleClearSelection, | ||
}; | ||
return { selectedIds, onSelectRow, onSelectAllRow, onClearSelection }; | ||
}; | ||
export { useRowSelection }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
9200