mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-05-07 01:02:36 +00:00
chore: restructure project into yarn workspaces, remove next
This commit is contained in:
parent
49e308507e
commit
8d06327c03
266 changed files with 16466 additions and 3350 deletions
43
packages/design-system/atoms/popover/Popover.tsx
Normal file
43
packages/design-system/atoms/popover/Popover.tsx
Normal file
|
@ -0,0 +1,43 @@
|
|||
import { globalOnKeyUp } from '@roleypoly/design-system/atoms/key-events';
|
||||
import * as React from 'react';
|
||||
import { IoMdClose } from 'react-icons/io';
|
||||
import {
|
||||
DefocusHandler,
|
||||
PopoverBase,
|
||||
PopoverContent,
|
||||
PopoverHead,
|
||||
PopoverHeadCloser,
|
||||
} from './Popover.styled';
|
||||
|
||||
type PopoverProps = {
|
||||
children: () => React.ReactNode;
|
||||
position: 'top left' | 'top right' | 'bottom left' | 'bottom right';
|
||||
active: boolean;
|
||||
canDefocus?: boolean;
|
||||
onExit?: (type: 'escape' | 'defocus' | 'explicit') => void;
|
||||
headContent: React.ReactNode;
|
||||
preferredWidth?: number;
|
||||
};
|
||||
|
||||
export const Popover = (props: PopoverProps) => {
|
||||
globalOnKeyUp(['Escape'], () => props.onExit?.('escape'), props.active);
|
||||
return (
|
||||
<>
|
||||
<PopoverBase active={props.active} preferredWidth={props.preferredWidth}>
|
||||
<PopoverHead>
|
||||
<PopoverHeadCloser onClick={() => props.onExit?.('explicit')}>
|
||||
<IoMdClose />
|
||||
</PopoverHeadCloser>
|
||||
<div>{props.headContent}</div>
|
||||
</PopoverHead>
|
||||
<PopoverContent>{props.children()}</PopoverContent>
|
||||
</PopoverBase>
|
||||
{props.canDefocus && (
|
||||
<DefocusHandler
|
||||
active={props.active}
|
||||
onClick={() => props.onExit?.('defocus')}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue