Skip to content

Commit

Permalink
feat: timing function in skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
junghyeonsu committed Sep 10, 2024
1 parent b07d7da commit 383c013
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
8 changes: 7 additions & 1 deletion component-docs/activities/skeleton/SkeletonWaveActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import * as React from "react";

import Layout from "@/activities/ActivityLayout";
import { Skeleton } from "@/seed-design/ui/skeleton";
import { useSkeletonDuration, useSkeletonLoading } from "@/stores/skeleton";
import {
useSkeletonDuration,
useSkeletonLoading,
useSkeletonTimingFunction,
} from "@/stores/skeleton";

declare module "@stackflow/config" {
interface Register {
Expand All @@ -27,6 +31,7 @@ const Fallback = () => {
const SkeletonWaveActivity: ActivityComponentType<"SkeletonWave"> = () => {
const isLoading = useSkeletonLoading();
const animationDuration = useSkeletonDuration();
const animationTiming = useSkeletonTimingFunction();

return (
<Layout>
Expand All @@ -35,6 +40,7 @@ const SkeletonWaveActivity: ActivityComponentType<"SkeletonWave"> = () => {
{
padding: "16px",
"--skeleton-animation-duration": animationDuration,
"--skeleton-animation-timing-function": animationTiming,
} as React.CSSProperties
}
>
Expand Down
15 changes: 14 additions & 1 deletion component-docs/components/SkeletonControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
useSkeletonDuration,
useSkeletonGradient,
useSkeletonLoading,
useSkeletonTimingFunction,
} from "@/stores/skeleton";
import * as React from "react";
import { controlBlock, controlInput, controlLabel } from "./SkeletonControls.css";
Expand All @@ -13,6 +14,7 @@ export const SkeletonControls = () => {
const { toggleLoading, setControls } = useSkeletonActions();
const [duration, setDuration] = React.useState(useSkeletonDuration());
const [gradient, setGradient] = React.useState(useSkeletonGradient());
const [timingFunction, setTimingFunction] = React.useState(useSkeletonTimingFunction());

return (
<div>
Expand All @@ -32,7 +34,7 @@ export const SkeletonControls = () => {
/>
</div>
<div className={controlBlock}>
<label className={controlLabel} htmlFor="duration">
<label className={controlLabel} htmlFor="gradient">
Gradient
</label>
<input
Expand All @@ -42,6 +44,17 @@ export const SkeletonControls = () => {
onChange={(e) => setGradient(e.target.value)}
/>
</div>
<div className={controlBlock}>
<label className={controlLabel} htmlFor="timing-function">
Timing Function
</label>
<input
className={controlInput}
id="timing-function"
value={timingFunction}
onChange={(e) => setTimingFunction(e.target.value)}
/>
</div>
<BoxButton type="button" onClick={() => setControls({ duration, gradient })}>
적용
</BoxButton>
Expand Down
2 changes: 1 addition & 1 deletion component-docs/seed-design/ui/skeleton.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const skeleton = recipe({

animationName: wave,
animationDuration: "var(--skeleton-animation-duration, 1.5s)",
animationTimingFunction: "ease-in-out",
animationTimingFunction: "var(--skeleton-animation-timing-function, ease-in-out)",
animationIterationCount: "infinite",
},
},
Expand Down
3 changes: 3 additions & 0 deletions component-docs/stores/skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ interface SkeletonState {
isLoading: boolean;
duration: string;
gradient: string;
timingFunction: string;
actions: {
toggleLoading: () => void;
setControls: (state: { duration: string; gradient: string }) => void;
Expand All @@ -14,6 +15,7 @@ const useSkeleton = create<SkeletonState>((set) => ({
isLoading: true,
duration: "1.5s",
gradient: "linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%)",
timingFunction: "ease-in-out",
actions: {
toggleLoading: () => set((state) => ({ isLoading: !state.isLoading })),
setControls: set,
Expand All @@ -24,3 +26,4 @@ export const useSkeletonLoading = () => useSkeleton((state) => state.isLoading);
export const useSkeletonActions = () => useSkeleton((state) => state.actions);
export const useSkeletonDuration = () => useSkeleton((state) => state.duration);
export const useSkeletonGradient = () => useSkeleton((state) => state.gradient);
export const useSkeletonTimingFunction = () => useSkeleton((state) => state.timingFunction);

0 comments on commit 383c013

Please sign in to comment.