Skip to content

Commit 5d060be

Browse files
authored
Feat layout shift demo (#8)
* fix: updated layout shift demo * fix: fixed the close/open menu text
1 parent f1fbd85 commit 5d060be

File tree

6 files changed

+30
-17
lines changed

6 files changed

+30
-17
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# package artifacts
22
node_modules/
3-
.next/
3+
**/.next/
44
dist/
55
coverage/
66
test-results/

examples/demo/src/app/(test)/ReactState.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,14 @@ function Header({ theme }: { theme: 'light' | 'dark' }) {
4747
<div
4848
ref={ref}
4949
className="space-y-2 text-center">
50-
<h1 className={`text-3xl font-bold ${theme === 'light' ? 'text-gray-900' : 'text-white'}`}>React State Management</h1>
51-
52-
<p className={`${theme === 'light' ? 'text-gray-600' : 'text-gray-400'}`}>Reactive state management with React</p>
50+
<h1 className={`text-3xl font-bold ${theme === 'light' ? 'text-gray-900' : 'text-white'}`}>
51+
React State <span className="max-[450px]:hidden">Management</span>
52+
</h1>
53+
54+
<p className={`${theme === 'light' ? 'text-gray-600' : 'text-gray-400'}`}>
55+
Reactive state management with React <br />
56+
<span className="text-xs text-gray-500">Re-renders O(n)</span>
57+
</p>
5358
</div>
5459
);
5560
}
@@ -148,7 +153,7 @@ function InteractiveCard({
148153
{/* Sliding Menu */}
149154
<div className={`overflow-hidden ${menuOpen ? 'max-h-[160px]' : 'max-h-0'} `}>
150155
<div className={`border-t border-gray-200 p-6 transition-all duration-0! ${theme === 'dark' ? 'bg-gray-700' : 'bg-white'}`}>
151-
<p className={`${theme === 'dark' ? 'text-gray-300' : 'text-gray-600'}`}>✨ This panel slides open and has to re-render!</p>
156+
<p className={`${theme === 'dark' ? 'text-gray-300' : 'text-gray-600'} text-center`}>✨ This panel slides open and has to re-render!</p>
152157
</div>
153158
</div>
154159
</div>
@@ -160,9 +165,11 @@ function StateDisplay({ theme, accent, menuOpen }: { theme: 'light' | 'dark'; ac
160165
const ref = useRenderTracker('StateDisplay');
161166

162167
return (
163-
<div ref={ref}>
168+
<div
169+
ref={ref}
170+
className="max-[450px]:hidden">
164171
<div
165-
className={`mt-5 flex justify-center gap-4 space-y-1 text-center font-mono text-sm capitalize ${accent === 'violet' ? 'text-violet-500' : accent === 'emerald' ? 'text-emerald-500' : 'text-amber-500'}`}>
172+
className={`mt-5 **:text-nowrap flex justify-center gap-4 space-y-1 text-center font-mono text-sm capitalize ${accent === 'violet' ? 'text-violet-500' : accent === 'emerald' ? 'text-emerald-500' : 'text-amber-500'}`}>
166173
<div className="flex gap-1">theme: {theme} </div>
167174
<div className="flex gap-1">accent: {accent}</div>
168175
<div className="flex gap-1">menu: {menuOpen ? 'Open' : 'Closed'}</div>

examples/demo/src/app/(test)/ZeroState.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import useUI from '@austinserb/react-zero-ui';
44
import { useRenderTracker } from './ReactTracker';
55

6-
export function TestComponent() {
6+
export function TestComponentZero() {
77
const ref = useRenderTracker('TestComponent');
88
const [, setTheme] = useUI<'light' | 'dark'>('theme', 'light');
99
const [, setAccent] = useUI<'violet' | 'emerald' | 'amber'>('accent', 'violet');
@@ -33,7 +33,7 @@ function Header() {
3333
<h1 className="theme-light:text-gray-900 theme-dark:text-white text-3xl font-bold">Zero UI</h1>
3434

3535
<p className="theme-light:text-gray-600 theme-dark:text-gray-400">
36-
Reactive state without re-rendering OR prop drilling. <br />
36+
Reactive state without re-rendering .<br />
3737
<span className="text-sm">
3838
<span className="theme-light:text-gray-900 theme-dark:text-white font-bold">Zero</span> re-renders,{' '}
3939
<span className="theme-light:text-gray-900 theme-dark:text-white font-bold">Reactive</span> &{' '}
@@ -112,15 +112,15 @@ function InteractiveCard({ toggleMenu }: { toggleMenu: () => void }) {
112112
aria-label="button"
113113
onClick={toggleMenu}
114114
className="accent-violet:bg-violet-500 accent-emerald:bg-emerald-500 accent-amber:bg-amber-500 w-full rounded-lg py-3 font-medium text-white hover:scale-[1.02]">
115-
<span className="menu-open-true:hidden">Close Panel</span>
116-
<span className="menu-open-false:hidden">Open Panel</span>
115+
<span className="menu-open-false:hidden">Close Panel</span>
116+
<span className="menu-open-true:hidden">Open Panel</span>
117117
</button>
118118
</div>
119119

120120
{/* Sliding Panel */}
121-
<div className="menu-open-true:max-h-[160px] menu-open-false:max-h-0 overflow-hidden">
121+
<div className="menu-open-true:max-h-[80px] menu-open-false:max-h-0 overflow-hidden">
122122
<div className="theme-dark:bg-gray-700 theme-light:bg-white border-t border-gray-200 p-6 transition-all duration-0!">
123-
<p className="theme-dark:text-gray-300 theme-light:text-gray-600">✨ This panel slides open without re-rendering!</p>
123+
<p className="theme-dark:text-gray-300 theme-light:text-gray-600 text-center">✨ This panel slides open without re-rendering!</p>
124124
</div>
125125
</div>
126126
</div>
@@ -132,7 +132,9 @@ function StateDisplay() {
132132
const ref = useRenderTracker('StateDisplay');
133133

134134
return (
135-
<div ref={ref}>
135+
<div
136+
ref={ref}
137+
className="max-[450px]:hidden">
136138
<div className="theme-light:text-gray-500 theme-dark:text-gray-400 **:accent-violet:text-violet-500 **:accent-emerald:text-emerald-500 **:accent-amber:text-amber-500 mt-5 flex justify-center gap-4 space-y-1 text-center font-mono text-sm capitalize">
137139
<div className="flex gap-1 text-nowrap **:text-nowrap">
138140
theme: <span className="theme-dark:hidden">Light</span>

examples/demo/src/app/(test)/layout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import { domAnimation, LazyMotion } from 'motion/react';
12
import { RenderTracker } from './ReactTracker';
23

34
const layout: React.FC<{ children: React.ReactNode }> = ({ children }) => {
45
return (
56
<div className="relative py-10">
6-
{children}
7+
<LazyMotion features={domAnimation}>{children}</LazyMotion>
78
<RenderTracker />
89
<div className="fixed right-0 bottom-0 z-10 h-fit w-full rounded-lg bg-white/80 px-4 py-2 ring-1 ring-black/5 backdrop-blur-sm md:bg-white/20">
910
<div className="pb-2 text-sm text-blue-500">(Layout.tsx) Global UI State Variables</div>

examples/demo/src/app/(test)/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { Icon } from '@/app/components/Icon';
44
import { TestComponentWithState } from './ReactState';
5-
import { TestComponent } from './ZeroState';
5+
import { TestComponentZero } from './ZeroState';
66
import { useUI } from '@austinserb/react-zero-ui';
77

88
export default function Page() {
@@ -36,7 +36,7 @@ export default function Page() {
3636

3737
<div className="h-full w-full overflow-hidden rounded-b-lg border border-t-0 border-gray-200">
3838
<div className="active-zero:translate-x-0 active-react:translate-x-[-50%] grid h-full w-[200%] grid-cols-2 items-center justify-start transition-transform duration-300">
39-
<TestComponent />
39+
<TestComponentZero />
4040
<TestComponentWithState />
4141
</div>
4242
</div>

examples/demo/src/app/globals.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
0px 25px 25px -3.75px rgba(0, 0, 0, 0.11), 0px -5px 5px -3.75px rgba(0, 0, 0, 0.11);
88
}
99

10+
/* * {
11+
border: 1px dotted red;
12+
} */
1013
button:not(:disabled),
1114
[role='button']:not(:disabled) {
1215
cursor: pointer;

0 commit comments

Comments
 (0)