Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yusufff committed Aug 16, 2023
0 parents commit 318ee4c
Show file tree
Hide file tree
Showing 24 changed files with 2,520 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>React WeekView</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
50 changes: 50 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "react-weekview",
"version": "0.0.1",
"description": "Week view component and hook for React",
"author": "Yusuf YILDIZ",
"keywords": [
"weekview",
"week",
"react"
],
"files": [
"dist",
"README.md"
],
"type": "module",
"main": "./dist/index.umd.js",
"module": "./dist/index.es.js",
"exports": {
".": {
"import": "./dist/index.es.js",
"require": "./dist/index.umd.js"
}
},
"scripts": {
"dev": "vite --open",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"date-fns": "^2.30.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@vitejs/plugin-react": "^4.0.3",
"autoprefixer": "^10.4.15",
"eslint": "^8.45.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"postcss": "^8.4.27",
"tailwindcss": "^3.3.3",
"typescript": "^5.0.2",
"vite": "^4.4.5"
}
}
6 changes: 6 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
1 change: 1 addition & 0 deletions public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}

@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}

.card {
padding: 2em;
}

.read-the-docs {
color: #888;
}
11 changes: 11 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { WeekView } from "./lib";

function App() {
return (
<div className="h-screen">
<WeekView />
</div>
);
}

export default App;
1 change: 1 addition & 0 deletions src/assets/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
35 changes: 35 additions & 0 deletions src/lib/days-header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { getUnixTime } from "date-fns";
import { Days } from "./use-weekview";

export default function DaysHeader({ days }: { days: Days }) {
return (
<div className="sticky top-0 z-30 flex-none bg-white shadow">
<div className="grid grid-cols-7 text-sm leading-6 text-slate-500">
{days.map((day, index) => (
<div
key={getUnixTime(day.date)}
className={`
flex items-center justify-center h-14 border-l border-gray-100
${index === 0 && "border-l-0"}
`}
>
<span className={day.isToday ? "flex items-center" : ""}>
{day.shortName}{" "}
<span
className={`
font-semibold text-slate-900
${
day.isToday &&
"flex items-center justify-center rounded-full w-8 h-8 ml-1.5 text-white bg-indigo-600"
}
`}
>
{day.dayOfMonthWithZero}
</span>
</span>
</div>
))}
</div>
</div>
);
}
73 changes: 73 additions & 0 deletions src/lib/grid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { ReactNode } from "react";
import { getMinutes, getUnixTime } from "date-fns";

import { Cell, Days } from "./use-weekview";

export default function Grid({
days,
rowHeight = 56,
CellContent,
onCellClick,
}: {
days: Days;
rowHeight?: number;
onCellClick?: (cell: Cell) => void;
CellContent?: (cell: Cell) => ReactNode;
}) {
return (
<div
style={{
display: "grid",
gridTemplateColumns: `repeat(${days.length}, minmax(0, 1fr))`,
gridTemplateRows: `repeat(${days[0].cells.length}, minmax(${rowHeight}px, 1fr))`,
}}
>
{days.map((day, dayIndex) =>
day.cells.map((cell, cellIndex) => (
<button
key={getUnixTime(cell.date)}
className="relative border-t border-l border-gray-100 transition-colors cursor-pointer hover:bg-slate-100 disabled:bg-slate-50"
style={{
gridRowStart: cellIndex + 1,
gridRowEnd: cellIndex + 2,
gridColumnStart: dayIndex + 1,
gridColumnEnd: dayIndex + 2,
}}
disabled={cell.disabled}
onClick={() => onCellClick?.(cell)}
>
{CellContent && CellContent(cell)}
</button>
))
)}
<div
className="sticky left-0 grid pointer-events-none"
style={{
display: "grid",
gridRowStart: 1,
gridRowEnd: -1,
gridColumnStart: 1,
gridTemplateRows: `repeat(${days[0].cells.length}, minmax(${rowHeight}px, 1fr))`,
}}
>
{days[0].cells.map(
(cell, cellIndex) =>
getMinutes(cell.date) === 0 && (
<div
key={getUnixTime(cell.date)}
className="relative flex items-center justify-center border-t border-gray-100"
style={{
gridRowStart: cellIndex + 1,
gridRowEnd: cellIndex + 2,
}}
>
<span className="absolute top-0 left-0 text-xs text-slate-400 px-1">
{cell.hourAndMinute}
</span>
</div>
)
)}
</div>
</div>
);
}
Loading

0 comments on commit 318ee4c

Please sign in to comment.