mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-14 08:42:08 +10:00
refactor(v4.0.0-alpha): beginning of a new era
This commit is contained in:
54
libs/ui/src/components/accordion.tsx
Normal file
54
libs/ui/src/components/accordion.tsx
Normal file
@ -0,0 +1,54 @@
|
||||
import { CaretDown } from "@phosphor-icons/react";
|
||||
import * as AccordionPrimitive from "@radix-ui/react-accordion";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
export const Accordion = AccordionPrimitive.Root;
|
||||
|
||||
export const AccordionItem = forwardRef<
|
||||
React.ElementRef<typeof AccordionPrimitive.Item>,
|
||||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<AccordionPrimitive.Item ref={ref} className={cn("border-b", className)} {...props} />
|
||||
));
|
||||
|
||||
AccordionItem.displayName = "AccordionItem";
|
||||
|
||||
export const AccordionTrigger = forwardRef<
|
||||
React.ElementRef<typeof AccordionPrimitive.Trigger>,
|
||||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<AccordionPrimitive.Header className="flex">
|
||||
<AccordionPrimitive.Trigger
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex flex-1 items-center justify-between py-4 font-medium leading-none outline-none transition-all hover:underline focus-visible:bg-secondary-accent [&[data-state=open]>svg]:rotate-180",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<CaretDown className="h-4 w-4 shrink-0 transition-transform duration-200" />
|
||||
</AccordionPrimitive.Trigger>
|
||||
</AccordionPrimitive.Header>
|
||||
));
|
||||
|
||||
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName;
|
||||
|
||||
export const AccordionContent = forwardRef<
|
||||
React.ElementRef<typeof AccordionPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<AccordionPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"overflow-hidden text-sm leading-relaxed transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<div className="pb-4 pt-0">{children}</div>
|
||||
</AccordionPrimitive.Content>
|
||||
));
|
||||
|
||||
AccordionContent.displayName = AccordionPrimitive.Content.displayName;
|
||||
128
libs/ui/src/components/alert-dialog.tsx
Normal file
128
libs/ui/src/components/alert-dialog.tsx
Normal file
@ -0,0 +1,128 @@
|
||||
import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
import { buttonVariants } from "../variants/button";
|
||||
import { ButtonProps } from "./button";
|
||||
|
||||
export const AlertDialog = AlertDialogPrimitive.Root;
|
||||
|
||||
export const AlertDialogTrigger = AlertDialogPrimitive.Trigger;
|
||||
|
||||
export const AlertDialogPortal = (props: AlertDialogPrimitive.AlertDialogPortalProps) => (
|
||||
<AlertDialogPrimitive.Portal {...props} />
|
||||
);
|
||||
|
||||
AlertDialogPortal.displayName = AlertDialogPrimitive.Portal.displayName;
|
||||
|
||||
export const AlertDialogOverlay = forwardRef<
|
||||
React.ElementRef<typeof AlertDialogPrimitive.Overlay>,
|
||||
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<AlertDialogPrimitive.Overlay
|
||||
className={cn(
|
||||
"fixed inset-0 z-50 bg-background/80 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
ref={ref}
|
||||
/>
|
||||
));
|
||||
|
||||
AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName;
|
||||
|
||||
export const AlertDialogContent = forwardRef<
|
||||
React.ElementRef<typeof AlertDialogPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<AlertDialogPortal>
|
||||
<AlertDialogOverlay />
|
||||
<AlertDialogPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 rounded border bg-background p-6 duration-200 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-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] md:w-full",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</AlertDialogPortal>
|
||||
));
|
||||
|
||||
AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName;
|
||||
|
||||
export const AlertDialogHeader = ({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div className={cn("flex flex-col space-y-2 text-center sm:text-left", className)} {...props} />
|
||||
);
|
||||
|
||||
AlertDialogHeader.displayName = "AlertDialogHeader";
|
||||
|
||||
export const AlertDialogFooter = ({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={cn("mt-4 flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-4", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
|
||||
AlertDialogFooter.displayName = "AlertDialogFooter";
|
||||
|
||||
export const AlertDialogTitle = forwardRef<
|
||||
React.ElementRef<typeof AlertDialogPrimitive.Title>,
|
||||
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<AlertDialogPrimitive.Title
|
||||
ref={ref}
|
||||
className={cn("text-base font-medium", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName;
|
||||
|
||||
export const AlertDialogDescription = forwardRef<
|
||||
React.ElementRef<typeof AlertDialogPrimitive.Description>,
|
||||
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<AlertDialogPrimitive.Description
|
||||
ref={ref}
|
||||
className={cn("text-sm leading-relaxed", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
AlertDialogDescription.displayName = AlertDialogPrimitive.Description.displayName;
|
||||
|
||||
type AlertDialogActionProps = React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action> & {
|
||||
variant?: ButtonProps["variant"];
|
||||
};
|
||||
|
||||
export const AlertDialogAction = forwardRef<
|
||||
React.ElementRef<typeof AlertDialogPrimitive.Action>,
|
||||
AlertDialogActionProps
|
||||
>(({ className, variant, ...props }, ref) => (
|
||||
<AlertDialogPrimitive.Action
|
||||
ref={ref}
|
||||
className={cn(buttonVariants({ variant }), className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName;
|
||||
|
||||
export const AlertDialogCancel = forwardRef<
|
||||
React.ElementRef<typeof AlertDialogPrimitive.Cancel>,
|
||||
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<AlertDialogPrimitive.Cancel
|
||||
ref={ref}
|
||||
className={cn(buttonVariants({ variant: "outline" }), "mt-2 sm:mt-0", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName;
|
||||
37
libs/ui/src/components/alert.tsx
Normal file
37
libs/ui/src/components/alert.tsx
Normal file
@ -0,0 +1,37 @@
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { type VariantProps } from "class-variance-authority";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
import { alertVariants } from "../variants/alert";
|
||||
|
||||
interface AlertProps
|
||||
extends React.HTMLAttributes<HTMLDivElement>,
|
||||
VariantProps<typeof alertVariants> {}
|
||||
|
||||
export const Alert = forwardRef<HTMLDivElement, AlertProps>(
|
||||
({ className, variant, ...props }, ref) => (
|
||||
<div ref={ref} role="alert" className={cn(alertVariants({ variant }), className)} {...props} />
|
||||
),
|
||||
);
|
||||
|
||||
Alert.displayName = "Alert";
|
||||
|
||||
export const AlertTitle = forwardRef<
|
||||
HTMLParagraphElement,
|
||||
React.HTMLAttributes<HTMLHeadingElement>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<h5 ref={ref} className={cn("font-medium tracking-tight", className)} {...props}>
|
||||
{children}
|
||||
</h5>
|
||||
));
|
||||
|
||||
AlertTitle.displayName = "AlertTitle";
|
||||
|
||||
export const AlertDescription = forwardRef<
|
||||
HTMLParagraphElement,
|
||||
React.HTMLAttributes<HTMLParagraphElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div ref={ref} className={cn("pt-0.5 leading-normal", className)} {...props} />
|
||||
));
|
||||
|
||||
AlertDescription.displayName = "AlertDescription";
|
||||
3
libs/ui/src/components/aspect-ratio.tsx
Normal file
3
libs/ui/src/components/aspect-ratio.tsx
Normal file
@ -0,0 +1,3 @@
|
||||
import * as AspectRatioPrimitive from "@radix-ui/react-aspect-ratio";
|
||||
|
||||
export const AspectRatio = AspectRatioPrimitive.Root;
|
||||
45
libs/ui/src/components/avatar.tsx
Normal file
45
libs/ui/src/components/avatar.tsx
Normal file
@ -0,0 +1,45 @@
|
||||
import * as AvatarPrimitive from "@radix-ui/react-avatar";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
export const Avatar = forwardRef<
|
||||
React.ElementRef<typeof AvatarPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<AvatarPrimitive.Root
|
||||
ref={ref}
|
||||
className={cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
Avatar.displayName = AvatarPrimitive.Root.displayName;
|
||||
|
||||
export const AvatarImage = forwardRef<
|
||||
React.ElementRef<typeof AvatarPrimitive.Image>,
|
||||
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<AvatarPrimitive.Image
|
||||
ref={ref}
|
||||
className={cn("aspect-square h-full w-full object-cover", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
AvatarImage.displayName = AvatarPrimitive.Image.displayName;
|
||||
|
||||
export const AvatarFallback = forwardRef<
|
||||
React.ElementRef<typeof AvatarPrimitive.Fallback>,
|
||||
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<AvatarPrimitive.Fallback
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex h-full w-full items-center justify-center rounded-full bg-secondary",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName;
|
||||
49
libs/ui/src/components/badge-input.tsx
Normal file
49
libs/ui/src/components/badge-input.tsx
Normal file
@ -0,0 +1,49 @@
|
||||
import { forwardRef, useCallback, useEffect, useState } from "react";
|
||||
|
||||
import { Input, InputProps } from "./input";
|
||||
|
||||
type BadgeInputProps = Omit<InputProps, "value" | "onChange"> & {
|
||||
value: string[];
|
||||
onChange: (value: string[]) => void;
|
||||
};
|
||||
|
||||
export const BadgeInput = forwardRef<HTMLInputElement, BadgeInputProps>(
|
||||
({ value, onChange, ...props }, ref) => {
|
||||
const [label, setLabel] = useState("");
|
||||
|
||||
const processInput = useCallback(() => {
|
||||
const newLabels = label
|
||||
.split(",")
|
||||
.map((str) => str.trim())
|
||||
.filter(Boolean)
|
||||
.filter((str) => !value.includes(str));
|
||||
onChange([...new Set([...value, ...newLabels])]);
|
||||
setLabel("");
|
||||
}, [label, value, onChange]);
|
||||
|
||||
useEffect(() => {
|
||||
if (label.includes(",")) {
|
||||
processInput();
|
||||
}
|
||||
}, [label, processInput]);
|
||||
|
||||
const onKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
processInput();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Input
|
||||
{...props}
|
||||
ref={ref}
|
||||
value={label}
|
||||
onKeyDown={onKeyDown}
|
||||
onChange={(event) => setLabel(event.target.value)}
|
||||
/>
|
||||
);
|
||||
},
|
||||
);
|
||||
12
libs/ui/src/components/badge.tsx
Normal file
12
libs/ui/src/components/badge.tsx
Normal file
@ -0,0 +1,12 @@
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { type VariantProps } from "class-variance-authority";
|
||||
|
||||
import { badgeVariants } from "../variants/badge";
|
||||
|
||||
export interface BadgeProps
|
||||
extends React.HTMLAttributes<HTMLDivElement>,
|
||||
VariantProps<typeof badgeVariants> {}
|
||||
|
||||
export const Badge = ({ className, variant, outline, ...props }: BadgeProps) => (
|
||||
<div className={cn(badgeVariants({ variant, outline }), className)} {...props} />
|
||||
);
|
||||
28
libs/ui/src/components/button.tsx
Normal file
28
libs/ui/src/components/button.tsx
Normal file
@ -0,0 +1,28 @@
|
||||
import { Slot } from "@radix-ui/react-slot";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import type { VariantProps } from "class-variance-authority";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
import { buttonVariants } from "../variants/button";
|
||||
|
||||
export interface ButtonProps
|
||||
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||
VariantProps<typeof buttonVariants> {
|
||||
asChild?: boolean;
|
||||
}
|
||||
|
||||
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
({ className, variant, size, asChild = false, ...props }, ref) => {
|
||||
const Component = asChild ? Slot : "button";
|
||||
|
||||
return (
|
||||
<Component
|
||||
ref={ref}
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
Button.displayName = "Button";
|
||||
63
libs/ui/src/components/card.tsx
Normal file
63
libs/ui/src/components/card.tsx
Normal file
@ -0,0 +1,63 @@
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
export const Card = forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
||||
({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn("flex flex-col space-y-3 rounded border bg-background p-6", className)}
|
||||
{...props}
|
||||
/>
|
||||
),
|
||||
);
|
||||
|
||||
Card.displayName = "Card";
|
||||
|
||||
export const CardHeader = forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
||||
({ className, ...props }, ref) => (
|
||||
<div ref={ref} className={cn("flex flex-col space-y-1", className)} {...props} />
|
||||
),
|
||||
);
|
||||
|
||||
CardHeader.displayName = "CardHeader";
|
||||
|
||||
export const CardTitle = forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLHeadingElement>>(
|
||||
({ className, ...props }, ref) => (
|
||||
<h3
|
||||
ref={ref}
|
||||
className={cn("font-semibold leading-normal tracking-tight", className)}
|
||||
{...props}
|
||||
>
|
||||
{props.children}
|
||||
</h3>
|
||||
),
|
||||
);
|
||||
|
||||
CardTitle.displayName = "CardTitle";
|
||||
|
||||
export const CardDescription = forwardRef<
|
||||
HTMLParagraphElement,
|
||||
React.HTMLAttributes<HTMLParagraphElement>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn("text-xs font-medium leading-relaxed opacity-80", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
CardDescription.displayName = "CardDescription";
|
||||
|
||||
export const CardContent = forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
||||
({ className, ...props }, ref) => <div ref={ref} className={className} {...props} />,
|
||||
);
|
||||
|
||||
CardContent.displayName = "CardContent";
|
||||
|
||||
export const CardFooter = forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
||||
({ className, ...props }, ref) => (
|
||||
<div ref={ref} className={cn("flex items-center", className)} {...props} />
|
||||
),
|
||||
);
|
||||
|
||||
CardFooter.displayName = "CardFooter";
|
||||
24
libs/ui/src/components/checkbox.tsx
Normal file
24
libs/ui/src/components/checkbox.tsx
Normal file
@ -0,0 +1,24 @@
|
||||
import { Check } from "@phosphor-icons/react";
|
||||
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
export const Checkbox = forwardRef<
|
||||
React.ElementRef<typeof CheckboxPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<CheckboxPrimitive.Root
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"peer h-4 w-4 shrink-0 rounded border border-primary focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<CheckboxPrimitive.Indicator className={cn("flex items-center justify-center text-current")}>
|
||||
<Check size={12} weight="bold" />
|
||||
</CheckboxPrimitive.Indicator>
|
||||
</CheckboxPrimitive.Root>
|
||||
));
|
||||
|
||||
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
|
||||
138
libs/ui/src/components/combobox.tsx
Normal file
138
libs/ui/src/components/combobox.tsx
Normal file
@ -0,0 +1,138 @@
|
||||
import { CaretDown, Check } from "@phosphor-icons/react";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { forwardRef, useState } from "react";
|
||||
|
||||
import { Button } from "./button";
|
||||
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem } from "./command";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "./popover";
|
||||
import { ScrollArea } from "./scroll-area";
|
||||
|
||||
export interface ComboboxOption {
|
||||
value: string;
|
||||
label: React.ReactNode;
|
||||
}
|
||||
|
||||
type ComboboxPropsSingle = {
|
||||
options: ComboboxOption[];
|
||||
emptyText?: string;
|
||||
clearable?: boolean;
|
||||
selectPlaceholder?: string;
|
||||
searchPlaceholder?: string;
|
||||
multiple?: false;
|
||||
value?: string;
|
||||
onValueChange?: (value: string) => void;
|
||||
};
|
||||
|
||||
type ComboboxPropsMultiple = {
|
||||
options: ComboboxOption[];
|
||||
emptyText?: string;
|
||||
clearable?: boolean;
|
||||
selectPlaceholder?: string;
|
||||
searchPlaceholder?: string;
|
||||
multiple: true;
|
||||
value?: string[];
|
||||
onValueChange?: (value: string[]) => void;
|
||||
};
|
||||
|
||||
export type ComboboxProps = ComboboxPropsSingle | ComboboxPropsMultiple;
|
||||
|
||||
export const handleSingleSelect = (props: ComboboxPropsSingle, option: ComboboxOption) => {
|
||||
if (props.clearable) {
|
||||
props.onValueChange?.(option.value === props.value ? "" : option.value);
|
||||
} else {
|
||||
props.onValueChange?.(option.value);
|
||||
}
|
||||
};
|
||||
|
||||
export const handleMultipleSelect = (props: ComboboxPropsMultiple, option: ComboboxOption) => {
|
||||
if (props.value?.includes(option.value)) {
|
||||
if (!props.clearable && props.value.length === 1) return false;
|
||||
props.onValueChange?.(props.value.filter((value) => value !== option.value));
|
||||
} else {
|
||||
props.onValueChange?.([...(props.value ?? []), option.value]);
|
||||
}
|
||||
};
|
||||
|
||||
export const Combobox = forwardRef(
|
||||
(props: ComboboxProps, ref: React.ForwardedRef<HTMLInputElement>) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<Button
|
||||
role="combobox"
|
||||
variant="outline"
|
||||
aria-expanded={open}
|
||||
className="w-full justify-between hover:bg-secondary/20 active:scale-100"
|
||||
>
|
||||
<span className="line-clamp-1 text-left font-normal">
|
||||
{props.multiple && props.value && props.value.length > 0 && (
|
||||
<span className="mr-2">{props.value.join(", ")}</span>
|
||||
)}
|
||||
|
||||
{!props.multiple &&
|
||||
props.value &&
|
||||
props.value !== "" &&
|
||||
props.options.find((option) => option.value === props.value)?.label}
|
||||
|
||||
{!props.value ||
|
||||
(props.value.length === 0 && (props.selectPlaceholder ?? "Select an option"))}
|
||||
</span>
|
||||
<CaretDown
|
||||
className={cn(
|
||||
"ml-2 h-4 w-4 shrink-0 rotate-0 opacity-50 transition-transform",
|
||||
open && "rotate-180",
|
||||
)}
|
||||
/>
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent align="start" className="p-0">
|
||||
<Command>
|
||||
<CommandInput
|
||||
ref={ref}
|
||||
placeholder={props.searchPlaceholder ?? "Search for an option"}
|
||||
/>
|
||||
<CommandEmpty>{props.emptyText ?? "No results found"}</CommandEmpty>
|
||||
<CommandGroup>
|
||||
<ScrollArea orientation="vertical">
|
||||
<div className="max-h-60">
|
||||
{props.options.map((option) => (
|
||||
<CommandItem
|
||||
key={option.value}
|
||||
value={option.value.toLowerCase().trim()}
|
||||
onSelect={(selectedValue) => {
|
||||
const option = props.options.find(
|
||||
(option) => option.value.toLowerCase().trim() === selectedValue,
|
||||
);
|
||||
|
||||
if (!option) return null;
|
||||
|
||||
if (props.multiple) {
|
||||
handleMultipleSelect(props, option);
|
||||
} else {
|
||||
handleSingleSelect(props, option);
|
||||
|
||||
setOpen(false);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Check
|
||||
className={cn(
|
||||
"mr-2 h-4 w-4 opacity-0",
|
||||
!props.multiple && props.value === option.value && "opacity-100",
|
||||
props.multiple && props.value?.includes(option.value) && "opacity-100",
|
||||
)}
|
||||
/>
|
||||
{option.label}
|
||||
</CommandItem>
|
||||
))}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</CommandGroup>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
},
|
||||
);
|
||||
118
libs/ui/src/components/command.tsx
Normal file
118
libs/ui/src/components/command.tsx
Normal file
@ -0,0 +1,118 @@
|
||||
import { MagnifyingGlass } from "@phosphor-icons/react";
|
||||
import { DialogProps } from "@radix-ui/react-dialog";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { Command as CommandPrimitive } from "cmdk";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
import { Dialog, DialogContent } from "./dialog";
|
||||
|
||||
export const Command = forwardRef<
|
||||
React.ElementRef<typeof CommandPrimitive>,
|
||||
React.ComponentPropsWithoutRef<typeof CommandPrimitive>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<CommandPrimitive
|
||||
ref={ref}
|
||||
className={cn("flex h-full w-full flex-col overflow-hidden rounded border", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
Command.displayName = CommandPrimitive.displayName;
|
||||
|
||||
interface CommandDialogProps extends DialogProps {}
|
||||
|
||||
export const CommandDialog = ({ children, ...props }: CommandDialogProps) => (
|
||||
<Dialog {...props}>
|
||||
<DialogContent className="overflow-hidden p-0">
|
||||
<Command className="[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-secondary [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">
|
||||
{children}
|
||||
</Command>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
|
||||
export const CommandInput = forwardRef<
|
||||
React.ElementRef<typeof CommandPrimitive.Input>,
|
||||
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Input>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<div className="flex items-center border-b px-3" cmdk-input-wrapper="">
|
||||
<MagnifyingGlass size={16} className="mr-1 shrink-0 opacity-50" />
|
||||
<CommandPrimitive.Input
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex h-9 w-full rounded border-none bg-transparent py-3 text-sm outline-none focus:ring-transparent disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
));
|
||||
|
||||
CommandInput.displayName = CommandPrimitive.Input.displayName;
|
||||
|
||||
export const CommandList = forwardRef<
|
||||
React.ElementRef<typeof CommandPrimitive.List>,
|
||||
React.ComponentPropsWithoutRef<typeof CommandPrimitive.List>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<CommandPrimitive.List
|
||||
ref={ref}
|
||||
className={cn("max-h-[300px] overflow-y-auto overflow-x-hidden", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
CommandList.displayName = CommandPrimitive.List.displayName;
|
||||
|
||||
export const CommandEmpty = forwardRef<
|
||||
React.ElementRef<typeof CommandPrimitive.Empty>,
|
||||
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Empty>
|
||||
>((props, ref) => (
|
||||
<CommandPrimitive.Empty ref={ref} className="py-6 text-center text-sm" {...props} />
|
||||
));
|
||||
|
||||
CommandEmpty.displayName = CommandPrimitive.Empty.displayName;
|
||||
|
||||
export const CommandGroup = forwardRef<
|
||||
React.ElementRef<typeof CommandPrimitive.Group>,
|
||||
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Group>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<CommandPrimitive.Group
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:opacity-60",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
CommandGroup.displayName = CommandPrimitive.Group.displayName;
|
||||
|
||||
export const CommandSeparator = forwardRef<
|
||||
React.ElementRef<typeof CommandPrimitive.Separator>,
|
||||
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Separator>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<CommandPrimitive.Separator
|
||||
ref={ref}
|
||||
className={cn("-mx-1 h-px bg-border", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
CommandSeparator.displayName = CommandPrimitive.Separator.displayName;
|
||||
|
||||
export const CommandItem = forwardRef<
|
||||
React.ElementRef<typeof CommandPrimitive.Item>,
|
||||
React.ComponentPropsWithoutRef<typeof CommandPrimitive.Item>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<CommandPrimitive.Item
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative flex cursor-default select-none items-center rounded px-2 py-1.5 text-sm outline-none aria-selected:bg-secondary/40 aria-selected:text-secondary-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
CommandItem.displayName = CommandPrimitive.Item.displayName;
|
||||
166
libs/ui/src/components/context-menu.tsx
Normal file
166
libs/ui/src/components/context-menu.tsx
Normal file
@ -0,0 +1,166 @@
|
||||
import { CaretRight, Check } from "@phosphor-icons/react";
|
||||
import * as ContextMenuPrimitive from "@radix-ui/react-context-menu";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
export const ContextMenu = ContextMenuPrimitive.Root;
|
||||
|
||||
export const ContextMenuTrigger = ContextMenuPrimitive.Trigger;
|
||||
|
||||
export const ContextMenuGroup = ContextMenuPrimitive.Group;
|
||||
|
||||
export const ContextMenuPortal = ContextMenuPrimitive.Portal;
|
||||
|
||||
export const ContextMenuSub = ContextMenuPrimitive.Sub;
|
||||
|
||||
export const ContextMenuRadioGroup = ContextMenuPrimitive.RadioGroup;
|
||||
|
||||
export const ContextMenuSubTrigger = forwardRef<
|
||||
React.ElementRef<typeof ContextMenuPrimitive.SubTrigger>,
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.SubTrigger> & {
|
||||
inset?: boolean;
|
||||
}
|
||||
>(({ className, inset, children, ...props }, ref) => (
|
||||
<ContextMenuPrimitive.SubTrigger
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-secondary focus:text-secondary-foreground data-[state=open]:bg-secondary data-[state=open]:text-secondary-foreground",
|
||||
inset && "pl-8",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<CaretRight className="ml-auto h-4 w-4" />
|
||||
</ContextMenuPrimitive.SubTrigger>
|
||||
));
|
||||
|
||||
ContextMenuSubTrigger.displayName = ContextMenuPrimitive.SubTrigger.displayName;
|
||||
|
||||
export const ContextMenuSubContent = forwardRef<
|
||||
React.ElementRef<typeof ContextMenuPrimitive.SubContent>,
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.SubContent>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<ContextMenuPrimitive.SubContent
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-background p-1 shadow-md 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}
|
||||
/>
|
||||
));
|
||||
|
||||
ContextMenuSubContent.displayName = ContextMenuPrimitive.SubContent.displayName;
|
||||
|
||||
export const ContextMenuContent = forwardRef<
|
||||
React.ElementRef<typeof ContextMenuPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Content>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<ContextMenuPrimitive.Portal>
|
||||
<ContextMenuPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-background p-1 shadow-md 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}
|
||||
/>
|
||||
</ContextMenuPrimitive.Portal>
|
||||
));
|
||||
|
||||
ContextMenuContent.displayName = ContextMenuPrimitive.Content.displayName;
|
||||
|
||||
export const ContextMenuItem = forwardRef<
|
||||
React.ElementRef<typeof ContextMenuPrimitive.Item>,
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Item> & {
|
||||
inset?: boolean;
|
||||
}
|
||||
>(({ className, inset, ...props }, ref) => (
|
||||
<ContextMenuPrimitive.Item
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-secondary focus:text-secondary-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
||||
inset && "pl-8",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
ContextMenuItem.displayName = ContextMenuPrimitive.Item.displayName;
|
||||
|
||||
export const ContextMenuCheckboxItem = forwardRef<
|
||||
React.ElementRef<typeof ContextMenuPrimitive.CheckboxItem>,
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.CheckboxItem>
|
||||
>(({ className, children, checked, ...props }, ref) => (
|
||||
<ContextMenuPrimitive.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 focus:bg-secondary focus:text-secondary-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
||||
className,
|
||||
)}
|
||||
checked={checked}
|
||||
{...props}
|
||||
>
|
||||
<span className="absolute left-2 flex h-4 w-4 items-center justify-center">
|
||||
<ContextMenuPrimitive.ItemIndicator>
|
||||
<Check size={14} />
|
||||
</ContextMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</ContextMenuPrimitive.CheckboxItem>
|
||||
));
|
||||
|
||||
ContextMenuCheckboxItem.displayName = ContextMenuPrimitive.CheckboxItem.displayName;
|
||||
|
||||
export const ContextMenuRadioItem = forwardRef<
|
||||
React.ElementRef<typeof ContextMenuPrimitive.RadioItem>,
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.RadioItem>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<ContextMenuPrimitive.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 focus:bg-secondary focus:text-secondary-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span className="absolute left-2 flex h-4 w-4 items-center justify-center">
|
||||
<ContextMenuPrimitive.ItemIndicator>
|
||||
<Check size={14} className="fill-current" />
|
||||
</ContextMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</ContextMenuPrimitive.RadioItem>
|
||||
));
|
||||
|
||||
ContextMenuRadioItem.displayName = ContextMenuPrimitive.RadioItem.displayName;
|
||||
|
||||
export const ContextMenuLabel = forwardRef<
|
||||
React.ElementRef<typeof ContextMenuPrimitive.Label>,
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Label> & {
|
||||
inset?: boolean;
|
||||
}
|
||||
>(({ className, inset, ...props }, ref) => (
|
||||
<ContextMenuPrimitive.Label
|
||||
ref={ref}
|
||||
className={cn("px-2 py-1.5 text-sm font-semibold text-foreground", inset && "pl-8", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
ContextMenuLabel.displayName = ContextMenuPrimitive.Label.displayName;
|
||||
|
||||
export const ContextMenuSeparator = forwardRef<
|
||||
React.ElementRef<typeof ContextMenuPrimitive.Separator>,
|
||||
React.ComponentPropsWithoutRef<typeof ContextMenuPrimitive.Separator>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<ContextMenuPrimitive.Separator
|
||||
ref={ref}
|
||||
className={cn("-mx-1 my-1 h-px bg-border", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
ContextMenuSeparator.displayName = ContextMenuPrimitive.Separator.displayName;
|
||||
96
libs/ui/src/components/dialog.tsx
Normal file
96
libs/ui/src/components/dialog.tsx
Normal file
@ -0,0 +1,96 @@
|
||||
import { X } from "@phosphor-icons/react";
|
||||
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
export const Dialog = DialogPrimitive.Root;
|
||||
|
||||
export const DialogTrigger = DialogPrimitive.Trigger;
|
||||
|
||||
export const DialogPortal = (props: DialogPrimitive.DialogPortalProps) => (
|
||||
<DialogPrimitive.Portal {...props} />
|
||||
);
|
||||
|
||||
DialogPortal.displayName = DialogPrimitive.Portal.displayName;
|
||||
|
||||
export const DialogOverlay = forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Overlay>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DialogPrimitive.Overlay
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"fixed inset-0 z-50 bg-background/80 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
|
||||
|
||||
export const DialogContent = forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<DialogPortal>
|
||||
<DialogOverlay />
|
||||
<DialogPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-sm translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 duration-200 focus:outline-none focus:ring-1 focus:ring-secondary focus:ring-offset-1 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-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:max-w-xl sm:rounded-sm md:w-full",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-secondary focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary data-[state=open]:text-secondary-foreground">
|
||||
<X className="h-4 w-4" />
|
||||
<span className="sr-only">Close</span>
|
||||
</DialogPrimitive.Close>
|
||||
</DialogPrimitive.Content>
|
||||
</DialogPortal>
|
||||
));
|
||||
|
||||
DialogContent.displayName = DialogPrimitive.Content.displayName;
|
||||
|
||||
export const DialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div className={cn("flex flex-col space-y-3 text-left", className)} {...props} />
|
||||
);
|
||||
|
||||
DialogHeader.displayName = "DialogHeader";
|
||||
|
||||
export const DialogFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-3", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
|
||||
DialogFooter.displayName = "DialogFooter";
|
||||
|
||||
export const DialogTitle = forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Title>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DialogPrimitive.Title
|
||||
ref={ref}
|
||||
className={cn("text-base font-semibold leading-none tracking-tight", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
DialogTitle.displayName = DialogPrimitive.Title.displayName;
|
||||
|
||||
export const DialogDescription = forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Description>,
|
||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DialogPrimitive.Description
|
||||
ref={ref}
|
||||
className={cn("text-sm leading-relaxed text-primary-accent", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
DialogDescription.displayName = DialogPrimitive.Description.displayName;
|
||||
172
libs/ui/src/components/dropdown-menu.tsx
Normal file
172
libs/ui/src/components/dropdown-menu.tsx
Normal file
@ -0,0 +1,172 @@
|
||||
import { CaretRight, Check, DotOutline } from "@phosphor-icons/react";
|
||||
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
export const DropdownMenu = DropdownMenuPrimitive.Root;
|
||||
|
||||
export const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;
|
||||
|
||||
export const DropdownMenuGroup = DropdownMenuPrimitive.Group;
|
||||
|
||||
export const DropdownMenuPortal = DropdownMenuPrimitive.Portal;
|
||||
|
||||
export const DropdownMenuSub = DropdownMenuPrimitive.Sub;
|
||||
|
||||
export const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup;
|
||||
|
||||
export const DropdownMenuSubTrigger = forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.SubTrigger>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & {
|
||||
inset?: boolean;
|
||||
}
|
||||
>(({ className, inset, children, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.SubTrigger
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-secondary data-[state=open]:bg-secondary",
|
||||
inset && "pl-8",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<CaretRight className="ml-auto h-4 w-4" />
|
||||
</DropdownMenuPrimitive.SubTrigger>
|
||||
));
|
||||
|
||||
DropdownMenuSubTrigger.displayName = DropdownMenuPrimitive.SubTrigger.displayName;
|
||||
|
||||
export const DropdownMenuSubContent = forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.SubContent>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.Portal>
|
||||
<DropdownMenuPrimitive.SubContent
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-background p-1 text-foreground shadow-sm 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}
|
||||
/>
|
||||
</DropdownMenuPrimitive.Portal>
|
||||
));
|
||||
|
||||
DropdownMenuSubContent.displayName = DropdownMenuPrimitive.SubContent.displayName;
|
||||
|
||||
export const DropdownMenuContent = forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>
|
||||
>(({ className, children, sideOffset = 6, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.Portal>
|
||||
<DropdownMenuPrimitive.Content
|
||||
ref={ref}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"z-50 min-w-[8rem] overflow-hidden rounded-md border bg-background p-1 text-foreground shadow-sm",
|
||||
"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}
|
||||
>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.Content>
|
||||
</DropdownMenuPrimitive.Portal>
|
||||
));
|
||||
|
||||
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;
|
||||
|
||||
export const DropdownMenuItem = forwardRef<
|
||||
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 ease-in-out focus:bg-secondary focus:text-secondary-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
||||
inset && "pl-8",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName;
|
||||
|
||||
export const DropdownMenuCheckboxItem = 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 ease-in-out focus:bg-secondary focus:text-secondary-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>
|
||||
<Check className="h-4 w-4" />
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.CheckboxItem>
|
||||
));
|
||||
|
||||
DropdownMenuCheckboxItem.displayName = DropdownMenuPrimitive.CheckboxItem.displayName;
|
||||
|
||||
export const DropdownMenuRadioItem = 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 ease-in-out focus:bg-secondary focus:text-secondary-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>
|
||||
<DotOutline size={18} weight="fill" className="fill-current" />
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.RadioItem>
|
||||
));
|
||||
|
||||
DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName;
|
||||
|
||||
export const DropdownMenuLabel = 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;
|
||||
|
||||
export const DropdownMenuSeparator = 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-secondary", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName;
|
||||
115
libs/ui/src/components/form.tsx
Normal file
115
libs/ui/src/components/form.tsx
Normal file
@ -0,0 +1,115 @@
|
||||
import * as LabelPrimitive from "@radix-ui/react-label";
|
||||
import { Slot } from "@radix-ui/react-slot";
|
||||
import { FormFieldContext, FormItemContext, useFormField } from "@reactive-resume/hooks";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { forwardRef, useId } from "react";
|
||||
import { Controller, ControllerProps, FieldPath, FieldValues, FormProvider } from "react-hook-form";
|
||||
|
||||
import { Label } from "./label";
|
||||
|
||||
export const Form = FormProvider;
|
||||
|
||||
export const FormField = <
|
||||
TFieldValues extends FieldValues = FieldValues,
|
||||
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
||||
>({
|
||||
...props
|
||||
}: ControllerProps<TFieldValues, TName>) => (
|
||||
<FormFieldContext.Provider value={{ name: props.name }}>
|
||||
<Controller {...props} />
|
||||
</FormFieldContext.Provider>
|
||||
);
|
||||
|
||||
export const FormItem = forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
||||
({ className, ...props }, ref) => {
|
||||
const id = useId();
|
||||
|
||||
return (
|
||||
<FormItemContext.Provider value={{ id }}>
|
||||
<div ref={ref} className={cn("w-full space-y-1", className)} {...props} />
|
||||
</FormItemContext.Provider>
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
FormItem.displayName = "FormItem";
|
||||
|
||||
export const FormLabel = forwardRef<
|
||||
React.ElementRef<typeof LabelPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>
|
||||
>(({ className, ...props }, ref) => {
|
||||
const { error, formItemId } = useFormField();
|
||||
|
||||
return (
|
||||
<Label
|
||||
ref={ref}
|
||||
htmlFor={formItemId}
|
||||
className={cn(error && "text-error", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
FormLabel.displayName = "FormLabel";
|
||||
|
||||
export const FormControl = forwardRef<
|
||||
React.ElementRef<typeof Slot>,
|
||||
React.ComponentPropsWithoutRef<typeof Slot>
|
||||
>(({ ...props }, ref) => {
|
||||
const { error, formItemId, formDescriptionId, formMessageId } = useFormField();
|
||||
|
||||
return (
|
||||
<Slot
|
||||
ref={ref}
|
||||
id={formItemId}
|
||||
aria-invalid={!!error}
|
||||
aria-describedby={!error ? `${formDescriptionId}` : `${formDescriptionId} ${formMessageId}`}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
FormControl.displayName = "FormControl";
|
||||
|
||||
export const FormDescription = forwardRef<
|
||||
HTMLParagraphElement,
|
||||
React.HTMLAttributes<HTMLParagraphElement>
|
||||
>(({ className, ...props }, ref) => {
|
||||
const { formDescriptionId } = useFormField();
|
||||
|
||||
return (
|
||||
<p
|
||||
ref={ref}
|
||||
id={formDescriptionId}
|
||||
className={cn("text-xs leading-relaxed opacity-60", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
FormDescription.displayName = "FormDescription";
|
||||
|
||||
export const FormMessage = forwardRef<
|
||||
HTMLParagraphElement,
|
||||
React.HTMLAttributes<HTMLParagraphElement>
|
||||
>(({ className, children, ...props }, ref) => {
|
||||
const { error, formMessageId } = useFormField();
|
||||
const body = error ? String(error?.message) : children;
|
||||
|
||||
if (!body) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<p
|
||||
ref={ref}
|
||||
id={formMessageId}
|
||||
className={cn("text-xs font-medium leading-relaxed text-error", className)}
|
||||
{...props}
|
||||
>
|
||||
{body}
|
||||
</p>
|
||||
);
|
||||
});
|
||||
|
||||
FormMessage.displayName = "FormMessage";
|
||||
25
libs/ui/src/components/hover-card.tsx
Normal file
25
libs/ui/src/components/hover-card.tsx
Normal file
@ -0,0 +1,25 @@
|
||||
import * as HoverCardPrimitive from "@radix-ui/react-hover-card";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
export const HoverCard = HoverCardPrimitive.Root;
|
||||
|
||||
export const HoverCardTrigger = HoverCardPrimitive.Trigger;
|
||||
|
||||
export const HoverCardContent = forwardRef<
|
||||
React.ElementRef<typeof HoverCardPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof HoverCardPrimitive.Content>
|
||||
>(({ className, align = "center", sideOffset = 6, ...props }, ref) => (
|
||||
<HoverCardPrimitive.Content
|
||||
ref={ref}
|
||||
align={align}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"z-50 rounded-md border bg-background p-4 text-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}
|
||||
/>
|
||||
));
|
||||
|
||||
HoverCardContent.displayName = HoverCardPrimitive.Content.displayName;
|
||||
36
libs/ui/src/components/index.ts
Normal file
36
libs/ui/src/components/index.ts
Normal file
@ -0,0 +1,36 @@
|
||||
export * from "./accordion";
|
||||
export * from "./alert";
|
||||
export * from "./alert-dialog";
|
||||
export * from "./aspect-ratio";
|
||||
export * from "./avatar";
|
||||
export * from "./badge";
|
||||
export * from "./badge-input";
|
||||
export * from "./button";
|
||||
export * from "./card";
|
||||
export * from "./checkbox";
|
||||
export * from "./combobox";
|
||||
export * from "./command";
|
||||
export * from "./context-menu";
|
||||
export * from "./dialog";
|
||||
export * from "./dropdown-menu";
|
||||
export * from "./form";
|
||||
export * from "./hover-card";
|
||||
export * from "./input";
|
||||
export * from "./label";
|
||||
export * from "./popover";
|
||||
export * from "./portal";
|
||||
export * from "./resizable-panel";
|
||||
export * from "./rich-input";
|
||||
export * from "./scroll-area";
|
||||
export * from "./select";
|
||||
export * from "./separator";
|
||||
export * from "./sheet";
|
||||
export * from "./shortcut";
|
||||
export * from "./skeleton";
|
||||
export * from "./slider";
|
||||
export * from "./switch";
|
||||
export * from "./tabs";
|
||||
export * from "./toast";
|
||||
export * from "./toggle";
|
||||
export * from "./toggle-group";
|
||||
export * from "./tooltip";
|
||||
25
libs/ui/src/components/input.tsx
Normal file
25
libs/ui/src/components/input.tsx
Normal file
@ -0,0 +1,25 @@
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
||||
hasError?: boolean;
|
||||
}
|
||||
|
||||
export const Input = forwardRef<HTMLInputElement, InputProps>(
|
||||
({ className, type, hasError = false, ...props }, ref) => (
|
||||
<input
|
||||
ref={ref}
|
||||
type={type}
|
||||
autoComplete="off"
|
||||
className={cn(
|
||||
"flex h-9 w-full rounded border border-border bg-transparent px-3 py-0.5 !text-sm ring-0 ring-offset-transparent transition-colors [appearance:textfield] placeholder:opacity-80 hover:bg-secondary/20 focus:border-primary focus:bg-secondary/20 focus-visible:outline-none focus-visible:ring-0 disabled:cursor-not-allowed disabled:opacity-50 [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none",
|
||||
"file:border-0 file:bg-transparent file:pt-1 file:text-sm file:font-medium file:text-primary",
|
||||
hasError ? "border-error" : "border-border",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
),
|
||||
);
|
||||
|
||||
Input.displayName = "Input";
|
||||
17
libs/ui/src/components/label.tsx
Normal file
17
libs/ui/src/components/label.tsx
Normal file
@ -0,0 +1,17 @@
|
||||
import * as LabelPrimitive from "@radix-ui/react-label";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
export const labelVariants = cva(
|
||||
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-60",
|
||||
);
|
||||
|
||||
export const Label = forwardRef<
|
||||
React.ElementRef<typeof LabelPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & VariantProps<typeof labelVariants>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<LabelPrimitive.Root ref={ref} className={cn(labelVariants(), className)} {...props} />
|
||||
));
|
||||
|
||||
Label.displayName = LabelPrimitive.Root.displayName;
|
||||
29
libs/ui/src/components/popover.tsx
Normal file
29
libs/ui/src/components/popover.tsx
Normal file
@ -0,0 +1,29 @@
|
||||
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
export const Popover = PopoverPrimitive.Root;
|
||||
|
||||
export const PopoverArrow = PopoverPrimitive.Arrow;
|
||||
|
||||
export const PopoverTrigger = PopoverPrimitive.Trigger;
|
||||
|
||||
export const PopoverContent = forwardRef<
|
||||
React.ElementRef<typeof PopoverPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
|
||||
>(({ className, align = "center", sideOffset = 6, ...props }, ref) => (
|
||||
<PopoverPrimitive.PopoverPortal>
|
||||
<PopoverPrimitive.Content
|
||||
ref={ref}
|
||||
align={align}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"z-50 rounded border bg-background p-4 shadow-sm 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.PopoverPortal>
|
||||
));
|
||||
|
||||
PopoverContent.displayName = PopoverPrimitive.Content.displayName;
|
||||
3
libs/ui/src/components/portal.tsx
Normal file
3
libs/ui/src/components/portal.tsx
Normal file
@ -0,0 +1,3 @@
|
||||
import * as PortalPrimitive from "@radix-ui/react-portal";
|
||||
|
||||
export const Portal = PortalPrimitive.Root;
|
||||
35
libs/ui/src/components/resizable-panel.tsx
Normal file
35
libs/ui/src/components/resizable-panel.tsx
Normal file
@ -0,0 +1,35 @@
|
||||
import { DotsSixVertical } from "@phosphor-icons/react";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import * as PanelPrimitive from "react-resizable-panels";
|
||||
|
||||
export const PanelGroup = PanelPrimitive.PanelGroup;
|
||||
|
||||
export const Panel = PanelPrimitive.Panel;
|
||||
|
||||
type PanelResizeHandleProps = React.ComponentProps<typeof PanelPrimitive.PanelResizeHandle> & {
|
||||
isDragging?: boolean;
|
||||
};
|
||||
|
||||
export const PanelResizeHandle = ({
|
||||
className,
|
||||
isDragging,
|
||||
onDragging,
|
||||
...props
|
||||
}: PanelResizeHandleProps) => (
|
||||
<PanelPrimitive.PanelResizeHandle
|
||||
className={cn("relative h-screen", className)}
|
||||
onDragging={onDragging}
|
||||
{...props}
|
||||
>
|
||||
<div className="flex h-full items-center justify-center">
|
||||
<div
|
||||
className={cn(
|
||||
"absolute z-20 rounded-lg bg-transparent py-2 opacity-25 transition-all hover:bg-info hover:opacity-100",
|
||||
isDragging && "bg-info opacity-100",
|
||||
)}
|
||||
>
|
||||
<DotsSixVertical weight="bold" />
|
||||
</div>
|
||||
</div>
|
||||
</PanelPrimitive.PanelResizeHandle>
|
||||
);
|
||||
506
libs/ui/src/components/rich-input.tsx
Normal file
506
libs/ui/src/components/rich-input.tsx
Normal file
@ -0,0 +1,506 @@
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import {
|
||||
ArrowClockwise,
|
||||
ArrowCounterClockwise,
|
||||
Code,
|
||||
CodeBlock,
|
||||
HighlighterCircle,
|
||||
Image as ImageIcon,
|
||||
KeyReturn,
|
||||
LinkSimple,
|
||||
ListBullets,
|
||||
ListNumbers,
|
||||
Minus,
|
||||
Paragraph,
|
||||
TextAlignCenter,
|
||||
TextAlignJustify,
|
||||
TextAlignLeft,
|
||||
TextAlignRight,
|
||||
TextAUnderline,
|
||||
TextB,
|
||||
TextHOne,
|
||||
TextHThree,
|
||||
TextHTwo,
|
||||
TextIndent,
|
||||
TextItalic,
|
||||
TextOutdent,
|
||||
TextStrikethrough,
|
||||
} from "@phosphor-icons/react";
|
||||
import { PopoverTrigger } from "@radix-ui/react-popover";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { Highlight } from "@tiptap/extension-highlight";
|
||||
import { Image } from "@tiptap/extension-image";
|
||||
import { Link } from "@tiptap/extension-link";
|
||||
import { TextAlign } from "@tiptap/extension-text-align";
|
||||
import { Underline } from "@tiptap/extension-underline";
|
||||
import { Editor, EditorContent, EditorContentProps, useEditor } from "@tiptap/react";
|
||||
import { StarterKit } from "@tiptap/starter-kit";
|
||||
import { forwardRef, useCallback } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
|
||||
import { Button } from "./button";
|
||||
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from "./form";
|
||||
import { Input } from "./input";
|
||||
import { Popover, PopoverContent } from "./popover";
|
||||
import { ScrollArea } from "./scroll-area";
|
||||
import { Separator } from "./separator";
|
||||
import { Skeleton } from "./skeleton";
|
||||
import { Toggle } from "./toggle";
|
||||
import { Tooltip } from "./tooltip";
|
||||
|
||||
const InsertImageFormSchema = z.object({
|
||||
src: z.string(),
|
||||
alt: z.string().optional(),
|
||||
});
|
||||
|
||||
type InsertImageFormValues = z.infer<typeof InsertImageFormSchema>;
|
||||
|
||||
type InsertImageProps = {
|
||||
onInsert: (value: InsertImageFormValues) => void;
|
||||
};
|
||||
|
||||
const InsertImageForm = ({ onInsert }: InsertImageProps) => {
|
||||
const form = useForm<InsertImageFormValues>({
|
||||
resolver: zodResolver(InsertImageFormSchema),
|
||||
defaultValues: { src: "", alt: "" },
|
||||
});
|
||||
|
||||
const onSubmit = (values: InsertImageFormValues) => {
|
||||
onInsert(values);
|
||||
form.reset();
|
||||
};
|
||||
|
||||
return (
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-3">
|
||||
<p className="prose prose-sm prose-zinc dark:prose-invert">
|
||||
Insert an image from an external URL and use it on your resume.
|
||||
</p>
|
||||
|
||||
<FormField
|
||||
name="src"
|
||||
control={form.control}
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>URL</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="http://..." {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
name="alt"
|
||||
control={form.control}
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Description</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
</FormControl>
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<div className="!mt-5 ml-auto max-w-fit">
|
||||
<Button type="submit" variant="secondary" size="sm">
|
||||
Insert Image
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</Form>
|
||||
);
|
||||
};
|
||||
|
||||
const Toolbar = ({ editor }: { editor: Editor }) => {
|
||||
const setLink = useCallback(() => {
|
||||
const previousUrl = editor.getAttributes("link").href;
|
||||
const url = window.prompt("URL", previousUrl);
|
||||
|
||||
// cancelled
|
||||
if (url === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// empty
|
||||
if (url === "") {
|
||||
editor.chain().focus().extendMarkRange("link").unsetLink().run();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// update link
|
||||
editor.chain().focus().extendMarkRange("link").setLink({ href: url }).run();
|
||||
}, [editor]);
|
||||
|
||||
return (
|
||||
<div className="absolute inset-x-0 top-2 px-2">
|
||||
<ScrollArea orientation="horizontal">
|
||||
<div className="flex h-8 gap-1">
|
||||
<Tooltip content="Bold">
|
||||
<Toggle
|
||||
size="sm"
|
||||
pressed={editor.isActive("bold")}
|
||||
disabled={!editor.can().chain().focus().toggleBold().run()}
|
||||
onPressedChange={() => editor.chain().focus().toggleBold().run()}
|
||||
>
|
||||
<TextB />
|
||||
</Toggle>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip content="Italic">
|
||||
<Toggle
|
||||
size="sm"
|
||||
pressed={editor.isActive("italic")}
|
||||
disabled={!editor.can().chain().focus().toggleItalic().run()}
|
||||
onPressedChange={() => editor.chain().focus().toggleItalic().run()}
|
||||
>
|
||||
<TextItalic />
|
||||
</Toggle>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip content="Strikethrough">
|
||||
<Toggle
|
||||
size="sm"
|
||||
pressed={editor.isActive("strike")}
|
||||
disabled={!editor.can().chain().focus().toggleStrike().run()}
|
||||
onPressedChange={() => editor.chain().focus().toggleStrike().run()}
|
||||
>
|
||||
<TextStrikethrough />
|
||||
</Toggle>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip content="Underline">
|
||||
<Toggle
|
||||
size="sm"
|
||||
pressed={editor.isActive("underline")}
|
||||
disabled={!editor.can().chain().focus().toggleUnderline().run()}
|
||||
onPressedChange={() => editor.chain().focus().toggleUnderline().run()}
|
||||
>
|
||||
<TextAUnderline />
|
||||
</Toggle>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip content="Highlight">
|
||||
<Toggle
|
||||
size="sm"
|
||||
pressed={editor.isActive("highlight")}
|
||||
disabled={!editor.can().chain().focus().toggleHighlight().run()}
|
||||
onPressedChange={() => editor.chain().focus().toggleHighlight().run()}
|
||||
>
|
||||
<HighlighterCircle />
|
||||
</Toggle>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip content="Hyperlink">
|
||||
<Button type="button" size="sm" variant="ghost" className="px-2" onClick={setLink}>
|
||||
<LinkSimple />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
|
||||
<Separator orientation="vertical" className="mx-1" />
|
||||
|
||||
<Tooltip content="Inline Code">
|
||||
<Toggle
|
||||
size="sm"
|
||||
pressed={editor.isActive("code")}
|
||||
disabled={!editor.can().chain().focus().toggleCode().run()}
|
||||
onPressedChange={() => editor.chain().focus().toggleCode().run()}
|
||||
>
|
||||
<Code />
|
||||
</Toggle>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip content="Code Block">
|
||||
<Toggle
|
||||
size="sm"
|
||||
pressed={editor.isActive("codeBlock")}
|
||||
disabled={!editor.can().chain().focus().toggleCodeBlock().run()}
|
||||
onPressedChange={() => editor.chain().focus().toggleCodeBlock().run()}
|
||||
>
|
||||
<CodeBlock />
|
||||
</Toggle>
|
||||
</Tooltip>
|
||||
|
||||
<Separator orientation="vertical" className="mx-1" />
|
||||
|
||||
<Tooltip content="Heading 1">
|
||||
<Toggle
|
||||
size="sm"
|
||||
pressed={editor.isActive("heading", { level: 1 })}
|
||||
disabled={!editor.can().chain().focus().toggleHeading({ level: 1 }).run()}
|
||||
onPressedChange={() => editor.chain().focus().toggleHeading({ level: 1 }).run()}
|
||||
>
|
||||
<TextHOne />
|
||||
</Toggle>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip content="Heading 2">
|
||||
<Toggle
|
||||
size="sm"
|
||||
pressed={editor.isActive("heading", { level: 2 })}
|
||||
disabled={!editor.can().chain().focus().toggleHeading({ level: 2 }).run()}
|
||||
onPressedChange={() => editor.chain().focus().toggleHeading({ level: 2 }).run()}
|
||||
>
|
||||
<TextHTwo />
|
||||
</Toggle>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip content="Heading 3">
|
||||
<Toggle
|
||||
size="sm"
|
||||
pressed={editor.isActive("heading", { level: 3 })}
|
||||
disabled={!editor.can().chain().focus().toggleHeading({ level: 3 }).run()}
|
||||
onPressedChange={() => editor.chain().focus().toggleHeading({ level: 3 }).run()}
|
||||
>
|
||||
<TextHThree />
|
||||
</Toggle>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip content="Paragraph">
|
||||
<Toggle
|
||||
size="sm"
|
||||
pressed={editor.isActive("paragraph")}
|
||||
onPressedChange={() => editor.chain().focus().setParagraph().run()}
|
||||
>
|
||||
<Paragraph />
|
||||
</Toggle>
|
||||
</Tooltip>
|
||||
|
||||
<Separator orientation="vertical" className="mx-1" />
|
||||
|
||||
<Tooltip content="Align Left">
|
||||
<Toggle
|
||||
size="sm"
|
||||
pressed={editor.isActive({ textAlign: "left" })}
|
||||
disabled={!editor.can().chain().focus().setTextAlign("left").run()}
|
||||
onPressedChange={() => editor.chain().focus().setTextAlign("left").run()}
|
||||
>
|
||||
<TextAlignLeft />
|
||||
</Toggle>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip content="Align Center">
|
||||
<Toggle
|
||||
size="sm"
|
||||
pressed={editor.isActive({ textAlign: "center" })}
|
||||
disabled={!editor.can().chain().focus().setTextAlign("center").run()}
|
||||
onPressedChange={() => editor.chain().focus().setTextAlign("center").run()}
|
||||
>
|
||||
<TextAlignCenter />
|
||||
</Toggle>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip content="Align Right">
|
||||
<Toggle
|
||||
size="sm"
|
||||
pressed={editor.isActive({ textAlign: "right" })}
|
||||
disabled={!editor.can().chain().focus().setTextAlign("right").run()}
|
||||
onPressedChange={() => editor.chain().focus().setTextAlign("right").run()}
|
||||
>
|
||||
<TextAlignRight />
|
||||
</Toggle>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip content="Align Justify">
|
||||
<Toggle
|
||||
size="sm"
|
||||
pressed={editor.isActive({ textAlign: "justify" })}
|
||||
disabled={!editor.can().chain().focus().setTextAlign("justify").run()}
|
||||
onPressedChange={() => editor.chain().focus().setTextAlign("justify").run()}
|
||||
>
|
||||
<TextAlignJustify />
|
||||
</Toggle>
|
||||
</Tooltip>
|
||||
|
||||
<Separator orientation="vertical" className="mx-1" />
|
||||
|
||||
<Tooltip content="Bullet List">
|
||||
<Toggle
|
||||
size="sm"
|
||||
pressed={editor.isActive("bulletList")}
|
||||
disabled={!editor.can().chain().focus().toggleBulletList().run()}
|
||||
onPressedChange={() => editor.chain().focus().toggleBulletList().run()}
|
||||
>
|
||||
<ListBullets />
|
||||
</Toggle>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip content="Numbered List">
|
||||
<Toggle
|
||||
size="sm"
|
||||
pressed={editor.isActive("orderedList")}
|
||||
disabled={!editor.can().chain().focus().toggleOrderedList().run()}
|
||||
onPressedChange={() => editor.chain().focus().toggleOrderedList().run()}
|
||||
>
|
||||
<ListNumbers />
|
||||
</Toggle>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip content="Outdent">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="px-2"
|
||||
onClick={() => editor.chain().focus().liftListItem("listItem").run()}
|
||||
disabled={!editor.can().chain().focus().liftListItem("listItem").run()}
|
||||
>
|
||||
<TextOutdent />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip content="Indent">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="px-2"
|
||||
onClick={() => editor.chain().focus().sinkListItem("listItem").run()}
|
||||
disabled={!editor.can().chain().focus().sinkListItem("listItem").run()}
|
||||
>
|
||||
<TextIndent />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
|
||||
<Separator orientation="vertical" className="mx-1" />
|
||||
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<Button size="sm" variant="ghost" className="px-2">
|
||||
<ImageIcon />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-80">
|
||||
<InsertImageForm onInsert={(props) => editor.chain().focus().setImage(props).run()} />
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
|
||||
<Tooltip content="Insert Break Line">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="px-2"
|
||||
onClick={() => editor.chain().focus().setHardBreak().run()}
|
||||
disabled={!editor.can().chain().focus().setHardBreak().run()}
|
||||
>
|
||||
<KeyReturn />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip content="Insert Horizontal Rule">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="px-2"
|
||||
onClick={() => editor.chain().focus().setHorizontalRule().run()}
|
||||
disabled={!editor.can().chain().focus().setHorizontalRule().run()}
|
||||
>
|
||||
<Minus />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
|
||||
<Separator orientation="vertical" className="mx-1" />
|
||||
|
||||
<Tooltip content="Undo">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="px-2"
|
||||
disabled={!editor.can().undo()}
|
||||
onClick={() => editor.chain().focus().undo().run()}
|
||||
>
|
||||
<ArrowCounterClockwise />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip content="Redo">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="px-2"
|
||||
disabled={!editor.can().redo()}
|
||||
onClick={() => editor.chain().focus().redo().run()}
|
||||
>
|
||||
<ArrowClockwise />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
|
||||
<Separator className="mt-2" />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
interface RichInputProps
|
||||
extends Omit<
|
||||
EditorContentProps,
|
||||
"ref" | "editor" | "content" | "value" | "onChange" | "className"
|
||||
> {
|
||||
content?: string;
|
||||
onChange?: (value: string) => void;
|
||||
hideToolbar?: boolean;
|
||||
className?: string;
|
||||
editorClassName?: string;
|
||||
footer?: (editor: Editor) => React.ReactNode;
|
||||
}
|
||||
|
||||
export const RichInput = forwardRef<Editor, RichInputProps>(
|
||||
(
|
||||
{ content, onChange, footer, hideToolbar = false, className, editorClassName, ...props },
|
||||
_ref,
|
||||
) => {
|
||||
const editor = useEditor({
|
||||
extensions: [
|
||||
StarterKit,
|
||||
Image,
|
||||
Underline,
|
||||
Highlight,
|
||||
Link.configure({ openOnClick: false }),
|
||||
TextAlign.configure({ types: ["heading", "paragraph"] }),
|
||||
],
|
||||
editorProps: {
|
||||
attributes: {
|
||||
class: cn(
|
||||
"prose prose-sm prose-zinc max-h-[200px] max-w-none overflow-y-scroll dark:prose-invert focus:outline-none [&_*]:my-2",
|
||||
editorClassName,
|
||||
),
|
||||
},
|
||||
},
|
||||
content,
|
||||
parseOptions: { preserveWhitespace: "full" },
|
||||
onUpdate: ({ editor }) => onChange?.(editor.getHTML()),
|
||||
});
|
||||
|
||||
if (!editor) {
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<Skeleton className={cn("h-[42px] w-full", hideToolbar && "hidden")} />
|
||||
<Skeleton className="h-[90px] w-full" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
{!hideToolbar && <Toolbar editor={editor} />}
|
||||
|
||||
<EditorContent
|
||||
editor={editor}
|
||||
className={cn(
|
||||
"grid min-h-[160px] w-full rounded-sm border bg-transparent px-3 pb-2 pt-14 text-sm placeholder:opacity-80 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50",
|
||||
hideToolbar && "pt-2",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
|
||||
{footer?.(editor)}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
RichInput.displayName = "RichInput";
|
||||
46
libs/ui/src/components/scroll-area.tsx
Normal file
46
libs/ui/src/components/scroll-area.tsx
Normal file
@ -0,0 +1,46 @@
|
||||
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
export const ScrollArea = forwardRef<
|
||||
React.ElementRef<typeof ScrollAreaPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root> & {
|
||||
orientation?: "vertical" | "horizontal";
|
||||
}
|
||||
>(({ type = "scroll", orientation = "vertical", className, children, ...props }, ref) => (
|
||||
<ScrollAreaPrimitive.Root
|
||||
ref={ref}
|
||||
type={type}
|
||||
className={cn("relative overflow-hidden", className)}
|
||||
{...props}
|
||||
>
|
||||
<ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]">
|
||||
{children}
|
||||
</ScrollAreaPrimitive.Viewport>
|
||||
<ScrollBar orientation={orientation} />
|
||||
<ScrollAreaPrimitive.Corner />
|
||||
</ScrollAreaPrimitive.Root>
|
||||
));
|
||||
|
||||
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName;
|
||||
|
||||
export const ScrollBar = forwardRef<
|
||||
React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>,
|
||||
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>
|
||||
>(({ className, orientation, ...props }, ref) => (
|
||||
<ScrollAreaPrimitive.ScrollAreaScrollbar
|
||||
ref={ref}
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
"flex touch-none select-none transition-colors",
|
||||
orientation === "vertical" && "h-full w-2.5 border-l border-l-transparent p-[1px]",
|
||||
orientation === "horizontal" && "h-2.5 border-t border-t-transparent p-[1px]",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 rounded-full bg-border" />
|
||||
</ScrollAreaPrimitive.ScrollAreaScrollbar>
|
||||
));
|
||||
|
||||
ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName;
|
||||
111
libs/ui/src/components/select.tsx
Normal file
111
libs/ui/src/components/select.tsx
Normal file
@ -0,0 +1,111 @@
|
||||
import { CaretUpDown, Check } from "@phosphor-icons/react";
|
||||
import * as SelectPrimitive from "@radix-ui/react-select";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
export const Select = SelectPrimitive.Root;
|
||||
|
||||
export const SelectGroup = SelectPrimitive.Group;
|
||||
|
||||
export const SelectValue = SelectPrimitive.Value;
|
||||
|
||||
export const SelectTrigger = forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.Trigger>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<SelectPrimitive.Trigger
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex h-9 w-full items-center justify-between rounded border border-border bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-secondary-foreground focus:outline-none focus:ring-1 focus:ring-primary disabled:cursor-not-allowed disabled:opacity-50",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<SelectPrimitive.Icon asChild>
|
||||
<CaretUpDown className="h-4 w-4 opacity-50" />
|
||||
</SelectPrimitive.Icon>
|
||||
</SelectPrimitive.Trigger>
|
||||
));
|
||||
|
||||
SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
|
||||
|
||||
export const SelectContent = forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
|
||||
>(({ className, children, position = "popper", ...props }, ref) => (
|
||||
<SelectPrimitive.Portal>
|
||||
<SelectPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative z-50 min-w-[8rem] overflow-hidden rounded border border-border bg-background text-foreground shadow-md 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",
|
||||
position === "popper" &&
|
||||
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
|
||||
className,
|
||||
)}
|
||||
position={position}
|
||||
{...props}
|
||||
>
|
||||
<SelectPrimitive.Viewport
|
||||
className={cn(
|
||||
"p-1",
|
||||
position === "popper" &&
|
||||
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]",
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</SelectPrimitive.Viewport>
|
||||
</SelectPrimitive.Content>
|
||||
</SelectPrimitive.Portal>
|
||||
));
|
||||
|
||||
SelectContent.displayName = SelectPrimitive.Content.displayName;
|
||||
|
||||
export const SelectLabel = forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.Label>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SelectPrimitive.Label
|
||||
ref={ref}
|
||||
className={cn("px-2 py-1.5 text-sm font-semibold", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
SelectLabel.displayName = SelectPrimitive.Label.displayName;
|
||||
|
||||
export const SelectItem = forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.Item>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<SelectPrimitive.Item
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative flex w-full cursor-default select-none items-center rounded py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-secondary focus:text-secondary-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span className="absolute right-2 flex h-3.5 w-3.5 items-center justify-center">
|
||||
<SelectPrimitive.ItemIndicator>
|
||||
<Check className="h-4 w-4" />
|
||||
</SelectPrimitive.ItemIndicator>
|
||||
</span>
|
||||
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
|
||||
</SelectPrimitive.Item>
|
||||
));
|
||||
|
||||
SelectItem.displayName = SelectPrimitive.Item.displayName;
|
||||
|
||||
export const SelectSeparator = forwardRef<
|
||||
React.ElementRef<typeof SelectPrimitive.Separator>,
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SelectPrimitive.Separator
|
||||
ref={ref}
|
||||
className={cn("-mx-1 my-1 h-px opacity-60", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
|
||||
22
libs/ui/src/components/separator.tsx
Normal file
22
libs/ui/src/components/separator.tsx
Normal file
@ -0,0 +1,22 @@
|
||||
import * as SeparatorPrimitive from "@radix-ui/react-separator";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
export const Separator = forwardRef<
|
||||
React.ElementRef<typeof SeparatorPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>
|
||||
>(({ className, orientation = "horizontal", decorative = true, ...props }, ref) => (
|
||||
<SeparatorPrimitive.Root
|
||||
ref={ref}
|
||||
decorative={decorative}
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
"shrink-0 bg-border",
|
||||
orientation === "horizontal" ? "h-[1px] w-full" : "h-full w-[1px]",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
Separator.displayName = SeparatorPrimitive.Root.displayName;
|
||||
99
libs/ui/src/components/sheet.tsx
Normal file
99
libs/ui/src/components/sheet.tsx
Normal file
@ -0,0 +1,99 @@
|
||||
import { X } from "@phosphor-icons/react";
|
||||
import * as SheetPrimitive from "@radix-ui/react-dialog";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { type VariantProps } from "class-variance-authority";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
import { sheetVariants } from "../variants/sheet";
|
||||
|
||||
export const Sheet = SheetPrimitive.Root;
|
||||
|
||||
export const SheetTrigger = SheetPrimitive.Trigger;
|
||||
|
||||
export const SheetClose = SheetPrimitive.Close;
|
||||
|
||||
export const SheetPortal = (props: SheetPrimitive.DialogPortalProps) => (
|
||||
<SheetPrimitive.Portal {...props} />
|
||||
);
|
||||
|
||||
SheetPortal.displayName = SheetPrimitive.Portal.displayName;
|
||||
|
||||
export const SheetOverlay = forwardRef<
|
||||
React.ElementRef<typeof SheetPrimitive.Overlay>,
|
||||
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Overlay>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SheetPrimitive.Overlay
|
||||
className={cn(
|
||||
"fixed inset-0 z-50 bg-background/80 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
ref={ref}
|
||||
/>
|
||||
));
|
||||
|
||||
SheetOverlay.displayName = SheetPrimitive.Overlay.displayName;
|
||||
|
||||
export interface SheetContentProps
|
||||
extends React.ComponentPropsWithoutRef<typeof SheetPrimitive.Content>,
|
||||
VariantProps<typeof sheetVariants> {
|
||||
showClose?: boolean;
|
||||
}
|
||||
|
||||
export const SheetContent = forwardRef<
|
||||
React.ElementRef<typeof SheetPrimitive.Content>,
|
||||
SheetContentProps
|
||||
>(({ side = "right", className, children, showClose = true, ...props }, ref) => (
|
||||
<SheetPortal>
|
||||
<SheetOverlay />
|
||||
<SheetPrimitive.Content ref={ref} className={cn(sheetVariants({ side }), className)} {...props}>
|
||||
{children}
|
||||
|
||||
{showClose && (
|
||||
<SheetPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary">
|
||||
<X className="h-4 w-4" />
|
||||
<span className="sr-only">Close</span>
|
||||
</SheetPrimitive.Close>
|
||||
)}
|
||||
</SheetPrimitive.Content>
|
||||
</SheetPortal>
|
||||
));
|
||||
|
||||
SheetContent.displayName = SheetPrimitive.Content.displayName;
|
||||
|
||||
export const SheetHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div className={cn("flex flex-col space-y-2 text-center sm:text-left", className)} {...props} />
|
||||
);
|
||||
|
||||
SheetHeader.displayName = "SheetHeader";
|
||||
|
||||
export const SheetFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
|
||||
SheetFooter.displayName = "SheetFooter";
|
||||
|
||||
export const SheetTitle = forwardRef<
|
||||
React.ElementRef<typeof SheetPrimitive.Title>,
|
||||
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Title>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SheetPrimitive.Title
|
||||
ref={ref}
|
||||
className={cn("text-base font-medium text-foreground", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
SheetTitle.displayName = SheetPrimitive.Title.displayName;
|
||||
|
||||
export const SheetDescription = forwardRef<
|
||||
React.ElementRef<typeof SheetPrimitive.Description>,
|
||||
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Description>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SheetPrimitive.Description ref={ref} className={cn("opacity-60", className)} {...props} />
|
||||
));
|
||||
|
||||
SheetDescription.displayName = SheetPrimitive.Description.displayName;
|
||||
47
libs/ui/src/components/shortcut.tsx
Normal file
47
libs/ui/src/components/shortcut.tsx
Normal file
@ -0,0 +1,47 @@
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { useEffect } from "react";
|
||||
import { useBoolean } from "usehooks-ts";
|
||||
|
||||
// Keyboard Icons
|
||||
// Shift ⇧
|
||||
// Control ⌃
|
||||
// Option ⌥
|
||||
// Command ⌘
|
||||
|
||||
type KeyboardShortcutProps = Omit<React.HTMLAttributes<HTMLSpanElement>, "defaultValue"> & {
|
||||
defaultValue?: boolean;
|
||||
};
|
||||
|
||||
export const KeyboardShortcut = ({
|
||||
className,
|
||||
defaultValue = false,
|
||||
...props
|
||||
}: KeyboardShortcutProps) => {
|
||||
const { value, setValue } = useBoolean(defaultValue);
|
||||
|
||||
useEffect(() => {
|
||||
const onKeyDown = (e: KeyboardEvent) => e.key === "Control" && setValue(true);
|
||||
const onKeyUp = (e: KeyboardEvent) => e.key === "Control" && setValue(false);
|
||||
|
||||
document.addEventListener("keydown", onKeyDown);
|
||||
document.addEventListener("keyup", onKeyUp);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener("keydown", onKeyDown);
|
||||
document.removeEventListener("keyup", onKeyUp);
|
||||
};
|
||||
}, [setValue]);
|
||||
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
"ml-auto scale-0 text-xs tracking-widest opacity-0 transition-[opacity]",
|
||||
value && "scale-100 opacity-60",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
KeyboardShortcut.displayName = "KeyboardShortcut";
|
||||
5
libs/ui/src/components/skeleton.tsx
Normal file
5
libs/ui/src/components/skeleton.tsx
Normal file
@ -0,0 +1,5 @@
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
|
||||
export const Skeleton = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
|
||||
<div className={cn("animate-pulse rounded-md bg-secondary", className)} {...props} />
|
||||
);
|
||||
21
libs/ui/src/components/slider.tsx
Normal file
21
libs/ui/src/components/slider.tsx
Normal file
@ -0,0 +1,21 @@
|
||||
import * as SliderPrimitive from "@radix-ui/react-slider";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
export const Slider = forwardRef<
|
||||
React.ElementRef<typeof SliderPrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof SliderPrimitive.Root>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SliderPrimitive.Root
|
||||
ref={ref}
|
||||
className={cn("relative flex w-full touch-none select-none items-center", className)}
|
||||
{...props}
|
||||
>
|
||||
<SliderPrimitive.Track className="relative h-2.5 w-full grow overflow-hidden rounded-full bg-secondary">
|
||||
<SliderPrimitive.Range className="absolute h-full bg-primary" />
|
||||
</SliderPrimitive.Track>
|
||||
<SliderPrimitive.Thumb className="block h-5 w-5 rounded-full border-2 border-primary bg-background ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50" />
|
||||
</SliderPrimitive.Root>
|
||||
));
|
||||
|
||||
Slider.displayName = SliderPrimitive.Root.displayName;
|
||||
25
libs/ui/src/components/switch.tsx
Normal file
25
libs/ui/src/components/switch.tsx
Normal file
@ -0,0 +1,25 @@
|
||||
import * as SwitchPrimitives from "@radix-ui/react-switch";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
export const Switch = forwardRef<
|
||||
React.ElementRef<typeof SwitchPrimitives.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<SwitchPrimitives.Root
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"peer inline-flex h-[24px] w-[44px] shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-border",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<SwitchPrimitives.Thumb
|
||||
className={cn(
|
||||
"pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0",
|
||||
)}
|
||||
/>
|
||||
</SwitchPrimitives.Root>
|
||||
));
|
||||
|
||||
Switch.displayName = SwitchPrimitives.Root.displayName;
|
||||
50
libs/ui/src/components/tabs.tsx
Normal file
50
libs/ui/src/components/tabs.tsx
Normal file
@ -0,0 +1,50 @@
|
||||
import * as TabsPrimitive from "@radix-ui/react-tabs";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
export const Tabs = TabsPrimitive.Root;
|
||||
|
||||
export const TabsList = forwardRef<
|
||||
React.ElementRef<typeof TabsPrimitive.List>,
|
||||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<TabsPrimitive.List
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"inline-flex h-9 items-center justify-center rounded bg-secondary-accent px-0.5 text-foreground",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
TabsList.displayName = TabsPrimitive.List.displayName;
|
||||
|
||||
export const TabsTrigger = forwardRef<
|
||||
React.ElementRef<typeof TabsPrimitive.Trigger>,
|
||||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<TabsPrimitive.Trigger
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"inline-flex items-center justify-center whitespace-nowrap rounded-sm px-4 py-1 text-sm font-medium transition-all focus-visible:outline-none focus-visible:ring-0 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName;
|
||||
|
||||
export const TabsContent = forwardRef<
|
||||
React.ElementRef<typeof TabsPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<TabsPrimitive.Content
|
||||
ref={ref}
|
||||
className={cn("mt-3 focus-visible:outline-none focus-visible:ring-0", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
TabsContent.displayName = TabsPrimitive.Content.displayName;
|
||||
117
libs/ui/src/components/toast.tsx
Normal file
117
libs/ui/src/components/toast.tsx
Normal file
@ -0,0 +1,117 @@
|
||||
import { X } from "@phosphor-icons/react";
|
||||
import * as ToastPrimitives from "@radix-ui/react-toast";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { type VariantProps } from "class-variance-authority";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
import { toastVariants } from "../variants/toast";
|
||||
|
||||
export const ToastProvider = ToastPrimitives.Provider;
|
||||
|
||||
export const ToastViewport = forwardRef<
|
||||
React.ElementRef<typeof ToastPrimitives.Viewport>,
|
||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<ToastPrimitives.Viewport
|
||||
ref={ref}
|
||||
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]",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
ToastViewport.displayName = ToastPrimitives.Viewport.displayName;
|
||||
|
||||
export const Toast = forwardRef<
|
||||
React.ElementRef<typeof ToastPrimitives.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> & VariantProps<typeof toastVariants>
|
||||
>(({ className, variant, ...props }, ref) => {
|
||||
return (
|
||||
<ToastPrimitives.Root
|
||||
ref={ref}
|
||||
className={cn(toastVariants({ variant }), className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
Toast.displayName = ToastPrimitives.Root.displayName;
|
||||
|
||||
export const ToastAction = forwardRef<
|
||||
React.ElementRef<typeof ToastPrimitives.Action>,
|
||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<ToastPrimitives.Action
|
||||
ref={ref}
|
||||
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-primary disabled:pointer-events-none disabled:opacity-50",
|
||||
"group/primary:border-border/40 group-hover/primary:border-primary/30 group-hover/primary:bg-primary group-hover/primary:text-primary-foreground group-focus/primary:ring-primary",
|
||||
"group/secondary:border-border/40 group-hover/secondary:border-secondary/30 group-hover/secondary:bg-secondary group-hover/secondary:text-secondary-foreground group-focus/secondary:ring-secondary",
|
||||
"group/error:border-border/40 group-hover/error:border-error/30 group-hover/error:bg-error group-hover/error:text-error-foreground group-focus/error:ring-error",
|
||||
"group/warning:border-border/40 group-hover/warning:border-warning/30 group-hover/warning:bg-warning group-hover/warning:text-warning-foreground group-focus/warning:ring-warning",
|
||||
"group/info:border-border/40 group-hover/info:border-info/30 group-hover/info:bg-info group-hover/info:text-info-foreground group-focus/info:ring-info",
|
||||
"group/success:border-border/40 group-hover/success:border-success/30 group-hover/success:bg-success group-hover/success:text-success-foreground group-focus/success:ring-success",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
ToastAction.displayName = ToastPrimitives.Action.displayName;
|
||||
|
||||
export const ToastClose = forwardRef<
|
||||
React.ElementRef<typeof ToastPrimitives.Close>,
|
||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<ToastPrimitives.Close
|
||||
ref={ref}
|
||||
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/primary:text-primary group-hover/primary:text-primary-foreground group-focus/primary:ring-primary group-focus/primary:ring-offset-primary",
|
||||
"group/secondary:text-secondary group-hover/secondary:text-secondary-foreground group-focus/secondary:ring-secondary group-focus/secondary:ring-offset-secondary",
|
||||
"group/error:text-error group-hover/error:text-error-foreground group-focus/error:ring-error group-focus/error:ring-offset-error",
|
||||
"group/warning:text-warning group-hover/warning:text-warning-foreground group-focus/warning:ring-warning group-focus/warning:ring-offset-warning",
|
||||
"group/info:text-info group-hover/info:text-info-foreground group-focus/info:ring-info group-focus/info:ring-offset-info",
|
||||
"group/success:text-success group-hover/success:text-success-foreground group-focus/success:ring-success group-focus/success:ring-offset-success",
|
||||
className,
|
||||
)}
|
||||
toast-close=""
|
||||
{...props}
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</ToastPrimitives.Close>
|
||||
));
|
||||
|
||||
ToastClose.displayName = ToastPrimitives.Close.displayName;
|
||||
|
||||
export const ToastTitle = forwardRef<
|
||||
React.ElementRef<typeof ToastPrimitives.Title>,
|
||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<ToastPrimitives.Title
|
||||
ref={ref}
|
||||
className={cn("text-sm font-semibold [&+div]:text-xs", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
ToastTitle.displayName = ToastPrimitives.Title.displayName;
|
||||
|
||||
export const ToastDescription = forwardRef<
|
||||
React.ElementRef<typeof ToastPrimitives.Description>,
|
||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<ToastPrimitives.Description
|
||||
ref={ref}
|
||||
className={cn("line-clamp-2 text-sm opacity-90", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
ToastDescription.displayName = ToastPrimitives.Description.displayName;
|
||||
|
||||
export type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>;
|
||||
|
||||
export type ToastActionElement = React.ReactElement<typeof ToastAction>;
|
||||
23
libs/ui/src/components/toggle-group.tsx
Normal file
23
libs/ui/src/components/toggle-group.tsx
Normal file
@ -0,0 +1,23 @@
|
||||
import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { VariantProps } from "class-variance-authority";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
import { toggleVariants } from "../variants/toggle";
|
||||
|
||||
export const ToggleGroup = ToggleGroupPrimitive.Root;
|
||||
|
||||
export const ToggleGroupItem = forwardRef<
|
||||
React.ElementRef<typeof ToggleGroupPrimitive.Item>,
|
||||
React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Item> &
|
||||
VariantProps<typeof toggleVariants>
|
||||
>(({ className, variant, size, ...props }, ref) => (
|
||||
<ToggleGroupPrimitive.Item
|
||||
ref={ref}
|
||||
className={cn(
|
||||
toggleVariants({ variant, size, className }),
|
||||
"rounded-none first:rounded-l last:rounded-r",
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
19
libs/ui/src/components/toggle.tsx
Normal file
19
libs/ui/src/components/toggle.tsx
Normal file
@ -0,0 +1,19 @@
|
||||
import * as TogglePrimitive from "@radix-ui/react-toggle";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { type VariantProps } from "class-variance-authority";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
import { toggleVariants } from "../variants/toggle";
|
||||
|
||||
export const Toggle = forwardRef<
|
||||
React.ElementRef<typeof TogglePrimitive.Root>,
|
||||
React.ComponentPropsWithoutRef<typeof TogglePrimitive.Root> & VariantProps<typeof toggleVariants>
|
||||
>(({ className, variant, size, ...props }, ref) => (
|
||||
<TogglePrimitive.Root
|
||||
ref={ref}
|
||||
className={cn(toggleVariants({ variant, size, className }))}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
Toggle.displayName = TogglePrimitive.Root.displayName;
|
||||
41
libs/ui/src/components/tooltip.tsx
Normal file
41
libs/ui/src/components/tooltip.tsx
Normal file
@ -0,0 +1,41 @@
|
||||
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
||||
import { cn } from "@reactive-resume/utils";
|
||||
import { forwardRef } from "react";
|
||||
|
||||
export const TooltipProvider = TooltipPrimitive.Provider;
|
||||
|
||||
export const TooltipRoot = TooltipPrimitive.Root;
|
||||
|
||||
export const TooltipTrigger = TooltipPrimitive.Trigger;
|
||||
|
||||
export const TooltipContent = forwardRef<
|
||||
React.ElementRef<typeof TooltipPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
|
||||
>(({ className, children, sideOffset = 6, ...props }, ref) => (
|
||||
<TooltipPrimitive.Portal>
|
||||
<TooltipPrimitive.Content
|
||||
ref={ref}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"z-50 overflow-hidden rounded bg-primary px-3 py-1.5 text-xs text-primary-foreground shadow-sm 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",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</TooltipPrimitive.Content>
|
||||
</TooltipPrimitive.Portal>
|
||||
));
|
||||
|
||||
TooltipContent.displayName = TooltipPrimitive.Content.displayName;
|
||||
|
||||
type TooltipProps = React.ComponentPropsWithoutRef<typeof TooltipContent> & {
|
||||
content: React.ReactNode;
|
||||
};
|
||||
|
||||
export const Tooltip = ({ content, children, ...props }: TooltipProps) => (
|
||||
<TooltipRoot>
|
||||
<TooltipTrigger asChild>{children}</TooltipTrigger>
|
||||
<TooltipContent {...props}>{content}</TooltipContent>
|
||||
</TooltipRoot>
|
||||
);
|
||||
2
libs/ui/src/index.ts
Normal file
2
libs/ui/src/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from "./components";
|
||||
export * from "./variants";
|
||||
21
libs/ui/src/variants/alert.ts
Normal file
21
libs/ui/src/variants/alert.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { cva } from "class-variance-authority";
|
||||
|
||||
export const alertVariants = cva(
|
||||
"relative w-full rounded p-4 transition-colors [&>svg+div]:translate-y-[-4px] [&>svg]:absolute [&>svg]:left-3.5 [&>svg]:top-[18px] [&>svg~*]:pl-6",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "border bg-background text-foreground [&>svg]:text-foreground",
|
||||
primary: "bg-primary text-primary-foreground [&>svg]:text-primary-foreground",
|
||||
secondary: "bg-secondary text-secondary-foreground [&>svg]:text-secondary-foreground",
|
||||
error: "bg-error text-error-foreground [&>svg]:text-error-foreground",
|
||||
warning: "bg-warning text-warning-foreground [&>svg]:text-warning-foreground",
|
||||
info: "bg-info text-info-foreground [&>svg]:text-info-foreground",
|
||||
success: "bg-success text-success-foreground [&>svg]:text-success-foreground",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
},
|
||||
);
|
||||
32
libs/ui/src/variants/badge.ts
Normal file
32
libs/ui/src/variants/badge.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { cva } from "class-variance-authority";
|
||||
|
||||
export const badgeVariants = cva(
|
||||
"inline-flex items-center rounded-full border px-3 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
primary: "border-primary bg-primary text-primary-foreground",
|
||||
secondary: "border-secondary bg-secondary text-secondary-foreground",
|
||||
error: "border-error bg-error text-error-foreground",
|
||||
warning: "border-warning bg-warning text-warning-foreground",
|
||||
info: "border-info bg-info text-info-foreground",
|
||||
success: "border-success bg-success text-success-foreground",
|
||||
},
|
||||
outline: {
|
||||
true: "bg-transparent",
|
||||
},
|
||||
},
|
||||
compoundVariants: [
|
||||
{ outline: true, variant: "primary", className: "text-primary" },
|
||||
{ outline: true, variant: "secondary", className: "text-secondary" },
|
||||
{ outline: true, variant: "error", className: "text-error" },
|
||||
{ outline: true, variant: "warning", className: "text-warning" },
|
||||
{ outline: true, variant: "info", className: "text-info" },
|
||||
{ outline: true, variant: "success", className: "text-success" },
|
||||
],
|
||||
defaultVariants: {
|
||||
variant: "primary",
|
||||
outline: false,
|
||||
},
|
||||
},
|
||||
);
|
||||
40
libs/ui/src/variants/button.ts
Normal file
40
libs/ui/src/variants/button.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { cva } from "class-variance-authority";
|
||||
|
||||
export const buttonVariants = cva(
|
||||
[
|
||||
"inline-flex items-center justify-center rounded-sm text-sm font-medium ring-offset-background disabled:pointer-events-none disabled:opacity-50",
|
||||
"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary focus-visible:ring-offset-2",
|
||||
"scale-100 transition-[transform,background-color] active:scale-95",
|
||||
],
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
primary: "bg-primary text-primary-foreground hover:bg-primary/80",
|
||||
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
||||
error: "bg-error text-error-foreground hover:bg-error/80",
|
||||
warning: "bg-warning text-warning-foreground hover:bg-warning/80",
|
||||
info: "bg-info text-info-foreground hover:bg-info/80",
|
||||
success: "bg-success text-success-foreground hover:bg-success/80",
|
||||
outline:
|
||||
"border border-secondary bg-transparent hover:bg-secondary hover:text-secondary-foreground",
|
||||
ghost: "hover:bg-secondary hover:text-secondary-foreground",
|
||||
link: "text-primary underline-offset-4 hover:underline",
|
||||
},
|
||||
size: {
|
||||
sm: "h-8 px-4 text-xs",
|
||||
md: "h-9 px-5",
|
||||
lg: "h-10 px-6",
|
||||
icon: "h-9 w-9",
|
||||
},
|
||||
},
|
||||
compoundVariants: [
|
||||
{ variant: "link", size: "sm", className: "h-auto px-0" },
|
||||
{ variant: "link", size: "md", className: "h-auto px-0" },
|
||||
{ variant: "link", size: "lg", className: "h-auto px-0" },
|
||||
],
|
||||
defaultVariants: {
|
||||
variant: "primary",
|
||||
size: "md",
|
||||
},
|
||||
},
|
||||
);
|
||||
6
libs/ui/src/variants/index.ts
Normal file
6
libs/ui/src/variants/index.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export * from "./alert";
|
||||
export * from "./badge";
|
||||
export * from "./button";
|
||||
export * from "./sheet";
|
||||
export * from "./toast";
|
||||
export * from "./toggle";
|
||||
20
libs/ui/src/variants/sheet.ts
Normal file
20
libs/ui/src/variants/sheet.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { cva } from "class-variance-authority";
|
||||
|
||||
export const sheetVariants = cva(
|
||||
"fixed z-50 gap-4 bg-background p-4 shadow-sm transition ease-in-out focus:outline-none data-[state=closed]:duration-300 data-[state=open]:duration-500 data-[state=open]:animate-in data-[state=closed]:animate-out",
|
||||
{
|
||||
variants: {
|
||||
side: {
|
||||
top: "inset-x-0 top-0 w-screen border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",
|
||||
bottom:
|
||||
"inset-x-0 bottom-0 w-screen border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",
|
||||
left: "inset-y-0 left-0 h-screen w-11/12 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",
|
||||
right:
|
||||
"inset-y-0 right-0 h-screen w-11/12 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
side: "right",
|
||||
},
|
||||
},
|
||||
);
|
||||
21
libs/ui/src/variants/toast.ts
Normal file
21
libs/ui/src/variants/toast.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { cva } from "class-variance-authority";
|
||||
|
||||
export 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",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "border bg-background text-foreground",
|
||||
primary: "group/primary border-primary bg-primary text-primary-foreground",
|
||||
secondary: "group/secondary border-secondary bg-secondary text-secondary-foreground",
|
||||
error: "group/error border-error bg-error text-error-foreground",
|
||||
warning: "group/warning border-warning bg-warning text-warning-foreground",
|
||||
info: "group/info border-info bg-info text-info-foreground",
|
||||
success: "group/success border-success bg-success text-success-foreground",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
},
|
||||
);
|
||||
22
libs/ui/src/variants/toggle.ts
Normal file
22
libs/ui/src/variants/toggle.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { cva } from "class-variance-authority";
|
||||
|
||||
export const toggleVariants = cva(
|
||||
"inline-flex items-center justify-center rounded text-sm font-medium transition-colors hover:bg-secondary/60 hover:text-secondary-foreground focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-secondary data-[state=on]:text-secondary-foreground",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-transparent",
|
||||
outline: "border bg-transparent hover:bg-secondary/60 hover:text-secondary-foreground",
|
||||
},
|
||||
size: {
|
||||
sm: "h-8 w-8",
|
||||
md: "h-9 w-9",
|
||||
lg: "h-10 w-10",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "md",
|
||||
},
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user