From a4a1c456e0788ca52261efb38ff3998710a42a59 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 17 Apr 2021 13:08:48 +0300 Subject: feat: add Filters to Page --- src/components/Input.tsx | 1 + src/components/Select.tsx | 1 + src/containers/Page.tsx | 35 ++++++++++++++++++++++------------- src/lib/ServiceContext.tsx | 6 ++++++ src/lib/ServiceList.tsx | 11 ++++++++++- 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/components/Input.tsx b/src/components/Input.tsx index a8a6f31..086093c 100644 --- a/src/components/Input.tsx +++ b/src/components/Input.tsx @@ -24,4 +24,5 @@ const InputBase: React.FC = ({ label, ...props }) => { const Input: React.FC = props => ; +export { InputBase }; export default Input; diff --git a/src/components/Select.tsx b/src/components/Select.tsx index 6b04e20..e65f8c4 100644 --- a/src/components/Select.tsx +++ b/src/components/Select.tsx @@ -34,4 +34,5 @@ const SelectBase: React.FC = ({ label, options, ...props }) => { const Select: React.FC = props => ; +export { SelectBase }; export default Select; diff --git a/src/containers/Page.tsx b/src/containers/Page.tsx index ae9e231..2fe54fa 100644 --- a/src/containers/Page.tsx +++ b/src/containers/Page.tsx @@ -1,28 +1,37 @@ import React from 'react'; import Paper from '../components/Paper'; import Button from '../components/Button'; -import { Action } from '../lib/ServiceContext'; +import { Action, Filter } from '../lib/ServiceContext'; +import { SelectBase } from '../components/Select'; interface Props { title?: string; actions?: Action[]; + filters?: Filter[]; className?: string; } const style = 'mb-2 flex justify-between md:flex-row md:items-center'; -const Page: React.FC = ({ title, actions, className, children }) => ( - -
1 ? 'flex-col items-start' : 'flex-row items-center'}`}> - {title} -
- {actions?.map(action => ())} +const Page: React.FC = ({ title, actions, filters, className, children }) => { + return ( + +
1 ? 'flex-col items-start' : 'flex-row items-center'}`}> + {title} +
+
+ {filters?.map(filter => ())} +
+
+ {actions?.map(action => ())} +
+
-
-
- {children} -
- -); +
+ {children} +
+ + ); +}; export default Page; diff --git a/src/lib/ServiceContext.tsx b/src/lib/ServiceContext.tsx index f7170d1..ec76106 100644 --- a/src/lib/ServiceContext.tsx +++ b/src/lib/ServiceContext.tsx @@ -2,11 +2,17 @@ import React from 'react'; import { FormikProps } from 'formik'; import { Props as ButtonProps } from '../components/Button'; import { Field } from '../components/ListTable'; +import { Option } from '../components/Select'; export interface Action extends ButtonProps { name: string; } +export interface Filter { + field: string; + options: Option[]; +} + export interface PanelProps { item: T; mutate: (item: T) => void; diff --git a/src/lib/ServiceList.tsx b/src/lib/ServiceList.tsx index e7015ae..a3c9842 100644 --- a/src/lib/ServiceList.tsx +++ b/src/lib/ServiceList.tsx @@ -16,6 +16,15 @@ const ServiceList: React.FC = () => { route: `/${service.route}/add${location.search}`, }]; + const filters = [{ + field: '_id', + options: [ + { key: 'a', label: 'a' }, + { key: 'b', label: 'b' }, + { key: 'c', label: 'c' }, + ], + }]; + const handleRowClick = (item: any) => { const route = service.rowLink ? service.rowLink(item) @@ -25,7 +34,7 @@ const ServiceList: React.FC = () => { }; return ( - + ); -- cgit v1.2.3