-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b593875
commit 0e4a50d
Showing
11 changed files
with
115 additions
and
12 deletions.
There are no files selected for viewing
Binary file added
BIN
+582 Bytes
packages/fuselage/.loki/reference/chrome_iphone7_Misc_Menu_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 modified
BIN
-5 Bytes
(100%)
packages/fuselage/.loki/reference/chrome_iphone7_Misc_Options_CheckOption.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 modified
BIN
+0 Bytes
(100%)
packages/fuselage/.loki/reference/chrome_iphone7_Misc_Options_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
+291 Bytes
packages/fuselage/.loki/reference/chrome_laptop_Misc_Menu_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 modified
BIN
-3 Bytes
(100%)
packages/fuselage/.loki/reference/chrome_laptop_Misc_Options_CheckOption.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 modified
BIN
+1 Byte
(100%)
packages/fuselage/.loki/reference/chrome_laptop_Misc_Options_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,67 @@ | ||
import React, { useRef, useCallback } from 'react'; | ||
|
||
import { | ||
Button, | ||
PositionAnimated, | ||
Options, | ||
Icon, | ||
useCursor, | ||
} from '..'; | ||
|
||
const menuAction = ([selected], options) => { | ||
options[selected].action(); | ||
}; | ||
|
||
const mapOptions = (options) => Object.entries(options).map(([value, { label }]) => [value, label]); | ||
|
||
export const Menu = ({ | ||
options, | ||
optionWidth = '240px', | ||
placement = 'bottom right', | ||
...props }) => { | ||
const mappedOptions = mapOptions(options); | ||
const [cursor, handleKeyDown, handleKeyUp, reset, [visible, hide, show]] = useCursor(-1, mappedOptions, (args, [, hide]) => { | ||
menuAction(args, options); | ||
reset(); | ||
hide(); | ||
}); | ||
|
||
const ref = useRef(); | ||
const onClick = useCallback(() => ref.current.focus() & show(), [show]); | ||
|
||
const handleSelection = useCallback((args) => { | ||
menuAction(args, options); | ||
reset(); | ||
hide(); | ||
}, [hide, reset, options]); | ||
|
||
return ( | ||
<> | ||
<Button | ||
ref={ref} | ||
small | ||
ghost | ||
onClick={onClick} | ||
onBlur={hide} | ||
onKeyUp={handleKeyUp} | ||
onKeyDown={handleKeyDown} | ||
{...props} | ||
> | ||
<Icon name='menu' size={20} /> | ||
</Button> | ||
<PositionAnimated | ||
width='auto' | ||
visible={visible} | ||
anchor={ref} | ||
placement={placement} | ||
> | ||
<Options | ||
width={optionWidth} | ||
onSelect={handleSelection} | ||
options={mappedOptions} | ||
cursor={cursor} | ||
/> | ||
</PositionAnimated> | ||
</> | ||
); | ||
}; |
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,32 @@ | ||
import { action } from '@storybook/addon-actions'; | ||
import { Meta, Preview, Props, Story } from '@storybook/addon-docs/blocks'; | ||
// import LinkTo from '@storybook/addon-links/react'; | ||
// import { PropsVariationSection } from '../../../.storybook/helpers'; | ||
import { Box, Icon, Menu } from '../' | ||
const options = { | ||
'makeAdmin': { | ||
label: <Box display='flex' alignItems='center'><Icon mie='x4' name='key' size='x16'/>Make Admin</Box>, | ||
action: () => console.log('[...] is now admin'), | ||
}, | ||
'delete': { | ||
label: <Box display='flex' alignItems='center' textColor='danger'><Icon mie='x4' name='trash' size='x16'/>Delete</Box>, | ||
action: () => console.log('[...] no longer exists'), | ||
} | ||
} | ||
|
||
<Meta title='Misc/Menu' parameters={{ jest: ['Menu/spec'] }} /> | ||
|
||
# Menu | ||
|
||
Kebab Menu | ||
|
||
<Preview> | ||
<Story name='Default'> | ||
<Box style={{ position: 'relative', maxWidth: 250 }} > | ||
<Menu options={options} /> | ||
</Box> | ||
</Story> | ||
</Preview> | ||
|
||
<Props of={Menu} /> | ||
|
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
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