Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
chore(docs): Added Sticky Hover Mode Example
- Loading branch information
Showing
4 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
packages/documentation/src/components/Demos/Utils/StickyHoverMode.md
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,4 @@ | ||
The `useHoverMode` hook can also be updated to implement a "sticky" spec that | ||
allows the user to click the element to toggle the visibility state. Once the | ||
element has been clicked, the `onMouseEnter` and `onMouseLeave` behavior will be | ||
disabled until the visibility is set to `false` once more. |
40 changes: 40 additions & 0 deletions
40
packages/documentation/src/components/Demos/Utils/StickyHoverMode.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,40 @@ | ||
import React, { ReactElement, useRef } from "react"; | ||
import { Button } from "@react-md/button"; | ||
import { DialogContent, FixedDialog } from "@react-md/dialog"; | ||
import { BELOW_CENTER_ANCHOR, useHoverMode } from "@react-md/utils"; | ||
|
||
export default function StickyHoverMode(): ReactElement { | ||
const { | ||
stuck, | ||
active, | ||
handlers, | ||
stickyHandlers, | ||
visible, | ||
setVisible, | ||
} = useHoverMode({ | ||
sticky: true, | ||
}); | ||
const buttonRef = useRef<HTMLButtonElement>(null); | ||
|
||
return ( | ||
<> | ||
<Button {...stickyHandlers} ref={buttonRef}> | ||
Button | ||
</Button> | ||
<FixedDialog | ||
aria-label="Additional Information" | ||
id="some-dialog-id" | ||
visible={visible} | ||
onRequestClose={() => setVisible(false)} | ||
{...handlers} | ||
anchor={BELOW_CENTER_ANCHOR} | ||
fixedTo={buttonRef} | ||
options={{ preventOverlap: true }} | ||
overlay={!stuck && active ? false : undefined} | ||
disableScrollLock={!active} | ||
> | ||
<DialogContent>Some amazing content!</DialogContent> | ||
</FixedDialog> | ||
</> | ||
); | ||
} |
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