import React from 'react' import moment from 'moment' import { type Meta, type StoryObj } from '@storybook/react-vite' import { DocsTemplate } from '../../../.storybook' import TextInput from '../Form/TextInput' import { toast } from '../Toast/Toast' import { filterStatesDummyData } from './filter-stories-helper' import Filter from './Filter' const meta: Meta = { title: 'Components/Filter', component: Filter, parameters: { docs: { page: () => ( The Filter component is a versatile and customizable form element that offers a variety of filter options to help users refine data and search results. It includes several child elements such as Select, MultiSelect, Toggle, Picker,TextInput,{' '} Datepicker, and allows the addition of other custom children elements. The Filter component empowers users to apply various filter criteria to quickly find the information they need. } infoBullets={[ Use the Filter component in data-heavy interfaces or search functionalities where users need to refine results based on specific criteria. , Provide clear labels and instructions for each filter option, guiding users on how to use the filters effectively. , The Filter component includes proper styling to maintain a cohesive and user-friendly design. , ]} /> ), }, }, } export default meta type Story = StoryObj const Template: Story = { render: (args) => { return }, } export const Basic: Story = { ...Template, args: { filterStates: filterStatesDummyData, filterCallout: () => { toast({ message: 'You clicked filter button', type: 'success' }) }, cancelCallout: () => { toast({ message: 'You clicked cancel button', type: 'success' }) }, }, } export const DateRangeWithoutSearch: Story = { ...Template, args: { filterStates: { ...filterStatesDummyData, dates: { type: 'dates', defaultValue: { start_date: moment(), end_date: moment(), }, labelText: 'Date Range Without Search', stateName: 'date_range_no_search', }, }, }, } export const DateRangeWithFutureDatesEnabled: Story = { ...Template, args: { filterStates: { ...filterStatesDummyData, dates: { type: 'dates', defaultValue: { start_date: moment(), end_date: moment(), }, labelText: 'Date Range With Future Dates Enabled', stateName: 'date_range_future', }, }, }, } export const WithAppliedFilterCount: Story = { ...Template, args: { filterStates: filterStatesDummyData, filterCallout: () => { toast({ message: 'You clicked filter button', type: 'success' }) }, cancelCallout: () => { toast({ message: 'You clicked cancel button', type: 'success' }) }, appliedFilters: 4, }, } export const WithCustomChildren: Story = { ...Template, args: { filterStates: filterStatesDummyData, filterCallout: () => { toast({ message: 'You clicked filter button', type: 'success' }) }, cancelCallout: () => { toast({ message: 'You clicked cancel button', type: 'success' }) }, children: ({ close }) => ( { return }} value={''} labelText='Search' debounce={250} keyUp={() => close?.()} stateName={'search'} /> ), }, } export const WithTooltip: Story = { ...Template, args: { filterStates: filterStatesDummyData, filterCallout: () => { toast({ message: 'You clicked filter button', type: 'success' }) }, cancelCallout: () => { toast({ message: 'You clicked cancel button', type: 'success' }) }, }, } export const WithRightLabel: Story = { ...Template, args: { filterStates: filterStatesDummyData, filterCallout: () => { toast({ message: 'You clicked filter button', type: 'success' }) }, cancelCallout: () => { toast({ message: 'You clicked cancel button', type: 'success' }) }, }, } export const DisabledFilter: Story = { ...Template, args: { filterStates: filterStatesDummyData, filterCallout: () => { toast({ message: 'You clicked filter button', type: 'success' }) }, cancelCallout: () => { toast({ message: 'You clicked cancel button', type: 'success' }) }, disableFilterButton: true, }, } const MobileFilterWrapper = (args): React.JSX.Element => { const isMobileView = useMediaQuery({ type: 'max', breakpoint: 'md' }) return isMobileView ? ( ) : (

This view is available when the viewport is < 768px. Please resize the screen to see the mobile filter.

) } const Template2: Story = { render: (args) => { return }, } export const MobileFilter: Story = { ...Template2, args: { filterStates: filterStatesDummyData, filterCallout: () => { toast({ message: 'You clicked filter button', type: 'success' }) }, cancelCallout: () => { toast({ message: 'You clicked cancel button', type: 'success' }) }, }, } MobileFilter.storyName = 'Responsive' export const MobileFilterWithoutButtonText: Story = { ...Template2, args: { filterStates: filterStatesDummyData, filterCallout: () => { toast({ message: 'You clicked filter button', type: 'success' }) }, cancelCallout: () => { toast({ message: 'You clicked cancel button', type: 'success' }) }, hideMobileButtonText: true, }, } MobileFilterWithoutButtonText.storyName = 'Responsive without button text'