Implement new Select in FilterBar
This commit is contained in:
parent
1e3480e3c0
commit
d8d864a5fe
4 changed files with 82 additions and 47 deletions
|
|
@ -25,7 +25,8 @@
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select,
|
||||||
|
.SelectTrigger {
|
||||||
// background: url("/icons/Arrow.svg"), $grey-90;
|
// background: url("/icons/Arrow.svg"), $grey-90;
|
||||||
// background-repeat: no-repeat;
|
// background-repeat: no-repeat;
|
||||||
// background-position-y: center;
|
// background-position-y: center;
|
||||||
|
|
@ -37,6 +38,14 @@
|
||||||
max-width: 200px;
|
max-width: 200px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.SelectTrigger {
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
span {
|
||||||
|
font-size: $font-small;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.UserInfo {
|
.UserInfo {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
import React from 'react'
|
import React, { useState } from 'react'
|
||||||
import { useTranslation } from 'next-i18next'
|
import { useTranslation } from 'next-i18next'
|
||||||
import classNames from 'classnames'
|
import classNames from 'classnames'
|
||||||
|
|
||||||
import RaidDropdown from '~components/RaidDropdown'
|
import RaidDropdown from '~components/RaidDropdown'
|
||||||
|
|
||||||
import './index.scss'
|
import './index.scss'
|
||||||
|
import Select from '~components/Select'
|
||||||
|
import SelectItem from '~components/SelectItem'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
children: React.ReactNode
|
children: React.ReactNode
|
||||||
|
|
@ -27,6 +29,9 @@ const FilterBar = (props: Props) => {
|
||||||
// Set up translation
|
// Set up translation
|
||||||
const { t } = useTranslation('common')
|
const { t } = useTranslation('common')
|
||||||
|
|
||||||
|
const [recencyOpen, setRecencyOpen] = useState(false)
|
||||||
|
const [elementOpen, setElementOpen] = useState(false)
|
||||||
|
|
||||||
// Set up refs for filter dropdowns
|
// Set up refs for filter dropdowns
|
||||||
const elementSelect = React.createRef<HTMLSelectElement>()
|
const elementSelect = React.createRef<HTMLSelectElement>()
|
||||||
const raidSelect = React.createRef<HTMLSelectElement>()
|
const raidSelect = React.createRef<HTMLSelectElement>()
|
||||||
|
|
@ -38,17 +43,21 @@ const FilterBar = (props: Props) => {
|
||||||
shadow: props.scrolled,
|
shadow: props.scrolled,
|
||||||
})
|
})
|
||||||
|
|
||||||
function elementSelectChanged() {
|
function openElementSelect() {
|
||||||
const elementValue = elementSelect.current
|
setElementOpen(!elementOpen)
|
||||||
? parseInt(elementSelect.current.value)
|
}
|
||||||
: -1
|
|
||||||
|
function openRecencySelect() {
|
||||||
|
setRecencyOpen(!recencyOpen)
|
||||||
|
}
|
||||||
|
|
||||||
|
function elementSelectChanged(value: string) {
|
||||||
|
const elementValue = parseInt(value)
|
||||||
props.onFilter({ element: elementValue })
|
props.onFilter({ element: elementValue })
|
||||||
}
|
}
|
||||||
|
|
||||||
function recencySelectChanged() {
|
function recencySelectChanged(value: string) {
|
||||||
const recencyValue = recencySelect.current
|
const recencyValue = parseInt(value)
|
||||||
? parseInt(recencySelect.current.value)
|
|
||||||
: -1
|
|
||||||
props.onFilter({ recency: recencyValue })
|
props.onFilter({ recency: recencyValue })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -59,65 +68,76 @@ const FilterBar = (props: Props) => {
|
||||||
return (
|
return (
|
||||||
<div className={classes}>
|
<div className={classes}>
|
||||||
{props.children}
|
{props.children}
|
||||||
<select
|
<Select
|
||||||
|
defaultValue={-1}
|
||||||
|
trigger={'All elements'}
|
||||||
|
open={elementOpen}
|
||||||
onChange={elementSelectChanged}
|
onChange={elementSelectChanged}
|
||||||
ref={elementSelect}
|
onClick={openElementSelect}
|
||||||
value={props.element}
|
|
||||||
>
|
>
|
||||||
<option data-element="all" key={-1} value={-1}>
|
<SelectItem data-element="all" key={-1} value={-1}>
|
||||||
{t('elements.full.all')}
|
{t('elements.full.all')}
|
||||||
</option>
|
</SelectItem>
|
||||||
<option data-element="null" key={0} value={0}>
|
<SelectItem data-element="null" key={0} value={0}>
|
||||||
{t('elements.full.null')}
|
{t('elements.full.null')}
|
||||||
</option>
|
</SelectItem>
|
||||||
<option data-element="wind" key={1} value={1}>
|
<SelectItem data-element="wind" key={1} value={1}>
|
||||||
{t('elements.full.wind')}
|
{t('elements.full.wind')}
|
||||||
</option>
|
</SelectItem>
|
||||||
<option data-element="fire" key={2} value={2}>
|
<SelectItem data-element="fire" key={2} value={2}>
|
||||||
{t('elements.full.fire')}
|
{t('elements.full.fire')}
|
||||||
</option>
|
</SelectItem>
|
||||||
<option data-element="water" key={3} value={3}>
|
<SelectItem data-element="water" key={3} value={3}>
|
||||||
{t('elements.full.water')}
|
{t('elements.full.water')}
|
||||||
</option>
|
</SelectItem>
|
||||||
<option data-element="earth" key={4} value={4}>
|
<SelectItem data-element="earth" key={4} value={4}>
|
||||||
{t('elements.full.earth')}
|
{t('elements.full.earth')}
|
||||||
</option>
|
</SelectItem>
|
||||||
<option data-element="dark" key={5} value={5}>
|
<SelectItem data-element="dark" key={5} value={5}>
|
||||||
{t('elements.full.dark')}
|
{t('elements.full.dark')}
|
||||||
</option>
|
</SelectItem>
|
||||||
<option data-element="light" key={6} value={6}>
|
<SelectItem data-element="light" key={6} value={6}>
|
||||||
{t('elements.full.light')}
|
{t('elements.full.light')}
|
||||||
</option>
|
</SelectItem>
|
||||||
</select>
|
</Select>
|
||||||
|
|
||||||
<RaidDropdown
|
<RaidDropdown
|
||||||
currentRaid={props.raidSlug}
|
currentRaid={props.raidSlug}
|
||||||
|
defaultRaid="all"
|
||||||
showAllRaidsOption={true}
|
showAllRaidsOption={true}
|
||||||
onChange={raidSelectChanged}
|
onChange={raidSelectChanged}
|
||||||
ref={raidSelect}
|
ref={raidSelect}
|
||||||
/>
|
/>
|
||||||
<select onChange={recencySelectChanged} ref={recencySelect}>
|
|
||||||
<option key={-1} value={-1}>
|
<Select
|
||||||
|
defaultValue={-1}
|
||||||
|
trigger={'All time'}
|
||||||
|
open={recencyOpen}
|
||||||
|
onChange={recencySelectChanged}
|
||||||
|
onClick={openRecencySelect}
|
||||||
|
>
|
||||||
|
<SelectItem key={-1} value={-1}>
|
||||||
{t('recency.all_time')}
|
{t('recency.all_time')}
|
||||||
</option>
|
</SelectItem>
|
||||||
<option key={86400} value={86400}>
|
<SelectItem key={86400} value={86400}>
|
||||||
{t('recency.last_day')}
|
{t('recency.last_day')}
|
||||||
</option>
|
</SelectItem>
|
||||||
<option key={604800} value={604800}>
|
<SelectItem key={604800} value={604800}>
|
||||||
{t('recency.last_week')}
|
{t('recency.last_week')}
|
||||||
</option>
|
</SelectItem>
|
||||||
<option key={2629746} value={2629746}>
|
<SelectItem key={2629746} value={2629746}>
|
||||||
{t('recency.last_month')}
|
{t('recency.last_month')}
|
||||||
</option>
|
</SelectItem>
|
||||||
<option key={7889238} value={7889238}>
|
<SelectItem key={7889238} value={7889238}>
|
||||||
{t('recency.last_3_months')}
|
{t('recency.last_3_months')}
|
||||||
</option>
|
</SelectItem>
|
||||||
<option key={15778476} value={15778476}>
|
<SelectItem key={15778476} value={15778476}>
|
||||||
{t('recency.last_6_months')}
|
{t('recency.last_6_months')}
|
||||||
</option>
|
</SelectItem>
|
||||||
<option key={31556952} value={31556952}>
|
<SelectItem key={31556952} value={31556952}>
|
||||||
{t('recency.last_year')}
|
{t('recency.last_year')}
|
||||||
</option>
|
</SelectItem>
|
||||||
</select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import './index.scss'
|
||||||
interface Props {
|
interface Props {
|
||||||
showAllRaidsOption: boolean
|
showAllRaidsOption: boolean
|
||||||
currentRaid?: string
|
currentRaid?: string
|
||||||
|
defaultRaid?: string
|
||||||
onChange?: (slug?: string) => void
|
onChange?: (slug?: string) => void
|
||||||
onBlur?: (event: React.ChangeEvent<HTMLSelectElement>) => void
|
onBlur?: (event: React.ChangeEvent<HTMLSelectElement>) => void
|
||||||
}
|
}
|
||||||
|
|
@ -129,6 +130,7 @@ const RaidDropdown = React.forwardRef<HTMLSelectElement, Props>(
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Select
|
<Select
|
||||||
|
defaultValue={props.defaultRaid}
|
||||||
trigger={'Select a raid...'}
|
trigger={'Select a raid...'}
|
||||||
placeholder={'Select a raid...'}
|
placeholder={'Select a raid...'}
|
||||||
open={open}
|
open={open}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import './index.scss'
|
||||||
// Props
|
// Props
|
||||||
interface Props {
|
interface Props {
|
||||||
open: boolean
|
open: boolean
|
||||||
|
defaultValue?: string | number
|
||||||
placeholder?: string
|
placeholder?: string
|
||||||
trigger?: React.ReactNode
|
trigger?: React.ReactNode
|
||||||
children?: React.ReactNode
|
children?: React.ReactNode
|
||||||
|
|
@ -22,7 +23,10 @@ const Select = React.forwardRef<HTMLSelectElement, Props>(function useFieldSet(
|
||||||
ref
|
ref
|
||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<RadixSelect.Root onValueChange={props.onChange}>
|
<RadixSelect.Root
|
||||||
|
defaultValue={props.defaultValue as string}
|
||||||
|
onValueChange={props.onChange}
|
||||||
|
>
|
||||||
<RadixSelect.Trigger
|
<RadixSelect.Trigger
|
||||||
className={classNames('SelectTrigger', props.triggerClass)}
|
className={classNames('SelectTrigger', props.triggerClass)}
|
||||||
placeholder={props.placeholder}
|
placeholder={props.placeholder}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue