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 Icon Button Hover #411

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions src/components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ export const _Icon = {
<Button variant="icon" model="border">
<FiDisc color={colorWarning} />
</Button>
&nbsp;
<Button hoverText="this is a hovered icon" variant="icon" model="border">
<FiDisc color={colorWarning} />
</Button>
<br />
<br />
<Button variant="icon" model="border" disabled>
Expand Down
33 changes: 31 additions & 2 deletions src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import React from 'react';
import React, { useState } from 'react';

import { ReactNode, ComponentPropsWithoutRef } from 'react';
import { IconContext } from 'react-icons/lib';
Expand All @@ -13,6 +13,7 @@ export interface ButtonProps extends ComponentPropsWithoutRef<'button'> {
pressed?: boolean;
variant?: 'secondary' | 'primary' | 'danger' | 'toggle' | 'icon' | undefined;
customClass?: string;
hoverText?: string;
pivilartisant marked this conversation as resolved.
Show resolved Hide resolved
}

export function ButtonToggle(props: ButtonProps) {
Expand All @@ -35,7 +36,17 @@ export function ButtonToggle(props: ButtonProps) {
}

export function ButtonIcon(props: ButtonProps) {
const { children, model = 'single', customClass = '', ...rest } = props;
const {
children,
model = 'single',
customClass = '',
hoverText,
...rest
} = props;

const [isHovered, setIsHovered] = useState(false);

const showHoverText = hoverText && isHovered;

const models: Models = {
border:
Expand All @@ -53,8 +64,26 @@ export function ButtonIcon(props: ButtonProps) {
data-testid="button"
type="button"
className={`default-button default-icon ${models[model]} ${customClass}`}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
{...rest}
>
<div className="relative w-full flex justify-center items-center">
{showHoverText && (
<div
className="absolute text-primary top-[-44px] w-fit z-10 bg-neutral
mas-caption rounded-md whitespace-nowrap"
>
<p className="w-fit py-1 px-2">{hoverText}</p>
<div className="absolute flex flex-col w-full items-center justify-center">
<div
className="w-0 h-0 border-4 border-solid border-neutral
border-l-transparent border-r-transparent border-b-transparent"
></div>
</div>
</div>
)}
</div>
<div className="w-fit m-auto flex gap-2 items-baseline">{children}</div>
</button>
);
Expand Down
Loading