2020-04-10 04:40:22 +02:00
|
|
|
import React, { createRef, useState } from 'react';
|
|
|
|
import styled from 'styled-components';
|
2020-04-20 05:02:55 +02:00
|
|
|
import { action } from '@storybook/addon-actions';
|
2020-04-21 01:04:27 +02:00
|
|
|
import DropdownMenu from '.';
|
2020-04-10 04:40:22 +02:00
|
|
|
|
|
|
|
export default {
|
|
|
|
component: DropdownMenu,
|
|
|
|
title: 'DropdownMenu',
|
|
|
|
parameters: {
|
|
|
|
backgrounds: [
|
|
|
|
{ name: 'white', value: '#ffffff' },
|
|
|
|
{ name: 'gray', value: '#f8f8f8' },
|
|
|
|
{ name: 'darkBlue', value: '#262c49', default: true },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const Container = styled.div`
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
`;
|
|
|
|
const Button = styled.div`
|
|
|
|
font-size: 18px;
|
|
|
|
padding: 15px 20px;
|
|
|
|
color: #fff;
|
|
|
|
background: #000;
|
|
|
|
`;
|
|
|
|
|
|
|
|
export const Default = () => {
|
|
|
|
const [menu, setMenu] = useState({
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
isOpen: false,
|
|
|
|
});
|
|
|
|
const $buttonRef: any = createRef();
|
|
|
|
const onClick = () => {
|
|
|
|
console.log($buttonRef.current.getBoundingClientRect());
|
|
|
|
setMenu({
|
|
|
|
isOpen: !menu.isOpen,
|
|
|
|
left: $buttonRef.current.getBoundingClientRect().right,
|
|
|
|
top: $buttonRef.current.getBoundingClientRect().bottom,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Container>
|
|
|
|
<Button onClick={onClick} ref={$buttonRef}>
|
|
|
|
Click me
|
|
|
|
</Button>
|
|
|
|
</Container>
|
2020-04-21 01:04:27 +02:00
|
|
|
{menu.isOpen && (
|
|
|
|
<DropdownMenu
|
|
|
|
onCloseDropdown={() => {
|
|
|
|
setMenu({ top: 0, left: 0, isOpen: false });
|
|
|
|
}}
|
|
|
|
onLogout={action('on logout')}
|
|
|
|
left={menu.left}
|
|
|
|
top={menu.top}
|
|
|
|
/>
|
|
|
|
)}
|
2020-04-10 04:40:22 +02:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|