-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17d24be
commit 330484e
Showing
5 changed files
with
249 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,40 @@ | ||
import { create } from "zustand"; | ||
|
||
interface SkeletonState { | ||
loadingDurationMs: number; | ||
initTransitionDuration: string; | ||
isRealLoading: boolean; | ||
realLoadingStartTimeMs: number; | ||
isLoading: boolean; | ||
duration: string; | ||
gradient: string; | ||
timingFunction: string; | ||
actions: { | ||
toggleLoading: () => void; | ||
setControls: (state: { duration: string; gradient: string }) => void; | ||
setControls: (state: Partial<Omit<SkeletonState, "actions">>) => void; | ||
}; | ||
} | ||
|
||
const useSkeleton = create<SkeletonState>((set) => ({ | ||
isLoading: true, | ||
loadingDurationMs: 1000, | ||
initTransitionDuration: "0.2s", | ||
realLoadingStartTimeMs: 200, | ||
isRealLoading: false, | ||
isLoading: false, | ||
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, | ||
}, | ||
})); | ||
|
||
export const useSkeletonLoading = () => useSkeleton((state) => state.isLoading); | ||
export const useSkeletonInitTransitionDuration = () => | ||
useSkeleton((state) => state.initTransitionDuration); | ||
export const useIsRealLoading = () => useSkeleton((state) => state.isRealLoading); | ||
export const useRealLoadingStartTimeMs = () => useSkeleton((state) => state.realLoadingStartTimeMs); | ||
export const useSkeletonActions = () => useSkeleton((state) => state.actions); | ||
export const useSkeletonDuration = () => useSkeleton((state) => state.duration); | ||
export const useSkeletonGradient = () => useSkeleton((state) => state.gradient); | ||
export const useLoadingDurationMs = () => useSkeleton((state) => state.loadingDurationMs); | ||
export const useSkeletonTimingFunction = () => useSkeleton((state) => state.timingFunction); |