Skip to content

Commit

Permalink
Merge pull request #55 from react18-tools/feat/54-loading-prop
Browse files Browse the repository at this point in the history
Feat/54-loading-prop
  • Loading branch information
mayank1513 authored Jun 7, 2024
2 parents 4e430ee + 471d679 commit 5e39fee
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 9 deletions.
6 changes: 6 additions & 0 deletions lib/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# react18-loaders

## 1.1.0

### Minor Changes

- 032f2f8: Added loading prop to loader-container and improved styles

## 1.0.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "react18-loaders",
"author": "Mayank Kumar Chaudhari <https://mayank-chaudhari.vercel.app>",
"private": false,
"version": "1.0.3",
"version": "1.1.0",
"description": "A comprehensive library that unleashes the full potential of React 18 server components, providing customizable loading animation components alongside a fullscreen loader container. Designed to seamlessly integrate with React and Next.js.",
"license": "MPL-2.0",
"main": "./dist/index.js",
Expand Down
19 changes: 17 additions & 2 deletions lib/src/client/loader-container/loader-container.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,22 @@
display: flex;
align-items: center;
justify-content: center;
backdrop-filter: blur(3px);
background: #87ceeb85;
z-index: 1000;
pointer-events: none;
backdrop-filter: blur(1px);
background: radial-gradient(circle, #535bf200 0%, #535bf200 150%, #8489f685, #535bf255);
opacity: 0;
transition: all 0.5s;
* {
animation-play-state: paused !important;
}
}
.loading {
backdrop-filter: blur(3px);
background: radial-gradient(circle, #535bf200 0%, #535bf200 0%, #8489f6b5 10%, #535bf255 100%);
pointer-events: all;
opacity: 1;
* {
animation-play-state: running !important;
}
}
4 changes: 4 additions & 0 deletions lib/src/client/loader-container/loader-container.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ describe.concurrent("loader-container", () => {
test("check if renders without erros", () => {
render(<LoaderContainer />);
});

test("check if renders without erros", () => {
render(<LoaderContainer loading />);
});
});
10 changes: 7 additions & 3 deletions lib/src/client/loader-container/loader-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import { LOADER_RGS_KEY } from "../../constants";

interface LoaderContainerProps extends React.HTMLProps<HTMLDivElement> {
children?: React.ReactNode;
loading?: boolean;
}

/**
* # LoaderContainer
* A full screen container for the loading animation.
*/
export function LoaderContainer({ children }: LoaderContainerProps) {
const [loading] = useRGS(LOADER_RGS_KEY, false);
return loading ? <div className={styles.container}>{children}</div> : null;
export function LoaderContainer({ children, loading }: LoaderContainerProps) {
const [_loading] = useRGS(LOADER_RGS_KEY, false);
const loading_ = loading ?? _loading;
return (
<div className={[styles.container, loading_ ? styles.loading : ""].join(" ")}>{children}</div>
);
}
5 changes: 3 additions & 2 deletions lib/src/hooks/use-loader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import { cleanup, render, renderHook, act } from "@testing-library/react";
import { afterEach, describe, test } from "vitest";
import { LoaderContainer } from "../client";
import { useLoader } from "./use-loader";
import styles from "../client/loader-container/loader-container.module.scss";

describe.concurrent("loader-container", () => {
afterEach(cleanup);

test("Test hook", ({ expect }) => {
const { result } = renderHook(() => useLoader());
const { container } = render(<LoaderContainer />);
expect(container.childElementCount).toBe(0);
expect(container.children[0].classList).not.toContain(styles.loading);
act(() => result.current.setLoading(true));
expect(container.childElementCount).toBe(1);
expect(container.children[0].classList).toContain(styles.loading);
});
});
7 changes: 7 additions & 0 deletions packages/shared/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @repo/shared

## 0.0.7

### Patch Changes

- Updated dependencies [032f2f8]
- [email protected]

## 0.0.6

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@repo/shared",
"version": "0.0.6",
"version": "0.0.7",
"private": true,
"sideEffects": false,
"main": "./dist/index.js",
Expand Down

0 comments on commit 5e39fee

Please sign in to comment.