Skip to content

Commit

Permalink
feat: Icon이 onClick 이벤트도 prop으로 받을 수 있도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
dahyeo-n committed Dec 17, 2024
1 parent 11b161b commit ed6550b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
15 changes: 13 additions & 2 deletions src/components/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,26 @@ const Icon: React.FC<IconProps> = ({
name,
size = 'm',
className = '',
onClick,
}: IconProps) => {
const Component = iconsNames[name];
const Component = iconsNames[name] as React.ComponentType<{
className?: string;
onClick?: () => void;
}>;

const iconSize = iconSizes[size];
const cursorStyle = onClick ? 'cursor-pointer' : '';

if (!Component) {
return null;
}

return <Component className={`${iconSize} ${className}`} />;
return (
<Component
className={`${iconSize} ${className} ${cursorStyle}`}
onClick={onClick}
/>
);
};

export default Icon;
8 changes: 7 additions & 1 deletion src/components/Icon/icons/Close.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
const Close = ({ className }: { className?: string }) => {
import React from 'react';

const Close: React.FC<{ className?: string; onClick?: () => void }> = ({
className,
onClick,
}) => {
return (
<svg
className={className}
onClick={onClick}
viewBox='0 0 30 30'
fill='none'
xmlns='http://www.w3.org/2000/svg'
Expand Down
6 changes: 5 additions & 1 deletion src/components/Icon/icons/Menu.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const Menu = ({ className }: { className?: string }) => {
const Menu: React.FC<{ className?: string; onClick?: () => void }> = ({
className,
onClick,
}) => {
return (
<svg
className={className}
onClick={onClick}
viewBox='0 0 30 30'
fill='none'
xmlns='http://www.w3.org/2000/svg'
Expand Down
5 changes: 4 additions & 1 deletion src/components/Icon/iconsNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ import Search from './icons/Search';
import Star from './icons/Star';
import UploadShare from './icons/UploadShare';

export const iconsNames: Record<string, React.FC<{ className?: string }>> = {
export const iconsNames: Record<
string,
React.FC<{ className?: string; onClick?: () => void }>
> = {
AlertCircle,
AlternateShare,
ArrowLeft,
Expand Down
1 change: 1 addition & 0 deletions src/types/IconProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export interface IconProps {
name: keyof typeof iconsNames;
size?: IconSize;
className?: string;
onClick?: () => void;
}

0 comments on commit ed6550b

Please sign in to comment.