Skip to content

Commit

Permalink
feat : moveTopButton ๊ตฌํ˜„ (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
kangminguu authored Oct 29, 2024
1 parent a409ab4 commit b632962
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 0 deletions.
1 change: 1 addition & 0 deletions public/arrow_up.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/shared/ui/MoveTopButton/MoveTopButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Meta, StoryObj } from '@storybook/react';
import MoveTopButton from './MoveTopButton';

const meta: Meta<typeof MoveTopButton> = {
title: 'shared/UI/MoveTopButton',
component: MoveTopButton,
tags: ['autodocs']
};

export default meta;
type Story = StoryObj<typeof MoveTopButton>;

export const Default: Story = {};
97 changes: 97 additions & 0 deletions src/shared/ui/MoveTopButton/MoveTopButton.styled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import styled, { keyframes } from 'styled-components';

const moveAnimation = keyframes`
0%, 100% {
// transform: translateY(0);
background-color: #ff480e;
}
50% {
// transform: translateY(-5px);
background-color: #ff480ebb;
}
`;

const moveImgAnimation = keyframes`
0%, 100% {
transform: translateY(0) rotate(-45deg);
}
50% {
transform: translateY(-5px) rotate(-45deg);
}
`;

export const StyledButton = styled.button`
position: fixed;
bottom: 20px;
right: 20px;
width: 91px;
height: 91px;
border: none;
border-radius: 100px;
background-color: #ff480e;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
gap: -20px;
cursor: pointer;
z-index: 1000;
&::before {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 85%;
height: 85%;
border: 1px solid #ffffff;
border-radius: 100px;
transform: translate(-50%, -50%);
z-index: -1;
}
&::after {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 70%;
height: 70%;
border: 1px solid #ffffff4c;
border-radius: 100px;
transform: translate(-50%, -50%);
z-index: -1;
}
&:hover {
animation: ${moveAnimation} 1s ease-in-out infinite;
}
// &:hover text {
// animation: ${moveAnimation} 1s ease-in-out infinite;
// }
&:hover img {
animation: ${moveImgAnimation} 1s ease-in-out infinite;
}
`;

export const StyledText = styled.span`
color: #ffffff;
font-weight: bold;
font-size: 14px;
font-family: 'Pretendard', sans-serif;
`;

export const Container = styled.div`
width: 100%;
height: 1200px;
`;

export const StyledImg = styled.img`
height: 25px;
width: 25px;
transform: rotate(-45deg);
display: inline-block;
cursor: pointer;
`;
25 changes: 25 additions & 0 deletions src/shared/ui/MoveTopButton/MoveTopButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import {
StyledButton,
Container,
StyledImg,
StyledText
} from './MoveTopButton.styled';

const MoveTopButton = () => {
/** ํ™”๋ฉด ์ตœ์ƒ๋‹จ์œผ๋กœ ์ด๋™ํ•˜๋Š” ์ด๋ฒคํŠธ */
const handleClick = () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
};

return (
<Container>
<StyledButton onClick={handleClick}>
<StyledImg src="/arrow_up.svg" />
<StyledText>Top</StyledText>
</StyledButton>
</Container>
);
};

export default MoveTopButton;

0 comments on commit b632962

Please sign in to comment.