-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(fuselage):
PaginatedSelectFiltered
filter state (#661)
* fix * Simplify stories * Split into subcomponents * Rename directory Co-authored-by: Tiago Evangelista Pinto <tiago.evangelista@rocket.chat>
- Loading branch information
1 parent
9e170ff
commit 0975754
Showing
17 changed files
with
417 additions
and
4,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
File renamed without changes.
48 changes: 48 additions & 0 deletions
48
packages/fuselage/src/components/PaginatedSelect/PaginatedMultiSelectFiltered.stories.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,48 @@ | ||
import { useArgs } from '@storybook/client-api'; | ||
import type { ComponentStory, ComponentMeta } from '@storybook/react'; | ||
import React from 'react'; | ||
|
||
import { PaginatedMultiSelectFiltered } from '.'; | ||
|
||
export default { | ||
title: 'Inputs/PaginatedMultiSelectFiltered', | ||
component: PaginatedMultiSelectFiltered, | ||
args: { | ||
placeholder: 'Placeholder here...', | ||
options: Array.from({ length: 1000 }, (_, i) => ({ | ||
value: i, | ||
label: `Item #${i}`, | ||
})), | ||
}, | ||
parameters: { | ||
actions: { argTypesRegex: '^on.*' }, | ||
layout: 'centered', | ||
}, | ||
} as ComponentMeta<typeof PaginatedMultiSelectFiltered>; | ||
|
||
export const Normal: ComponentStory<typeof PaginatedMultiSelectFiltered> = ( | ||
args | ||
) => { | ||
const [, updateArgs] = useArgs(); | ||
|
||
return ( | ||
<PaginatedMultiSelectFiltered | ||
setFilter={(filter) => updateArgs({ filter })} | ||
{...args} | ||
/> | ||
); | ||
}; | ||
|
||
export const Errored: ComponentStory<typeof PaginatedMultiSelectFiltered> = ( | ||
args | ||
) => <PaginatedMultiSelectFiltered {...args} />; | ||
Errored.args = { | ||
error: true, | ||
}; | ||
|
||
export const Disabled: ComponentStory<typeof PaginatedMultiSelectFiltered> = ( | ||
args | ||
) => <PaginatedMultiSelectFiltered {...args} />; | ||
Disabled.args = { | ||
disabled: true, | ||
}; |
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
15 changes: 15 additions & 0 deletions
15
packages/fuselage/src/components/PaginatedSelect/PaginatedSelectAddon.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,15 @@ | ||
import type { ComponentProps, Ref } from 'react'; | ||
import React, { forwardRef } from 'react'; | ||
|
||
import { Box } from '../Box'; | ||
|
||
type PaginatedSelectAddonProps = ComponentProps<typeof Box>; | ||
|
||
const PaginatedSelectAddon = forwardRef(function PaginatedSelectAddon( | ||
props: PaginatedSelectAddonProps, | ||
ref: Ref<HTMLDivElement> | ||
) { | ||
return <Box is='div' rcx-select__addon ref={ref} {...props} />; | ||
}); | ||
|
||
export default PaginatedSelectAddon; |
37 changes: 37 additions & 0 deletions
37
packages/fuselage/src/components/PaginatedSelect/PaginatedSelectFiltered.stories.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,37 @@ | ||
import type { ComponentStory, ComponentMeta } from '@storybook/react'; | ||
import React from 'react'; | ||
|
||
import { PaginatedSelectFiltered } from '.'; | ||
|
||
export default { | ||
title: 'Inputs/PaginatedSelectFiltered', | ||
component: PaginatedSelectFiltered, | ||
args: { | ||
placeholder: 'Placeholder here...', | ||
options: Array.from({ length: 1000 }, (_, i) => ({ | ||
value: i, | ||
label: `Item #${i}`, | ||
})), | ||
width: '250px', | ||
}, | ||
parameters: { | ||
actions: { argTypesRegex: '^on.*' }, | ||
layout: 'centered', | ||
}, | ||
} as ComponentMeta<typeof PaginatedSelectFiltered>; | ||
|
||
const Template: ComponentStory<typeof PaginatedSelectFiltered> = (args) => ( | ||
<PaginatedSelectFiltered {...args} /> | ||
); | ||
|
||
export const normal = Template.bind({}); | ||
|
||
export const errored = Template.bind({}); | ||
errored.args = { | ||
error: 'Error', | ||
}; | ||
|
||
export const disabled = Template.bind({}); | ||
disabled.args = { | ||
disabled: true, | ||
}; |
58 changes: 58 additions & 0 deletions
58
packages/fuselage/src/components/PaginatedSelect/PaginatedSelectFiltered.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,58 @@ | ||
import { useMutableCallback } from '@rocket.chat/fuselage-hooks'; | ||
import type { FormEvent, Ref } from 'react'; | ||
import React, { useMemo, forwardRef } from 'react'; | ||
|
||
import { InputBox } from '../InputBox'; | ||
import type { PaginatedSelectProps } from './PaginatedSelect'; | ||
import { PaginatedSelect } from './PaginatedSelect'; | ||
|
||
type PaginatedSelectFilteredProps = Omit<PaginatedSelectProps, 'setFilter'> & { | ||
setFilter: (value: string | undefined | number) => void; | ||
}; | ||
|
||
export const PaginatedSelectFiltered = ({ | ||
filter, | ||
setFilter, | ||
options, | ||
placeholder, | ||
...props | ||
}: PaginatedSelectFilteredProps) => { | ||
const anchor = useMemo( | ||
() => | ||
forwardRef( | ||
( | ||
{ | ||
filter, | ||
onChange: _onChange, | ||
...props | ||
}: PaginatedSelectFilteredProps, | ||
ref: Ref<HTMLInputElement> | ||
) => ( | ||
<InputBox.Input | ||
mi='x4' | ||
flexGrow={1} | ||
className='rcx-select__focus' | ||
ref={ref} | ||
placeholder={placeholder} | ||
value={filter} | ||
onChange={useMutableCallback((e: FormEvent<HTMLInputElement>) => { | ||
setFilter(e.currentTarget.value); | ||
})} | ||
{...props} | ||
rcx-input-box--undecorated | ||
/> | ||
) | ||
), | ||
[placeholder, setFilter] | ||
); | ||
|
||
return ( | ||
<PaginatedSelect | ||
placeholder={undefined} | ||
filter={filter} | ||
options={options} | ||
{...props} | ||
anchor={anchor} | ||
/> | ||
); | ||
}; |
25 changes: 25 additions & 0 deletions
25
packages/fuselage/src/components/PaginatedSelect/PaginatedSelectFocus.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 type { ComponentProps, Ref } from 'react'; | ||
import React, { forwardRef } from 'react'; | ||
|
||
import { Box } from '../Box'; | ||
|
||
type PaginatedSelectFocusProps = ComponentProps<typeof Box>; | ||
|
||
const PaginatedSelectFocus = forwardRef(function PaginatedSelectFocus( | ||
props: PaginatedSelectFocusProps, | ||
ref: Ref<HTMLButtonElement> | ||
) { | ||
return ( | ||
<Box | ||
ref={ref} | ||
fontScale='p2m' | ||
color='hint' | ||
rcx-select__focus | ||
is='button' | ||
type='button' | ||
{...props} | ||
/> | ||
); | ||
}); | ||
|
||
export default PaginatedSelectFocus; |
15 changes: 15 additions & 0 deletions
15
packages/fuselage/src/components/PaginatedSelect/PaginatedSelectWrapper.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,15 @@ | ||
import type { ComponentProps, Ref } from 'react'; | ||
import React, { forwardRef } from 'react'; | ||
|
||
import { Box } from '../Box'; | ||
|
||
type PaginatedSelectWrapperProps = ComponentProps<typeof Box>; | ||
|
||
const PaginatedSelectWrapper = forwardRef(function PaginatedSelectWrapper( | ||
props: PaginatedSelectWrapperProps, | ||
ref: Ref<HTMLDivElement> | ||
) { | ||
return <Box is='div' rcx-select__wrapper ref={ref} {...props} />; | ||
}); | ||
|
||
export default PaginatedSelectWrapper; |
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,2 @@ | ||
export { PaginatedSelectFiltered } from './PaginatedSelectFiltered'; | ||
export { PaginatedMultiSelectFiltered } from './PaginatedMultiSelect'; |
File renamed without changes.
Oops, something went wrong.