Skip to content

Commit

Permalink
Location filter modal (#27)
Browse files Browse the repository at this point in the history
* Add Location filter modal, update TimeFilter to also use the same FilterButton

* Rename "United Kingdom of Great Britain and Northern Island" to "United Kingdom"

* Remove count from Global/Online filter options
  • Loading branch information
gustavlrsn authored Jan 11, 2023
1 parent dc4871a commit e34dd27
Show file tree
Hide file tree
Showing 7 changed files with 429 additions and 143 deletions.
76 changes: 0 additions & 76 deletions components/Dropdown.tsx

This file was deleted.

42 changes: 11 additions & 31 deletions components/FilterArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import React, { Fragment } from 'react';
import AnimateHeight from 'react-animate-height';

import CategoryFilter from './CategorySelect';
import Dropdown from './Dropdown';
import { CloseIcon, DateIcon, FilterIcon, LocationPin } from './Icons';
import { CloseIcon, FilterIcon } from './Icons';
import { LocationFilter } from './LocationFilter';
import { TimeFilter } from './TimeFilter';

export const Filters = ({
filter,
Expand All @@ -16,7 +17,6 @@ export const Filters = ({
collectivesInView,
}) => {
const [expanded, setExpanded] = React.useState(!mobile);

return (
<div className="relative z-50 bg-white">
{mobile && (
Expand Down Expand Up @@ -49,43 +49,23 @@ export const Filters = ({
<AnimateHeight id="date-location-filters" duration={500} height={collectivesInView ? 'auto' : 0}>
<div className="mt-1 border-t pb-1 pt-2 lg:mt-4 lg:pt-4">
<div className="space-y-1 lg:space-y-2">
<Dropdown
ariaLabel="Location"
<LocationFilter
filter={filter}
currentCategoryColor={currentCategory.color.name}
fieldLabel={
<div className="flex items-center gap-2 whitespace-nowrap text-sm font-medium">
<LocationPin />
<span>Location</span>
</div>
}
options={locationOptions.map(option => ({
...option,
value: JSON.stringify({ type: option.type, value: option.value }),
}))}
value={JSON.stringify(filter.location)}
onOpen={() => {
mobile && setExpanded(false);
}}
onChange={option => {
setFilter({ location: JSON.parse(option.value) });
locationOptions={locationOptions}
setLocationFilter={locationFilter => {
setFilter({ location: locationFilter });
}}
/>
<Dropdown
ariaLabel="Date range"
<TimeFilter
filter={filter}
currentCategoryColor={currentCategory.color.name}
fieldLabel={
<div className="flex items-center gap-2 whitespace-nowrap text-sm font-medium">
<DateIcon />
<span>Date range</span>
</div>
}
options={[
{ value: 'ALL', label: 'All time' },
{ value: 'PAST_YEAR', label: 'Past 12 months' },
{ value: 'PAST_QUARTER', label: 'Past 3 months' },
]}
value={filter.timePeriod}
onChange={({ value }) => {
setTimeFilter={value => {
setFilter({ timePeriod: value });
}}
/>
Expand Down
39 changes: 39 additions & 0 deletions components/FilterButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React, { forwardRef } from 'react';

import { ChevronUpDown } from './Icons';

interface Props {
currentCategoryColor: string;
selectedOption?: any;
icon: any;
label: string;
onClick?: any;
}

const FilterButton: React.ForwardRefRenderFunction<HTMLButtonElement, Props> = (
{ currentCategoryColor, selectedOption, icon, label, onClick },
ref,
) => {
return (
<button
ref={ref}
onClick={onClick}
className={`group flex w-full items-center justify-between gap-2 rounded-lg border-2 bg-opacity-75 py-2 px-3 transition-colors ${
selectedOption && selectedOption.value !== 'ALL'
? `bg-${currentCategoryColor}-50 border-transparent hover:bg-opacity-100 hover:border-${currentCategoryColor}-100`
: 'border-transparent bg-white hover:border-gray-100 hover:bg-gray-50 '
}`}
>
<div className="flex items-center gap-2 whitespace-nowrap font-medium">
{icon}
<span>{label}</span>
</div>
<div className="flex items-center gap-1.5 overflow-hidden whitespace-nowrap">
<span className="overflow-hidden overflow-ellipsis">{selectedOption?.label ?? 'All locations'}</span>{' '}
<ChevronUpDown className="-mr-1 -ml-0.5 mt-0.5 h-4 w-4 flex-shrink-0" />
</div>
</button>
);
};

export default forwardRef<HTMLButtonElement, Props>(FilterButton);
Loading

1 comment on commit e34dd27

@vercel
Copy link

@vercel vercel bot commented on e34dd27 Jan 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.