-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fuselage): Component Dropdown (#594)
Co-authored-by: juliajforesti <juliajforesti@gmail.com>
- Loading branch information
1 parent
62ba8f1
commit 31314b3
Showing
9 changed files
with
175 additions
and
15 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
Binary file added
BIN
+66.1 KB
packages/fuselage/.loki/reference/chrome_iphone7_Dropdown_Dropdown_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17.7 KB
packages/fuselage/.loki/reference/chrome_laptop_Dropdown_Dropdown_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions
37
packages/fuselage/src/components/Dropdown/Dropdown.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 React, { useRef } from 'react'; | ||
|
||
import { ActionButton, Box } from '..'; | ||
import Option from '../Options/Option/Option'; | ||
import { Dropdown } from './Dropdown'; | ||
|
||
export default { | ||
title: 'Dropdown/Dropdown', | ||
component: Dropdown, | ||
parameters: { | ||
jest: ['Dropdown.spec.tsx'], | ||
}, | ||
}; | ||
|
||
export const Default = () => { | ||
const anchor = useRef(null); | ||
const target = useRef(null); | ||
|
||
const list = Array.from(new Array(20)); | ||
|
||
return ( | ||
<Box | ||
w='400px' | ||
h='500px' | ||
display='flex' | ||
justifyContent='center' | ||
alignItems='center' | ||
> | ||
<ActionButton ref={anchor} icon='doner' /> | ||
<Dropdown ref={target} reference={anchor} placement='bottom-end'> | ||
{list.map((_, i) => ( | ||
<Option>Example {i + 1}</Option> | ||
))} | ||
</Dropdown> | ||
</Box> | ||
); | ||
}; |
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,34 @@ | ||
import { useMediaQuery, usePosition } from '@rocket.chat/fuselage-hooks'; | ||
import React, { forwardRef, ReactNode, Ref, RefObject } from 'react'; | ||
|
||
import { DropdownDesktop } from './DropdownDesktop'; | ||
import { DropdownMobile } from './DropdownMobile'; | ||
|
||
export const Dropdown = forwardRef(function Dropdown< | ||
T extends HTMLElement, | ||
R extends HTMLElement | ||
>( | ||
{ | ||
children, | ||
reference, | ||
placement = 'bottom-start', | ||
}: { | ||
reference: RefObject<T>; | ||
placement?: Parameters<typeof usePosition>[2]['placement']; | ||
children: ReactNode; | ||
}, | ||
ref: Ref<R> | ||
) { | ||
const notSmall = useMediaQuery('(min-width: 500px)'); | ||
|
||
return notSmall ? ( | ||
<DropdownDesktop | ||
reference={reference} | ||
children={children} | ||
placement={placement} | ||
ref={ref} | ||
/> | ||
) : ( | ||
<DropdownMobile children={children} ref={ref} /> | ||
); | ||
}); |
39 changes: 39 additions & 0 deletions
39
packages/fuselage/src/components/Dropdown/DropdownDesktop.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,39 @@ | ||
import { usePosition } from '@rocket.chat/fuselage-hooks'; | ||
import React, { forwardRef, ReactNode, Ref, RefObject } from 'react'; | ||
|
||
import { Box, Tile } from '..'; | ||
|
||
export const DropdownDesktop = forwardRef(function DropdownDesktop< | ||
T extends HTMLElement, | ||
R extends HTMLElement | ||
>( | ||
{ | ||
children, | ||
reference, | ||
placement = 'bottom-start', | ||
}: { | ||
reference: RefObject<T>; | ||
placement?: Parameters<typeof usePosition>[2]['placement']; | ||
children: ReactNode; | ||
}, | ||
ref: Ref<R> | ||
) { | ||
const { style } = usePosition(reference, ref as RefObject<R>, { placement }); | ||
|
||
return ( | ||
<Tile | ||
style={style} | ||
ref={ref} | ||
elevation='2' | ||
pi='0' | ||
pb='0' | ||
display='flex' | ||
flexDirection='column' | ||
overflow='auto' | ||
> | ||
<Box flexShrink={1} pb='x16'> | ||
{children} | ||
</Box> | ||
</Tile> | ||
); | ||
}); |
35 changes: 35 additions & 0 deletions
35
packages/fuselage/src/components/Dropdown/DropdownMobile.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,35 @@ | ||
import React, { forwardRef, ReactNode, Ref } from 'react'; | ||
|
||
import { Box, Tile } from '..'; | ||
|
||
export const DropdownMobile = forwardRef(function DropdownMobile< | ||
R extends HTMLElement | ||
>( | ||
{ | ||
children, | ||
}: { | ||
children: ReactNode; | ||
}, | ||
ref: Ref<R> | ||
) { | ||
return ( | ||
<Tile | ||
ref={ref} | ||
elevation='2' | ||
pi='0' | ||
pb='0' | ||
w='100%' | ||
maxHeight='80%' | ||
position='fixed' | ||
display='flex' | ||
flexDirection='column' | ||
overflow='auto' | ||
style={{ bottom: 0, left: 0 }} | ||
zIndex={2} | ||
> | ||
<Box flexShrink={1} pb='x16'> | ||
{children} | ||
</Box> | ||
</Tile> | ||
); | ||
}); |
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 './Dropdown'; |
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