Skip to content

Commit 4db96c3

Browse files
committed
add
1 parent d37345f commit 4db96c3

File tree

4 files changed

+99
-42
lines changed

4 files changed

+99
-42
lines changed

package-lock.json

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
"@types/react": "^18.3.3",
4141
"@types/react-dom": "^18.3.0",
4242
"autoprefixer": "^10.4.19",
43+
"class-variance-authority": "^0.7.1",
44+
"clsx": "^2.1.1",
4345
"gray-matter": "^4.0.3",
4446
"mdast-util-gfm": "^3.1.0",
4547
"next": "^14.2.0",
@@ -55,6 +57,7 @@
5557
"rehype-slug": "^6.0.0",
5658
"remark": "^15.0.1",
5759
"remark-gfm": "^4.0.0",
60+
"tailwind-merge": "^3.3.0",
5861
"tailwindcss": "^3.4.3",
5962
"tslib": "^2.8.1",
6063
"typescript": "^5.4.5"

src/components/Container.tsx

Lines changed: 56 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,71 @@
1+
'use client';
2+
13
import React, { useEffect, useState } from 'react';
4+
import { cva, type VariantProps } from 'class-variance-authority';
5+
import { cn } from '../lib/utils';
6+
7+
const containerVariants = cva(
8+
"container mx-auto transition-colors duration-300",
9+
{
10+
variants: {
11+
maxWidth: {
12+
sm: "max-w-screen-sm",
13+
md: "max-w-screen-md",
14+
lg: "max-w-screen-lg",
15+
xl: "max-w-screen-xl",
16+
"2xl": "max-w-screen-2xl",
17+
full: "max-w-full",
18+
prose: "max-w-prose",
19+
},
20+
padding: {
21+
none: "px-0",
22+
sm: "px-3 sm:px-4",
23+
md: "px-4 sm:px-6 lg:px-8",
24+
lg: "px-6 sm:px-10 lg:px-12",
25+
},
26+
withBackground: {
27+
true: "bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-sm",
28+
false: "",
29+
},
30+
},
31+
defaultVariants: {
32+
maxWidth: "lg",
33+
padding: "md",
34+
withBackground: false,
35+
},
36+
}
37+
);
238

3-
interface ContainerProps {
39+
interface ContainerProps extends React.HTMLAttributes<HTMLDivElement>, VariantProps<typeof containerVariants> {
440
children: React.ReactNode;
5-
className?: string;
6-
maxWidth?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 'full' | 'prose';
7-
padding?: 'none' | 'sm' | 'md' | 'lg';
8-
withBackground?: boolean;
941
}
1042

11-
const Container: React.FC<ContainerProps> = ({
12-
children,
13-
className = '',
14-
maxWidth = 'lg',
15-
padding = 'md',
16-
withBackground = false
17-
}) => {
43+
const Container = ({
44+
children,
45+
className,
46+
maxWidth,
47+
padding,
48+
withBackground,
49+
...props
50+
}: ContainerProps) => {
1851
const [mounted, setMounted] = useState(false);
1952

2053
useEffect(() => {
2154
setMounted(true);
55+
return () => setMounted(false);
2256
}, []);
2357

24-
// Map maxWidth to tailwind classes
25-
const maxWidthClasses = {
26-
sm: 'max-w-screen-sm',
27-
md: 'max-w-screen-md',
28-
lg: 'max-w-screen-lg',
29-
xl: 'max-w-screen-xl',
30-
'2xl': 'max-w-screen-2xl',
31-
full: 'max-w-full',
32-
prose: 'max-w-prose'
33-
};
34-
35-
// Map padding to tailwind classes
36-
const paddingClasses = {
37-
none: 'px-0',
38-
sm: 'px-3 sm:px-4',
39-
md: 'px-4 sm:px-6 lg:px-8',
40-
lg: 'px-6 sm:px-10 lg:px-12'
41-
};
42-
43-
const backgroundClasses = withBackground
44-
? 'bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-md shadow-sm'
45-
: '';
46-
4758
return (
48-
<div className={`
49-
container mx-auto ${maxWidthClasses[maxWidth]} ${paddingClasses[padding]}
50-
${backgroundClasses} transition-all duration-200 ease-in-out
51-
${mounted ? 'opacity-100' : 'opacity-0 translate-y-2'}
52-
${className}
53-
`}>
54-
<div className={`${withBackground ? 'p-4 sm:p-6' : ''}`}>
59+
<div
60+
className={cn(
61+
containerVariants({ maxWidth, padding, withBackground }),
62+
mounted ? "opacity-100 translate-y-0" : "opacity-0 translate-y-2",
63+
"transition duration-300 ease-in-out",
64+
className
65+
)}
66+
{...props}
67+
>
68+
<div className={withBackground ? "p-4 sm:p-6" : ""}>
5569
{children}
5670
</div>
5771
</div>

src/lib/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { type ClassValue, clsx } from 'clsx';
2+
import { twMerge } from 'tailwind-merge';
3+
4+
export function cn(...inputs: ClassValue[]) {
5+
return twMerge(clsx(inputs));
6+
}

0 commit comments

Comments
 (0)