Skip to content

Commit

Permalink
add date options to composed filter
Browse files Browse the repository at this point in the history
  • Loading branch information
balanza committed Aug 2, 2024
1 parent 8ed8ccd commit c4a6be7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
15 changes: 11 additions & 4 deletions assets/js/common/ComposedFilter/ComposedFilter.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import React, { useState } from 'react';
import Button from '@common/Button';
import Filter from '@common/Filter';
import DateFilter from '@common/DateFilter';

const renderFilter = ({ type, ...filterProps }, value, onChange) =>
type === 'select' ? (
<Filter {...filterProps} value={value} onChange={onChange} />
) : null;
const renderFilter = ({ type, ...filterProps }, value, onChange) => {
switch (type) {
case 'select':
return <Filter {...filterProps} value={value} onChange={onChange} />;
case 'date':
return <DateFilter {...filterProps} value={value} onChange={onChange} />;
default:
return null;
}
};

/**
* Define a filter which is the composition of several filters.
Expand Down
21 changes: 21 additions & 0 deletions assets/js/common/ComposedFilter/ComposedFilter.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,24 @@ export const Default = {
onChange: action('onChange'),
},
};

export const WithDateFilter = {
args: {
filters: [
{
key: 'filter1',
type: 'select',
title: 'Pasta',
options: ['Carbonara', 'Amatriciana', 'Ajo & Ojo', 'Gricia'],
},
{
key: 'filter2',
type: 'date',
title: 'Date',
prefill: true,
options: [['My birthday', () => new Date(1986, 0, 24)]],
},
],
onChange: action('onChange'),
},
};

0 comments on commit c4a6be7

Please sign in to comment.