-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add helper function for creating a DataTable column filter
Signed-off-by: Mike Murray <hellomikemurray@gmail.com>
- Loading branch information
1 parent
a8ed974
commit d665bc0
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
package/src/components/DataTableFilter/helpers/makeDataTableColumnFilter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import DataTableFilter from "../DataTableFilter"; | ||
|
||
/** | ||
* @name makeDataTableColumnFilter | ||
* @summary Helper function for creating a column filter for the DataTable. | ||
* @param {Object} props Props to be applied to the DataTableFilter component | ||
* @param {Array} props.options Array of options `[{ label: "Display Label", value: "value" }] | ||
* @param {String} props.title Title to be displayed for the drop down button, or in the card title | ||
* @returns {PropTypes.elementType} DataTableFilter component configured with props | ||
*/ | ||
export default function makeDataTableColumnFilter(props) { | ||
const DataTableColumnFilter = ({ | ||
column: { filterValue, setFilter }, | ||
container, | ||
className | ||
}) => ( | ||
<DataTableFilter | ||
title="Filter" | ||
className={className} | ||
container={container} | ||
onSelect={(value) => setFilter(value)} | ||
value={filterValue} | ||
{...props} | ||
/> | ||
); | ||
|
||
DataTableColumnFilter.propTypes = { | ||
className: PropTypes.string, | ||
column: PropTypes.shape({ | ||
filterValue: PropTypes.any, | ||
setFilter: PropTypes.func | ||
}), | ||
container: PropTypes.oneOf(["default", "card"]) | ||
}; | ||
|
||
return DataTableColumnFilter; | ||
} |