fix: changes from review

This commit is contained in:
marcelines 2023-06-27 11:09:27 +01:00
parent 92f7dd20c3
commit c2a7c9b67b
No known key found for this signature in database
GPG Key ID: 56B1E53E2A3F43C7
5 changed files with 69 additions and 48 deletions

View File

@ -20,7 +20,7 @@ type Data = {
type Props = { type Props = {
data: Data[] data: Data[]
label: string label: string
noPadding?: boolean placeholder?: string
} }
const isAvatar = (value: unknown): value is string => { const isAvatar = (value: unknown): value is string => {
@ -43,8 +43,8 @@ const RenderIcon = (props: Data) => {
return cloneElement(props.avatar) || <></> return cloneElement(props.avatar) || <></>
} }
const FilterWithCheckboxes = (props: Props) => { const DropdownFilter = (props: Props) => {
const { data, label, noPadding } = props const { data, label, placeholder } = props
const [filterText, setFilterText] = useState('') const [filterText, setFilterText] = useState('')
@ -59,7 +59,7 @@ const FilterWithCheckboxes = (props: Props) => {
const currentBreakpoint = useCurrentBreakpoint() const currentBreakpoint = useCurrentBreakpoint()
return ( return (
<div className={noPadding ? '' : 'pr-2'}> <div>
<DropdownMenu onOpenChange={() => setIsOpen(!isOpen)}> <DropdownMenu onOpenChange={() => setIsOpen(!isOpen)}>
<Button <Button
size={32} size={32}
@ -82,7 +82,7 @@ const FilterWithCheckboxes = (props: Props) => {
> >
<div className="p-2 px-1"> <div className="p-2 px-1">
<Input <Input
placeholder="Find epics" placeholder={placeholder || 'Search'}
icon={<SearchIcon size={20} />} icon={<SearchIcon size={20} />}
size={32} size={32}
value={filterText} value={filterText}
@ -135,5 +135,5 @@ const FilterWithCheckboxes = (props: Props) => {
) )
} }
export { FilterWithCheckboxes } export { DropdownFilter }
export type { Props as FilterWithCheckboxesProps } export type { Props as DropdownFilterProps }

View File

@ -11,17 +11,15 @@ type Data = {
type Props = { type Props = {
data: Data[] data: Data[]
noPadding?: boolean
} }
const Sort = (props: Props) => { const DropdownSort = (props: Props) => {
const { data, noPadding } = props const { data } = props
const [selectedValue, setSelectedValue] = useState<number>() const [selectedValue, setSelectedValue] = useState<number>()
return ( return (
<div className={noPadding ? '' : 'pr-2'}> <div>
<DropdownMenu> <DropdownMenu>
<div className="relative"> <div className="relative">
<IconButton icon={<SortIcon size={20} />} variant="outline" /> <IconButton icon={<SortIcon size={20} />} variant="outline" />
@ -69,5 +67,5 @@ const Sort = (props: Props) => {
) )
} }
export { Sort } export { DropdownSort }
export type { Props as SortProps } export type { Props as DropdownSortProps }

View File

@ -1,3 +1,3 @@
export { FilterWithCheckboxes } from './filter-with-checkboxes' export { DropdownFilter } from './dropdown-filter'
export { Sort } from './sort' export { DropdownSort } from './dropdown-sort'
export { Tabs } from './tabs' export { Tabs } from './tabs'

View File

@ -6,10 +6,10 @@ import Link from 'next/link'
import { useCurrentBreakpoint } from '@/hooks/use-current-breakpoint' import { useCurrentBreakpoint } from '@/hooks/use-current-breakpoint'
import { FilterWithCheckboxes, Sort, Tabs } from './filters' import { DropdownFilter, DropdownSort, Tabs } from './filters'
import type { FilterWithCheckboxesProps } from './filters/filter-with-checkboxes' import type { DropdownFilterProps } from './filters/dropdown-filter'
import type { SortProps } from './filters/sort' import type { DropdownSortProps } from './filters/dropdown-sort'
import type { TextInput } from 'react-native' import type { TextInput } from 'react-native'
const issues = [ const issues = [
@ -55,7 +55,7 @@ const issues = [
}, },
] ]
const authors: FilterWithCheckboxesProps['data'] = [ const authors: DropdownFilterProps['data'] = [
{ {
id: 4, id: 4,
name: 'marcelines', name: 'marcelines',
@ -78,7 +78,7 @@ const authors: FilterWithCheckboxesProps['data'] = [
}, },
] ]
const epics: FilterWithCheckboxesProps['data'] = [ const epics: DropdownFilterProps['data'] = [
{ {
id: 4, id: 4,
name: 'E:ActivityCenter', name: 'E:ActivityCenter',
@ -101,7 +101,7 @@ const epics: FilterWithCheckboxesProps['data'] = [
}, },
] ]
const labels: FilterWithCheckboxesProps['data'] = [ const labels: DropdownFilterProps['data'] = [
{ {
id: 4, id: 4,
name: 'Mobile', name: 'Mobile',
@ -124,7 +124,7 @@ const labels: FilterWithCheckboxesProps['data'] = [
}, },
] ]
const assignees: FilterWithCheckboxesProps['data'] = [ const assignees: DropdownFilterProps['data'] = [
{ {
id: 1, id: 1,
name: 'Unassigned', name: 'Unassigned',
@ -152,7 +152,7 @@ const assignees: FilterWithCheckboxesProps['data'] = [
}, },
] ]
const repositories: FilterWithCheckboxesProps['data'] = [ const repositories: DropdownFilterProps['data'] = [
{ {
id: 1, id: 1,
name: 'status-mobile', name: 'status-mobile',
@ -191,7 +191,7 @@ const repositories: FilterWithCheckboxesProps['data'] = [
}, },
] ]
const sortOptions: SortProps['data'] = [ const sortOptions: DropdownSortProps['data'] = [
{ {
id: 1, id: 1,
name: 'Default', name: 'Default',
@ -217,7 +217,6 @@ const sortOptions: SortProps['data'] = [
const TableIssues = () => { const TableIssues = () => {
const [issuesSearchText, setIssuesSearchText] = useState('') const [issuesSearchText, setIssuesSearchText] = useState('')
const inputRef = useRef<TextInput>(null) const inputRef = useRef<TextInput>(null)
const [isMinimized, setIsMinimized] = useState(true)
const currentBreakpoint = useCurrentBreakpoint() const currentBreakpoint = useCurrentBreakpoint()
@ -228,29 +227,51 @@ const TableIssues = () => {
<Tabs /> <Tabs />
<div className="flex-1"> <div className="flex-1">
<div className="flex items-center 2xl:justify-end"> <div className="flex items-center 2xl:justify-end">
<div className="flex w-full justify-between pr-2 pt-4 2xl:justify-end 2xl:pt-0"> <div className="flex w-full justify-between pt-4 2xl:justify-end 2xl:pt-0">
<div className="flex"> <div className="flex gap-2">
<div className="pr-2 transition-all"> <div className="transition-all">
<Input <Input
placeholder="Find Author" placeholder="Find Author"
icon={<SearchIcon size={20} />} icon={<SearchIcon size={20} />}
size={32} size={32}
value={issuesSearchText} value={issuesSearchText}
onChangeText={setIssuesSearchText} onChangeText={setIssuesSearchText}
onHandleMinimized={() => setIsMinimized(!isMinimized)} variant="retractable"
minimized={isMinimized}
direction={currentBreakpoint === '2xl' ? 'rtl' : 'ltr'} direction={currentBreakpoint === '2xl' ? 'rtl' : 'ltr'}
ref={inputRef} ref={inputRef}
/> />
</div> </div>
<FilterWithCheckboxes data={authors} label="Author" /> <DropdownFilter
<FilterWithCheckboxes data={epics} label="Epics" /> data={authors}
<FilterWithCheckboxes data={labels} label="Labels" /> label="Author"
<FilterWithCheckboxes data={assignees} label="Assignee" /> placeholder="Find author"
<FilterWithCheckboxes data={repositories} label="Repos" /> />
<DropdownFilter
data={epics}
label="Epics"
placeholder="Find epic"
/>
<DropdownFilter
data={labels}
label="Labels"
placeholder="Find label"
/>
<DropdownFilter
data={assignees}
label="Assignee"
placeholder="Find assignee"
/>
<DropdownFilter
data={repositories}
label="Repos"
placeholder="Find repo"
/>
</div>
<div className="pl-2">
<DropdownSort data={sortOptions} />
</div> </div>
<Sort data={sortOptions} noPadding />
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,4 +1,4 @@
import { cloneElement, forwardRef } from 'react' import { cloneElement, forwardRef, useState } from 'react'
import { ClearIcon } from '@status-im/icons' import { ClearIcon } from '@status-im/icons'
import { setupReactNative, Stack, styled } from '@tamagui/core' import { setupReactNative, Stack, styled } from '@tamagui/core'
@ -24,10 +24,9 @@ type Props = GetProps<typeof InputFrame> & {
icon?: React.ReactElement icon?: React.ReactElement
label?: string label?: string
onClear?: () => void onClear?: () => void
onHandleMinimized?: (isMinimized: boolean) => void variant?: 'default' | 'retractable'
size?: 40 | 32 size?: 40 | 32
error?: boolean error?: boolean
minimized?: boolean
direction?: 'ltr' | 'rtl' direction?: 'ltr' | 'rtl'
} }
@ -41,14 +40,17 @@ const _Input = (props: Props, ref: Ref<TextInput>) => {
label, label,
onClear, onClear,
size = 40, size = 40,
minimized,
placeholder, placeholder,
value, value,
direction = 'ltr', direction = 'ltr',
onHandleMinimized, variant = 'default',
...rest ...rest
} = props } = props
const [isMinimized, setIsMinimized] = useState(variant === 'retractable')
const isRetractable = variant === 'retractable'
return ( return (
<Stack flexDirection={direction === 'ltr' ? 'row' : 'row-reverse'}> <Stack flexDirection={direction === 'ltr' ? 'row' : 'row-reverse'}>
{Boolean(label || endLabel) && ( {Boolean(label || endLabel) && (
@ -68,13 +70,13 @@ const _Input = (props: Props, ref: Ref<TextInput>) => {
<InputContainer <InputContainer
size={size} size={size}
error={error} error={error}
minimized={minimized} minimized={isMinimized}
onPress={event => { onPress={event => {
event.stopPropagation() event.stopPropagation()
event.preventDefault() event.preventDefault()
if (onHandleMinimized && minimized) { if (isRetractable && isMinimized) {
onHandleMinimized(false) setIsMinimized(false)
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore ref is not inferred correctly here // @ts-ignore ref is not inferred correctly here
@ -87,12 +89,12 @@ const _Input = (props: Props, ref: Ref<TextInput>) => {
) : null} ) : null}
<InputBase <InputBase
value={value} value={value}
placeholder={minimized && !value ? '' : placeholder} placeholder={isMinimized && !value ? '' : placeholder}
flex={1} flex={1}
ref={ref} ref={ref}
onBlur={() => { onBlur={() => {
if (!value && onHandleMinimized && !minimized) { if (!value && isRetractable && !isMinimized) {
onHandleMinimized?.(true) setIsMinimized(true)
} }
}} }}
{...rest} {...rest}