Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic docs for AnchoredOverlay #1192

Merged
merged 2 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/selfish-cats-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/components": patch
---

Add basic docs for `AnchoredOverlay`
39 changes: 39 additions & 0 deletions docs/content/AnchoredOverlay.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
title: AnchoredOverlay
status: Alpha
---

An `AnchoredOverlay` provides an anchor that will open a floating overlay positioned relative to the anchor.
The overlay can be opened and navigated using keyboard or mouse.

## Example

```jsx live
<State default={false}>
{([isOpen, setIsOpen]) => {
const openOverlay = React.useCallback(() => setIsOpen(true), [setIsOpen])
const closeOverlay = React.useCallback(() => setIsOpen(false), [setIsOpen])
return (
<AnchoredOverlay
renderAnchor={(anchorProps) => (
<DropdownButton {...anchorProps}>
Click me to open
</DropdownButton>
)}
open={isOpen}
onOpen={openOverlay}
onClose={closeOverlay}
>
<Flex flexDirection="column" maxWidth="300px" padding={2}>
<p>
This menu automatically receives a focus trap and focus zone. Use up/down keys to navigate between buttons
</p>
<Button mb={1}>Button 1</Button>
<Button mb={1}>Button 2</Button>
<Button>Button 3</Button>
</Flex>
</AnchoredOverlay>
)
}}
</State>
```
4 changes: 3 additions & 1 deletion docs/src/@primer/gatsby-theme-doctocat/live-code-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from '@primer/octicons-react'
import State from '../../../components/State'
import {Dialog as Dialog2} from '../../../../src/Dialog/Dialog'
import {AnchoredOverlay} from '../../../../src/AnchoredOverlay'
import {ConfirmationDialog, useConfirm} from '../../../../src/Dialog/ConfirmationDialog'

export default {
Expand All @@ -46,5 +47,6 @@ export default {
VersionsIcon,
Dialog2,
ConfirmationDialog,
useConfirm
useConfirm,
AnchoredOverlay
}
2 changes: 1 addition & 1 deletion src/AnchoredOverlay/AnchoredOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface AnchoredOverlayProps {
}

/**
* An `AnchoredOverlay` provides an anchor (button by default) that will open a floating overlay.
* An `AnchoredOverlay` provides an anchor that will open a floating overlay positioned relative to the anchor.
* The overlay can be opened and navigated using keyboard or mouse.
*/
export const AnchoredOverlay: React.FC<AnchoredOverlayProps> = ({renderAnchor, children, open, onOpen, onClose}) => {
Expand Down