From 0c158a4b220e5eff05fa71d79da6d574fbeb1232 Mon Sep 17 00:00:00 2001 From: Pijus Kamandulis Date: Sun, 6 Oct 2024 17:31:02 +0300 Subject: [PATCH] Style estimation session list --- src/components/Card.tsx | 29 ++++++++++++++++++++++++++ src/components/GridList.tsx | 41 +++++++++++++++++++++++++++++++++++++ src/components/index.ts | 4 +++- src/pages/Home.tsx | 33 +++++++++++++++++++++++------ tailwind.config.js | 17 ++++++++++++++- 5 files changed, 116 insertions(+), 8 deletions(-) create mode 100644 src/components/Card.tsx create mode 100644 src/components/GridList.tsx diff --git a/src/components/Card.tsx b/src/components/Card.tsx new file mode 100644 index 0000000..55cd5b4 --- /dev/null +++ b/src/components/Card.tsx @@ -0,0 +1,29 @@ +import classNames from 'classnames'; + +interface CardProps { + title: string; + description: string; + onClick?: () => void; +} + +const Card: React.FC = ({ title, description, onClick }) => { + const className = classNames( + 'p-4 border rounded-lg shadow-sm transition', + { + 'hover:bg-gray-100 dark:hover:bg-nero-800 cursor-pointer': onClick, + 'cursor-default': !onClick, + }, + 'border-gray-300 dark:border-nero-700', + 'bg-white dark:bg-nero-900', + 'text-gray-800 dark:text-nero-200', + ); + + return ( +
+

{title}

+

{description}

+
+ ); +}; + +export default Card; diff --git a/src/components/GridList.tsx b/src/components/GridList.tsx new file mode 100644 index 0000000..fa92bd1 --- /dev/null +++ b/src/components/GridList.tsx @@ -0,0 +1,41 @@ +interface GridListProps { + items: T[]; + colNum: number; + onAddItem: () => void; + itemComponent: React.ComponentType<{ item: T }>; +} + +const AddItemButton = ({ onAddItem }: { onAddItem: () => void }) => { + return ( +
+ + Add Item +
+ ); +}; + +const GridList = ({ + items, + colNum, + onAddItem, + itemComponent: ItemComponent, +}: GridListProps) => { + return ( +
+ {onAddItem && } + + {items.map((item, index) => ( + + ))} +
+ ); +}; + +export default GridList; diff --git a/src/components/index.ts b/src/components/index.ts index 6289584..614e837 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -1,4 +1,6 @@ import Input from './Input'; import Button, { ButtonColor } from './Button'; +import GridList from './GridList'; +import Card from './Card'; -export { Input, Button, ButtonColor }; +export { Input, Button, ButtonColor, GridList, Card }; diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx index 015efda..8276677 100644 --- a/src/pages/Home.tsx +++ b/src/pages/Home.tsx @@ -1,12 +1,16 @@ import reactLogo from '../assets/react.svg'; import viteLogo from '/vite.svg'; import './Home.css'; -import { Link } from '@tanstack/react-router'; +import { getRouteApi, Link } from '@tanstack/react-router'; import { useUser } from '../lib/context/user'; import { useEstimationSessions } from '../lib/context/estimationSession'; +import { Card, GridList } from '../components'; + +const route = getRouteApi('/'); function Home() { const user = useUser(); + const navigate = route.useNavigate(); const estimationSessions = useEstimationSessions(); return ( @@ -33,11 +37,28 @@ function Home() {

Estimation sessions

- {estimationSessions?.current.map((session) => ( - - {session.Name} - - ))} + ( + { + navigate({ + to: '/estimate/session/$sessionId', + params: { sessionId: item.$id }, + }); + }} + /> + )} + onAddItem={() => + navigate({ + to: '/estimate/new', + }) + } + />
); diff --git a/tailwind.config.js b/tailwind.config.js index d21f1cd..bb5dda2 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -2,7 +2,22 @@ export default { content: ['./index.html', './src/**/*.{js,ts,jsx,tsx}'], theme: { - extend: {}, + extend: { + colors: { + nero: { + 50: '#f7f7f7', + 100: '#e1e1e1', + 200: '#cfcfcf', + 300: '#a8a8a8', + 400: '#737373', + 500: '#4e4e4e', + 600: '#383838', + 700: '#2f2f2f', + 800: '#282828', + 900: '#242424', + }, + }, + }, }, plugins: [], };