Skip to content

Commit

Permalink
chore: implement disabled button tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
epiqueras committed Sep 16, 2020
1 parent 6589f7e commit c9e40c5
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export default function ChallengeButton({ request, contract, submissionID }) {
width: "100%",
}}
disabled={disputed && currentReasonIsNotDuplicate}
disabledTooltip="Already Challenged"
>
Challenge Request
</Button>
Expand Down
93 changes: 64 additions & 29 deletions components/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,77 @@ import { forwardRef } from "react";
import { MoonLoader } from "react-spinners";
import { Box, Button as _Button } from "theme-ui";

import Popup from "./popup";
import Text from "./text";

const Button = forwardRef(
({ id, sx, type = "button", disabled, children, loading, ...rest }, ref) => (
<_Button
ref={ref}
id={id}
sx={{
backgroundImage({ colors: { primary, secondary } }) {
return `linear-gradient(90deg, ${primary} 0%, ${secondary} 100%)`;
},
...sx,
}}
type={type}
disabled={disabled || !children || loading}
data-loading={loading}
{...rest}
>
<Text
id={id && `${id}-text`}
(
{
id,
sx,
type = "button",
disabled,
children,
loading,
disabledTooltip,
...rest
},
ref
) => {
const button = (
<_Button
ref={ref}
id={id}
sx={{
alignItems: "center",
display: "flex",
justifyContent: "space-evenly",
minWidth: "100px",
backgroundImage({ colors: { primary, secondary } }) {
return `linear-gradient(90deg, ${primary} 0%, ${secondary} 100%)`;
},
...sx,
}}
type={type}
disabled={disabled || !children || loading}
data-loading={loading}
{...rest}
>
{children}
{loading && (
<Box variant="buttons.primary.spinner">
<MoonLoader size={16} />
<Text
id={id && `${id}-text`}
sx={{
alignItems: "center",
display: "flex",
justifyContent: "space-evenly",
minWidth: "100px",
}}
>
{children}
{loading && (
<Box variant="buttons.primary.spinner">
<MoonLoader size={16} />
</Box>
)}
</Text>
</_Button>
);
return disabled && disabledTooltip ? (
<Popup
trigger={
<Box
sx={{
display: "inline-block",
height: sx?.height,
width: sx?.width,
}}
>
{button}
</Box>
)}
</Text>
</_Button>
)
}
on={["focus", "hover"]}
>
{disabledTooltip}
</Popup>
) : (
button
);
}
);
Button.displayName = "Button";
export default Button;
4 changes: 4 additions & 0 deletions components/theme-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ const theme = merge(merge(base, toTheme(typographyTheme)), {
secondary: {
backgroundColor: "secondary",
backgroundImage: "none !important",
"&:disabled:not([data-loading=true])": {
backgroundColor: "skeleton",
backgroundImage: "none !important",
},
},
},
cards: {
Expand Down

0 comments on commit c9e40c5

Please sign in to comment.