Assemble을 만들면서 데이터 통신은 점점 늘고 사용자가 데이터를 불러오는동안 빈화면만 보이는것은 사용자 경험에서 좋지않다는것은 우리 모두가 다 아는 내용들입니다.
그래서 처음에는 스피너로 모든 로딩들을 처리해줬습니다.
화면 기록 2023-09-18 오후 4.31.15.mov
화면 기록 2023-09-18 오후 4.33.51.mov
스피너보다는 스켈레톤을 통해서 보는것이 무언가를 불러오고있구나 라는 생각을 하게하는 경우가 많아서 그렇습니다. 프론트엔드 영역에서의 사용자 경험은 상당한 부분을 차지하는데 같은 로딩시간을 걸린다고해도 사용자가 보기에 좀더 쾌적한 사이트를 만드는것에는 스켈레톤 UI를 넣어야한다는 생각이 있어서 도입하였습니다.
스켈레톤UI는 많은 라이브러리가 존재합니다. 하지만 이번에는 CSS로 구현을 하고싶다는 생각을 하여 아래와 같이 직접 제작해봤습니다. 아래와 같이 직접 작성하면 내가 만든것이다 보니 유지보수 그리고 코드 재사용이 쉽다는 점입니다. 하나의 코드를 통해 비슷한 디자인의 코드에 재사용성도 높고, 디자인이 변경된다면 바로바로 수정이 쉽다는 점이있었습니다.
import { styled } from 'styled-components'
function CardSkeleton() {
return (
<S.Wrapper>
<S.WrapperBox></S.WrapperBox>
<S.Text></S.Text>
<S.Img></S.Img>
<S.Info></S.Info>
</S.Wrapper>
)
}
export default CardSkeleton
const Wrapper = styled.div`
background: #f2f2f2;
min-height: 30vh;
width: 100%;
height: 100%;
border-radius: 2rem;
display: flex;
justify-content: center;
position: relative;
overflow: hidden;
margin-bottom: 2rem;
`
const WrapperBox = styled.div`
width: 30%;
height: 100%;
background-color: rgba(255, 255, 255, 0.4);
box-shadow: 0 0 30px 30px rgba(255, 255, 255, 0.05);
animation: loading 2s infinite;
@keyframes loading {
0% {
transform: translateX(-400%);
}
50% {
transform: translateX(-300%);
}
100% {
transform: translateX(230%);
}
}
`
const Text = styled.div`
width: 83%;
text-align: center;
background-color: #dddddd;
height: 65%;
border-radius: 1.5rem;
position: absolute;
top: 2rem;
`
const Img = styled.div`
background-color: #dddddd;
width: 5rem;
height: 5rem;
border-radius: 50%;
position: absolute;
bottom: 2rem;
left: 2.5rem;
`
const Info = styled.div`
background-color: #dddddd;
position: absolute;
bottom: 3rem;
right: 3rem;
width: 15rem;
height: 3rem;
@media screen and (max-width: ${({ theme }) => theme.MEDIA.mobile}) {
width: 10rem;
}
`
const S = {
Wrapper,
WrapperBox,
Text,
Img,
Info,
}