-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plasma-core): focusTrap, arrow and offset for Popover
- Loading branch information
Showing
10 changed files
with
239 additions
and
70 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
97 changes: 97 additions & 0 deletions
97
packages/plasma-b2c/src/components/Popover/Popover.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,97 @@ | ||
import React, { useRef } from 'react'; | ||
import styled from 'styled-components'; | ||
import { Story, Meta } from '@storybook/react'; | ||
import { surfaceSolid03 } from '@salutejs/plasma-tokens-web'; | ||
import { InSpacingDecorator, disableProps } from '@salutejs/plasma-sb-utils'; | ||
|
||
import { Button } from '../Button'; | ||
|
||
import { Popover, PopoverProps, PopoverPlacement } from '.'; | ||
|
||
const placements: Array<PopoverPlacement> = ['top', 'bottom', 'right', 'left', 'auto']; | ||
|
||
export default { | ||
title: 'Controls/Popover', | ||
decorators: [InSpacingDecorator], | ||
} as Meta; | ||
|
||
const StyledArrow = styled.div` | ||
visibility: hidden; | ||
&, | ||
&::before { | ||
position: absolute; | ||
width: 0.5rem; | ||
height: 0.5rem; | ||
background: ${surfaceSolid03}; | ||
} | ||
&::before { | ||
visibility: visible; | ||
content: ''; | ||
transform: rotate(45deg); | ||
} | ||
`; | ||
|
||
const StyledContent = styled.div` | ||
background: ${surfaceSolid03}; | ||
padding: 1rem; | ||
`; | ||
|
||
export const Live: Story<PopoverProps & { skidding?: number; distance?: number }> = ({ | ||
skidding = 0, | ||
distance = 0, | ||
...args | ||
}) => { | ||
const [isOpen, setIsOpen] = React.useState(false); | ||
|
||
return ( | ||
<> | ||
<Button style={{ margin: '0 16' }} tabIndex={0} onClick={() => setIsOpen(true)}> | ||
Open | ||
</Button> | ||
<Popover | ||
isOpen={isOpen} | ||
onToggle={(is) => setIsOpen(is)} | ||
role="presentation" | ||
id="popover" | ||
target={<div>Trigger</div>} | ||
arrow={<StyledArrow />} | ||
offset={[skidding, distance]} | ||
{...args} | ||
> | ||
<StyledContent> | ||
<>Content</> | ||
<Button onClick={() => setIsOpen(false)}>close1</Button> | ||
<Button onClick={() => setIsOpen(false)}>close2</Button> | ||
</StyledContent> | ||
</Popover> | ||
</> | ||
); | ||
}; | ||
|
||
Live.args = { | ||
placement: 'bottom', | ||
trigger: 'click', | ||
closeOnOverlayClick: true, | ||
closeOnEsc: true, | ||
isFocusTrapped: false, | ||
skidding: 0, | ||
distance: 6, | ||
}; | ||
|
||
Live.argTypes = { | ||
placement: { | ||
options: placements, | ||
control: { | ||
type: 'select', | ||
}, | ||
}, | ||
trigger: { | ||
options: ['click', 'hover'], | ||
control: { | ||
type: 'select', | ||
}, | ||
}, | ||
...disableProps(['isOpen']), | ||
}; |
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 { Popover } from '@salutejs/plasma-hope'; | ||
export type { PopoverProps, PopoverPlacement } from '@salutejs/plasma-hope'; |
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
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
Oops, something went wrong.