-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: Add Button.disabled can be a tooltip #202
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f080e39
feat: Add Button.disabledReason.
stephenh 7fef0bb
Combine disabledReason into reason.
stephenh c3de1e2
Show the disabled can be a ReactNode.
stephenh 039b39a
Add support to IconButton.
stephenh 40f4215
Fix ReactNode error in ButtonGroup.
stephenh 48ac193
Go back to cloneElement.
stephenh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,31 @@ | ||
import { Meta } from "@storybook/react"; | ||
import { Css } from "src/Css"; | ||
import { Placement, Tooltip as TooltipComponent } from "./Tooltip"; | ||
import { Placement, Tooltip } from "./Tooltip"; | ||
|
||
export default { | ||
component: TooltipComponent, | ||
component: Tooltip, | ||
title: "Components/Tooltip", | ||
} as Meta; | ||
|
||
export function Tooltip() { | ||
export function TooltipPlacements() { | ||
const placements: Placement[] = ["auto", "bottom", "left", "right", "top"]; | ||
return ( | ||
<div css={Css.w25.ml("25%").$}> | ||
{placements.map((placement, i) => ( | ||
<TooltipComponent title="Tooltip Info" placement={placement} key={i}> | ||
<Tooltip title="Tooltip Info" placement={placement} key={i}> | ||
<span css={Css.db.tc.my5.bgGray400.br4.$}> | ||
This tooltip is positioned at: <span css={Css.b.$}>{placement}</span> | ||
</span> | ||
</TooltipComponent> | ||
</Tooltip> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
export function TooltipDisabled() { | ||
return ( | ||
<Tooltip title="Tooltip Info" disabled={true}> | ||
<span css={Css.db.tc.my5.bgGray400.br4.$}>Content</span> | ||
</Tooltip> | ||
); | ||
} |
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,4 +1,4 @@ | ||
import React, { ReactElement, ReactNode, useRef, useState } from "react"; | ||
import React, { cloneElement, ReactElement, ReactNode, useRef, useState } from "react"; | ||
import { mergeProps, useTooltip, useTooltipTrigger } from "react-aria"; | ||
import { usePopper } from "react-popper"; | ||
import { useTooltipTriggerState } from "react-stately"; | ||
|
@@ -10,27 +10,28 @@ import { Css } from "src/Css"; | |
|
||
interface TooltipProps { | ||
/** The content that shows up when hovered */ | ||
title: string; | ||
title: ReactNode; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! @kbesingeryeh the fix got in! |
||
children: ReactElement; | ||
placement?: Placement; | ||
delay?: number; | ||
disabled?: boolean; | ||
} | ||
|
||
export function Tooltip(props: TooltipProps) { | ||
const state = useTooltipTriggerState({ delay: 500, ...props }); | ||
const { placement, children, title, disabled, delay } = props; | ||
|
||
const state = useTooltipTriggerState({ delay, isDisabled: disabled }); | ||
const triggerRef = React.useRef(null); | ||
const { placement, children, title, disabled } = props; | ||
const { triggerProps, tooltipProps: _tooltipProps } = useTooltipTrigger( | ||
{ ...props, isDisabled: disabled }, | ||
{ delay, isDisabled: disabled }, | ||
state, | ||
triggerRef, | ||
); | ||
const { tooltipProps } = useTooltip(_tooltipProps, state); | ||
|
||
return ( | ||
<> | ||
{React.cloneElement(children, { ref: triggerRef, ...triggerProps })} | ||
{cloneElement(children, { ref: triggerRef, ...triggerProps })} | ||
{state.isOpen && ( | ||
<Popper | ||
{...mergeProps(_tooltipProps, tooltipProps)} | ||
|
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 |
---|---|---|
|
@@ -8,8 +8,12 @@ export interface BeamFocusableProps { | |
} | ||
|
||
export interface BeamButtonProps { | ||
/** Whether the interactive element is disabled. */ | ||
disabled?: boolean; | ||
/** | ||
* Whether the interactive element is disabled. | ||
* | ||
* If a ReactNode, it's treated as a "disabled reason" that's shown in a tooltip. | ||
*/ | ||
disabled?: boolean | ReactNode; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💯 |
||
/** Handler that is called when the press is released over the target. */ | ||
onClick?: (e: PressEvent) => void; | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting! I never knew a Tooltip could be disabled!