generated from shadcn-ui/next-template
-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: create balloon spinner and implement it in scfini scroll * style: fix main page layout --------- Co-authored-by: Pjaijai <[email protected]>
- Loading branch information
1 parent
092a111
commit 56bbb75
Showing
4 changed files
with
90 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from "react" | ||
import { render, screen } from "@testing-library/react" | ||
|
||
import "@testing-library/jest-dom" | ||
import LoadingBalloonSpinner from "@/components/customized-ui/spinner/ball" | ||
|
||
describe("LoadingBalloonSpinner", () => { | ||
it("renders with default props", () => { | ||
render(<LoadingBalloonSpinner />) | ||
const balls = screen.getAllByTestId("spinner-ball") | ||
expect(balls).toHaveLength(5) | ||
expect(balls[0]).toHaveClass("bg-indigo-400") | ||
}) | ||
|
||
it("renders with custom number of balls", () => { | ||
render(<LoadingBalloonSpinner numberOfBalls={7} />) | ||
const balls = screen.getAllByTestId("spinner-ball") | ||
expect(balls).toHaveLength(7) | ||
}) | ||
|
||
it("renders with custom color", () => { | ||
render(<LoadingBalloonSpinner color="bg-red-500" />) | ||
const balls = screen.getAllByTestId("spinner-ball") | ||
expect(balls[0]).toHaveClass("bg-red-500") | ||
}) | ||
|
||
it("renders random number of balls within maxRandomBalls", () => { | ||
jest.spyOn(global.Math, "random").mockReturnValue(0.5) | ||
render(<LoadingBalloonSpinner isRandom={true} maxRandomBalls={8} />) | ||
const balls = screen.getAllByTestId("spinner-ball") | ||
expect(balls.length).toBeGreaterThanOrEqual(1) | ||
expect(balls.length).toBeLessThanOrEqual(8) | ||
jest.spyOn(global.Math, "random").mockRestore() | ||
}) | ||
|
||
it("applies animation delay to each ball", () => { | ||
render(<LoadingBalloonSpinner numberOfBalls={3} />) | ||
const balls = screen.getAllByTestId("spinner-ball") | ||
expect(balls[0]).toHaveStyle("animation-delay: 0s") | ||
expect(balls[1]).toHaveStyle("animation-delay: 0.15s") | ||
expect(balls[2]).toHaveStyle("animation-delay: 0.3s") | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React, { useEffect, useState } from "react" | ||
|
||
interface LoadingBalloonSpinnerProps { | ||
isRandom?: boolean | ||
numberOfBalls?: number | ||
maxRandomBalls?: number | ||
color?: string | ||
} | ||
|
||
const LoadingBalloonSpinner: React.FC<LoadingBalloonSpinnerProps> = ({ | ||
isRandom = false, | ||
numberOfBalls = 5, | ||
maxRandomBalls = 5, | ||
color = "bg-indigo-400", | ||
}) => { | ||
const [ballCount, setBallCount] = useState(numberOfBalls) | ||
|
||
useEffect(() => { | ||
if (isRandom) { | ||
const randomCount = Math.floor(Math.random() * maxRandomBalls) + 1 | ||
setBallCount(randomCount) | ||
} else { | ||
setBallCount(numberOfBalls) | ||
} | ||
}, [isRandom, numberOfBalls, maxRandomBalls]) | ||
|
||
return ( | ||
<div className="flex items-center justify-center space-x-2"> | ||
{[...Array(ballCount)].map((_, index) => ( | ||
<div | ||
key={index} | ||
className={`h-4 w-4 animate-bounce rounded-full ${color}`} | ||
style={{ | ||
animationDelay: `${index * 0.15}s`, | ||
}} | ||
data-testid="spinner-ball" | ||
></div> | ||
))} | ||
</div> | ||
) | ||
} | ||
|
||
export default LoadingBalloonSpinner |
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