Skip to content

Commit

Permalink
Add basic docs for AnchoredOverlay (#1192)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgreif committed Apr 29, 2021
1 parent ebc0697 commit 17957f2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
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

1 comment on commit 17957f2

@vercel
Copy link

@vercel vercel bot commented on 17957f2 Apr 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.