-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from medyo/develop
Version 1.15.1
- Loading branch information
Showing
29 changed files
with
547 additions
and
318 deletions.
There are no files selected for viewing
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
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
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
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
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
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,41 @@ | ||
import { Option } from 'src/types' | ||
import { useState } from 'react' | ||
|
||
type ChipProps = { | ||
option: Option | ||
onSelect: (option: Option) => void | ||
active: boolean | ||
} | ||
|
||
const Chip = ({ option, onSelect, active = false }: ChipProps) => { | ||
return ( | ||
<button className={'chip ' + (active && 'active')} onClick={() => onSelect(option)}> | ||
{option.label} | ||
</button> | ||
) | ||
} | ||
|
||
type ChipsSetProps = { | ||
options: Option[] | ||
defaultValue: Option | ||
onChange: (option: Option) => void | ||
} | ||
|
||
export const ChipsSet = ({ options, onChange, defaultValue }: ChipsSetProps) => { | ||
const [selectedChip, setSelectedChip] = useState<Option>(defaultValue) | ||
|
||
const onSelect = (option: Option) => { | ||
setSelectedChip(option) | ||
onChange(option) | ||
} | ||
|
||
return ( | ||
<div className="chipsSet"> | ||
{options.map((option) => { | ||
return ( | ||
<Chip option={option} onSelect={onSelect} active={selectedChip.value === option.value} /> | ||
) | ||
})} | ||
</div> | ||
) | ||
} |
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 @@ | ||
export * from "./ChipsSet" |
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,95 @@ | ||
import { SupportedCard, GLOBAL_TAG, MY_LANGUAGES_TAG, dateRanges } from 'src/config' | ||
import { FiFilter } from 'react-icons/fi' | ||
import { useState } from 'react' | ||
import { BottomSheet } from 'react-spring-bottom-sheet' | ||
import 'react-spring-bottom-sheet/dist/style.css' | ||
import { useUserPreferences } from 'src/stores/preferences' | ||
import { trackCardLanguageSelect, trackCardDateRangeSelect } from 'src/lib/analytics' | ||
import { ChipsSet } from 'src/components/Elements' | ||
|
||
type ListingFilterMobileProps = { | ||
card: SupportedCard | ||
filters?: ('datesRange' | 'language')[] | ||
} | ||
|
||
export const FloatingFilter = ({ card, filters = ['language'] }: ListingFilterMobileProps) => { | ||
const [open, setOpen] = useState(false) | ||
const { userSelectedTags, cardsSettings, setCardSettings } = useUserPreferences() | ||
const [availableTagOptions] = useState( | ||
[GLOBAL_TAG, ...userSelectedTags, MY_LANGUAGES_TAG].map((tag) => ({ | ||
label: tag.label, | ||
value: tag.value, | ||
})) | ||
) | ||
return ( | ||
<> | ||
<button | ||
className="floatingFilter" | ||
onClick={() => setOpen(true)} | ||
style={open ? { display: 'none' } : {}}> | ||
<FiFilter className="floatingFilterIcon" /> | ||
</button> | ||
|
||
<BottomSheet | ||
defaultSnap={({ maxHeight }) => maxHeight / 2} | ||
open={open} | ||
expandOnContentDrag={true} | ||
onDismiss={() => setOpen(false)}> | ||
<div style={{ padding: '16px' }}> | ||
<div className="settings floatingFilterBottomSheet"> | ||
<h1 className="title">Customize {card.label}</h1> | ||
|
||
{filters.includes('language') && ( | ||
<div className="settingRow"> | ||
<p className="settingTitle">Language</p> | ||
<div className="settingContent"> | ||
<ChipsSet | ||
defaultValue={ | ||
availableTagOptions.find( | ||
(tag) => tag.value === cardsSettings[card.value]?.language | ||
) || { | ||
label: GLOBAL_TAG.label, | ||
value: GLOBAL_TAG.value, | ||
} | ||
} | ||
options={availableTagOptions} | ||
onChange={(option) => { | ||
setCardSettings(card.value, { | ||
...cardsSettings[card.value], | ||
language: option.value, | ||
}) | ||
trackCardLanguageSelect(card.analyticsTag, option.value) | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
)} | ||
|
||
{filters.includes('datesRange') && ( | ||
<div className="settingRow"> | ||
<p className="settingTitle">Date Range</p> | ||
<div className="settingContent"> | ||
<ChipsSet | ||
defaultValue={ | ||
dateRanges.find( | ||
(date) => date.value === cardsSettings[card.value]?.dateRange | ||
) || dateRanges[0] | ||
} | ||
options={dateRanges} | ||
onChange={(option) => { | ||
setCardSettings(card.value, { | ||
...cardsSettings[card.value], | ||
dateRange: option.value, | ||
}) | ||
trackCardDateRangeSelect(card.analyticsTag, option.value) | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
</BottomSheet> | ||
</> | ||
) | ||
} |
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 @@ | ||
export * from "./FloatingFilter" |
25 changes: 25 additions & 0 deletions
25
src/components/Elements/InlineTextFilter/InlineTextFilter.tsx
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,25 @@ | ||
import DropDownMenu from '../../DropDownMenu' | ||
|
||
type Option = { | ||
label: string | ||
value: string | ||
} | ||
type InlineTextFilterProps = { | ||
options: Option[] | ||
value: string | undefined | ||
onChange: (option: Option) => void | ||
} | ||
|
||
export const InlineTextFilter = ({ options, value, onChange }: InlineTextFilterProps) => { | ||
const tagId = `inline-text-filter-${Math.random().toString(16).slice(2)}` | ||
return ( | ||
<DropDownMenu | ||
data={options} | ||
tagId={tagId} | ||
label={options.find((opt) => opt.value === value)?.label || options[0].label} | ||
setSelectedDropDownItem={(item: Option) => { | ||
onChange(item) | ||
}} | ||
/> | ||
) | ||
} |
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 @@ | ||
export * from "./InlineTextFilter" |
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
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
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
Oops, something went wrong.