diff --git a/src/components/filters/FilterAccordion.tsx b/src/components/filters/FilterAccordion.tsx index e69de29..a6454dd 100644 --- a/src/components/filters/FilterAccordion.tsx +++ b/src/components/filters/FilterAccordion.tsx @@ -0,0 +1,37 @@ +import React from 'react'; +import { + Accordion, + AccordionButton, + AccordionIcon, + AccordionItem, + AccordionPanel, + Box, +} from '@chakra-ui/react'; + +import { getAccordionItems } from '@components/filters/FilterOptions'; + +export function FilterAccordion(props) { + const accordionItems = getAccordionItems(props); + + return ( + <> + + {accordionItems.map(({ title, content }, index) => ( + +

+ + + {title} + + + +

+ + {content} + +
+ ))} +
+ + ); +} diff --git a/src/components/filters/FilterDrawer.tsx b/src/components/filters/FilterDrawer.tsx index 72a3fe2..da1885d 100644 --- a/src/components/filters/FilterDrawer.tsx +++ b/src/components/filters/FilterDrawer.tsx @@ -16,6 +16,7 @@ import { } from '@chakra-ui/react'; import { DrawerType } from '@components/types'; +// import { FilterAccordion } from '@components/filters/FilterAccordion'; export function FilterDrawer({ isOpen, @@ -52,16 +53,34 @@ export function FilterDrawer({ Filtrar por: + {/* */} + Idioma @@ -92,7 +111,7 @@ export function FilterDrawer({ ))} handleAllRadioChange('language')}> - Todos los Idiomas + Todos @@ -125,7 +144,7 @@ export function FilterDrawer({ ))} handleAllRadioChange('year')}> - Todos los Años + Todos diff --git a/src/components/filters/FilterOptions.tsx b/src/components/filters/FilterOptions.tsx new file mode 100644 index 0000000..d194bbd --- /dev/null +++ b/src/components/filters/FilterOptions.tsx @@ -0,0 +1,96 @@ +import React from 'react'; + +import { FilterNumberPages } from '@components/filters/FilterNumberPages'; +import { FilterRadioGroup } from '@components/filters/FilterRadioGroup'; +import { capitalizeWords } from '@utils/utils'; + +interface FilterAccordionTypes { + selectedMinPages: string; + selectedMaxPages: string; + handleMinChange: React.ChangeEventHandler; + handleMaxChange: React.ChangeEventHandler; + selectedLanguage: string; + handleLanguageChange: (value: string) => void; + languages: string[]; + selectedYear: string; + handleYearChange: (value: string) => void; + years: string[]; + selectedAuthor: string; + handleAuthorChange: (value: string) => void; + authors: string[]; +} + +export function getAccordionItems({ + selectedMinPages, + selectedMaxPages, + handleMinChange, + handleMaxChange, + selectedLanguage, + handleLanguageChange, + languages, + selectedYear, + handleYearChange, + years, + selectedAuthor, + handleAuthorChange, + authors, +}: FilterAccordionTypes) { + return [ + { + title: 'N° de páginas', + content: ( + + ), + }, + { + title: 'Idioma', + content: ( + ({ + value: language, + label: language, + count, + }))} + selectedValue={selectedLanguage} + onChange={handleLanguageChange} + allLabel='Todos' + /> + ), + }, + { + title: 'Año', + content: ( + ({ + value: String(year), + label: String(year), + count, + }))} + selectedValue={selectedYear} + onChange={handleYearChange} + allLabel='Todos' + /> + ), + }, + { + title: 'Autor', + content: ( + ({ + value: authors, + label: capitalizeWords(authors), + count, + }))} + selectedValue={selectedAuthor} + onChange={handleAuthorChange} + allLabel='Todos' + /> + ), + }, + ]; +} diff --git a/src/components/filters/FilterRadioGroup.tsx b/src/components/filters/FilterRadioGroup.tsx new file mode 100644 index 0000000..629ce81 --- /dev/null +++ b/src/components/filters/FilterRadioGroup.tsx @@ -0,0 +1,38 @@ +import React from 'react'; +import { RadioGroup, Radio, Box, Flex } from '@chakra-ui/react'; + +interface OptionType { + value: string; + label: string; + count: number; +} + +interface FilterRadioGroupType { + options: Array; + selectedValue: string; + onChange: (value: string) => void; + allLabel: string; +} + +export function FilterRadioGroup({ + options, + selectedValue, + onChange, + allLabel, +}: FilterRadioGroupType) { + return ( + + + {allLabel} + {options.map(({ value, label, count }) => ( + + {label} + + ({count}) + + + ))} + + + ); +} diff --git a/src/components/nav/MobileNav.tsx b/src/components/nav/MobileNav.tsx index 33f2356..c2bb668 100644 --- a/src/components/nav/MobileNav.tsx +++ b/src/components/nav/MobileNav.tsx @@ -188,7 +188,8 @@ export function MobileNav() { - - -

- - - N° de páginas - - - -

- - - -
- -

- - - Idioma - - - -

- - - - Todos los Idiomas - {Array.isArray(languages) && - languages.map(({ language, count }: any) => ( - - {language} - - ({count}) - - - ))} - - - -
- -

- - - Año - - - -

- - - - Todos los Años - {Array.isArray(years) && - years.map(({ year, count }: any) => ( - - {year} - - ({count}) - - - ))} - - - -
- -

- - - Autor - - - -

- - - - Todos los Autores - {Array.isArray(authors) && - authors.map(({ authors, count }: any) => ( - - {capitalizeWords(authors)} - - ({count}) - - - ))} - - - -
-
+ );