Compare commits
11
Commits
532337a46a
...
590d7f6fa1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
590d7f6fa1 | ||
|
|
4c21dc2764 | ||
|
|
4d01112006 | ||
|
|
984c386588 | ||
|
|
0efe5bfa9e | ||
|
|
7ba7c4b04b | ||
|
|
bb53ba6cb4 | ||
|
|
57dcbdec14 | ||
|
|
825dc4365f | ||
|
|
67f9e19eb8 | ||
|
|
06c1af92b3 |
@@ -1,19 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
root: true,
|
|
||||||
env: { browser: true, es2020: true, node: false },
|
|
||||||
extends: [
|
|
||||||
"eslint:recommended",
|
|
||||||
"plugin:@typescript-eslint/recommended",
|
|
||||||
"plugin:react-hooks/recommended",
|
|
||||||
"prettier",
|
|
||||||
],
|
|
||||||
ignorePatterns: ["dist", ".eslintrc.cjs"],
|
|
||||||
parser: "@typescript-eslint/parser",
|
|
||||||
plugins: ["react-refresh"],
|
|
||||||
rules: {
|
|
||||||
"react-refresh/only-export-components": [
|
|
||||||
"warn",
|
|
||||||
{ allowConstantExport: true },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
"endOfLine": "lf",
|
"endOfLine": "lf",
|
||||||
"plugins": ["prettier-plugin-tailwindcss"]
|
"plugins": ["prettier-plugin-tailwindcss"],
|
||||||
|
"tailwindStylesheet": "./src/index.css"
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
# Base Node Environment.
|
# Base Node Environment.
|
||||||
FROM node:21.7-alpine3.19 AS app-base
|
FROM node:22-alpine AS app-base
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
ENV PATH=/app/node_modules/.bin:$PATH
|
ENV PATH=/app/node_modules/.bin:$PATH
|
||||||
COPY package.json ./
|
COPY package.json ./
|
||||||
|
|||||||
+3
-2
@@ -4,7 +4,7 @@
|
|||||||
"rsc": false,
|
"rsc": false,
|
||||||
"tsx": true,
|
"tsx": true,
|
||||||
"tailwind": {
|
"tailwind": {
|
||||||
"config": "tailwind.config.js",
|
"config": "",
|
||||||
"css": "src/index.css",
|
"css": "src/index.css",
|
||||||
"baseColor": "stone",
|
"baseColor": "stone",
|
||||||
"cssVariables": true,
|
"cssVariables": true,
|
||||||
@@ -16,5 +16,6 @@
|
|||||||
"ui": "@/components/ui",
|
"ui": "@/components/ui",
|
||||||
"lib": "@/lib",
|
"lib": "@/lib",
|
||||||
"hooks": "@/hooks"
|
"hooks": "@/hooks"
|
||||||
}
|
},
|
||||||
|
"iconLibrary": "lucide"
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
const { defineConfig, globalIgnores } = require("eslint/config");
|
||||||
|
|
||||||
|
const globals = require("globals");
|
||||||
|
|
||||||
|
const { fixupConfigRules } = require("@eslint/compat");
|
||||||
|
|
||||||
|
const tsParser = require("@typescript-eslint/parser");
|
||||||
|
const reactRefresh = require("eslint-plugin-react-refresh");
|
||||||
|
const js = require("@eslint/js");
|
||||||
|
|
||||||
|
const { FlatCompat } = require("@eslint/eslintrc");
|
||||||
|
|
||||||
|
const compat = new FlatCompat({
|
||||||
|
baseDirectory: __dirname,
|
||||||
|
recommendedConfig: js.configs.recommended,
|
||||||
|
allConfig: js.configs.all,
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = defineConfig([
|
||||||
|
{
|
||||||
|
languageOptions: {
|
||||||
|
globals: {
|
||||||
|
...globals.browser,
|
||||||
|
...Object.fromEntries(
|
||||||
|
Object.entries(globals.node).map(([key]) => [key, "off"]),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
|
||||||
|
parser: tsParser,
|
||||||
|
},
|
||||||
|
|
||||||
|
extends: fixupConfigRules(
|
||||||
|
compat.extends(
|
||||||
|
"eslint:recommended",
|
||||||
|
"plugin:@typescript-eslint/recommended",
|
||||||
|
"plugin:react-hooks/recommended",
|
||||||
|
"prettier",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
plugins: {
|
||||||
|
"react-refresh": reactRefresh,
|
||||||
|
},
|
||||||
|
|
||||||
|
rules: {
|
||||||
|
"react-refresh/only-export-components": [
|
||||||
|
"warn",
|
||||||
|
{
|
||||||
|
allowConstantExport: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
globalIgnores(["**/dist", "eslint.config.cjs"]),
|
||||||
|
]);
|
||||||
Generated
+2393
-2605
File diff suppressed because it is too large
Load Diff
+41
-36
@@ -11,50 +11,55 @@
|
|||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hookform/resolvers": "^3.9.0",
|
"@hookform/resolvers": "^5.1.1",
|
||||||
"@radix-ui/react-checkbox": "^1.0.4",
|
"@radix-ui/react-checkbox": "^1.3.2",
|
||||||
"@radix-ui/react-dropdown-menu": "^2.0.6",
|
"@radix-ui/react-dropdown-menu": "^2.1.15",
|
||||||
"@radix-ui/react-icons": "^1.3.0",
|
"@radix-ui/react-label": "^2.1.7",
|
||||||
"@radix-ui/react-label": "^2.1.0",
|
"@radix-ui/react-popover": "^1.1.14",
|
||||||
"@radix-ui/react-popover": "^1.0.7",
|
"@radix-ui/react-separator": "^1.1.7",
|
||||||
"@radix-ui/react-separator": "^1.0.3",
|
"@radix-ui/react-slot": "^1.2.3",
|
||||||
"@radix-ui/react-slot": "^1.1.0",
|
"@radix-ui/react-toast": "^1.2.14",
|
||||||
"@radix-ui/react-toast": "^1.1.5",
|
"@radix-ui/react-tooltip": "^1.2.7",
|
||||||
"@radix-ui/react-tooltip": "^1.0.7",
|
"@tailwindcss/vite": "^4.1.8",
|
||||||
"class-variance-authority": "^0.7.0",
|
"class-variance-authority": "^0.7.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"date-fns": "^3.6.0",
|
"date-fns": "^4.1.0",
|
||||||
"embla-carousel-react": "^8.0.2",
|
"embla-carousel-react": "^8.6.0",
|
||||||
"lucide-react": "^0.378.0",
|
"lucide-react": "^0.513.0",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-day-picker": "^8.10.1",
|
"react-day-picker": "^9.7.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-hook-form": "^7.53.0",
|
"react-hook-form": "^7.57.0",
|
||||||
"react-router-dom": "^6.23.0",
|
"react-router-dom": "^6.23.0",
|
||||||
"swr": "^2.2.5",
|
"swr": "^2.3.3",
|
||||||
"tailwind-merge": "^2.3.0",
|
"tailwind-merge": "^3.3.0",
|
||||||
"zod": "^3.23.8",
|
"zod": "^3.25.57",
|
||||||
"zustand": "^4.5.2"
|
"zustand": "^5.0.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.12.8",
|
"@eslint/compat": "^1.2.9",
|
||||||
|
"@eslint/eslintrc": "^3.3.1",
|
||||||
|
"@eslint/js": "^9.28.0",
|
||||||
|
"@iconify-icon/react": "^3.0.0",
|
||||||
|
"@tailwindcss/postcss": "^4.1.8",
|
||||||
|
"@types/node": "^22.15.30",
|
||||||
"@types/react": "^18.2.66",
|
"@types/react": "^18.2.66",
|
||||||
"@types/react-dom": "^18.2.22",
|
"@types/react-dom": "^18.2.22",
|
||||||
"@types/react-router-dom": "^5.3.3",
|
"@types/react-router-dom": "^5.3.3",
|
||||||
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
"@typescript-eslint/eslint-plugin": "^8.34.0",
|
||||||
"@typescript-eslint/parser": "^7.2.0",
|
"@typescript-eslint/parser": "^8.34.0",
|
||||||
"@vitejs/plugin-react-swc": "^3.5.0",
|
"@vitejs/plugin-react-swc": "^3.10.1",
|
||||||
"autoprefixer": "^10.4.19",
|
"eslint": "^9.28.0",
|
||||||
"eslint": "^8.57.0",
|
"eslint-config-prettier": "^10.1.5",
|
||||||
"eslint-config-prettier": "^9.1.0",
|
"eslint-plugin-react-hooks": "^5.2.0",
|
||||||
"eslint-plugin-react-hooks": "^4.6.0",
|
"eslint-plugin-react-refresh": "^0.4.20",
|
||||||
"eslint-plugin-react-refresh": "^0.4.6",
|
"globals": "^16.2.0",
|
||||||
"postcss": "^8.4.38",
|
"postcss": "^8.5.4",
|
||||||
"prettier": "^3.3.3",
|
"prettier": "^3.5.3",
|
||||||
"prettier-plugin-tailwindcss": "^0.6.6",
|
"prettier-plugin-tailwindcss": "^0.6.12",
|
||||||
"tailwindcss": "^3.4.3",
|
"tailwindcss": "^4.1.8",
|
||||||
"tailwindcss-animate": "^1.0.7",
|
"tw-animate-css": "^1.3.4",
|
||||||
"typescript": "^5.2.2",
|
"typescript": "^5.8.3",
|
||||||
"vite": "^5.2.0"
|
"vite": "^6.3.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
export default {
|
export default {
|
||||||
plugins: {
|
plugins: {
|
||||||
tailwindcss: {},
|
'@tailwindcss/postcss': {},
|
||||||
autoprefixer: {},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { RoomCategory } from "@/model/RoomCategory";
|
|||||||
import { fetcher, fetcherUnwraper } from "./backend";
|
import { fetcher, fetcherUnwraper } from "./backend";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
|
|
||||||
export function useAPIRoomCategories() {
|
export function useAPIRoomCategoryList() {
|
||||||
const { data, error, isLoading } = useSWR<RoomCategory[]>(
|
const { data, error, isLoading } = useSWR<RoomCategory[]>(
|
||||||
"/api/room/category",
|
"/api/room/category",
|
||||||
fetcherUnwraper,
|
fetcherUnwraper,
|
||||||
@@ -15,8 +15,8 @@ export function useAPIRoomCategories() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useAPIRoomCategoryId(categoryId: number) {
|
export function useAPIRoomCategory(categoryId: number) {
|
||||||
const url = categoryId ? "/api/room/category/" + categoryId : null;
|
const url = `/api/room/category/${categoryId}`;
|
||||||
|
|
||||||
const { data, error, isLoading } = useSWR<RoomCategory>(url, fetcher);
|
const { data, error, isLoading } = useSWR<RoomCategory>(url, fetcher);
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ import {
|
|||||||
export function useAPIRoomAvailability(filter: AvailabilityFilter | null) {
|
export function useAPIRoomAvailability(filter: AvailabilityFilter | null) {
|
||||||
const request: AvailabilityRequest | null = filter
|
const request: AvailabilityRequest | null = filter
|
||||||
? {
|
? {
|
||||||
filter: filter,
|
startDate: filter.startDate,
|
||||||
|
endDate: filter.endDate,
|
||||||
}
|
}
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
@@ -32,12 +33,14 @@ export function useAPIRoomAvailability(filter: AvailabilityFilter | null) {
|
|||||||
export function useAPIRoomPrices(filter: FareFilter | null) {
|
export function useAPIRoomPrices(filter: FareFilter | null) {
|
||||||
const request: FareRequest | null = filter
|
const request: FareRequest | null = filter
|
||||||
? {
|
? {
|
||||||
filter: filter,
|
roomCategory: filter.roomCategory,
|
||||||
|
startDate: filter.startDate,
|
||||||
|
endDate: filter.endDate,
|
||||||
}
|
}
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
const { data, isLoading, error } = useSWR(
|
const { data, isLoading, error } = useSWR(
|
||||||
request ? ["/api/search/fares", request] : null,
|
request ? ["/api/search/prices", request] : null,
|
||||||
([url, request]) => fetcherUnwraperWithFilter<RoomPrice[]>(url, request),
|
([url, request]) => fetcherUnwraperWithFilter<RoomPrice[]>(url, request),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { useAPIRoomCategoryId } from "@/api/api-roomCategories";
|
import { useAPIRoomCategory } from "@/api/api-roomCategories";
|
||||||
import { Card, CardContent } from "../ui/card";
|
import { Card, CardContent } from "../ui/card";
|
||||||
import { useMemo } from "react";
|
|
||||||
import { Typography } from "../ui/typography";
|
import { Typography } from "../ui/typography";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
@@ -12,14 +11,14 @@ import {
|
|||||||
} from "../ui/table";
|
} from "../ui/table";
|
||||||
import { Skeleton } from "../ui/skeleton";
|
import { Skeleton } from "../ui/skeleton";
|
||||||
import { useAppStore } from "@/store";
|
import { useAppStore } from "@/store";
|
||||||
import { DateRange } from "react-day-picker";
|
|
||||||
import { FareFilter } from "@/model/RoomSearch";
|
|
||||||
import { useAPIRoomPrices } from "@/api/api-roomSearch";
|
import { useAPIRoomPrices } from "@/api/api-roomSearch";
|
||||||
import { NumberSelector } from "../ui/number-selector";
|
import { NumberSelector } from "../ui/number-selector";
|
||||||
import { NewBooking, NewBookingRoom } from "@/model/Bookings";
|
import { NewBooking, NewBookingRoom } from "@/model/Bookings";
|
||||||
import { RoomItemCard } from "./room-item-card";
|
import { RoomItemCard } from "./room-item-card";
|
||||||
import { IconWithTooltip } from "../ui/icon-number-tooltip";
|
import { IconWithTooltip } from "../ui/icon-number-tooltip";
|
||||||
import { UserIcon } from "lucide-react";
|
import { UserIcon } from "lucide-react";
|
||||||
|
import { makeFareFilterFromSearchFilter } from "@/utils/utils";
|
||||||
|
import { SearchFilter } from "@/model/InternalTypes";
|
||||||
|
|
||||||
function RoomBooking({
|
function RoomBooking({
|
||||||
roomCategoryId,
|
roomCategoryId,
|
||||||
@@ -28,12 +27,12 @@ function RoomBooking({
|
|||||||
roomCategoryId: number;
|
roomCategoryId: number;
|
||||||
availableAmount: number;
|
availableAmount: number;
|
||||||
}) {
|
}) {
|
||||||
const currentDates: DateRange = useAppStore(
|
const appSearchFilter: SearchFilter = useAppStore(
|
||||||
(state) => state.searchFilter.dateRange,
|
(state) => state.searchFilter,
|
||||||
);
|
);
|
||||||
const addNewRoom = useAppStore((state) => state.addNewBookingRoom);
|
const addNewRoom = useAppStore((state) => state.currentBookingAddRoom);
|
||||||
const bookingRooms: NewBooking | null = useAppStore(
|
const bookingRooms: NewBooking | null = useAppStore(
|
||||||
(state) => state.newBookingData,
|
(state) => state.currentBooking,
|
||||||
);
|
);
|
||||||
|
|
||||||
function onSelectedAmountUpdate(
|
function onSelectedAmountUpdate(
|
||||||
@@ -59,34 +58,35 @@ function RoomBooking({
|
|||||||
addNewRoom(newRoom);
|
addNewRoom(newRoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
const totalSelected = () => {
|
const getSelectedRoomAmount = (guestNumber: number | null) => {
|
||||||
let sum = 0;
|
let sum = 0;
|
||||||
bookingRooms &&
|
if (bookingRooms) {
|
||||||
|
//Rooms with same category and, if guestNumber is set, rooms with same guestNumber.
|
||||||
bookingRooms.rooms
|
bookingRooms.rooms
|
||||||
.filter((v) => v.roomCategory == roomCategoryId)
|
.filter((v) => {
|
||||||
|
const isSameCat = v.roomCategory == roomCategoryId;
|
||||||
|
const isSameGuestNum =
|
||||||
|
guestNumber != null ? v.guestNumber == guestNumber : true;
|
||||||
|
return isSameCat && isSameGuestNum;
|
||||||
|
})
|
||||||
.forEach((v) => (sum += v.amount));
|
.forEach((v) => (sum += v.amount));
|
||||||
|
}
|
||||||
return sum;
|
return sum;
|
||||||
};
|
};
|
||||||
const canAddMore: boolean = availableAmount > totalSelected();
|
const totalSelectAmount = getSelectedRoomAmount(null);
|
||||||
|
const canAddMoreRooms: boolean = availableAmount > totalSelectAmount;
|
||||||
|
|
||||||
//This seems a little bit overkill, but IDK.
|
//This seems a little bit overkill, but IDK.
|
||||||
const fareFilter: FareFilter | null = useMemo(() => {
|
const fareFilter = makeFareFilterFromSearchFilter(
|
||||||
if (currentDates && currentDates.from && currentDates.to) {
|
appSearchFilter,
|
||||||
const filter: FareFilter = {
|
roomCategoryId,
|
||||||
startDate: currentDates.from?.toDateString(),
|
);
|
||||||
endDate: currentDates.to?.toDateString(),
|
|
||||||
roomCategory: roomCategoryId,
|
|
||||||
};
|
|
||||||
return filter;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}, [currentDates, roomCategoryId]);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
roomCategory,
|
roomCategory,
|
||||||
isLoading: isLoadingCategory,
|
isLoading: isLoadingCategory,
|
||||||
isError: isErrorCategory,
|
isError: isErrorCategory,
|
||||||
} = useAPIRoomCategoryId(roomCategoryId);
|
} = useAPIRoomCategory(roomCategoryId);
|
||||||
const {
|
const {
|
||||||
roomPriceList,
|
roomPriceList,
|
||||||
isLoading: isLoadingPrices,
|
isLoading: isLoadingPrices,
|
||||||
@@ -111,31 +111,40 @@ function RoomBooking({
|
|||||||
const hasPrices = roomPriceList != null && roomPriceList?.length > 0;
|
const hasPrices = roomPriceList != null && roomPriceList?.length > 0;
|
||||||
let priceTable = null;
|
let priceTable = null;
|
||||||
if (hasPrices) {
|
if (hasPrices) {
|
||||||
const tableRows = roomPriceList?.map((el) => {
|
//A row for each room guestNumber.
|
||||||
return (
|
let tableRows = null;
|
||||||
<TableRow key={el.guestNumber}>
|
if (!isLoadingPrices) {
|
||||||
<TableCell>
|
tableRows = roomPriceList?.map((el) => {
|
||||||
<IconWithTooltip
|
const selectedRoomAmount =
|
||||||
label={el.guestNumber?.toString()}
|
totalSelectAmount > 0 ? getSelectedRoomAmount(el.guestNumber) : 0;
|
||||||
tooltipText={"Guest Number"}
|
|
||||||
labelPosition={"right"}
|
|
||||||
>
|
|
||||||
<UserIcon></UserIcon>
|
|
||||||
</IconWithTooltip>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>{el.price / 100} €</TableCell>
|
|
||||||
<TableCell>
|
|
||||||
<NumberSelector
|
|
||||||
updateCount={(count) =>
|
|
||||||
onSelectedAmountUpdate(el.guestNumber, count, el.price)
|
|
||||||
}
|
|
||||||
addEnabled={canAddMore}
|
|
||||||
></NumberSelector>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TableRow key={roomCategoryId + "-" + el.guestNumber}>
|
||||||
|
<TableCell>
|
||||||
|
<IconWithTooltip
|
||||||
|
label={el.guestNumber?.toString()}
|
||||||
|
tooltipText={"Guest Number"}
|
||||||
|
labelPosition={"right"}
|
||||||
|
>
|
||||||
|
<UserIcon></UserIcon>
|
||||||
|
</IconWithTooltip>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>{el.price / 100} €</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<NumberSelector
|
||||||
|
updateCount={(count) =>
|
||||||
|
onSelectedAmountUpdate(el.guestNumber, count, el.price)
|
||||||
|
}
|
||||||
|
addEnabled={canAddMoreRooms}
|
||||||
|
initialValue={selectedRoomAmount}
|
||||||
|
></NumberSelector>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//Element for
|
||||||
priceTable = (
|
priceTable = (
|
||||||
<Table className="overflow-hidden">
|
<Table className="overflow-hidden">
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import { Separator } from "../ui/separator";
|
import { Separator } from "../ui/separator";
|
||||||
import { Card, CardContent } from "../ui/card";
|
import { Card, CardContent } from "../ui/card";
|
||||||
import { Typography } from "../ui/typography";
|
import { Typography } from "../ui/typography";
|
||||||
import { BedDoubleIcon, BedSingleIcon, UserIcon } from "lucide-react";
|
import { UserIcon } from "lucide-react";
|
||||||
import { RoomCategory, RoomCategoryPhoto } from "@/model/RoomCategory";
|
import { RoomCategory, RoomCategoryPhoto } from "@/model/RoomCategory";
|
||||||
import { IconWithTooltip } from "../ui/icon-number-tooltip";
|
import { IconWithTooltip } from "../ui/icon-number-tooltip";
|
||||||
import roomImg from "@/res/SomniaRoomImage.svg";
|
import roomImg from "@/res/SomniaRoomImage.svg";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
import { Icon } from "@iconify-icon/react";
|
||||||
|
|
||||||
interface RoomItemCardProps {
|
interface RoomItemCardProps {
|
||||||
room: RoomCategory;
|
room: RoomCategory;
|
||||||
@@ -16,38 +17,43 @@ const defaultRoom: RoomCategory = {
|
|||||||
id: -1,
|
id: -1,
|
||||||
name: "Sample Room",
|
name: "Sample Room",
|
||||||
description: "Lorem Ipsum",
|
description: "Lorem Ipsum",
|
||||||
bedType: "0,1",
|
|
||||||
maxGuestNum: 2,
|
maxGuestNum: 2,
|
||||||
roomCategoryDetails: [],
|
orderHomePage: undefined,
|
||||||
roomCategoryPhotos: [],
|
roomCategoryPhotos: [],
|
||||||
|
roomCategoryBedTypes: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
export function RoomItemCard({
|
export function RoomItemCard({
|
||||||
room = defaultRoom,
|
room = defaultRoom,
|
||||||
className,
|
className,
|
||||||
}: RoomItemCardProps) {
|
}: RoomItemCardProps) {
|
||||||
const mainPhoto: RoomCategoryPhoto | undefined = room.roomCategoryPhotos.find(
|
//FIXME: Use PhotoOrder.
|
||||||
(element) => {
|
const mainPhoto: RoomCategoryPhoto | undefined =
|
||||||
return (element.kind = "main");
|
room.roomCategoryPhotos.length > 0
|
||||||
},
|
? room.roomCategoryPhotos.at(0)
|
||||||
);
|
: undefined;
|
||||||
const bedTypeList: number[] = room.bedType
|
|
||||||
.split(",")
|
const bedTypeIconList = room.roomCategoryBedTypes.map((e) => {
|
||||||
.map((e) => Number.parseInt(e));
|
return (
|
||||||
const hasSingleBed: boolean =
|
<IconWithTooltip
|
||||||
bedTypeList.at(0) !== undefined && bedTypeList[0] > 0;
|
key={room.id.toString() + e.bedTypeIcon}
|
||||||
const hasDoubleBed: boolean =
|
tooltipText={e.bedTypeName}
|
||||||
bedTypeList.at(1) !== undefined && bedTypeList[1] > 0;
|
label={e.amount.toString()}
|
||||||
|
>
|
||||||
|
<Icon icon={e.bedTypeIcon} height="auto" />
|
||||||
|
</IconWithTooltip>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card id={room.id.toString()} className={cn(className, "relative")}>
|
<Card key={room.id} className={cn(className, "relative", "py-0")}>
|
||||||
{/* <CardHeader className="p-0 m-0 mb-5">
|
{/* <CardHeader className="p-0 m-0 mb-5">
|
||||||
</CardHeader> */}
|
</CardHeader> */}
|
||||||
<CardContent className="flex h-full w-full flex-col p-0">
|
<CardContent className="flex h-full w-full flex-col p-0">
|
||||||
<div className="">
|
<div className="">
|
||||||
<img
|
<img
|
||||||
src={mainPhoto?.path ?? roomImg}
|
src={mainPhoto?.path ?? roomImg}
|
||||||
className="aspect-[4/3] w-full rounded-t-md object-cover"
|
className="aspect-4/3 w-full rounded-t-md object-cover"
|
||||||
></img>
|
></img>
|
||||||
<Separator className="my-0 border-2" />
|
<Separator className="my-0 border-2" />
|
||||||
</div>
|
</div>
|
||||||
@@ -64,26 +70,7 @@ export function RoomItemCard({
|
|||||||
<div className="mt-auto pb-4">
|
<div className="mt-auto pb-4">
|
||||||
<Separator className="my-4" />
|
<Separator className="my-4" />
|
||||||
<div className="flex justify-around">
|
<div className="flex justify-around">
|
||||||
<div className="flex flex-row gap-2">
|
<div className="flex flex-row gap-2">{bedTypeIconList}</div>
|
||||||
{hasSingleBed && (
|
|
||||||
<IconWithTooltip
|
|
||||||
tooltipText="Single bed"
|
|
||||||
label={bedTypeList[0]?.toString()}
|
|
||||||
>
|
|
||||||
<BedSingleIcon />
|
|
||||||
</IconWithTooltip>
|
|
||||||
)}
|
|
||||||
{hasDoubleBed && (
|
|
||||||
<>
|
|
||||||
<IconWithTooltip
|
|
||||||
tooltipText="Double bed"
|
|
||||||
label={bedTypeList[1]?.toString()}
|
|
||||||
>
|
|
||||||
<BedDoubleIcon />
|
|
||||||
</IconWithTooltip>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div className="flex flex-row">
|
<div className="flex flex-row">
|
||||||
<IconWithTooltip
|
<IconWithTooltip
|
||||||
tooltipText="Max. gests"
|
tooltipText="Max. gests"
|
||||||
|
|||||||
@@ -6,37 +6,28 @@ import { DatePickerWithRange } from "../ui/dateRange-picker";
|
|||||||
import { Button } from "../ui/button";
|
import { Button } from "../ui/button";
|
||||||
import { SearchIcon } from "lucide-react";
|
import { SearchIcon } from "lucide-react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { SearchFilter } from "@/model/SearchFilter";
|
import { SearchFilter } from "@/model/InternalTypes";
|
||||||
import { DateRange } from "react-day-picker";
|
import { DateRange } from "react-day-picker";
|
||||||
import { useToast } from "../ui/use-toast";
|
import { useToast } from "../ui/use-toast";
|
||||||
import { useAppStore } from "@/store";
|
|
||||||
|
|
||||||
type funOnSearchClick = (newFilter: SearchFilter) => void;
|
type funOnSearchClick = (newFilter: SearchFilter) => void;
|
||||||
|
|
||||||
export function SearchFilterCard({
|
export function SearchFilterCard({
|
||||||
onSearchClick,
|
onSearchClick,
|
||||||
|
initialsearchFilter,
|
||||||
}: {
|
}: {
|
||||||
onSearchClick?: funOnSearchClick;
|
onSearchClick?: funOnSearchClick;
|
||||||
|
initialsearchFilter?: SearchFilter;
|
||||||
}) {
|
}) {
|
||||||
//App filter. Updated on btSearchClick.
|
|
||||||
const appSearchFilter = useAppStore((state) => state.searchFilter);
|
|
||||||
const setAppSearchFilter = useAppStore((state) => state.setSearchFilter);
|
|
||||||
|
|
||||||
//Local Filter state.
|
//Local Filter state.
|
||||||
const [searchFilter, setSearchFilter] =
|
const [searchFilter, setSearchFilter] = useState<SearchFilter | null>(
|
||||||
useState<SearchFilter>(appSearchFilter);
|
initialsearchFilter ?? null,
|
||||||
|
);
|
||||||
//On location change, try to load searchFilter from state.
|
|
||||||
//FIXME: Si llegamos sin state, hay que borrar el state global...
|
|
||||||
// const location = useLocation();
|
|
||||||
// useEffect(() => {
|
|
||||||
// setSearchFilter(location.state);
|
|
||||||
// }, [location]);
|
|
||||||
|
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
// Validate and call callback on btSearch click.
|
// Validate and call callback on btSearch click.
|
||||||
//TODOME: Add data validations and show messages.
|
//TODOME: Add data validations and show messages as form instead of toasts.
|
||||||
const btSearchClick = () => {
|
const btSearchClick = () => {
|
||||||
if (!searchFilter || !searchFilter.dateRange) {
|
if (!searchFilter || !searchFilter.dateRange) {
|
||||||
toast({
|
toast({
|
||||||
@@ -55,8 +46,6 @@ export function SearchFilterCard({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setAppSearchFilter(searchFilter);
|
|
||||||
|
|
||||||
if (onSearchClick) {
|
if (onSearchClick) {
|
||||||
onSearchClick(searchFilter);
|
onSearchClick(searchFilter);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { BookAIcon, HomeIcon } from "lucide-react";
|
|||||||
|
|
||||||
function AppHeader() {
|
function AppHeader() {
|
||||||
return (
|
return (
|
||||||
<Card className="mx-10 my-4 flex items-center">
|
<Card className="mx-10 my-4 flex items-center py-0">
|
||||||
<CardContent className="w-full py-2">
|
<CardContent className="w-full py-2">
|
||||||
<div className="flex items-center justify-around">
|
<div className="flex items-center justify-around">
|
||||||
<div className="relative flex flex-row items-center gap-2">
|
<div className="relative flex flex-row items-center gap-2">
|
||||||
@@ -15,7 +15,7 @@ function AppHeader() {
|
|||||||
<Typography variant={"largeText"}>Somnia Rooms</Typography>
|
<Typography variant={"largeText"}>Somnia Rooms</Typography>
|
||||||
<a
|
<a
|
||||||
href="https://duck.com"
|
href="https://duck.com"
|
||||||
className="absolute h-[100%] w-[100%]"
|
className="absolute h-full w-full"
|
||||||
></a>
|
></a>
|
||||||
</div>
|
</div>
|
||||||
<Button variant="ghost" className="h-15">
|
<Button variant="ghost" className="h-15">
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { Typography } from "../ui/typography";
|
|||||||
import { differenceInDays } from "date-fns";
|
import { differenceInDays } from "date-fns";
|
||||||
import { Separator } from "../ui/separator";
|
import { Separator } from "../ui/separator";
|
||||||
import { Button } from "../ui/button";
|
import { Button } from "../ui/button";
|
||||||
import { useAPIRoomCategories } from "@/api/api-roomCategories";
|
import { useAPIRoomCategoryList } from "@/api/api-roomCategories";
|
||||||
import { IconWithTooltip } from "../ui/icon-number-tooltip";
|
import { IconWithTooltip } from "../ui/icon-number-tooltip";
|
||||||
import { UserIcon } from "lucide-react";
|
import { UserIcon } from "lucide-react";
|
||||||
|
|
||||||
@@ -18,8 +18,8 @@ export function BookingDetails({
|
|||||||
onBookingConfirm?: OnBookingClickFunction;
|
onBookingConfirm?: OnBookingClickFunction;
|
||||||
mode: BookingDetailsModes;
|
mode: BookingDetailsModes;
|
||||||
}) {
|
}) {
|
||||||
const bookingData = useAppStore((state) => state.newBookingData);
|
const bookingData = useAppStore((state) => state.currentBooking);
|
||||||
const roomCategoryList = useAPIRoomCategories();
|
const roomCategoryList = useAPIRoomCategoryList();
|
||||||
|
|
||||||
const onBtBookingClick = () => {
|
const onBtBookingClick = () => {
|
||||||
if (onBookingConfirm) {
|
if (onBookingConfirm) {
|
||||||
@@ -51,7 +51,7 @@ export function BookingDetails({
|
|||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
key={room.roomCategory.toString() + room.guestNumber.toString()}
|
key={room.roomCategory.toString() + room.guestNumber.toString()}
|
||||||
className="my-3 flex flex-row bg-accent"
|
className="my-3 flex flex-row bg-accent py-0"
|
||||||
>
|
>
|
||||||
{photo && (
|
{photo && (
|
||||||
<img
|
<img
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { MoonIcon, SunIcon } from "@radix-ui/react-icons";
|
import { MonitorIcon, MoonIcon, SunIcon } from "lucide-react";
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
@@ -14,7 +14,7 @@ export function ModeToggle() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger>
|
||||||
<Button variant="outline" size="icon">
|
<Button variant="outline" size="icon">
|
||||||
<SunIcon className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
|
<SunIcon className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
|
||||||
<MoonIcon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
|
<MoonIcon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
|
||||||
@@ -23,12 +23,15 @@ export function ModeToggle() {
|
|||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align="end">
|
<DropdownMenuContent align="end">
|
||||||
<DropdownMenuItem onClick={() => setTheme("light")}>
|
<DropdownMenuItem onClick={() => setTheme("light")}>
|
||||||
|
<SunIcon className="h-[1.2rem] w-[1.2rem] scale-100" />
|
||||||
Light
|
Light
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem onClick={() => setTheme("dark")}>
|
<DropdownMenuItem onClick={() => setTheme("dark")}>
|
||||||
|
<MoonIcon className="h-[1.2rem] w-[1.2rem] scale-100" />
|
||||||
Dark
|
Dark
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem onClick={() => setTheme("system")}>
|
<DropdownMenuItem onClick={() => setTheme("system")}>
|
||||||
|
<MonitorIcon className="h-[1.2rem] w-[1.2rem] scale-100" />
|
||||||
System
|
System
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
|
|||||||
+22
-11
@@ -1,20 +1,22 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
|
import { Slot } from "@radix-ui/react-slot";
|
||||||
import { cva, type VariantProps } from "class-variance-authority";
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const badgeVariants = cva(
|
const badgeVariants = cva(
|
||||||
"inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
|
"inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
variant: {
|
variant: {
|
||||||
default:
|
default:
|
||||||
"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",
|
"border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
|
||||||
secondary:
|
secondary:
|
||||||
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
"border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
|
||||||
destructive:
|
destructive:
|
||||||
"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",
|
"border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
||||||
outline: "text-foreground",
|
outline:
|
||||||
|
"text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
defaultVariants: {
|
defaultVariants: {
|
||||||
@@ -23,14 +25,23 @@ const badgeVariants = cva(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
export interface BadgeProps
|
function Badge({
|
||||||
extends React.HTMLAttributes<HTMLDivElement>,
|
className,
|
||||||
VariantProps<typeof badgeVariants> {}
|
variant,
|
||||||
|
asChild = false,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"span"> &
|
||||||
|
VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
|
||||||
|
const Comp = asChild ? Slot : "span";
|
||||||
|
|
||||||
function Badge({ className, variant, ...props }: BadgeProps) {
|
|
||||||
return (
|
return (
|
||||||
<div className={cn(badgeVariants({ variant }), className)} {...props} />
|
<Comp
|
||||||
|
data-slot="badge"
|
||||||
|
className={cn(badgeVariants({ variant }), className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Badge };
|
// eslint-disable-next-line react-refresh/only-export-components
|
||||||
|
export { Badge, badgeVariants };
|
||||||
|
|||||||
@@ -5,26 +5,27 @@ import { cva, type VariantProps } from "class-variance-authority";
|
|||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const buttonVariants = cva(
|
const buttonVariants = cva(
|
||||||
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",
|
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
variant: {
|
variant: {
|
||||||
default:
|
default:
|
||||||
"bg-primary text-primary-foreground shadow hover:bg-primary/90",
|
"bg-primary text-primary-foreground shadow-xs hover:bg-primary/90",
|
||||||
destructive:
|
destructive:
|
||||||
"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
|
"bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
||||||
outline:
|
outline:
|
||||||
"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
|
"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
||||||
secondary:
|
secondary:
|
||||||
"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
|
"bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",
|
||||||
ghost: "hover:bg-accent hover:text-accent-foreground",
|
ghost:
|
||||||
|
"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
||||||
link: "text-primary underline-offset-4 hover:underline",
|
link: "text-primary underline-offset-4 hover:underline",
|
||||||
},
|
},
|
||||||
size: {
|
size: {
|
||||||
default: "h-9 px-4 py-2",
|
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
||||||
sm: "h-8 rounded-md px-3 text-xs",
|
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
||||||
lg: "h-10 rounded-md px-8",
|
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
||||||
icon: "h-9 w-9",
|
icon: "size-9",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
defaultVariants: {
|
defaultVariants: {
|
||||||
@@ -34,25 +35,26 @@ const buttonVariants = cva(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
export interface ButtonProps
|
function Button({
|
||||||
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
className,
|
||||||
VariantProps<typeof buttonVariants> {
|
variant,
|
||||||
asChild?: boolean;
|
size,
|
||||||
}
|
asChild = false,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"button"> &
|
||||||
|
VariantProps<typeof buttonVariants> & {
|
||||||
|
asChild?: boolean;
|
||||||
|
}) {
|
||||||
|
const Comp = asChild ? Slot : "button";
|
||||||
|
|
||||||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
return (
|
||||||
({ className, variant, size, asChild = false, ...props }, ref) => {
|
<Comp
|
||||||
const Comp = asChild ? Slot : "button";
|
data-slot="button"
|
||||||
return (
|
className={cn(buttonVariants({ variant, size, className }))}
|
||||||
<Comp
|
{...props}
|
||||||
className={cn(buttonVariants({ variant, size, className }))}
|
/>
|
||||||
ref={ref}
|
);
|
||||||
{...props}
|
}
|
||||||
/>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
Button.displayName = "Button";
|
|
||||||
|
|
||||||
// eslint-disable-next-line react-refresh/only-export-components
|
// eslint-disable-next-line react-refresh/only-export-components
|
||||||
export { Button, buttonVariants };
|
export { Button, buttonVariants };
|
||||||
|
|||||||
+182
-44
@@ -1,70 +1,208 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { ChevronLeftIcon, ChevronRightIcon } from "@radix-ui/react-icons";
|
import {
|
||||||
import { DayPicker } from "react-day-picker";
|
ChevronDownIcon,
|
||||||
|
ChevronLeftIcon,
|
||||||
|
ChevronRightIcon,
|
||||||
|
} from "lucide-react";
|
||||||
|
import { DayButton, DayPicker, getDefaultClassNames } from "react-day-picker";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { buttonVariants } from "@/components/ui/button";
|
import { Button, buttonVariants } from "@/components/ui/button";
|
||||||
|
|
||||||
export type CalendarProps = React.ComponentProps<typeof DayPicker>;
|
|
||||||
|
|
||||||
function Calendar({
|
function Calendar({
|
||||||
className,
|
className,
|
||||||
classNames,
|
classNames,
|
||||||
showOutsideDays = true,
|
showOutsideDays = true,
|
||||||
|
captionLayout = "label",
|
||||||
|
buttonVariant = "ghost",
|
||||||
|
formatters,
|
||||||
|
components,
|
||||||
...props
|
...props
|
||||||
}: CalendarProps) {
|
}: React.ComponentProps<typeof DayPicker> & {
|
||||||
|
buttonVariant?: React.ComponentProps<typeof Button>["variant"];
|
||||||
|
}) {
|
||||||
|
const defaultClassNames = getDefaultClassNames();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DayPicker
|
<DayPicker
|
||||||
showOutsideDays={showOutsideDays}
|
showOutsideDays={showOutsideDays}
|
||||||
className={cn("p-3", className)}
|
className={cn(
|
||||||
|
"group/calendar bg-background p-3 [--cell-size:--spacing(8)] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent",
|
||||||
|
String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,
|
||||||
|
String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
captionLayout={captionLayout}
|
||||||
|
formatters={{
|
||||||
|
formatMonthDropdown: (date) =>
|
||||||
|
date.toLocaleString("default", { month: "short" }),
|
||||||
|
...formatters,
|
||||||
|
}}
|
||||||
classNames={{
|
classNames={{
|
||||||
months: "flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0",
|
root: cn("w-fit", defaultClassNames.root),
|
||||||
month: "space-y-4",
|
months: cn(
|
||||||
caption: "flex justify-center pt-1 relative items-center",
|
"flex gap-4 flex-col md:flex-row relative",
|
||||||
caption_label: "text-sm font-medium",
|
defaultClassNames.months,
|
||||||
nav: "space-x-1 flex items-center",
|
|
||||||
nav_button: cn(
|
|
||||||
buttonVariants({ variant: "outline" }),
|
|
||||||
"h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100",
|
|
||||||
),
|
),
|
||||||
nav_button_previous: "absolute left-1",
|
month: cn("flex flex-col w-full gap-4", defaultClassNames.month),
|
||||||
nav_button_next: "absolute right-1",
|
nav: cn(
|
||||||
table: "w-full border-collapse space-y-1",
|
"flex items-center gap-1 w-full absolute top-0 inset-x-0 justify-between",
|
||||||
head_row: "flex",
|
defaultClassNames.nav,
|
||||||
head_cell:
|
),
|
||||||
"text-muted-foreground rounded-md w-8 font-normal text-[0.8rem]",
|
button_previous: cn(
|
||||||
row: "flex w-full mt-2",
|
buttonVariants({ variant: buttonVariant }),
|
||||||
cell: cn(
|
"size-(--cell-size) aria-disabled:opacity-50 p-0 select-none",
|
||||||
"relative p-0 text-center text-sm focus-within:relative focus-within:z-20 [&:has([aria-selected])]:bg-accent [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected].day-range-end)]:rounded-r-md",
|
defaultClassNames.button_previous,
|
||||||
props.mode === "range"
|
),
|
||||||
? "[&:has(>.day-range-end)]:rounded-r-md [&:has(>.day-range-start)]:rounded-l-md first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md"
|
button_next: cn(
|
||||||
: "[&:has([aria-selected])]:rounded-md",
|
buttonVariants({ variant: buttonVariant }),
|
||||||
|
"size-(--cell-size) aria-disabled:opacity-50 p-0 select-none",
|
||||||
|
defaultClassNames.button_next,
|
||||||
|
),
|
||||||
|
month_caption: cn(
|
||||||
|
"flex items-center justify-center h-(--cell-size) w-full px-(--cell-size)",
|
||||||
|
defaultClassNames.month_caption,
|
||||||
|
),
|
||||||
|
dropdowns: cn(
|
||||||
|
"w-full flex items-center text-sm font-medium justify-center h-(--cell-size) gap-1.5",
|
||||||
|
defaultClassNames.dropdowns,
|
||||||
|
),
|
||||||
|
dropdown_root: cn(
|
||||||
|
"relative has-focus:border-ring border border-input shadow-xs has-focus:ring-ring/50 has-focus:ring-[3px] rounded-md",
|
||||||
|
defaultClassNames.dropdown_root,
|
||||||
|
),
|
||||||
|
dropdown: cn("absolute inset-0 opacity-0", defaultClassNames.dropdown),
|
||||||
|
caption_label: cn(
|
||||||
|
"select-none font-medium",
|
||||||
|
captionLayout === "label"
|
||||||
|
? "text-sm"
|
||||||
|
: "rounded-md pl-2 pr-1 flex items-center gap-1 text-sm h-8 [&>svg]:text-muted-foreground [&>svg]:size-3.5",
|
||||||
|
defaultClassNames.caption_label,
|
||||||
|
),
|
||||||
|
table: "w-full border-collapse",
|
||||||
|
weekdays: cn("flex", defaultClassNames.weekdays),
|
||||||
|
weekday: cn(
|
||||||
|
"text-muted-foreground rounded-md flex-1 font-normal text-[0.8rem] select-none",
|
||||||
|
defaultClassNames.weekday,
|
||||||
|
),
|
||||||
|
week: cn("flex w-full mt-2", defaultClassNames.week),
|
||||||
|
week_number_header: cn(
|
||||||
|
"select-none w-(--cell-size)",
|
||||||
|
defaultClassNames.week_number_header,
|
||||||
|
),
|
||||||
|
week_number: cn(
|
||||||
|
"text-[0.8rem] select-none text-muted-foreground",
|
||||||
|
defaultClassNames.week_number,
|
||||||
),
|
),
|
||||||
day: cn(
|
day: cn(
|
||||||
buttonVariants({ variant: "ghost" }),
|
"relative w-full h-full p-0 text-center [&:first-child[data-selected=true]_button]:rounded-l-md [&:last-child[data-selected=true]_button]:rounded-r-md group/day aspect-square select-none",
|
||||||
"h-8 w-8 p-0 font-normal aria-selected:opacity-100",
|
defaultClassNames.day,
|
||||||
),
|
),
|
||||||
day_range_start: "day-range-start",
|
range_start: cn(
|
||||||
day_range_end: "day-range-end",
|
"rounded-l-md bg-accent",
|
||||||
day_selected:
|
defaultClassNames.range_start,
|
||||||
"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground",
|
),
|
||||||
day_today: "bg-accent text-accent-foreground",
|
range_middle: cn("rounded-none", defaultClassNames.range_middle),
|
||||||
day_outside:
|
range_end: cn("rounded-r-md bg-accent", defaultClassNames.range_end),
|
||||||
"day-outside text-muted-foreground opacity-50 aria-selected:bg-accent/50 aria-selected:text-muted-foreground aria-selected:opacity-30",
|
today: cn(
|
||||||
day_disabled: "text-muted-foreground opacity-50",
|
"bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",
|
||||||
day_range_middle:
|
defaultClassNames.today,
|
||||||
"aria-selected:bg-accent aria-selected:text-accent-foreground",
|
),
|
||||||
day_hidden: "invisible",
|
outside: cn(
|
||||||
|
"text-muted-foreground aria-selected:text-muted-foreground",
|
||||||
|
defaultClassNames.outside,
|
||||||
|
),
|
||||||
|
disabled: cn(
|
||||||
|
"text-muted-foreground opacity-50",
|
||||||
|
defaultClassNames.disabled,
|
||||||
|
),
|
||||||
|
hidden: cn("invisible", defaultClassNames.hidden),
|
||||||
...classNames,
|
...classNames,
|
||||||
}}
|
}}
|
||||||
components={{
|
components={{
|
||||||
IconLeft: () => <ChevronLeftIcon className="h-4 w-4" />,
|
Root: ({ className, rootRef, ...props }) => {
|
||||||
IconRight: () => <ChevronRightIcon className="h-4 w-4" />,
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="calendar"
|
||||||
|
ref={rootRef}
|
||||||
|
className={cn(className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
Chevron: ({ className, orientation, ...props }) => {
|
||||||
|
if (orientation === "left") {
|
||||||
|
return (
|
||||||
|
<ChevronLeftIcon className={cn("size-4", className)} {...props} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (orientation === "right") {
|
||||||
|
return (
|
||||||
|
<ChevronRightIcon
|
||||||
|
className={cn("size-4", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ChevronDownIcon className={cn("size-4", className)} {...props} />
|
||||||
|
);
|
||||||
|
},
|
||||||
|
DayButton: CalendarDayButton,
|
||||||
|
WeekNumber: ({ children, ...props }) => {
|
||||||
|
return (
|
||||||
|
<td {...props}>
|
||||||
|
<div className="flex size-(--cell-size) items-center justify-center text-center">
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
...components,
|
||||||
}}
|
}}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Calendar.displayName = "Calendar";
|
|
||||||
|
|
||||||
export { Calendar };
|
function CalendarDayButton({
|
||||||
|
className,
|
||||||
|
day,
|
||||||
|
modifiers,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DayButton>) {
|
||||||
|
const defaultClassNames = getDefaultClassNames();
|
||||||
|
|
||||||
|
const ref = React.useRef<HTMLButtonElement>(null);
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (modifiers.focused) ref.current?.focus();
|
||||||
|
}, [modifiers.focused]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
ref={ref}
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
data-day={day.date.toLocaleDateString()}
|
||||||
|
data-selected-single={
|
||||||
|
modifiers.selected &&
|
||||||
|
!modifiers.range_start &&
|
||||||
|
!modifiers.range_end &&
|
||||||
|
!modifiers.range_middle
|
||||||
|
}
|
||||||
|
data-range-start={modifiers.range_start}
|
||||||
|
data-range-end={modifiers.range_end}
|
||||||
|
data-range-middle={modifiers.range_middle}
|
||||||
|
className={cn(
|
||||||
|
"flex aspect-square size-auto w-full min-w-(--cell-size) flex-col gap-1 leading-none font-normal group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-[3px] group-data-[focused=true]/day:ring-ring/50 data-[range-end=true]:rounded-md data-[range-end=true]:rounded-r-md data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground data-[range-middle=true]:rounded-none data-[range-middle=true]:bg-accent data-[range-middle=true]:text-accent-foreground data-[range-start=true]:rounded-md data-[range-start=true]:rounded-l-md data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground dark:hover:text-accent-foreground [&>span]:text-xs [&>span]:opacity-70",
|
||||||
|
defaultClassNames.day,
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Calendar, CalendarDayButton };
|
||||||
|
|||||||
+74
-65
@@ -2,82 +2,91 @@ import * as React from "react";
|
|||||||
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const Card = React.forwardRef<
|
function Card({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
HTMLDivElement,
|
return (
|
||||||
React.HTMLAttributes<HTMLDivElement>
|
<div
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="card"
|
||||||
<div
|
className={cn(
|
||||||
ref={ref}
|
"flex flex-col gap-6 rounded-xl border bg-card py-6 text-card-foreground shadow-sm",
|
||||||
className={cn(
|
className,
|
||||||
"rounded-xl border bg-card text-card-foreground shadow",
|
)}
|
||||||
className,
|
{...props}
|
||||||
)}
|
/>
|
||||||
{...props}
|
);
|
||||||
/>
|
}
|
||||||
));
|
|
||||||
Card.displayName = "Card";
|
|
||||||
|
|
||||||
const CardHeader = React.forwardRef<
|
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
HTMLDivElement,
|
return (
|
||||||
React.HTMLAttributes<HTMLDivElement>
|
<div
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="card-header"
|
||||||
<div
|
className={cn(
|
||||||
ref={ref}
|
"@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",
|
||||||
className={cn("flex flex-col space-y-1.5 p-6", className)}
|
className,
|
||||||
{...props}
|
)}
|
||||||
/>
|
{...props}
|
||||||
));
|
/>
|
||||||
CardHeader.displayName = "CardHeader";
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const CardTitle = React.forwardRef<
|
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
HTMLParagraphElement,
|
return (
|
||||||
React.HTMLAttributes<HTMLHeadingElement>
|
<div
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="card-title"
|
||||||
<h3
|
className={cn("leading-none font-semibold", className)}
|
||||||
ref={ref}
|
{...props}
|
||||||
className={cn("font-semibold leading-none tracking-tight", className)}
|
/>
|
||||||
{...props}
|
);
|
||||||
/>
|
}
|
||||||
));
|
|
||||||
CardTitle.displayName = "CardTitle";
|
|
||||||
|
|
||||||
const CardDescription = React.forwardRef<
|
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
HTMLParagraphElement,
|
return (
|
||||||
React.HTMLAttributes<HTMLParagraphElement>
|
<div
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="card-description"
|
||||||
<p
|
className={cn("text-sm text-muted-foreground", className)}
|
||||||
ref={ref}
|
{...props}
|
||||||
className={cn("text-sm text-muted-foreground", className)}
|
/>
|
||||||
{...props}
|
);
|
||||||
/>
|
}
|
||||||
));
|
|
||||||
CardDescription.displayName = "CardDescription";
|
|
||||||
|
|
||||||
const CardContent = React.forwardRef<
|
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
HTMLDivElement,
|
return (
|
||||||
React.HTMLAttributes<HTMLDivElement>
|
<div
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="card-action"
|
||||||
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
|
className={cn(
|
||||||
));
|
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
|
||||||
CardContent.displayName = "CardContent";
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const CardFooter = React.forwardRef<
|
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
HTMLDivElement,
|
return (
|
||||||
React.HTMLAttributes<HTMLDivElement>
|
<div
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="card-content"
|
||||||
<div
|
className={cn("px-6", className)}
|
||||||
ref={ref}
|
{...props}
|
||||||
className={cn("flex items-center p-6 pt-0", className)}
|
/>
|
||||||
{...props}
|
);
|
||||||
/>
|
}
|
||||||
));
|
|
||||||
CardFooter.displayName = "CardFooter";
|
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="card-footer"
|
||||||
|
className={cn("flex items-center px-6 [.border-t]:pt-6", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Card,
|
Card,
|
||||||
CardHeader,
|
CardHeader,
|
||||||
CardFooter,
|
CardFooter,
|
||||||
CardTitle,
|
CardTitle,
|
||||||
|
CardAction,
|
||||||
CardDescription,
|
CardDescription,
|
||||||
CardContent,
|
CardContent,
|
||||||
};
|
};
|
||||||
|
|||||||
+113
-134
@@ -1,8 +1,8 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { ArrowLeftIcon, ArrowRightIcon } from "@radix-ui/react-icons";
|
|
||||||
import useEmblaCarousel, {
|
import useEmblaCarousel, {
|
||||||
type UseEmblaCarouselType,
|
type UseEmblaCarouselType,
|
||||||
} from "embla-carousel-react";
|
} from "embla-carousel-react";
|
||||||
|
import { ArrowLeft, ArrowRight } from "lucide-react";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
@@ -40,124 +40,106 @@ function useCarousel() {
|
|||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Carousel = React.forwardRef<
|
function Carousel({
|
||||||
HTMLDivElement,
|
orientation = "horizontal",
|
||||||
React.HTMLAttributes<HTMLDivElement> & CarouselProps
|
opts,
|
||||||
>(
|
setApi,
|
||||||
(
|
plugins,
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"div"> & CarouselProps) {
|
||||||
|
const [carouselRef, api] = useEmblaCarousel(
|
||||||
{
|
{
|
||||||
orientation = "horizontal",
|
...opts,
|
||||||
opts,
|
axis: orientation === "horizontal" ? "x" : "y",
|
||||||
setApi,
|
|
||||||
plugins,
|
|
||||||
className,
|
|
||||||
children,
|
|
||||||
...props
|
|
||||||
},
|
},
|
||||||
ref,
|
plugins,
|
||||||
) => {
|
);
|
||||||
const [carouselRef, api] = useEmblaCarousel(
|
const [canScrollPrev, setCanScrollPrev] = React.useState(false);
|
||||||
{
|
const [canScrollNext, setCanScrollNext] = React.useState(false);
|
||||||
...opts,
|
|
||||||
axis: orientation === "horizontal" ? "x" : "y",
|
|
||||||
},
|
|
||||||
plugins,
|
|
||||||
);
|
|
||||||
const [canScrollPrev, setCanScrollPrev] = React.useState(false);
|
|
||||||
const [canScrollNext, setCanScrollNext] = React.useState(false);
|
|
||||||
|
|
||||||
const onSelect = React.useCallback((api: CarouselApi) => {
|
const onSelect = React.useCallback((api: CarouselApi) => {
|
||||||
if (!api) {
|
if (!api) return;
|
||||||
return;
|
setCanScrollPrev(api.canScrollPrev());
|
||||||
|
setCanScrollNext(api.canScrollNext());
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const scrollPrev = React.useCallback(() => {
|
||||||
|
api?.scrollPrev();
|
||||||
|
}, [api]);
|
||||||
|
|
||||||
|
const scrollNext = React.useCallback(() => {
|
||||||
|
api?.scrollNext();
|
||||||
|
}, [api]);
|
||||||
|
|
||||||
|
const handleKeyDown = React.useCallback(
|
||||||
|
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
||||||
|
if (event.key === "ArrowLeft") {
|
||||||
|
event.preventDefault();
|
||||||
|
scrollPrev();
|
||||||
|
} else if (event.key === "ArrowRight") {
|
||||||
|
event.preventDefault();
|
||||||
|
scrollNext();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
[scrollPrev, scrollNext],
|
||||||
|
);
|
||||||
|
|
||||||
setCanScrollPrev(api.canScrollPrev());
|
React.useEffect(() => {
|
||||||
setCanScrollNext(api.canScrollNext());
|
if (!api || !setApi) return;
|
||||||
}, []);
|
setApi(api);
|
||||||
|
}, [api, setApi]);
|
||||||
|
|
||||||
const scrollPrev = React.useCallback(() => {
|
React.useEffect(() => {
|
||||||
api?.scrollPrev();
|
if (!api) return;
|
||||||
}, [api]);
|
onSelect(api);
|
||||||
|
api.on("reInit", onSelect);
|
||||||
|
api.on("select", onSelect);
|
||||||
|
|
||||||
const scrollNext = React.useCallback(() => {
|
return () => {
|
||||||
api?.scrollNext();
|
api?.off("select", onSelect);
|
||||||
}, [api]);
|
};
|
||||||
|
}, [api, onSelect]);
|
||||||
|
|
||||||
const handleKeyDown = React.useCallback(
|
return (
|
||||||
(event: React.KeyboardEvent<HTMLDivElement>) => {
|
<CarouselContext.Provider
|
||||||
if (event.key === "ArrowLeft") {
|
value={{
|
||||||
event.preventDefault();
|
carouselRef,
|
||||||
scrollPrev();
|
api: api,
|
||||||
} else if (event.key === "ArrowRight") {
|
opts,
|
||||||
event.preventDefault();
|
orientation:
|
||||||
scrollNext();
|
orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
|
||||||
}
|
scrollPrev,
|
||||||
},
|
scrollNext,
|
||||||
[scrollPrev, scrollNext],
|
canScrollPrev,
|
||||||
);
|
canScrollNext,
|
||||||
|
}}
|
||||||
React.useEffect(() => {
|
>
|
||||||
if (!api || !setApi) {
|
<div
|
||||||
return;
|
onKeyDownCapture={handleKeyDown}
|
||||||
}
|
className={cn("relative", className)}
|
||||||
|
role="region"
|
||||||
setApi(api);
|
aria-roledescription="carousel"
|
||||||
}, [api, setApi]);
|
data-slot="carousel"
|
||||||
|
{...props}
|
||||||
React.useEffect(() => {
|
|
||||||
if (!api) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
onSelect(api);
|
|
||||||
api.on("reInit", onSelect);
|
|
||||||
api.on("select", onSelect);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
api?.off("select", onSelect);
|
|
||||||
};
|
|
||||||
}, [api, onSelect]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<CarouselContext.Provider
|
|
||||||
value={{
|
|
||||||
carouselRef,
|
|
||||||
api: api,
|
|
||||||
opts,
|
|
||||||
orientation:
|
|
||||||
orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
|
|
||||||
scrollPrev,
|
|
||||||
scrollNext,
|
|
||||||
canScrollPrev,
|
|
||||||
canScrollNext,
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<div
|
{children}
|
||||||
ref={ref}
|
</div>
|
||||||
onKeyDownCapture={handleKeyDown}
|
</CarouselContext.Provider>
|
||||||
className={cn("relative", className)}
|
);
|
||||||
role="region"
|
}
|
||||||
aria-roledescription="carousel"
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
</CarouselContext.Provider>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
Carousel.displayName = "Carousel";
|
|
||||||
|
|
||||||
const CarouselContent = React.forwardRef<
|
function CarouselContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
HTMLDivElement,
|
|
||||||
React.HTMLAttributes<HTMLDivElement>
|
|
||||||
>(({ className, ...props }, ref) => {
|
|
||||||
const { carouselRef, orientation } = useCarousel();
|
const { carouselRef, orientation } = useCarousel();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={carouselRef} className="overflow-hidden">
|
<div
|
||||||
|
ref={carouselRef}
|
||||||
|
className="overflow-hidden"
|
||||||
|
data-slot="carousel-content"
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
ref={ref}
|
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex",
|
"flex",
|
||||||
orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col",
|
orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col",
|
||||||
@@ -167,20 +149,16 @@ const CarouselContent = React.forwardRef<
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
CarouselContent.displayName = "CarouselContent";
|
|
||||||
|
|
||||||
const CarouselItem = React.forwardRef<
|
function CarouselItem({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
HTMLDivElement,
|
|
||||||
React.HTMLAttributes<HTMLDivElement>
|
|
||||||
>(({ className, ...props }, ref) => {
|
|
||||||
const { orientation } = useCarousel();
|
const { orientation } = useCarousel();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={ref}
|
|
||||||
role="group"
|
role="group"
|
||||||
aria-roledescription="slide"
|
aria-roledescription="slide"
|
||||||
|
data-slot="carousel-item"
|
||||||
className={cn(
|
className={cn(
|
||||||
"min-w-0 shrink-0 grow-0 basis-full",
|
"min-w-0 shrink-0 grow-0 basis-full",
|
||||||
orientation === "horizontal" ? "pl-4" : "pt-4",
|
orientation === "horizontal" ? "pl-4" : "pt-4",
|
||||||
@@ -189,24 +167,25 @@ const CarouselItem = React.forwardRef<
|
|||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
CarouselItem.displayName = "CarouselItem";
|
|
||||||
|
|
||||||
const CarouselPrevious = React.forwardRef<
|
function CarouselPrevious({
|
||||||
HTMLButtonElement,
|
className,
|
||||||
React.ComponentProps<typeof Button>
|
variant = "outline",
|
||||||
>(({ className, variant = "outline", size = "icon", ...props }, ref) => {
|
size = "icon",
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof Button>) {
|
||||||
const { orientation, scrollPrev, canScrollPrev } = useCarousel();
|
const { orientation, scrollPrev, canScrollPrev } = useCarousel();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
ref={ref}
|
data-slot="carousel-previous"
|
||||||
variant={variant}
|
variant={variant}
|
||||||
size={size}
|
size={size}
|
||||||
className={cn(
|
className={cn(
|
||||||
"absolute h-8 w-8 rounded-full",
|
"absolute size-8 rounded-full",
|
||||||
orientation === "horizontal"
|
orientation === "horizontal"
|
||||||
? "-left-12 top-1/2 -translate-y-1/2"
|
? "top-1/2 -left-12 -translate-y-1/2"
|
||||||
: "-top-12 left-1/2 -translate-x-1/2 rotate-90",
|
: "-top-12 left-1/2 -translate-x-1/2 rotate-90",
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
@@ -214,28 +193,29 @@ const CarouselPrevious = React.forwardRef<
|
|||||||
onClick={scrollPrev}
|
onClick={scrollPrev}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<ArrowLeftIcon className="h-4 w-4" />
|
<ArrowLeft />
|
||||||
<span className="sr-only">Previous slide</span>
|
<span className="sr-only">Previous slide</span>
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
CarouselPrevious.displayName = "CarouselPrevious";
|
|
||||||
|
|
||||||
const CarouselNext = React.forwardRef<
|
function CarouselNext({
|
||||||
HTMLButtonElement,
|
className,
|
||||||
React.ComponentProps<typeof Button>
|
variant = "outline",
|
||||||
>(({ className, variant = "outline", size = "icon", ...props }, ref) => {
|
size = "icon",
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof Button>) {
|
||||||
const { orientation, scrollNext, canScrollNext } = useCarousel();
|
const { orientation, scrollNext, canScrollNext } = useCarousel();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
ref={ref}
|
data-slot="carousel-next"
|
||||||
variant={variant}
|
variant={variant}
|
||||||
size={size}
|
size={size}
|
||||||
className={cn(
|
className={cn(
|
||||||
"absolute h-8 w-8 rounded-full",
|
"absolute size-8 rounded-full",
|
||||||
orientation === "horizontal"
|
orientation === "horizontal"
|
||||||
? "-right-12 top-1/2 -translate-y-1/2"
|
? "top-1/2 -right-12 -translate-y-1/2"
|
||||||
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
|
: "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
@@ -243,12 +223,11 @@ const CarouselNext = React.forwardRef<
|
|||||||
onClick={scrollNext}
|
onClick={scrollNext}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<ArrowRightIcon className="h-4 w-4" />
|
<ArrowRight />
|
||||||
<span className="sr-only">Next slide</span>
|
<span className="sr-only">Next slide</span>
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
CarouselNext.displayName = "CarouselNext";
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
type CarouselApi,
|
type CarouselApi,
|
||||||
|
|||||||
@@ -1,28 +1,30 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
|
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
|
||||||
import { CheckIcon } from "@radix-ui/react-icons";
|
import { CheckIcon } from "lucide-react";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const Checkbox = React.forwardRef<
|
function Checkbox({
|
||||||
React.ElementRef<typeof CheckboxPrimitive.Root>,
|
className,
|
||||||
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
|
...props
|
||||||
>(({ className, ...props }, ref) => (
|
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
|
||||||
<CheckboxPrimitive.Root
|
return (
|
||||||
ref={ref}
|
<CheckboxPrimitive.Root
|
||||||
className={cn(
|
data-slot="checkbox"
|
||||||
"peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
|
className={cn(
|
||||||
className,
|
"peer size-4 shrink-0 rounded-[4px] border border-input shadow-xs transition-shadow outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:bg-input/30 dark:aria-invalid:ring-destructive/40 dark:data-[state=checked]:bg-primary",
|
||||||
)}
|
className,
|
||||||
{...props}
|
)}
|
||||||
>
|
{...props}
|
||||||
<CheckboxPrimitive.Indicator
|
|
||||||
className={cn("flex items-center justify-center text-current")}
|
|
||||||
>
|
>
|
||||||
<CheckIcon className="h-4 w-4" />
|
<CheckboxPrimitive.Indicator
|
||||||
</CheckboxPrimitive.Indicator>
|
data-slot="checkbox-indicator"
|
||||||
</CheckboxPrimitive.Root>
|
className="flex items-center justify-center text-current transition-none"
|
||||||
));
|
>
|
||||||
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
|
<CheckIcon className="size-3.5" />
|
||||||
|
</CheckboxPrimitive.Indicator>
|
||||||
|
</CheckboxPrimitive.Root>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export { Checkbox };
|
export { Checkbox };
|
||||||
|
|||||||
@@ -1,14 +1,8 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { CalendarIcon } from "@radix-ui/react-icons";
|
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
import {
|
import { DateBefore, DateRange, Matcher, Modifiers } from "react-day-picker";
|
||||||
ActiveModifiers,
|
|
||||||
DateBefore,
|
|
||||||
DateRange,
|
|
||||||
Matcher,
|
|
||||||
} from "react-day-picker";
|
|
||||||
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
@@ -19,6 +13,7 @@ import {
|
|||||||
PopoverTrigger,
|
PopoverTrigger,
|
||||||
} from "@/components/ui/popover";
|
} from "@/components/ui/popover";
|
||||||
import { Typography } from "./typography";
|
import { Typography } from "./typography";
|
||||||
|
import { CalendarIcon } from "lucide-react";
|
||||||
|
|
||||||
export type UpdateRangeFunction = (newRange: DateRange) => void;
|
export type UpdateRangeFunction = (newRange: DateRange) => void;
|
||||||
|
|
||||||
@@ -43,7 +38,7 @@ export function DatePickerWithRange({
|
|||||||
|
|
||||||
//TODOME: Si el día es mods.outside, navegar al mes correspondiente.
|
//TODOME: Si el día es mods.outside, navegar al mes correspondiente.
|
||||||
// Handle Day change events.
|
// Handle Day change events.
|
||||||
const handleDayClickFrom = (day: Date, mods: ActiveModifiers) => {
|
const handleDayClickFrom = (day: Date, mods: Modifiers) => {
|
||||||
const newDateRange: DateRange = {
|
const newDateRange: DateRange = {
|
||||||
from: mods.selected ? undefined : day,
|
from: mods.selected ? undefined : day,
|
||||||
to: undefined,
|
to: undefined,
|
||||||
@@ -52,7 +47,7 @@ export function DatePickerWithRange({
|
|||||||
fnUpdateRange(newDateRange);
|
fnUpdateRange(newDateRange);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDayClickTo = (day: Date, mods: ActiveModifiers) => {
|
const handleDayClickTo = (day: Date, mods: Modifiers) => {
|
||||||
const newDateRange: DateRange = {
|
const newDateRange: DateRange = {
|
||||||
from: dateRange?.from,
|
from: dateRange?.from,
|
||||||
to: mods.selected ? undefined : day,
|
to: mods.selected ? undefined : day,
|
||||||
@@ -90,18 +85,16 @@ export function DatePickerWithRange({
|
|||||||
Hasta
|
Hasta
|
||||||
</Typography>
|
</Typography>
|
||||||
<Popover>
|
<Popover>
|
||||||
<PopoverTrigger asChild>
|
<PopoverTrigger>
|
||||||
<Button
|
<Button
|
||||||
id="dateFrom"
|
id="dateFrom"
|
||||||
variant={"outline"}
|
variant="outline"
|
||||||
className={cn(
|
data-empty={!dateRange}
|
||||||
"justify-start text-left font-normal",
|
className="w-[100%] justify-start text-left font-normal data-[empty=true]:text-muted-foreground"
|
||||||
!dateRange && "text-muted-foreground",
|
|
||||||
)}
|
|
||||||
>
|
>
|
||||||
<CalendarIcon className="mr-2 h-4 w-4" />
|
<CalendarIcon />
|
||||||
{dateRange?.from ? (
|
{dateRange?.from ? (
|
||||||
format(dateRange.from, "LLL dd, y")
|
format(dateRange.from, "PPP")
|
||||||
) : (
|
) : (
|
||||||
<span>Pick a date</span>
|
<span>Pick a date</span>
|
||||||
)}
|
)}
|
||||||
@@ -109,7 +102,6 @@ export function DatePickerWithRange({
|
|||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent className="w-auto p-0" align="center">
|
<PopoverContent className="w-auto p-0" align="center">
|
||||||
<Calendar
|
<Calendar
|
||||||
initialFocus
|
|
||||||
mode="single"
|
mode="single"
|
||||||
defaultMonth={dateRange?.from}
|
defaultMonth={dateRange?.from}
|
||||||
selected={dateRange?.from}
|
selected={dateRange?.from}
|
||||||
@@ -120,14 +112,12 @@ export function DatePickerWithRange({
|
|||||||
</PopoverContent>
|
</PopoverContent>
|
||||||
</Popover>
|
</Popover>
|
||||||
<Popover>
|
<Popover>
|
||||||
<PopoverTrigger asChild>
|
<PopoverTrigger>
|
||||||
<Button
|
<Button
|
||||||
id="dateTo"
|
id="dateTo"
|
||||||
variant={"outline"}
|
variant={"outline"}
|
||||||
className={cn(
|
data-empty={!dateRange}
|
||||||
"justify-start text-left font-normal",
|
className="w-[100%] justify-start text-left font-normal data-[empty=true]:text-muted-foreground"
|
||||||
!dateRange && "text-muted-foreground",
|
|
||||||
)}
|
|
||||||
>
|
>
|
||||||
<CalendarIcon className="mr-2 h-4 w-4" />
|
<CalendarIcon className="mr-2 h-4 w-4" />
|
||||||
{dateRange?.to ? (
|
{dateRange?.to ? (
|
||||||
@@ -139,7 +129,7 @@ export function DatePickerWithRange({
|
|||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent className="w-auto p-0" align="center">
|
<PopoverContent className="w-auto p-0" align="center">
|
||||||
<Calendar
|
<Calendar
|
||||||
initialFocus
|
autoFocus
|
||||||
mode="single"
|
mode="single"
|
||||||
defaultMonth={dateRange?.to ?? dateRange?.from}
|
defaultMonth={dateRange?.to ?? dateRange?.from}
|
||||||
selected={dateRange?.to}
|
selected={dateRange?.to}
|
||||||
|
|||||||
+220
-168
@@ -1,203 +1,255 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
||||||
import {
|
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react";
|
||||||
CheckIcon,
|
|
||||||
ChevronRightIcon,
|
|
||||||
DotFilledIcon,
|
|
||||||
} from "@radix-ui/react-icons";
|
|
||||||
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const DropdownMenu = DropdownMenuPrimitive.Root;
|
function DropdownMenu({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
|
||||||
|
return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;
|
function DropdownMenuPortal({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const DropdownMenuGroup = DropdownMenuPrimitive.Group;
|
function DropdownMenuTrigger({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Trigger
|
||||||
|
data-slot="dropdown-menu-trigger"
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const DropdownMenuPortal = DropdownMenuPrimitive.Portal;
|
function DropdownMenuContent({
|
||||||
|
className,
|
||||||
|
sideOffset = 4,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Portal>
|
||||||
|
<DropdownMenuPrimitive.Content
|
||||||
|
data-slot="dropdown-menu-content"
|
||||||
|
sideOffset={sideOffset}
|
||||||
|
className={cn(
|
||||||
|
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
</DropdownMenuPrimitive.Portal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const DropdownMenuSub = DropdownMenuPrimitive.Sub;
|
function DropdownMenuGroup({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup;
|
function DropdownMenuItem({
|
||||||
|
className,
|
||||||
const DropdownMenuSubTrigger = React.forwardRef<
|
inset,
|
||||||
React.ElementRef<typeof DropdownMenuPrimitive.SubTrigger>,
|
variant = "default",
|
||||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & {
|
...props
|
||||||
inset?: boolean;
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
|
||||||
}
|
inset?: boolean;
|
||||||
>(({ className, inset, children, ...props }, ref) => (
|
variant?: "default" | "destructive";
|
||||||
<DropdownMenuPrimitive.SubTrigger
|
}) {
|
||||||
ref={ref}
|
return (
|
||||||
className={cn(
|
<DropdownMenuPrimitive.Item
|
||||||
"flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",
|
data-slot="dropdown-menu-item"
|
||||||
inset && "pl-8",
|
data-inset={inset}
|
||||||
className,
|
data-variant={variant}
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
<ChevronRightIcon className="ml-auto h-4 w-4" />
|
|
||||||
</DropdownMenuPrimitive.SubTrigger>
|
|
||||||
));
|
|
||||||
DropdownMenuSubTrigger.displayName =
|
|
||||||
DropdownMenuPrimitive.SubTrigger.displayName;
|
|
||||||
|
|
||||||
const DropdownMenuSubContent = React.forwardRef<
|
|
||||||
React.ElementRef<typeof DropdownMenuPrimitive.SubContent>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent>
|
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<DropdownMenuPrimitive.SubContent
|
|
||||||
ref={ref}
|
|
||||||
className={cn(
|
|
||||||
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
|
||||||
className,
|
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
));
|
|
||||||
DropdownMenuSubContent.displayName =
|
|
||||||
DropdownMenuPrimitive.SubContent.displayName;
|
|
||||||
|
|
||||||
const DropdownMenuContent = React.forwardRef<
|
|
||||||
React.ElementRef<typeof DropdownMenuPrimitive.Content>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>
|
|
||||||
>(({ className, sideOffset = 4, ...props }, ref) => (
|
|
||||||
<DropdownMenuPrimitive.Portal>
|
|
||||||
<DropdownMenuPrimitive.Content
|
|
||||||
ref={ref}
|
|
||||||
sideOffset={sideOffset}
|
|
||||||
className={cn(
|
className={cn(
|
||||||
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md",
|
"relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:!text-destructive",
|
||||||
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
</DropdownMenuPrimitive.Portal>
|
);
|
||||||
));
|
}
|
||||||
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;
|
|
||||||
|
|
||||||
const DropdownMenuItem = React.forwardRef<
|
function DropdownMenuCheckboxItem({
|
||||||
React.ElementRef<typeof DropdownMenuPrimitive.Item>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & {
|
|
||||||
inset?: boolean;
|
|
||||||
}
|
|
||||||
>(({ className, inset, ...props }, ref) => (
|
|
||||||
<DropdownMenuPrimitive.Item
|
|
||||||
ref={ref}
|
|
||||||
className={cn(
|
|
||||||
"relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
|
||||||
inset && "pl-8",
|
|
||||||
className,
|
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
));
|
|
||||||
DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName;
|
|
||||||
|
|
||||||
const DropdownMenuCheckboxItem = React.forwardRef<
|
|
||||||
React.ElementRef<typeof DropdownMenuPrimitive.CheckboxItem>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem>
|
|
||||||
>(({ className, children, checked, ...props }, ref) => (
|
|
||||||
<DropdownMenuPrimitive.CheckboxItem
|
|
||||||
ref={ref}
|
|
||||||
className={cn(
|
|
||||||
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
|
||||||
className,
|
|
||||||
)}
|
|
||||||
checked={checked}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
|
||||||
<DropdownMenuPrimitive.ItemIndicator>
|
|
||||||
<CheckIcon className="h-4 w-4" />
|
|
||||||
</DropdownMenuPrimitive.ItemIndicator>
|
|
||||||
</span>
|
|
||||||
{children}
|
|
||||||
</DropdownMenuPrimitive.CheckboxItem>
|
|
||||||
));
|
|
||||||
DropdownMenuCheckboxItem.displayName =
|
|
||||||
DropdownMenuPrimitive.CheckboxItem.displayName;
|
|
||||||
|
|
||||||
const DropdownMenuRadioItem = React.forwardRef<
|
|
||||||
React.ElementRef<typeof DropdownMenuPrimitive.RadioItem>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem>
|
|
||||||
>(({ className, children, ...props }, ref) => (
|
|
||||||
<DropdownMenuPrimitive.RadioItem
|
|
||||||
ref={ref}
|
|
||||||
className={cn(
|
|
||||||
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
|
||||||
className,
|
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
|
||||||
<DropdownMenuPrimitive.ItemIndicator>
|
|
||||||
<DotFilledIcon className="h-4 w-4 fill-current" />
|
|
||||||
</DropdownMenuPrimitive.ItemIndicator>
|
|
||||||
</span>
|
|
||||||
{children}
|
|
||||||
</DropdownMenuPrimitive.RadioItem>
|
|
||||||
));
|
|
||||||
DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName;
|
|
||||||
|
|
||||||
const DropdownMenuLabel = React.forwardRef<
|
|
||||||
React.ElementRef<typeof DropdownMenuPrimitive.Label>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Label> & {
|
|
||||||
inset?: boolean;
|
|
||||||
}
|
|
||||||
>(({ className, inset, ...props }, ref) => (
|
|
||||||
<DropdownMenuPrimitive.Label
|
|
||||||
ref={ref}
|
|
||||||
className={cn(
|
|
||||||
"px-2 py-1.5 text-sm font-semibold",
|
|
||||||
inset && "pl-8",
|
|
||||||
className,
|
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
));
|
|
||||||
DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName;
|
|
||||||
|
|
||||||
const DropdownMenuSeparator = React.forwardRef<
|
|
||||||
React.ElementRef<typeof DropdownMenuPrimitive.Separator>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>
|
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<DropdownMenuPrimitive.Separator
|
|
||||||
ref={ref}
|
|
||||||
className={cn("-mx-1 my-1 h-px bg-muted", className)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
));
|
|
||||||
DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName;
|
|
||||||
|
|
||||||
const DropdownMenuShortcut = ({
|
|
||||||
className,
|
className,
|
||||||
|
children,
|
||||||
|
checked,
|
||||||
...props
|
...props
|
||||||
}: React.HTMLAttributes<HTMLSpanElement>) => {
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>) {
|
||||||
return (
|
return (
|
||||||
<span
|
<DropdownMenuPrimitive.CheckboxItem
|
||||||
className={cn("ml-auto text-xs tracking-widest opacity-60", className)}
|
data-slot="dropdown-menu-checkbox-item"
|
||||||
|
className={cn(
|
||||||
|
"relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
checked={checked}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||||
|
<DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
<CheckIcon className="size-4" />
|
||||||
|
</DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
</span>
|
||||||
|
{children}
|
||||||
|
</DropdownMenuPrimitive.CheckboxItem>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuRadioGroup({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.RadioGroup
|
||||||
|
data-slot="dropdown-menu-radio-group"
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
DropdownMenuShortcut.displayName = "DropdownMenuShortcut";
|
|
||||||
|
function DropdownMenuRadioItem({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.RadioItem
|
||||||
|
data-slot="dropdown-menu-radio-item"
|
||||||
|
className={cn(
|
||||||
|
"relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
|
||||||
|
<DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
<CircleIcon className="size-2 fill-current" />
|
||||||
|
</DropdownMenuPrimitive.ItemIndicator>
|
||||||
|
</span>
|
||||||
|
{children}
|
||||||
|
</DropdownMenuPrimitive.RadioItem>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuLabel({
|
||||||
|
className,
|
||||||
|
inset,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
|
||||||
|
inset?: boolean;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Label
|
||||||
|
data-slot="dropdown-menu-label"
|
||||||
|
data-inset={inset}
|
||||||
|
className={cn(
|
||||||
|
"px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuSeparator({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Separator
|
||||||
|
data-slot="dropdown-menu-separator"
|
||||||
|
className={cn("-mx-1 my-1 h-px bg-border", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuShortcut({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"span">) {
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
data-slot="dropdown-menu-shortcut"
|
||||||
|
className={cn(
|
||||||
|
"ml-auto text-xs tracking-widest text-muted-foreground",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuSub({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
|
||||||
|
return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuSubTrigger({
|
||||||
|
className,
|
||||||
|
inset,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
|
||||||
|
inset?: boolean;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.SubTrigger
|
||||||
|
data-slot="dropdown-menu-sub-trigger"
|
||||||
|
data-inset={inset}
|
||||||
|
className={cn(
|
||||||
|
"flex cursor-default items-center rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[inset]:pl-8 data-[state=open]:bg-accent data-[state=open]:text-accent-foreground",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
<ChevronRightIcon className="ml-auto size-4" />
|
||||||
|
</DropdownMenuPrimitive.SubTrigger>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropdownMenuSubContent({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.SubContent
|
||||||
|
data-slot="dropdown-menu-sub-content"
|
||||||
|
className={cn(
|
||||||
|
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
|
DropdownMenuPortal,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
|
DropdownMenuGroup,
|
||||||
|
DropdownMenuLabel,
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuCheckboxItem,
|
DropdownMenuCheckboxItem,
|
||||||
|
DropdownMenuRadioGroup,
|
||||||
DropdownMenuRadioItem,
|
DropdownMenuRadioItem,
|
||||||
DropdownMenuLabel,
|
|
||||||
DropdownMenuSeparator,
|
DropdownMenuSeparator,
|
||||||
DropdownMenuShortcut,
|
DropdownMenuShortcut,
|
||||||
DropdownMenuGroup,
|
|
||||||
DropdownMenuPortal,
|
|
||||||
DropdownMenuSub,
|
DropdownMenuSub,
|
||||||
DropdownMenuSubContent,
|
|
||||||
DropdownMenuSubTrigger,
|
DropdownMenuSubTrigger,
|
||||||
DropdownMenuRadioGroup,
|
DropdownMenuSubContent,
|
||||||
};
|
};
|
||||||
|
|||||||
+33
-44
@@ -3,11 +3,12 @@ import * as LabelPrimitive from "@radix-ui/react-label";
|
|||||||
import { Slot } from "@radix-ui/react-slot";
|
import { Slot } from "@radix-ui/react-slot";
|
||||||
import {
|
import {
|
||||||
Controller,
|
Controller,
|
||||||
ControllerProps,
|
|
||||||
FieldPath,
|
|
||||||
FieldValues,
|
|
||||||
FormProvider,
|
FormProvider,
|
||||||
useFormContext,
|
useFormContext,
|
||||||
|
useFormState,
|
||||||
|
type ControllerProps,
|
||||||
|
type FieldPath,
|
||||||
|
type FieldValues,
|
||||||
} from "react-hook-form";
|
} from "react-hook-form";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
@@ -42,8 +43,8 @@ const FormField = <
|
|||||||
const useFormField = () => {
|
const useFormField = () => {
|
||||||
const fieldContext = React.useContext(FormFieldContext);
|
const fieldContext = React.useContext(FormFieldContext);
|
||||||
const itemContext = React.useContext(FormItemContext);
|
const itemContext = React.useContext(FormItemContext);
|
||||||
const { getFieldState, formState } = useFormContext();
|
const { getFieldState } = useFormContext();
|
||||||
|
const formState = useFormState({ name: fieldContext.name });
|
||||||
const fieldState = getFieldState(fieldContext.name, formState);
|
const fieldState = getFieldState(fieldContext.name, formState);
|
||||||
|
|
||||||
if (!fieldContext) {
|
if (!fieldContext) {
|
||||||
@@ -70,47 +71,44 @@ const FormItemContext = React.createContext<FormItemContextValue>(
|
|||||||
{} as FormItemContextValue,
|
{} as FormItemContextValue,
|
||||||
);
|
);
|
||||||
|
|
||||||
const FormItem = React.forwardRef<
|
function FormItem({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
HTMLDivElement,
|
|
||||||
React.HTMLAttributes<HTMLDivElement>
|
|
||||||
>(({ className, ...props }, ref) => {
|
|
||||||
const id = React.useId();
|
const id = React.useId();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormItemContext.Provider value={{ id }}>
|
<FormItemContext.Provider value={{ id }}>
|
||||||
<div ref={ref} className={cn("space-y-2", className)} {...props} />
|
<div
|
||||||
|
data-slot="form-item"
|
||||||
|
className={cn("grid gap-2", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
</FormItemContext.Provider>
|
</FormItemContext.Provider>
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
FormItem.displayName = "FormItem";
|
|
||||||
|
|
||||||
const FormLabel = React.forwardRef<
|
function FormLabel({
|
||||||
React.ElementRef<typeof LabelPrimitive.Root>,
|
className,
|
||||||
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>
|
...props
|
||||||
>(({ className, ...props }, ref) => {
|
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
|
||||||
const { error, formItemId } = useFormField();
|
const { error, formItemId } = useFormField();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Label
|
<Label
|
||||||
ref={ref}
|
data-slot="form-label"
|
||||||
className={cn(error && "text-destructive", className)}
|
data-error={!!error}
|
||||||
|
className={cn("data-[error=true]:text-destructive", className)}
|
||||||
htmlFor={formItemId}
|
htmlFor={formItemId}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
FormLabel.displayName = "FormLabel";
|
|
||||||
|
|
||||||
const FormControl = React.forwardRef<
|
function FormControl({ ...props }: React.ComponentProps<typeof Slot>) {
|
||||||
React.ElementRef<typeof Slot>,
|
|
||||||
React.ComponentPropsWithoutRef<typeof Slot>
|
|
||||||
>(({ ...props }, ref) => {
|
|
||||||
const { error, formItemId, formDescriptionId, formMessageId } =
|
const { error, formItemId, formDescriptionId, formMessageId } =
|
||||||
useFormField();
|
useFormField();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slot
|
<Slot
|
||||||
ref={ref}
|
data-slot="form-control"
|
||||||
id={formItemId}
|
id={formItemId}
|
||||||
aria-describedby={
|
aria-describedby={
|
||||||
!error
|
!error
|
||||||
@@ -121,32 +119,24 @@ const FormControl = React.forwardRef<
|
|||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
FormControl.displayName = "FormControl";
|
|
||||||
|
|
||||||
const FormDescription = React.forwardRef<
|
function FormDescription({ className, ...props }: React.ComponentProps<"p">) {
|
||||||
HTMLParagraphElement,
|
|
||||||
React.HTMLAttributes<HTMLParagraphElement>
|
|
||||||
>(({ className, ...props }, ref) => {
|
|
||||||
const { formDescriptionId } = useFormField();
|
const { formDescriptionId } = useFormField();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<p
|
<p
|
||||||
ref={ref}
|
data-slot="form-description"
|
||||||
id={formDescriptionId}
|
id={formDescriptionId}
|
||||||
className={cn("text-[0.8rem] text-muted-foreground", className)}
|
className={cn("text-sm text-muted-foreground", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
FormDescription.displayName = "FormDescription";
|
|
||||||
|
|
||||||
const FormMessage = React.forwardRef<
|
function FormMessage({ className, ...props }: React.ComponentProps<"p">) {
|
||||||
HTMLParagraphElement,
|
|
||||||
React.HTMLAttributes<HTMLParagraphElement>
|
|
||||||
>(({ className, children, ...props }, ref) => {
|
|
||||||
const { error, formMessageId } = useFormField();
|
const { error, formMessageId } = useFormField();
|
||||||
const body = error ? String(error?.message) : children;
|
const body = error ? String(error?.message ?? "") : props.children;
|
||||||
|
|
||||||
if (!body) {
|
if (!body) {
|
||||||
return null;
|
return null;
|
||||||
@@ -154,16 +144,15 @@ const FormMessage = React.forwardRef<
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<p
|
<p
|
||||||
ref={ref}
|
data-slot="form-message"
|
||||||
id={formMessageId}
|
id={formMessageId}
|
||||||
className={cn("text-[0.8rem] font-medium text-destructive", className)}
|
className={cn("text-sm text-destructive", className)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{body}
|
{body}
|
||||||
</p>
|
</p>
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
FormMessage.displayName = "FormMessage";
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
// eslint-disable-next-line react-refresh/only-export-components
|
// eslint-disable-next-line react-refresh/only-export-components
|
||||||
|
|||||||
+15
-19
@@ -2,24 +2,20 @@ import * as React from "react";
|
|||||||
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
export interface InputProps
|
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
||||||
extends React.InputHTMLAttributes<HTMLInputElement> {}
|
return (
|
||||||
|
<input
|
||||||
const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
type={type}
|
||||||
({ className, type, ...props }, ref) => {
|
data-slot="input"
|
||||||
return (
|
className={cn(
|
||||||
<input
|
"flex h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none selection:bg-primary selection:text-primary-foreground file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:bg-input/30",
|
||||||
type={type}
|
"focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",
|
||||||
className={cn(
|
"aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40",
|
||||||
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
|
className,
|
||||||
className,
|
)}
|
||||||
)}
|
{...props}
|
||||||
ref={ref}
|
/>
|
||||||
{...props}
|
);
|
||||||
/>
|
}
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
Input.displayName = "Input";
|
|
||||||
|
|
||||||
export { Input };
|
export { Input };
|
||||||
|
|||||||
+15
-17
@@ -1,24 +1,22 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import * as LabelPrimitive from "@radix-ui/react-label";
|
import * as LabelPrimitive from "@radix-ui/react-label";
|
||||||
import { cva, type VariantProps } from "class-variance-authority";
|
|
||||||
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const labelVariants = cva(
|
function Label({
|
||||||
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
|
className,
|
||||||
);
|
...props
|
||||||
|
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
|
||||||
const Label = React.forwardRef<
|
return (
|
||||||
React.ElementRef<typeof LabelPrimitive.Root>,
|
<LabelPrimitive.Root
|
||||||
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
|
data-slot="label"
|
||||||
VariantProps<typeof labelVariants>
|
className={cn(
|
||||||
>(({ className, ...props }, ref) => (
|
"flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
|
||||||
<LabelPrimitive.Root
|
className,
|
||||||
ref={ref}
|
)}
|
||||||
className={cn(labelVariants(), className)}
|
{...props}
|
||||||
{...props}
|
/>
|
||||||
/>
|
);
|
||||||
));
|
}
|
||||||
Label.displayName = LabelPrimitive.Root.displayName;
|
|
||||||
|
|
||||||
export { Label };
|
export { Label };
|
||||||
|
|||||||
@@ -8,12 +8,14 @@ export function NumberSelector({
|
|||||||
updateCount,
|
updateCount,
|
||||||
addEnabled = true,
|
addEnabled = true,
|
||||||
allowNegative = false,
|
allowNegative = false,
|
||||||
|
initialValue = 0,
|
||||||
}: {
|
}: {
|
||||||
updateCount: UpdateSelectedNumberFunction;
|
updateCount: UpdateSelectedNumberFunction;
|
||||||
addEnabled?: boolean;
|
addEnabled?: boolean;
|
||||||
allowNegative?: boolean;
|
allowNegative?: boolean;
|
||||||
|
initialValue?: number;
|
||||||
}) {
|
}) {
|
||||||
const [count, setCount] = useState<number>(0);
|
const [count, setCount] = useState<number>(initialValue);
|
||||||
|
|
||||||
const counterUpdated = (newAmount: number) => {
|
const counterUpdated = (newAmount: number) => {
|
||||||
setCount(newAmount);
|
setCount(newAmount);
|
||||||
|
|||||||
@@ -1,31 +1,46 @@
|
|||||||
import * as React from "react";
|
import * as React from "react"
|
||||||
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
import * as PopoverPrimitive from "@radix-ui/react-popover"
|
||||||
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
const Popover = PopoverPrimitive.Root;
|
function Popover({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof PopoverPrimitive.Root>) {
|
||||||
|
return <PopoverPrimitive.Root data-slot="popover" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
const PopoverTrigger = PopoverPrimitive.Trigger;
|
function PopoverTrigger({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof PopoverPrimitive.Trigger>) {
|
||||||
|
return <PopoverPrimitive.Trigger data-slot="popover-trigger" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
const PopoverAnchor = PopoverPrimitive.Anchor;
|
function PopoverContent({
|
||||||
|
className,
|
||||||
|
align = "center",
|
||||||
|
sideOffset = 4,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof PopoverPrimitive.Content>) {
|
||||||
|
return (
|
||||||
|
<PopoverPrimitive.Portal>
|
||||||
|
<PopoverPrimitive.Content
|
||||||
|
data-slot="popover-content"
|
||||||
|
align={align}
|
||||||
|
sideOffset={sideOffset}
|
||||||
|
className={cn(
|
||||||
|
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border p-4 shadow-md outline-hidden",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
</PopoverPrimitive.Portal>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const PopoverContent = React.forwardRef<
|
function PopoverAnchor({
|
||||||
React.ElementRef<typeof PopoverPrimitive.Content>,
|
...props
|
||||||
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
|
}: React.ComponentProps<typeof PopoverPrimitive.Anchor>) {
|
||||||
>(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
|
return <PopoverPrimitive.Anchor data-slot="popover-anchor" {...props} />
|
||||||
<PopoverPrimitive.Portal>
|
}
|
||||||
<PopoverPrimitive.Content
|
|
||||||
ref={ref}
|
|
||||||
align={align}
|
|
||||||
sideOffset={sideOffset}
|
|
||||||
className={cn(
|
|
||||||
"z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
|
||||||
className,
|
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
</PopoverPrimitive.Portal>
|
|
||||||
));
|
|
||||||
PopoverContent.displayName = PopoverPrimitive.Content.displayName;
|
|
||||||
|
|
||||||
export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor };
|
export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor }
|
||||||
|
|||||||
@@ -3,27 +3,24 @@ import * as SeparatorPrimitive from "@radix-ui/react-separator";
|
|||||||
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const Separator = React.forwardRef<
|
function Separator({
|
||||||
React.ElementRef<typeof SeparatorPrimitive.Root>,
|
className,
|
||||||
React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>
|
orientation = "horizontal",
|
||||||
>(
|
decorative = true,
|
||||||
(
|
...props
|
||||||
{ className, orientation = "horizontal", decorative = true, ...props },
|
}: React.ComponentProps<typeof SeparatorPrimitive.Root>) {
|
||||||
ref,
|
return (
|
||||||
) => (
|
|
||||||
<SeparatorPrimitive.Root
|
<SeparatorPrimitive.Root
|
||||||
ref={ref}
|
data-slot="separator"
|
||||||
decorative={decorative}
|
decorative={decorative}
|
||||||
orientation={orientation}
|
orientation={orientation}
|
||||||
className={cn(
|
className={cn(
|
||||||
"shrink-0 bg-border",
|
"shrink-0 bg-border data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",
|
||||||
orientation === "horizontal" ? "h-[1px] w-full" : "h-full w-[1px]",
|
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
),
|
);
|
||||||
);
|
}
|
||||||
Separator.displayName = SeparatorPrimitive.Root.displayName;
|
|
||||||
|
|
||||||
export { Separator };
|
export { Separator };
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
function Skeleton({
|
function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
className,
|
|
||||||
...props
|
|
||||||
}: React.HTMLAttributes<HTMLDivElement>) {
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn("animate-pulse rounded-md bg-primary/10", className)}
|
data-slot="skeleton"
|
||||||
|
className={cn("animate-pulse rounded-md bg-accent", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
+91
-97
@@ -2,111 +2,105 @@ import * as React from "react";
|
|||||||
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const Table = React.forwardRef<
|
function Table({ className, ...props }: React.ComponentProps<"table">) {
|
||||||
HTMLTableElement,
|
return (
|
||||||
React.HTMLAttributes<HTMLTableElement>
|
<div
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="table-container"
|
||||||
<div className="relative w-full overflow-auto">
|
className="relative w-full overflow-x-auto"
|
||||||
<table
|
>
|
||||||
ref={ref}
|
<table
|
||||||
className={cn("w-full caption-bottom text-sm", className)}
|
data-slot="table"
|
||||||
|
className={cn("w-full caption-bottom text-sm", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
|
||||||
|
return (
|
||||||
|
<thead
|
||||||
|
data-slot="table-header"
|
||||||
|
className={cn("[&_tr]:border-b", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
</div>
|
);
|
||||||
));
|
}
|
||||||
Table.displayName = "Table";
|
|
||||||
|
|
||||||
const TableHeader = React.forwardRef<
|
function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
|
||||||
HTMLTableSectionElement,
|
return (
|
||||||
React.HTMLAttributes<HTMLTableSectionElement>
|
<tbody
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="table-body"
|
||||||
<thead ref={ref} className={cn("[&_tr]:border-b", className)} {...props} />
|
className={cn("[&_tr:last-child]:border-0", className)}
|
||||||
));
|
{...props}
|
||||||
TableHeader.displayName = "TableHeader";
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const TableBody = React.forwardRef<
|
function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
|
||||||
HTMLTableSectionElement,
|
return (
|
||||||
React.HTMLAttributes<HTMLTableSectionElement>
|
<tfoot
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="table-footer"
|
||||||
<tbody
|
className={cn(
|
||||||
ref={ref}
|
"border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",
|
||||||
className={cn("[&_tr:last-child]:border-0", className)}
|
className,
|
||||||
{...props}
|
)}
|
||||||
/>
|
{...props}
|
||||||
));
|
/>
|
||||||
TableBody.displayName = "TableBody";
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const TableFooter = React.forwardRef<
|
function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
|
||||||
HTMLTableSectionElement,
|
return (
|
||||||
React.HTMLAttributes<HTMLTableSectionElement>
|
<tr
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="table-row"
|
||||||
<tfoot
|
className={cn(
|
||||||
ref={ref}
|
"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",
|
||||||
className={cn(
|
className,
|
||||||
"border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",
|
)}
|
||||||
className,
|
{...props}
|
||||||
)}
|
/>
|
||||||
{...props}
|
);
|
||||||
/>
|
}
|
||||||
));
|
|
||||||
TableFooter.displayName = "TableFooter";
|
|
||||||
|
|
||||||
const TableRow = React.forwardRef<
|
function TableHead({ className, ...props }: React.ComponentProps<"th">) {
|
||||||
HTMLTableRowElement,
|
return (
|
||||||
React.HTMLAttributes<HTMLTableRowElement>
|
<th
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="table-head"
|
||||||
<tr
|
className={cn(
|
||||||
ref={ref}
|
"h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
||||||
className={cn(
|
className,
|
||||||
"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",
|
)}
|
||||||
className,
|
{...props}
|
||||||
)}
|
/>
|
||||||
{...props}
|
);
|
||||||
/>
|
}
|
||||||
));
|
|
||||||
TableRow.displayName = "TableRow";
|
|
||||||
|
|
||||||
const TableHead = React.forwardRef<
|
function TableCell({ className, ...props }: React.ComponentProps<"td">) {
|
||||||
HTMLTableCellElement,
|
return (
|
||||||
React.ThHTMLAttributes<HTMLTableCellElement>
|
<td
|
||||||
>(({ className, ...props }, ref) => (
|
data-slot="table-cell"
|
||||||
<th
|
className={cn(
|
||||||
ref={ref}
|
"p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
||||||
className={cn(
|
className,
|
||||||
"h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
)}
|
||||||
className,
|
{...props}
|
||||||
)}
|
/>
|
||||||
{...props}
|
);
|
||||||
/>
|
}
|
||||||
));
|
|
||||||
TableHead.displayName = "TableHead";
|
|
||||||
|
|
||||||
const TableCell = React.forwardRef<
|
function TableCaption({
|
||||||
HTMLTableCellElement,
|
className,
|
||||||
React.TdHTMLAttributes<HTMLTableCellElement>
|
...props
|
||||||
>(({ className, ...props }, ref) => (
|
}: React.ComponentProps<"caption">) {
|
||||||
<td
|
return (
|
||||||
ref={ref}
|
<caption
|
||||||
className={cn(
|
data-slot="table-caption"
|
||||||
"p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
className={cn("mt-4 text-sm text-muted-foreground", className)}
|
||||||
className,
|
{...props}
|
||||||
)}
|
/>
|
||||||
{...props}
|
);
|
||||||
/>
|
}
|
||||||
));
|
|
||||||
TableCell.displayName = "TableCell";
|
|
||||||
|
|
||||||
const TableCaption = React.forwardRef<
|
|
||||||
HTMLTableCaptionElement,
|
|
||||||
React.HTMLAttributes<HTMLTableCaptionElement>
|
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<caption
|
|
||||||
ref={ref}
|
|
||||||
className={cn("mt-4 text-sm text-muted-foreground", className)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
));
|
|
||||||
TableCaption.displayName = "TableCaption";
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Table,
|
Table,
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { Cross2Icon } from "@radix-ui/react-icons";
|
|
||||||
import * as ToastPrimitives from "@radix-ui/react-toast";
|
import * as ToastPrimitives from "@radix-ui/react-toast";
|
||||||
import { cva, type VariantProps } from "class-variance-authority";
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
import { XIcon } from "lucide-react";
|
||||||
|
|
||||||
const ToastProvider = ToastPrimitives.Provider;
|
const ToastProvider = ToastPrimitives.Provider;
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ const ToastViewport = React.forwardRef<
|
|||||||
<ToastPrimitives.Viewport
|
<ToastPrimitives.Viewport
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",
|
"fixed top-0 z-100 flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
@@ -23,7 +23,7 @@ const ToastViewport = React.forwardRef<
|
|||||||
ToastViewport.displayName = ToastPrimitives.Viewport.displayName;
|
ToastViewport.displayName = ToastPrimitives.Viewport.displayName;
|
||||||
|
|
||||||
const toastVariants = cva(
|
const toastVariants = cva(
|
||||||
"group pointer-events-auto relative flex w-full items-center justify-between space-x-2 overflow-hidden rounded-md border p-4 pr-6 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",
|
"group pointer-events-auto relative flex w-full items-center justify-between space-x-2 overflow-hidden rounded-md border p-4 pr-6 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-(--radix-toast-swipe-end-x) data-[swipe=move]:translate-x-(--radix-toast-swipe-move-x) data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full sm:data-[state=open]:slide-in-from-bottom-full",
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
variant: {
|
variant: {
|
||||||
@@ -32,9 +32,7 @@ const toastVariants = cva(
|
|||||||
"destructive group border-destructive bg-destructive text-destructive-foreground",
|
"destructive group border-destructive bg-destructive text-destructive-foreground",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
defaultVariants: {
|
defaultVariants: { variant: "default" },
|
||||||
variant: "default",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -60,7 +58,7 @@ const ToastAction = React.forwardRef<
|
|||||||
<ToastPrimitives.Action
|
<ToastPrimitives.Action
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium transition-colors hover:bg-secondary focus:outline-none focus:ring-1 focus:ring-ring disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",
|
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium transition-colors hover:bg-secondary focus:outline-hidden focus:ring-1 focus:ring-ring disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 hover:group-[.destructive]:border-destructive/30 hover:group-[.destructive]:bg-destructive hover:group-[.destructive]:text-destructive-foreground focus:group-[.destructive]:ring-destructive",
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
@@ -75,13 +73,13 @@ const ToastClose = React.forwardRef<
|
|||||||
<ToastPrimitives.Close
|
<ToastPrimitives.Close
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"absolute right-1 top-1 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-1 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",
|
"absolute right-1 top-1 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-hidden focus:ring-1 group-hover:opacity-100 group-[.destructive]:text-red-300 hover:group-[.destructive]:text-red-50 focus:group-[.destructive]:ring-red-400 focus:group-[.destructive]:ring-offset-red-600",
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
toast-close=""
|
toast-close=""
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<Cross2Icon className="h-4 w-4" />
|
<XIcon className="h-4 w-4" />
|
||||||
</ToastPrimitives.Close>
|
</ToastPrimitives.Close>
|
||||||
));
|
));
|
||||||
ToastClose.displayName = ToastPrimitives.Close.displayName;
|
ToastClose.displayName = ToastPrimitives.Close.displayName;
|
||||||
|
|||||||
@@ -3,26 +3,57 @@ import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
|||||||
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const TooltipProvider = TooltipPrimitive.Provider;
|
function TooltipProvider({
|
||||||
|
delayDuration = 0,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof TooltipPrimitive.Provider>) {
|
||||||
|
return (
|
||||||
|
<TooltipPrimitive.Provider
|
||||||
|
data-slot="tooltip-provider"
|
||||||
|
delayDuration={delayDuration}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const Tooltip = TooltipPrimitive.Root;
|
function Tooltip({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof TooltipPrimitive.Root>) {
|
||||||
|
return (
|
||||||
|
<TooltipProvider>
|
||||||
|
<TooltipPrimitive.Root data-slot="tooltip" {...props} />
|
||||||
|
</TooltipProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const TooltipTrigger = TooltipPrimitive.Trigger;
|
function TooltipTrigger({
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof TooltipPrimitive.Trigger>) {
|
||||||
|
return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
const TooltipContent = React.forwardRef<
|
function TooltipContent({
|
||||||
React.ElementRef<typeof TooltipPrimitive.Content>,
|
className,
|
||||||
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
|
sideOffset = 0,
|
||||||
>(({ className, sideOffset = 4, ...props }, ref) => (
|
children,
|
||||||
<TooltipPrimitive.Content
|
...props
|
||||||
ref={ref}
|
}: React.ComponentProps<typeof TooltipPrimitive.Content>) {
|
||||||
sideOffset={sideOffset}
|
return (
|
||||||
className={cn(
|
<TooltipPrimitive.Portal>
|
||||||
"z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
<TooltipPrimitive.Content
|
||||||
className,
|
data-slot="tooltip-content"
|
||||||
)}
|
sideOffset={sideOffset}
|
||||||
{...props}
|
className={cn(
|
||||||
/>
|
"animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md bg-primary px-3 py-1.5 text-xs text-balance text-primary-foreground",
|
||||||
));
|
className,
|
||||||
TooltipContent.displayName = TooltipPrimitive.Content.displayName;
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
<TooltipPrimitive.Arrow className="z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-primary fill-primary" />
|
||||||
|
</TooltipPrimitive.Content>
|
||||||
|
</TooltipPrimitive.Portal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
|
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { Slot } from "@radix-ui/react-slot";
|
|||||||
const typographyVariants = cva("text-foreground", {
|
const typographyVariants = cva("text-foreground", {
|
||||||
variants: {
|
variants: {
|
||||||
variant: {
|
variant: {
|
||||||
h1: "scroll-m-20 text-4xl font-extrabold tracking-tight lg:text-5xl",
|
h1: "scroll-m-20 text-center text-4xl font-extrabold tracking-tight text-balance",
|
||||||
h2: "scroll-m-20 border-b pb-2 text-3xl font-semibold tracking-tight first:mt-0",
|
h2: "scroll-m-20 border-b pb-2 text-3xl font-semibold tracking-tight first:mt-0",
|
||||||
h3: "scroll-m-20 text-2xl font-semibold tracking-tight",
|
h3: "scroll-m-20 text-2xl font-semibold tracking-tight",
|
||||||
h4: "scroll-m-20 text-xl font-semibold tracking-tight",
|
h4: "scroll-m-20 text-xl font-semibold tracking-tight",
|
||||||
@@ -19,11 +19,11 @@ const typographyVariants = cva("text-foreground", {
|
|||||||
blockquote: "mt-6 border-l-2 pl-6 italic",
|
blockquote: "mt-6 border-l-2 pl-6 italic",
|
||||||
ul: "my-6 ml-6 list-disc [&>li]:mt-2",
|
ul: "my-6 ml-6 list-disc [&>li]:mt-2",
|
||||||
inlineCode:
|
inlineCode:
|
||||||
"relative rounded bg-muted px-[0.3rem] py-[0.2rem] font-mono text-sm font-semibold",
|
"bg-muted relative rounded px-[0.3rem] py-[0.2rem] font-mono text-sm font-semibold",
|
||||||
lead: "text-xl text-muted-foreground",
|
lead: "text-muted-foreground text-xl",
|
||||||
largeText: "text-lg font-semibold",
|
largeText: "text-lg font-semibold",
|
||||||
smallText: "text-sm font-medium leading-none",
|
smallText: "text-sm leading-none font-medium",
|
||||||
mutedText: "text-sm text-muted-foreground",
|
mutedText: "text-muted-foreground text-sm",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
defaultVariants: {
|
defaultVariants: {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// Inspired by react-hot-toast library
|
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
|
|
||||||
import type { ToastActionElement, ToastProps } from "src/components/ui/toast";
|
import type { ToastActionElement, ToastProps } from "src/components/ui/toast";
|
||||||
@@ -30,22 +29,10 @@ function genId() {
|
|||||||
type ActionType = typeof actionTypes;
|
type ActionType = typeof actionTypes;
|
||||||
|
|
||||||
type Action =
|
type Action =
|
||||||
| {
|
| { type: ActionType["ADD_TOAST"]; toast: ToasterToast }
|
||||||
type: ActionType["ADD_TOAST"];
|
| { type: ActionType["UPDATE_TOAST"]; toast: Partial<ToasterToast> }
|
||||||
toast: ToasterToast;
|
| { type: ActionType["DISMISS_TOAST"]; toastId?: ToasterToast["id"] }
|
||||||
}
|
| { type: ActionType["REMOVE_TOAST"]; toastId?: ToasterToast["id"] };
|
||||||
| {
|
|
||||||
type: ActionType["UPDATE_TOAST"];
|
|
||||||
toast: Partial<ToasterToast>;
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
type: ActionType["DISMISS_TOAST"];
|
|
||||||
toastId?: ToasterToast["id"];
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
type: ActionType["REMOVE_TOAST"];
|
|
||||||
toastId?: ToasterToast["id"];
|
|
||||||
};
|
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
toasts: ToasterToast[];
|
toasts: ToasterToast[];
|
||||||
@@ -60,10 +47,7 @@ const addToRemoveQueue = (toastId: string) => {
|
|||||||
|
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
toastTimeouts.delete(toastId);
|
toastTimeouts.delete(toastId);
|
||||||
dispatch({
|
dispatch({ type: "REMOVE_TOAST", toastId: toastId });
|
||||||
type: "REMOVE_TOAST",
|
|
||||||
toastId: toastId,
|
|
||||||
});
|
|
||||||
}, TOAST_REMOVE_DELAY);
|
}, TOAST_REMOVE_DELAY);
|
||||||
|
|
||||||
toastTimeouts.set(toastId, timeout);
|
toastTimeouts.set(toastId, timeout);
|
||||||
@@ -101,21 +85,13 @@ export const reducer = (state: State, action: Action): State => {
|
|||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
toasts: state.toasts.map((t) =>
|
toasts: state.toasts.map((t) =>
|
||||||
t.id === toastId || toastId === undefined
|
t.id === toastId || toastId === undefined ? { ...t, open: false } : t,
|
||||||
? {
|
|
||||||
...t,
|
|
||||||
open: false,
|
|
||||||
}
|
|
||||||
: t,
|
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case "REMOVE_TOAST":
|
case "REMOVE_TOAST":
|
||||||
if (action.toastId === undefined) {
|
if (action.toastId === undefined) {
|
||||||
return {
|
return { ...state, toasts: [] };
|
||||||
...state,
|
|
||||||
toasts: [],
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
@@ -141,10 +117,7 @@ function toast({ ...props }: Toast) {
|
|||||||
const id = genId();
|
const id = genId();
|
||||||
|
|
||||||
const update = (props: ToasterToast) =>
|
const update = (props: ToasterToast) =>
|
||||||
dispatch({
|
dispatch({ type: "UPDATE_TOAST", toast: { ...props, id } });
|
||||||
type: "UPDATE_TOAST",
|
|
||||||
toast: { ...props, id },
|
|
||||||
});
|
|
||||||
const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id });
|
const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id });
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
@@ -159,11 +132,7 @@ function toast({ ...props }: Toast) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return { id: id, dismiss, update };
|
||||||
id: id,
|
|
||||||
dismiss,
|
|
||||||
update,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function useToast() {
|
function useToast() {
|
||||||
|
|||||||
+217
-49
@@ -1,60 +1,228 @@
|
|||||||
@tailwind base;
|
@import 'tailwindcss';
|
||||||
@tailwind components;
|
@import "tw-animate-css";
|
||||||
@tailwind utilities;
|
|
||||||
|
|
||||||
@layer base {
|
@custom-variant dark (&:is(.dark *));
|
||||||
:root {
|
|
||||||
--background: 0 0% 100%;
|
|
||||||
--foreground: 240 10% 3.9%;
|
|
||||||
--card: 0 0% 100%;
|
|
||||||
--card-foreground: 240 10% 3.9%;
|
|
||||||
--popover: 0 0% 100%;
|
|
||||||
--popover-foreground: 240 10% 3.9%;
|
|
||||||
--primary: 142.1 76.2% 36.3%;
|
|
||||||
--primary-foreground: 355.7 100% 97.3%;
|
|
||||||
--secondary: 240 4.8% 95.9%;
|
|
||||||
--secondary-foreground: 240 5.9% 10%;
|
|
||||||
--muted: 240 4.8% 95.9%;
|
|
||||||
--muted-foreground: 240 3.8% 46.1%;
|
|
||||||
--accent: 240 4.8% 95.9%;
|
|
||||||
--accent-foreground: 240 5.9% 10%;
|
|
||||||
--destructive: 0 84.2% 60.2%;
|
|
||||||
--destructive-foreground: 0 0% 98%;
|
|
||||||
--border: 240 5.9% 90%;
|
|
||||||
--input: 240 5.9% 90%;
|
|
||||||
--ring: 142.1 76.2% 36.3%;
|
|
||||||
--radius: 0.75rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dark {
|
|
||||||
--background: 20 14.3% 4.1%;
|
@theme inline {
|
||||||
--foreground: 0 0% 95%;
|
|
||||||
--card: 24 9.8% 10%;
|
--radius-sm: calc(var(--radius) - 4px);
|
||||||
--card-foreground: 0 0% 95%;
|
|
||||||
--popover: 0 0% 9%;
|
--radius-md: calc(var(--radius) - 2px);
|
||||||
--popover-foreground: 0 0% 95%;
|
|
||||||
--primary: 142.1 70.6% 45.3%;
|
--radius-lg: var(--radius);
|
||||||
--primary-foreground: 144.9 80.4% 10%;
|
|
||||||
--secondary: 240 3.7% 15.9%;
|
--radius-xl: calc(var(--radius) + 4px);
|
||||||
--secondary-foreground: 0 0% 98%;
|
|
||||||
--muted: 0 0% 15%;
|
--color-background: var(--background);
|
||||||
--muted-foreground: 240 5% 64.9%;
|
|
||||||
--accent: 12 6.5% 15.1%;
|
--color-foreground: var(--foreground);
|
||||||
--accent-foreground: 0 0% 98%;
|
|
||||||
--destructive: 0 62.8% 30.6%;
|
--color-card: var(--card);
|
||||||
--destructive-foreground: 0 85.7% 97.3%;
|
|
||||||
--border: 240 3.7% 15.9%;
|
--color-card-foreground: var(--card-foreground);
|
||||||
--input: 240 3.7% 15.9%;
|
|
||||||
--ring: 142.4 71.8% 29.2%;
|
--color-popover: var(--popover);
|
||||||
}
|
|
||||||
|
--color-popover-foreground: var(--popover-foreground);
|
||||||
|
|
||||||
|
--color-primary: var(--primary);
|
||||||
|
|
||||||
|
--color-primary-foreground: var(--primary-foreground);
|
||||||
|
|
||||||
|
--color-secondary: var(--secondary);
|
||||||
|
|
||||||
|
--color-secondary-foreground: var(--secondary-foreground);
|
||||||
|
|
||||||
|
--color-muted: var(--muted);
|
||||||
|
|
||||||
|
--color-muted-foreground: var(--muted-foreground);
|
||||||
|
|
||||||
|
--color-accent: var(--accent);
|
||||||
|
|
||||||
|
--color-accent-foreground: var(--accent-foreground);
|
||||||
|
|
||||||
|
--color-destructive: var(--destructive);
|
||||||
|
|
||||||
|
--color-border: var(--border);
|
||||||
|
|
||||||
|
--color-input: var(--input);
|
||||||
|
|
||||||
|
--color-ring: var(--ring);
|
||||||
|
|
||||||
|
--color-chart-1: var(--chart-1);
|
||||||
|
|
||||||
|
--color-chart-2: var(--chart-2);
|
||||||
|
|
||||||
|
--color-chart-3: var(--chart-3);
|
||||||
|
|
||||||
|
--color-chart-4: var(--chart-4);
|
||||||
|
|
||||||
|
--color-chart-5: var(--chart-5);
|
||||||
|
|
||||||
|
--color-sidebar: var(--sidebar);
|
||||||
|
|
||||||
|
--color-sidebar-foreground: var(--sidebar-foreground);
|
||||||
|
|
||||||
|
--color-sidebar-primary: var(--sidebar-primary);
|
||||||
|
|
||||||
|
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
||||||
|
|
||||||
|
--color-sidebar-accent: var(--sidebar-accent);
|
||||||
|
|
||||||
|
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
||||||
|
|
||||||
|
--color-sidebar-border: var(--sidebar-border);
|
||||||
|
|
||||||
|
--color-sidebar-ring: var(--sidebar-ring);
|
||||||
|
}
|
||||||
|
|
||||||
|
:root {
|
||||||
|
|
||||||
|
--radius: 0.625rem;
|
||||||
|
|
||||||
|
--background: oklch(1 0 0);
|
||||||
|
|
||||||
|
--foreground: oklch(0.147 0.004 49.25);
|
||||||
|
|
||||||
|
--card: oklch(1 0 0);
|
||||||
|
|
||||||
|
--card-foreground: oklch(0.147 0.004 49.25);
|
||||||
|
|
||||||
|
--popover: oklch(1 0 0);
|
||||||
|
|
||||||
|
--popover-foreground: oklch(0.147 0.004 49.25);
|
||||||
|
|
||||||
|
--primary: oklch(0.216 0.006 56.043);
|
||||||
|
|
||||||
|
--primary-foreground: oklch(0.985 0.001 106.423);
|
||||||
|
|
||||||
|
--secondary: oklch(0.97 0.001 106.424);
|
||||||
|
|
||||||
|
--secondary-foreground: oklch(0.216 0.006 56.043);
|
||||||
|
|
||||||
|
--muted: oklch(0.97 0.001 106.424);
|
||||||
|
|
||||||
|
--muted-foreground: oklch(0.553 0.013 58.071);
|
||||||
|
|
||||||
|
--accent: oklch(0.97 0.001 106.424);
|
||||||
|
|
||||||
|
--accent-foreground: oklch(0.216 0.006 56.043);
|
||||||
|
|
||||||
|
--destructive: oklch(0.577 0.245 27.325);
|
||||||
|
|
||||||
|
--border: oklch(0.923 0.003 48.717);
|
||||||
|
|
||||||
|
--input: oklch(0.923 0.003 48.717);
|
||||||
|
|
||||||
|
--ring: oklch(0.709 0.01 56.259);
|
||||||
|
|
||||||
|
--chart-1: oklch(0.646 0.222 41.116);
|
||||||
|
|
||||||
|
--chart-2: oklch(0.6 0.118 184.704);
|
||||||
|
|
||||||
|
--chart-3: oklch(0.398 0.07 227.392);
|
||||||
|
|
||||||
|
--chart-4: oklch(0.828 0.189 84.429);
|
||||||
|
|
||||||
|
--chart-5: oklch(0.769 0.188 70.08);
|
||||||
|
|
||||||
|
--sidebar: oklch(0.985 0.001 106.423);
|
||||||
|
|
||||||
|
--sidebar-foreground: oklch(0.147 0.004 49.25);
|
||||||
|
|
||||||
|
--sidebar-primary: oklch(0.216 0.006 56.043);
|
||||||
|
|
||||||
|
--sidebar-primary-foreground: oklch(0.985 0.001 106.423);
|
||||||
|
|
||||||
|
--sidebar-accent: oklch(0.97 0.001 106.424);
|
||||||
|
|
||||||
|
--sidebar-accent-foreground: oklch(0.216 0.006 56.043);
|
||||||
|
|
||||||
|
--sidebar-border: oklch(0.923 0.003 48.717);
|
||||||
|
|
||||||
|
--sidebar-ring: oklch(0.709 0.01 56.259);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark {
|
||||||
|
|
||||||
|
--background: oklch(0.147 0.004 49.25);
|
||||||
|
|
||||||
|
--foreground: oklch(0.985 0.001 106.423);
|
||||||
|
|
||||||
|
--card: oklch(0.216 0.006 56.043);
|
||||||
|
|
||||||
|
--card-foreground: oklch(0.985 0.001 106.423);
|
||||||
|
|
||||||
|
--popover: oklch(0.216 0.006 56.043);
|
||||||
|
|
||||||
|
--popover-foreground: oklch(0.985 0.001 106.423);
|
||||||
|
|
||||||
|
--primary: oklch(0.923 0.003 48.717);
|
||||||
|
|
||||||
|
--primary-foreground: oklch(0.216 0.006 56.043);
|
||||||
|
|
||||||
|
--secondary: oklch(0.268 0.007 34.298);
|
||||||
|
|
||||||
|
--secondary-foreground: oklch(0.985 0.001 106.423);
|
||||||
|
|
||||||
|
--muted: oklch(0.268 0.007 34.298);
|
||||||
|
|
||||||
|
--muted-foreground: oklch(0.709 0.01 56.259);
|
||||||
|
|
||||||
|
--accent: oklch(0.268 0.007 34.298);
|
||||||
|
|
||||||
|
--accent-foreground: oklch(0.985 0.001 106.423);
|
||||||
|
|
||||||
|
--destructive: oklch(0.704 0.191 22.216);
|
||||||
|
|
||||||
|
--border: oklch(1 0 0 / 10%);
|
||||||
|
|
||||||
|
--input: oklch(1 0 0 / 15%);
|
||||||
|
|
||||||
|
--ring: oklch(0.553 0.013 58.071);
|
||||||
|
|
||||||
|
--chart-1: oklch(0.488 0.243 264.376);
|
||||||
|
|
||||||
|
--chart-2: oklch(0.696 0.17 162.48);
|
||||||
|
|
||||||
|
--chart-3: oklch(0.769 0.188 70.08);
|
||||||
|
|
||||||
|
--chart-4: oklch(0.627 0.265 303.9);
|
||||||
|
|
||||||
|
--chart-5: oklch(0.645 0.246 16.439);
|
||||||
|
|
||||||
|
--sidebar: oklch(0.216 0.006 56.043);
|
||||||
|
|
||||||
|
--sidebar-foreground: oklch(0.985 0.001 106.423);
|
||||||
|
|
||||||
|
--sidebar-primary: oklch(0.488 0.243 264.376);
|
||||||
|
|
||||||
|
--sidebar-primary-foreground: oklch(0.985 0.001 106.423);
|
||||||
|
|
||||||
|
--sidebar-accent: oklch(0.268 0.007 34.298);
|
||||||
|
|
||||||
|
--sidebar-accent-foreground: oklch(0.985 0.001 106.423);
|
||||||
|
|
||||||
|
--sidebar-border: oklch(1 0 0 / 10%);
|
||||||
|
|
||||||
|
--sidebar-ring: oklch(0.553 0.013 58.071);
|
||||||
}
|
}
|
||||||
|
|
||||||
@layer base {
|
@layer base {
|
||||||
* {
|
* {
|
||||||
@apply border-border;
|
@apply border-border outline-ring/50;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
@apply bg-background text-foreground;
|
@apply bg-background text-foreground;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* SomniaRooms Extended CSS */
|
||||||
|
|
||||||
|
@utility grid-cols-40/60 {
|
||||||
|
grid-template-columns: 40% 60%;
|
||||||
|
}
|
||||||
|
@utility grid-cols-60/40 {
|
||||||
|
grid-template-columns: 60% 40%;
|
||||||
|
}
|
||||||
|
|||||||
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
import { type ClassValue, clsx } from "clsx";
|
import { clsx, type ClassValue } from "clsx"
|
||||||
import { twMerge } from "tailwind-merge";
|
import { twMerge } from "tailwind-merge"
|
||||||
|
|
||||||
export function cn(...inputs: ClassValue[]) {
|
export function cn(...inputs: ClassValue[]) {
|
||||||
return twMerge(clsx(inputs));
|
return twMerge(clsx(inputs))
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ import ReactDOM from "react-dom/client";
|
|||||||
import "./index.css";
|
import "./index.css";
|
||||||
import { RouterProvider, createBrowserRouter } from "react-router-dom";
|
import { RouterProvider, createBrowserRouter } from "react-router-dom";
|
||||||
import Root from "./routes/Root";
|
import Root from "./routes/Root";
|
||||||
import ErrorPage from "./error-page";
|
import ErrorPage from "./routes/error-page";
|
||||||
import Homepage from "./routes/home-page";
|
import Homepage from "./routes/home-page";
|
||||||
import SearchPage from "./routes/search-page";
|
import SearchPage from "./routes/search-page";
|
||||||
import BookPage from "./routes/book-page";
|
import BookPage from "./routes/book-page";
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from "zod/v4";
|
||||||
|
|
||||||
export const BookingFormSchema = z.object({
|
export const BookingFormSchema = z.object({
|
||||||
name: z.string().min(2).max(50),
|
name: z.string().min(2).max(50),
|
||||||
surname: z.string().min(2).max(50),
|
surname: z.string().min(2).max(50),
|
||||||
email: z.string().email(),
|
email: z.email(),
|
||||||
phone: z.string().min(8),
|
phone: z.string().min(8),
|
||||||
});
|
});
|
||||||
|
|||||||
+10
-11
@@ -1,22 +1,21 @@
|
|||||||
export type RoomCategory = {
|
export type RoomCategory = {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string | undefined;
|
||||||
bedType: string;
|
|
||||||
maxGuestNum: number;
|
maxGuestNum: number;
|
||||||
|
orderHomePage: number | undefined;
|
||||||
roomCategoryPhotos: RoomCategoryPhoto[];
|
roomCategoryPhotos: RoomCategoryPhoto[];
|
||||||
roomCategoryDetails: RoomCategoryDetails[];
|
roomCategoryBedTypes: RoomCategoryBedType[];
|
||||||
};
|
|
||||||
|
|
||||||
export type RoomCategoryDetails = {
|
|
||||||
id: number;
|
|
||||||
detailsSection: string;
|
|
||||||
detailValue: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type RoomCategoryPhoto = {
|
export type RoomCategoryPhoto = {
|
||||||
id: number;
|
|
||||||
path: string;
|
path: string;
|
||||||
altText: string | undefined;
|
altText: string | undefined;
|
||||||
kind: string;
|
photoOrder: string | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type RoomCategoryBedType = {
|
||||||
|
amount: number;
|
||||||
|
bedTypeName: string;
|
||||||
|
bedTypeIcon: string;
|
||||||
|
}
|
||||||
@@ -9,7 +9,8 @@ export type RoomPrice = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type AvailabilityRequest = {
|
export type AvailabilityRequest = {
|
||||||
filter: AvailabilityFilter;
|
startDate: string;
|
||||||
|
endDate: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AvailabilityFilter = {
|
export type AvailabilityFilter = {
|
||||||
@@ -18,7 +19,9 @@ export type AvailabilityFilter = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type FareRequest = {
|
export type FareRequest = {
|
||||||
filter: FareFilter;
|
roomCategory: number;
|
||||||
|
startDate: string;
|
||||||
|
endDate: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type FareFilter = {
|
export type FareFilter = {
|
||||||
|
|||||||
@@ -14,3 +14,9 @@ html {
|
|||||||
padding: 2rem;
|
padding: 2rem;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
iconify-icon {
|
||||||
|
display: inline-block;
|
||||||
|
min-width: 1em;
|
||||||
|
min-height: 1em;
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import { useAppStore } from "@/store";
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { z } from "zod";
|
import { z } from "zod/v4";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
|
||||||
enum PageState {
|
enum PageState {
|
||||||
@@ -30,8 +30,8 @@ enum PageState {
|
|||||||
|
|
||||||
function BookPage() {
|
function BookPage() {
|
||||||
const [pageState, setPageState] = useState<PageState>(PageState.showForm);
|
const [pageState, setPageState] = useState<PageState>(PageState.showForm);
|
||||||
const bookingData = useAppStore((state) => state.newBookingData);
|
const bookingData = useAppStore((state) => state.currentBooking);
|
||||||
const setCustomerData = useAppStore((state) => state.setBookingCustomer);
|
const setCustomerData = useAppStore((state) => state.currentBookingSetCustomer);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const bookingForm = useForm<z.infer<typeof BookingFormSchema>>({
|
const bookingForm = useForm<z.infer<typeof BookingFormSchema>>({
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useAPIRoomCategories } from "@/api/api-roomCategories";
|
import { useAPIRoomCategoryList } from "@/api/api-roomCategories";
|
||||||
import { RoomItemCard } from "@/components/Rooms/room-item-card";
|
import { RoomItemCard } from "@/components/Rooms/room-item-card";
|
||||||
import { SearchFilterCard } from "@/components/Search/SearchFilterCard";
|
import { SearchFilterCard } from "@/components/Search/SearchFilterCard";
|
||||||
import BackendConnectionStatus from "@/components/backend-conection-status";
|
import BackendConnectionStatus from "@/components/backend-conection-status";
|
||||||
@@ -6,28 +6,50 @@ import { Separator } from "@/components/ui/separator";
|
|||||||
import { Skeleton } from "@/components/ui/skeleton";
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
import { Typography } from "@/components/ui/typography";
|
import { Typography } from "@/components/ui/typography";
|
||||||
import { RoomCategory } from "@/model/RoomCategory";
|
import { RoomCategory } from "@/model/RoomCategory";
|
||||||
import { SearchFilter } from "@/model/SearchFilter";
|
import { SearchFilter } from "@/model/InternalTypes";
|
||||||
|
import { eBookingState } from "@/utils/AppStateManager";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { LoaderIcon } from "lucide-react";
|
import { LoaderIcon } from "lucide-react";
|
||||||
import "./home-page.css";
|
import "./home-page.css";
|
||||||
|
import { useAppStore } from "@/store";
|
||||||
|
import { isValidSearchFilter, makeDayUTCDate } from "@/utils/utils";
|
||||||
|
|
||||||
function Homepage() {
|
function Homepage() {
|
||||||
const { roomCategoryList, isLoading, isError } = useAPIRoomCategories();
|
const appSearchFilter = useAppStore((state) => state.searchFilter);
|
||||||
|
const setAppSearchFilter = useAppStore((state) => state.setSearchFilter);
|
||||||
|
const setAppBookingState = useAppStore((state) => state.setBookingState);
|
||||||
|
const initAppBooking = useAppStore((state) => state.initCurrentBooking);
|
||||||
|
|
||||||
|
const { roomCategoryList, isLoading, isError } = useAPIRoomCategoryList();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const onBtSearchClick = (filter: SearchFilter) => {
|
const onBtSearchClick = (filter: SearchFilter) => {
|
||||||
|
if (!isValidSearchFilter(filter)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setAppSearchFilter(filter);
|
||||||
|
setAppBookingState(eBookingState.Searched);
|
||||||
|
|
||||||
|
initAppBooking(
|
||||||
|
makeDayUTCDate(filter.dateRange.from),
|
||||||
|
makeDayUTCDate(filter.dateRange.to),
|
||||||
|
);
|
||||||
|
|
||||||
navigate("/search", { state: filter });
|
navigate("/search", { state: filter });
|
||||||
};
|
};
|
||||||
|
|
||||||
const roomList = roomCategoryList?.map((element: RoomCategory) => {
|
const roomList = roomCategoryList?.map((element: RoomCategory) => {
|
||||||
return <RoomItemCard key={element.id} room={element} />;
|
return <RoomItemCard key={element.id} room={element} />;
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Typography variant={"h1"}>Somnia Rooms</Typography>
|
<Typography variant={"h1"}>Somnia Rooms</Typography>
|
||||||
<Separator className="my-10" />
|
<Separator className="my-10" />
|
||||||
<SearchFilterCard onSearchClick={onBtSearchClick} />
|
<SearchFilterCard
|
||||||
|
onSearchClick={onBtSearchClick}
|
||||||
|
initialsearchFilter={appSearchFilter}
|
||||||
|
/>
|
||||||
<Separator className="my-10" />
|
<Separator className="my-10" />
|
||||||
<div className="homePageRoomGrid grid gap-4">{roomList}</div>
|
<div className="homePageRoomGrid grid gap-4">{roomList}</div>
|
||||||
{isLoading && (
|
{isLoading && (
|
||||||
|
|||||||
+69
-64
@@ -6,75 +6,68 @@ import { BookingDetails } from "@/components/booking/booking-details";
|
|||||||
import { Separator } from "@/components/ui/separator";
|
import { Separator } from "@/components/ui/separator";
|
||||||
import { Skeleton } from "@/components/ui/skeleton";
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
import { Typography } from "@/components/ui/typography";
|
import { Typography } from "@/components/ui/typography";
|
||||||
import { AvailabilityFilter } from "@/model/RoomSearch";
|
import { SearchFilter } from "@/model/InternalTypes";
|
||||||
import { SearchFilter } from "@/model/SearchFilter";
|
import { eBookingState } from "@/utils/AppStateManager";
|
||||||
import { useAppStore } from "@/store";
|
import { useAppStore } from "@/store";
|
||||||
import { useMemo, useState } from "react";
|
import {
|
||||||
|
isValidSearchFilter,
|
||||||
|
makeAvailabilityFilterFromSearchFilter,
|
||||||
|
makeDayUTCDate,
|
||||||
|
} from "@/utils/utils";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
//TODOME: Igual podemos crear un StateMachine conjunta para los siguiente estados de la página: Sin Buscar, Sin disponibilidad, error, cargando.
|
//TODOME: Al pulsar el botón "buscar", si ya existen datos en la reserva (se han añadido habitaciones) mostrar un cuadro de aviso de que si se busca se borrará la selección actual.
|
||||||
|
//TODOME: Mediante los estados globales de la reserva, si ya está en estado "booking" añadiendo los datos, mostrar un mensaje y permitir redirigir directamente para que continue donde lo dejó.
|
||||||
function SearchPage() {
|
function SearchPage() {
|
||||||
//const [availabilityFilter, setAvailabilityFilter] = useState<AvailabilityFilter>();
|
const appBookingState = useAppStore((state) => state.bookingState);
|
||||||
const searchFilter = useAppStore((state) => state.searchFilter);
|
const setAppBookingState = useAppStore((state) => state.setBookingState);
|
||||||
const resetBooking = useAppStore((state) => state.resetBookingState);
|
const appSearchFilter = useAppStore((state) => state.searchFilter);
|
||||||
|
const setAppSearchFilter = useAppStore((state) => state.setSearchFilter);
|
||||||
|
const initAppBooking = useAppStore((state) => state.initCurrentBooking);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const [isSearched, setIsSearched] = useState<boolean>(false);
|
|
||||||
|
|
||||||
//This seems a little bit overkill, but IDK.
|
|
||||||
const availabilityFilter: AvailabilityFilter | null = useMemo(() => {
|
|
||||||
if (
|
|
||||||
searchFilter &&
|
|
||||||
searchFilter.dateRange &&
|
|
||||||
searchFilter.dateRange.from &&
|
|
||||||
searchFilter.dateRange.to
|
|
||||||
) {
|
|
||||||
const newAvailabilityFilter: AvailabilityFilter = {
|
|
||||||
startDate: searchFilter.dateRange.from.toDateString(),
|
|
||||||
endDate: searchFilter.dateRange.to.toDateString(),
|
|
||||||
};
|
|
||||||
return newAvailabilityFilter;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}, [searchFilter]);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
roomAvailabilityList,
|
roomAvailabilityList,
|
||||||
isLoading: isLoadingAvailability,
|
isLoading: isLoadingAvailability,
|
||||||
isError: isErrorAvailability,
|
isError: isErrorAvailability,
|
||||||
} = useAPIRoomAvailability(availabilityFilter ?? null);
|
} = useAPIRoomAvailability(
|
||||||
|
makeAvailabilityFilterFromSearchFilter(appSearchFilter) ?? null,
|
||||||
|
);
|
||||||
const isLoading = isLoadingAvailability;
|
const isLoading = isLoadingAvailability;
|
||||||
const isError = isErrorAvailability;
|
const isError = isErrorAvailability;
|
||||||
|
|
||||||
|
const hasRooms =
|
||||||
|
roomAvailabilityList?.length && roomAvailabilityList?.length > 0;
|
||||||
|
|
||||||
|
//TODOME: Hay que ver para mover esto a un método común.
|
||||||
const onBtSearchClick = (newFilter: SearchFilter) => {
|
const onBtSearchClick = (newFilter: SearchFilter) => {
|
||||||
console.log("onBtSearchClick: ");
|
if (!isValidSearchFilter(newFilter)) {
|
||||||
console.log(newFilter);
|
return;
|
||||||
|
|
||||||
if (
|
|
||||||
newFilter.dateRange &&
|
|
||||||
newFilter.dateRange.from &&
|
|
||||||
newFilter.dateRange.to
|
|
||||||
) {
|
|
||||||
setIsSearched(true);
|
|
||||||
|
|
||||||
resetBooking(newFilter.dateRange.from, newFilter.dateRange.to);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setAppSearchFilter(newFilter);
|
||||||
|
setAppBookingState(eBookingState.Searched);
|
||||||
|
|
||||||
|
initAppBooking(
|
||||||
|
makeDayUTCDate(newFilter.dateRange.from),
|
||||||
|
makeDayUTCDate(newFilter.dateRange.to),
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onBookingContinue = () => {
|
const onBookingContinue = () => {
|
||||||
navigate("/book");
|
navigate("/book");
|
||||||
};
|
};
|
||||||
|
|
||||||
const roomList = roomAvailabilityList?.map((element) => {
|
const roomList =
|
||||||
return (
|
roomAvailabilityList?.map((element) => {
|
||||||
<RoomBooking
|
return (
|
||||||
key={element.roomCategory}
|
<RoomBooking
|
||||||
availableAmount={element.availability}
|
key={element.roomCategory + "-" + appBookingState.lastSearchDate}
|
||||||
roomCategoryId={element.roomCategory}
|
availableAmount={element.availability}
|
||||||
/>
|
roomCategoryId={element.roomCategory}
|
||||||
);
|
/>
|
||||||
});
|
);
|
||||||
|
}) ?? null;
|
||||||
const noRoomsAvailable = (
|
const noRoomsAvailable = (
|
||||||
<>
|
<>
|
||||||
<Typography variant={"h3"} as="h3">
|
<Typography variant={"h3"} as="h3">
|
||||||
@@ -83,22 +76,23 @@ function SearchPage() {
|
|||||||
</Typography>
|
</Typography>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
const hasRooms =
|
|
||||||
roomAvailabilityList?.length && roomAvailabilityList?.length > 0;
|
|
||||||
console.log(hasRooms);
|
|
||||||
|
|
||||||
const pageContent = isLoading ? (
|
const pageContentSearch = (
|
||||||
|
<Typography>
|
||||||
|
Realiza una búsqueda para ver la disponibilidad y los precios.
|
||||||
|
</Typography>
|
||||||
|
);
|
||||||
|
const pageContentLoading = (
|
||||||
<>
|
<>
|
||||||
<Typography variant={"h3"} as="h2">
|
<Typography variant={"h3"} as="h2">
|
||||||
Loading...
|
Loading...
|
||||||
</Typography>
|
</Typography>
|
||||||
<Skeleton className="mx-auto h-[200px] w-full" />
|
<Skeleton className="mx-auto h-[200px] w-full" />
|
||||||
</>
|
</>
|
||||||
) : (
|
);
|
||||||
|
const pageContentLoaded = (
|
||||||
<div className="2xl:grid 2xl:grid-cols-60/40 2xl:gap-6">
|
<div className="2xl:grid 2xl:grid-cols-60/40 2xl:gap-6">
|
||||||
<div className="flex flex-col gap-5">
|
<div className="flex flex-col gap-5">{roomList}</div>
|
||||||
{hasRooms ? roomList : isSearched && noRoomsAvailable}
|
|
||||||
</div>
|
|
||||||
<Separator className="my-10 2xl:hidden" />
|
<Separator className="my-10 2xl:hidden" />
|
||||||
<BookingDetails
|
<BookingDetails
|
||||||
onBookingConfirm={onBookingContinue}
|
onBookingConfirm={onBookingContinue}
|
||||||
@@ -107,17 +101,28 @@ function SearchPage() {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const getPageContent = () => {
|
||||||
|
const isSearched = appBookingState.state == eBookingState.Searched;
|
||||||
|
if (!isSearched) {
|
||||||
|
return pageContentSearch;
|
||||||
|
}
|
||||||
|
if (isLoading) {
|
||||||
|
return pageContentLoading;
|
||||||
|
}
|
||||||
|
if (!hasRooms) {
|
||||||
|
return noRoomsAvailable;
|
||||||
|
}
|
||||||
|
return pageContentLoaded;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="bg-background text-foreground">
|
<div className="bg-background text-foreground">
|
||||||
<SearchFilterCard onSearchClick={onBtSearchClick} />
|
<SearchFilterCard
|
||||||
|
onSearchClick={onBtSearchClick}
|
||||||
|
initialsearchFilter={appSearchFilter}
|
||||||
|
/>
|
||||||
<Separator className="my-10" />
|
<Separator className="my-10" />
|
||||||
{hasRooms ? (
|
{getPageContent()}
|
||||||
pageContent
|
|
||||||
) : (
|
|
||||||
<Typography>
|
|
||||||
Realiza una búsqueda para ver la disponibilidad y los precios.
|
|
||||||
</Typography>
|
|
||||||
)}
|
|
||||||
<Separator className="my-10" />
|
<Separator className="my-10" />
|
||||||
<BackendConnectionStatus isLoading={isLoading} isError={isError} />
|
<BackendConnectionStatus isLoading={isLoading} isError={isError} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,13 +3,12 @@ import { Card, CardContent, CardHeader } from "@/components/ui/card";
|
|||||||
import { Typography } from "@/components/ui/typography";
|
import { Typography } from "@/components/ui/typography";
|
||||||
import { NewBookingResponse } from "@/model/Bookings";
|
import { NewBookingResponse } from "@/model/Bookings";
|
||||||
import { useAppStore } from "@/store";
|
import { useAppStore } from "@/store";
|
||||||
import { addDays } from "date-fns";
|
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useLocation, useNavigate } from "react-router-dom";
|
import { useLocation, useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
function SuccessPage() {
|
function SuccessPage() {
|
||||||
const [pageState, setPageState] = useState<NewBookingResponse | null>(null);
|
const [pageState, setPageState] = useState<NewBookingResponse | null>(null);
|
||||||
const resetBookingState = useAppStore((state) => state.resetBookingState);
|
const resetBookingState = useAppStore((state) => state.resetCurrentBooking);
|
||||||
|
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -22,7 +21,7 @@ function SuccessPage() {
|
|||||||
}, [location, navigate]);
|
}, [location, navigate]);
|
||||||
|
|
||||||
const handleBtBackClick = () => {
|
const handleBtBackClick = () => {
|
||||||
resetBookingState(new Date(), addDays(new Date(), 2));
|
resetBookingState();
|
||||||
navigate("/home");
|
navigate("/home");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+59
-34
@@ -1,19 +1,31 @@
|
|||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
import { SearchFilter } from "./model/SearchFilter";
|
import { SearchFilter } from "@/model/InternalTypes";
|
||||||
|
import {
|
||||||
|
BookingState,
|
||||||
|
eBookingState,
|
||||||
|
SetBookingState,
|
||||||
|
} from "./utils/AppStateManager";
|
||||||
import {
|
import {
|
||||||
NewBooking,
|
NewBooking,
|
||||||
NewBookingCustomerDetails,
|
NewBookingCustomerDetails,
|
||||||
NewBookingRoom,
|
NewBookingRoom,
|
||||||
} from "./model/Bookings";
|
} from "./model/Bookings";
|
||||||
|
|
||||||
interface AppState {
|
interface State {
|
||||||
searchFilter: SearchFilter;
|
searchFilter: SearchFilter;
|
||||||
|
currentBooking: NewBooking | null;
|
||||||
|
bookingState: BookingState;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Actions {
|
||||||
setSearchFilter: (newFilter: SearchFilter) => void;
|
setSearchFilter: (newFilter: SearchFilter) => void;
|
||||||
newBookingData: NewBooking | null;
|
resetSearchFilter: () => void;
|
||||||
setNewBooking: (newBooking: NewBooking) => void;
|
setCurrentBooking: (newBooking: NewBooking) => void;
|
||||||
resetBookingState: (arrival: Date, departure: Date) => void;
|
resetCurrentBooking: () => void;
|
||||||
addNewBookingRoom: (newRoom: NewBookingRoom) => void;
|
initCurrentBooking: (arrival: Date, departure: Date) => void;
|
||||||
setBookingCustomer: (newCustomer: NewBookingCustomerDetails) => void;
|
currentBookingAddRoom: (newRoom: NewBookingRoom) => void;
|
||||||
|
currentBookingSetCustomer: (newCustomer: NewBookingCustomerDetails) => void;
|
||||||
|
setBookingState: (newState: eBookingState) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultSearchFilter: SearchFilter = {
|
const defaultSearchFilter: SearchFilter = {
|
||||||
@@ -32,7 +44,12 @@ const defaultNewBooking: NewBooking = {
|
|||||||
rooms: [],
|
rooms: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
function getDefaultBookingData(arrivalDate: Date, departureDate: Date) {
|
const defaultBookingState: BookingState = {
|
||||||
|
state: eBookingState.None,
|
||||||
|
lastSearchDate: new Date(),
|
||||||
|
};
|
||||||
|
|
||||||
|
function getDefaultBooking(arrivalDate: Date, departureDate: Date) {
|
||||||
return {
|
return {
|
||||||
...defaultNewBooking,
|
...defaultNewBooking,
|
||||||
arrivalDate: arrivalDate,
|
arrivalDate: arrivalDate,
|
||||||
@@ -40,19 +57,19 @@ function getDefaultBookingData(arrivalDate: Date, departureDate: Date) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function addNewBookingRoomToCurrentState(
|
function addNewBookingRoom(
|
||||||
newRoom: NewBookingRoom,
|
newRoom: NewBookingRoom,
|
||||||
currentState: NewBooking | null,
|
currentBookingState: NewBooking | null,
|
||||||
): NewBooking | null {
|
): NewBooking | null {
|
||||||
if (currentState == null) {
|
if (currentBookingState == null) {
|
||||||
return currentState;
|
return currentBookingState;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Remove rooms with "same key".
|
//Remove rooms with "same key".
|
||||||
const filteredRooms = currentState.rooms.filter((room) => {
|
const filteredRooms = currentBookingState.rooms.filter((room) => {
|
||||||
const diffRoom = room.roomCategory != newRoom.roomCategory;
|
const isDiffRoom = room.roomCategory != newRoom.roomCategory;
|
||||||
const diffAmount = room.guestNumber != newRoom.guestNumber;
|
const isDiffAmount = room.guestNumber != newRoom.guestNumber;
|
||||||
if (diffRoom || (!diffRoom && diffAmount)) {
|
if (isDiffRoom || (!isDiffRoom && isDiffAmount)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -64,11 +81,11 @@ function addNewBookingRoomToCurrentState(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const newState: NewBooking = {
|
const newState: NewBooking = {
|
||||||
...currentState,
|
...currentBookingState,
|
||||||
rooms: filteredRooms ?? [],
|
rooms: filteredRooms ?? [],
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log("AddRoomNewState:");
|
console.log("Updated 'currentBooking' state:");
|
||||||
console.log(newState);
|
console.log(newState);
|
||||||
|
|
||||||
return newState;
|
return newState;
|
||||||
@@ -76,35 +93,43 @@ function addNewBookingRoomToCurrentState(
|
|||||||
|
|
||||||
function setBookingCustomer(
|
function setBookingCustomer(
|
||||||
newCustomer: NewBookingCustomerDetails,
|
newCustomer: NewBookingCustomerDetails,
|
||||||
currentState: NewBooking | null,
|
currentBookingState: NewBooking | null,
|
||||||
) {
|
) {
|
||||||
if (currentState == null) {
|
if (currentBookingState == null) {
|
||||||
return currentState;
|
return currentBookingState;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newState: NewBooking = {
|
const newState: NewBooking = {
|
||||||
...currentState,
|
...currentBookingState,
|
||||||
customerDetails: newCustomer,
|
customerDetails: newCustomer,
|
||||||
};
|
};
|
||||||
return newState;
|
return newState;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useAppStore = create<AppState>()((set) => ({
|
export const useAppStore = create<State & Actions>()((set) => ({
|
||||||
searchFilter: defaultSearchFilter,
|
searchFilter: defaultSearchFilter,
|
||||||
|
currentBooking: null,
|
||||||
|
bookingState: defaultBookingState,
|
||||||
|
|
||||||
setSearchFilter: (newFilter) => set(() => ({ searchFilter: newFilter })),
|
setSearchFilter: (newFilter) => set(() => ({ searchFilter: newFilter })),
|
||||||
newBookingData: null,
|
resetSearchFilter: () => set(() => ({ searchFilter: defaultSearchFilter })),
|
||||||
setNewBooking: (newBooking) => set(() => ({ newBookingData: newBooking })),
|
|
||||||
resetBookingState: (arrival, departure) =>
|
setCurrentBooking: (newBooking) =>
|
||||||
set(() => ({ newBookingData: getDefaultBookingData(arrival, departure) })),
|
set(() => ({ currentBooking: newBooking })),
|
||||||
addNewBookingRoom: (newRoom: NewBookingRoom) =>
|
resetCurrentBooking: () => set(() => ({ currentBooking: null })),
|
||||||
|
initCurrentBooking: (arrival, departure) =>
|
||||||
|
set(() => ({ currentBooking: getDefaultBooking(arrival, departure) })),
|
||||||
|
currentBookingAddRoom: (newRoom) =>
|
||||||
set((state) => ({
|
set((state) => ({
|
||||||
newBookingData: addNewBookingRoomToCurrentState(
|
currentBooking: addNewBookingRoom(newRoom, state.currentBooking),
|
||||||
newRoom,
|
|
||||||
state.newBookingData,
|
|
||||||
),
|
|
||||||
})),
|
})),
|
||||||
setBookingCustomer: (newCustomer: NewBookingCustomerDetails) =>
|
currentBookingSetCustomer: (newCustomer) =>
|
||||||
set((state) => ({
|
set((state) => ({
|
||||||
newBookingData: setBookingCustomer(newCustomer, state.newBookingData),
|
currentBooking: setBookingCustomer(newCustomer, state.currentBooking),
|
||||||
|
})),
|
||||||
|
|
||||||
|
setBookingState: (newState) =>
|
||||||
|
set((state) => ({
|
||||||
|
bookingState: SetBookingState(newState, state.bookingState),
|
||||||
})),
|
})),
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
export type BookingState = {
|
||||||
|
state: eBookingState;
|
||||||
|
lastSearchDate: Date;
|
||||||
|
};
|
||||||
|
|
||||||
|
export enum eBookingState {
|
||||||
|
None = "NONE",
|
||||||
|
Searched = "SEARCHED",
|
||||||
|
Booking = "BOOKING",
|
||||||
|
Booked = "BOOKED",
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SetBookingState(
|
||||||
|
newState: eBookingState,
|
||||||
|
currentAppBookingState: BookingState,
|
||||||
|
) {
|
||||||
|
const newAppState: BookingState = {
|
||||||
|
...currentAppBookingState,
|
||||||
|
state: newState,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (newState == eBookingState.Searched) {
|
||||||
|
newAppState.lastSearchDate = new Date();
|
||||||
|
}
|
||||||
|
|
||||||
|
return newAppState;
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import { AvailabilityFilter, FareFilter } from "@/model/RoomSearch";
|
||||||
|
import { SearchFilter } from "@/model/InternalTypes";
|
||||||
|
|
||||||
|
export function makeDayUTCDate(date: Date | undefined): Date {
|
||||||
|
if (!date) {
|
||||||
|
return new Date();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Date(
|
||||||
|
date.getFullYear(),
|
||||||
|
date.getMonth(),
|
||||||
|
date.getDate(),
|
||||||
|
23,
|
||||||
|
59,
|
||||||
|
59,
|
||||||
|
999,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isValidSearchFilter(sf: SearchFilter): boolean {
|
||||||
|
if (sf?.dateRange?.from && sf?.dateRange?.to) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function makeAvailabilityFilterFromSearchFilter(
|
||||||
|
sf: SearchFilter,
|
||||||
|
): AvailabilityFilter | null {
|
||||||
|
if (!isValidSearchFilter(sf)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
startDate: sf.dateRange.from!.toISOString(),
|
||||||
|
endDate: sf.dateRange.to!.toISOString(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function makeFareFilterFromSearchFilter(
|
||||||
|
sf: SearchFilter,
|
||||||
|
roomCategoryId: number,
|
||||||
|
): FareFilter | null {
|
||||||
|
if (!isValidSearchFilter(sf) || roomCategoryId < 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
startDate: sf.dateRange.from!.toISOString(),
|
||||||
|
endDate: sf.dateRange.to!.toISOString(),
|
||||||
|
roomCategory: roomCategoryId,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
import plugin from "tailwindcss-animate";
|
|
||||||
|
|
||||||
/** @type {import('tailwindcss').Config} */
|
|
||||||
export default {
|
|
||||||
darkMode: ["class"],
|
|
||||||
content: [
|
|
||||||
"./pages/**/*.{ts,tsx}",
|
|
||||||
"./components/**/*.{ts,tsx}",
|
|
||||||
"./app/**/*.{ts,tsx}",
|
|
||||||
"./src/**/*.{ts,tsx}",
|
|
||||||
],
|
|
||||||
prefix: "",
|
|
||||||
theme: {
|
|
||||||
container: {
|
|
||||||
center: true,
|
|
||||||
padding: "2rem",
|
|
||||||
screens: {
|
|
||||||
"2xl": "1400px",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
extend: {
|
|
||||||
colors: {
|
|
||||||
border: "hsl(var(--border))",
|
|
||||||
input: "hsl(var(--input))",
|
|
||||||
ring: "hsl(var(--ring))",
|
|
||||||
background: "hsl(var(--background))",
|
|
||||||
foreground: "hsl(var(--foreground))",
|
|
||||||
primary: {
|
|
||||||
DEFAULT: "hsl(var(--primary))",
|
|
||||||
foreground: "hsl(var(--primary-foreground))",
|
|
||||||
},
|
|
||||||
secondary: {
|
|
||||||
DEFAULT: "hsl(var(--secondary))",
|
|
||||||
foreground: "hsl(var(--secondary-foreground))",
|
|
||||||
},
|
|
||||||
destructive: {
|
|
||||||
DEFAULT: "hsl(var(--destructive))",
|
|
||||||
foreground: "hsl(var(--destructive-foreground))",
|
|
||||||
},
|
|
||||||
muted: {
|
|
||||||
DEFAULT: "hsl(var(--muted))",
|
|
||||||
foreground: "hsl(var(--muted-foreground))",
|
|
||||||
},
|
|
||||||
accent: {
|
|
||||||
DEFAULT: "hsl(var(--accent))",
|
|
||||||
foreground: "hsl(var(--accent-foreground))",
|
|
||||||
},
|
|
||||||
popover: {
|
|
||||||
DEFAULT: "hsl(var(--popover))",
|
|
||||||
foreground: "hsl(var(--popover-foreground))",
|
|
||||||
},
|
|
||||||
card: {
|
|
||||||
DEFAULT: "hsl(var(--card))",
|
|
||||||
foreground: "hsl(var(--card-foreground))",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
borderRadius: {
|
|
||||||
lg: "var(--radius)",
|
|
||||||
md: "calc(var(--radius) - 2px)",
|
|
||||||
sm: "calc(var(--radius) - 4px)",
|
|
||||||
},
|
|
||||||
keyframes: {
|
|
||||||
"accordion-down": {
|
|
||||||
from: { height: "0" },
|
|
||||||
to: { height: "var(--radix-accordion-content-height)" },
|
|
||||||
},
|
|
||||||
"accordion-up": {
|
|
||||||
from: { height: "var(--radix-accordion-content-height)" },
|
|
||||||
to: { height: "0" },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
animation: {
|
|
||||||
"accordion-down": "accordion-down 0.2s ease-out",
|
|
||||||
"accordion-up": "accordion-up 0.2s ease-out",
|
|
||||||
},
|
|
||||||
|
|
||||||
//SomniaRooms Extends
|
|
||||||
gridTemplateColumns: {
|
|
||||||
"60/40": "60% 40%",
|
|
||||||
"40/60": "40% 60%",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
plugins: [plugin],
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
// ...
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"@/*": [
|
||||||
|
"./src/*"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-1
@@ -1,10 +1,11 @@
|
|||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
import react from "@vitejs/plugin-react-swc";
|
import react from "@vitejs/plugin-react-swc";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import tailwindcss from "@tailwindcss/vite"
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react(), tailwindcss()],
|
||||||
server: {
|
server: {
|
||||||
host: true,
|
host: true,
|
||||||
port: 3000,
|
port: 3000,
|
||||||
|
|||||||
Reference in New Issue
Block a user