-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[components] Add
boundaryElement
property to popover component
- Loading branch information
1 parent
c3a16f2
commit 0e57923
Showing
5 changed files
with
106 additions
and
20 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
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
68 changes: 68 additions & 0 deletions
68
packages/@sanity/components/src/popover/stories/boundary.js
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,68 @@ | ||
import {Popover} from 'part:@sanity/components/popover' | ||
import {boolean, select, text} from 'part:@sanity/storybook/addons/knobs' | ||
import Sanity from 'part:@sanity/storybook/addons/sanity' | ||
import {CenteredContainer} from 'part:@sanity/storybook/components' | ||
import React, {useRef} from 'react' | ||
|
||
export function BoundaryStory() { | ||
const boundary = select( | ||
'Boundary', | ||
{viewport: 'Viewport', wrapper: 'Wrapper'}, | ||
'viewport', | ||
'Props' | ||
) | ||
const content = text('Content', 'Content', 'Props') | ||
const open = boolean('Open', true, 'Props') | ||
const placement = select( | ||
'Placement', | ||
{ | ||
'top-start': 'Top start', | ||
top: 'Top', | ||
'top-end': 'Top end', | ||
'right-start': 'Right start', | ||
right: 'Right', | ||
'right-end': 'Right end', | ||
'bottom-start': 'Bottom start', | ||
bottom: 'Bottom', | ||
'bottom-end': 'Bottom end', | ||
'left-start': 'Left start', | ||
left: 'Left', | ||
'left-end': 'Left end' | ||
}, | ||
'bottom', | ||
'Props' | ||
) | ||
|
||
return ( | ||
<Sanity part="part:@sanity/components/dialogs/default" propTables={[Popover]}> | ||
<CenteredContainer> | ||
<PopoverExample boundary={boundary} content={content} open={open} placement={placement} /> | ||
</CenteredContainer> | ||
</Sanity> | ||
) | ||
} | ||
|
||
function PopoverExample({boundary, content, open, placement}) { | ||
const boundaryRef = useRef(null) | ||
|
||
return ( | ||
<div ref={boundaryRef} style={{minWidth: 200, minHeight: 200, outline: '1px solid red'}}> | ||
<Popover | ||
boundaryElement={boundary === 'wrapper' ? boundaryRef.current : null} | ||
content={content ? <div style={{padding: '1em'}}>{content}</div> : null} | ||
open={open} | ||
placement={placement} | ||
> | ||
<span | ||
style={{ | ||
display: 'inline-block', | ||
padding: '0.25em', | ||
background: 'rgba(127, 127, 127, 0.5)' | ||
}} | ||
> | ||
Reference | ||
</span> | ||
</Popover> | ||
</div> | ||
) | ||
} |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import {storiesOf} from 'part:@sanity/storybook' | ||
import {withKnobs} from 'part:@sanity/storybook/addons/knobs' | ||
import {BoundaryStory} from './stories/boundary' | ||
import {DefaultStory} from './stories/default' | ||
import {MoveRefStory} from './stories/moveRef' | ||
|
||
storiesOf('@sanity/components/popover', module) | ||
.addDecorator(withKnobs) | ||
.add('Default', DefaultStory) | ||
.add('Move reference', MoveRefStory) | ||
.add('Boundary', BoundaryStory) |