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

[노철]- 도움말 버튼 #340

Merged
merged 3 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
55 changes: 55 additions & 0 deletions src/components/HelpButton/HelpButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'use client';

import { Icon } from '@/components';
import classNames from 'classnames';
import { useEffect, useRef, useState } from 'react';
import './index.scss';

interface HelpButtonProps {
textPosition?: Position;
helpText: string;
}

type Position =
| 'top-left'
| 'top'
| 'top-right'
| 'bottom-left'
| 'bottom'
| 'bottom-right';

export default function HelpButton({
textPosition = 'top',
helpText,
}: HelpButtonProps) {
const [isActive, setIsActive] = useState<boolean>(false);
const helpButton = useRef<HTMLButtonElement>(null);
useEffect(() => {
const handleClick = (event: MouseEvent) => {
const targetElement = event.target as HTMLElement;

if (targetElement && targetElement.parentElement === helpButton.current) {
setIsActive(true);
} else {
setIsActive(false);
}
};
window.addEventListener('click', handleClick);
return () => {
window.removeEventListener('click', handleClick);
};
}, []);
return (
<button
ref={helpButton}
className={classNames(
'help-button__button',
isActive && 'active',
textPosition,
'font-size-xs',
)}
data-help-text={helpText}>
<Icon name="HELP" size="xs" color="primary" />
</button>
);
}
45 changes: 45 additions & 0 deletions src/components/HelpButton/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.help-button {
&__button {
background-color: transparent;
width: 12px;
height: 12px;
position: relative;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;

&.active::after {
color: var(--origin-text-600);
content: attr(data-help-text);
background-color: rgba(black, 0.5);
white-space: pre;
word-break: keep-all;
display: inline-block;
padding: 0.5rem 1rem;
border-radius: var(--border-radius);
user-select: none;
pointer-events: none;
position: absolute;
}
&.top-left::after,
&.top::after,
&.top-right::after {
bottom: 12px;
}

&.bottom-left::after,
&.bottom::after,
&.bottom-right::after {
top: 12px;
}
&.bottom-left::after,
&.top-left::after {
right: 0;
}
&.top-right::after,
&.bottom-right::after {
left: 0;
}
}
}
3 changes: 2 additions & 1 deletion src/types/IconName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ export type IconName =
| 'STAR'
| 'FAVORITE'
| 'ARROW_UP'
| 'COPY';
| 'COPY'
| 'HELP';