Skip to content

Commit

Permalink
Add skeleton in drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallku committed Jan 20, 2025
1 parent 18f73cb commit 3ef3114
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
30 changes: 30 additions & 0 deletions apps/blog/src/components/DrawerComment/Skeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Typography from "@marshallku/ui/Typography";
import { classNames } from "@marshallku/utils";
import { DRAWER_COMMENT_COUNT } from "#constants";
import styles from "./index.module.scss";

const cx = classNames(styles, "drawer-comment");

function DrawerCommentSkeleton() {
return (
<ol className={cx()}>
{Array.from({ length: DRAWER_COMMENT_COUNT }).map((_, index) => (
<li className={cx("__comment")} key={index}>
<div className={cx("__link")}>
<figure className={cx("__avatar", "__skeleton")} />
<div className={cx("__skeleton-body")}>
<Typography className={cx("__body", "__skeleton")} marginBottom={4}>
Loading...
</Typography>
<Typography variant="c2" className={cx("__skeleton")}>
Loading...
</Typography>
</div>
</div>
</li>
))}
</ol>
);
}

export default DrawerCommentSkeleton;
36 changes: 36 additions & 0 deletions apps/blog/src/components/DrawerComment/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,40 @@
-webkit-box-orient: vertical;
overflow: hidden;
}

&__skeleton {
@keyframes skeleton-loading {
0% {
transform: translateX(100%) skewX(-10deg);
}
100% {
transform: translateX(-100%) skewX(-10deg);
}
}

position: relative;
overflow: hidden;

&::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 200%;
height: 100%;
background: linear-gradient(
90deg,
color(background-dimmed) 0%,
color(sub) 50%,
color(background-dimmed) 100%
);
animation: skeleton-loading 1.4s ease-in-out infinite;
}
}

&__skeleton-body {
width: 100%;
flex-grow: 1;
color: transparent;
}
}
5 changes: 3 additions & 2 deletions apps/blog/src/components/DrawerContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Icon, IconProps } from "@marshallku/icon";
import { classNames } from "@marshallku/utils";
import Hamburger from "#components/Hamburger";
import DrawerComment from "#components/DrawerComment";
import DrawerCommentSkeleton from "#components/DrawerComment/Skeleton";
import styles from "./index.module.scss";

interface DrawerContentProps {
Expand Down Expand Up @@ -91,8 +92,8 @@ function DrawerContent({ opened, closeDrawer, willClose, setWillClose }: DrawerC
))}
</ul>
</nav>
<ErrorBoundary fallback={null}>
<Suspense fallback={null}>
<ErrorBoundary fallback={<DrawerCommentSkeleton />}>
<Suspense fallback={<DrawerCommentSkeleton />}>
<DrawerComment closeDrawer={close} />
</Suspense>
</ErrorBoundary>
Expand Down

1 comment on commit 3ef3114

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Visual regression test result - success

Component Story Success Viewport MisMatch Percentage
components-button string-children phone 0.00%
components-button string-children tablet 0.10%
input-input default phone 0.00%
input-input default tablet 0.10%
input-input line phone 0.00%
input-input line tablet 0.04%
input-input box phone 0.00%
input-input box tablet 0.04%
input-textarea line phone 0.00%
input-textarea line tablet 0.04%
input-textarea box phone 0.00%
input-textarea box tablet 0.04%
typography-typography default phone 0.00%
typography-typography default tablet 0.07%

Please sign in to comment.