ui(components): New Dialog and Modal components for ui-next (#4772)
Co-authored-by: sedghi <ar.sedghi@gmail.com>
This commit is contained in:
1 parent
62b4fa3e89
commit
a3b51aa8db
90 files changed
+3459
-1357
No files matched your search
@@ -0,0 +1,114 @@
|
||||
import * as React from 'react';
|
||||
import { cn } from '../../lib/utils';
|
||||
import { Button } from '../Button';
|
||||
import { Icons } from '../Icons';
|
||||
|
||||
interface AboutModalProps {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function AboutModal({ children, className }: AboutModalProps) {
|
||||
return <div className={cn('space-y-1 text-center', className)}>{children}</div>;
|
||||
}
|
||||
|
||||
/** Sub component: Product Name */
|
||||
interface ProductNameProps {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
function ProductName({ children, className }: ProductNameProps) {
|
||||
return (
|
||||
<div className={cn('text-foreground pt-3 text-2xl font-medium leading-none', className)}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Sub-component: Product Version */
|
||||
interface ProductVersionProps {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
function ProductVersion({ children, className }: ProductVersionProps) {
|
||||
return (
|
||||
<div className={cn('text-muted-foreground text-2xl font-light leading-none', className)}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Sub-component: Product Beta */
|
||||
interface ProductBetaProps {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
function ProductBeta({ children, className }: ProductBetaProps) {
|
||||
return (
|
||||
<div className={cn('text-muted-foreground text-xl font-light', className)}>{children}</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Sub-component: Body (wraps all detail items) */
|
||||
interface BodyProps {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
function Body({ children, className }: BodyProps) {
|
||||
return (
|
||||
<div className={cn('my-3 flex flex-col items-center space-y-0', className)}>{children}</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Sub-component: Detail Item */
|
||||
interface DetailItemProps {
|
||||
label: string;
|
||||
value: string;
|
||||
className?: string;
|
||||
}
|
||||
function DetailItem({ label, value, className }: DetailItemProps) {
|
||||
return (
|
||||
<div className={cn('flex flex-col items-center', className)}>
|
||||
<div className="text-muted-foreground pt-2 text-sm font-semibold tracking-wide">{label}</div>
|
||||
<div className="text-muted-foreground text-sm">{value}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Sub-component: Social Item */
|
||||
interface SocialItemProps {
|
||||
icon: string;
|
||||
url: string;
|
||||
text: string;
|
||||
className?: string;
|
||||
}
|
||||
function SocialItem({ icon, url, text, className }: SocialItemProps) {
|
||||
return (
|
||||
<div className={cn('text-foreground flex items-center', className)}>
|
||||
<div className="inline-block">
|
||||
<Icons.ByName name={icon} />
|
||||
</div>
|
||||
<Button
|
||||
asChild
|
||||
variant="link"
|
||||
className="py-6 text-lg"
|
||||
>
|
||||
<a
|
||||
href={`https://github.com/${url}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
{text}
|
||||
</a>
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Attach sub-components to AboutModal as static properties */
|
||||
AboutModal.ProductName = ProductName;
|
||||
AboutModal.ProductVersion = ProductVersion;
|
||||
AboutModal.ProductBeta = ProductBeta;
|
||||
AboutModal.Body = Body;
|
||||
AboutModal.DetailItem = DetailItem;
|
||||
AboutModal.SocialItem = SocialItem;
|
||||
@@ -0,0 +1,231 @@
|
||||
import * as React from 'react';
|
||||
import { Input } from '../Input/Input';
|
||||
import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from '../Select/Select';
|
||||
import { Switch } from '../Switch/Switch';
|
||||
import { cn } from '../../lib/utils';
|
||||
|
||||
interface ImageModalProps {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main ImageModal container. By default, we do not force any
|
||||
* layout here. We'll use a "Body" subcomponent for the main area
|
||||
* that sets up a flex row with a 70/30 split.
|
||||
*/
|
||||
export function ImageModal({ children, className }: ImageModalProps) {
|
||||
return <div className={cn(className)}>{children}</div>;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Body subcomponent */
|
||||
|
||||
interface ImageBodyProps {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
function ImageBody({ children, className }: ImageBodyProps) {
|
||||
return <div className={cn('flex flex-col sm:flex-row', className)}>{children}</div>;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ImageVisual subcomponent */
|
||||
|
||||
interface ImageVisualProps {
|
||||
className?: string;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
function ImageVisual({ children, className }: ImageVisualProps) {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'flex-1 items-center justify-center rounded-2xl bg-black/80 p-4 sm:flex-[7]',
|
||||
'flex', // ensure the container is a flex box
|
||||
className
|
||||
)}
|
||||
>
|
||||
<div className="h-[512px] w-[512px] overflow-auto">{children}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ImageOptions subcomponent */
|
||||
|
||||
interface ImageOptionsProps {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
function ImageOptions({ children, className }: ImageOptionsProps) {
|
||||
return <div className={cn('flex-1 space-y-5 p-4 sm:flex-[3]', className)}>{children}</div>;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Filename subcomponent */
|
||||
|
||||
interface FilenameProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'children'> {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
/** Handler is optional. If not provided, default to a no‐op. */
|
||||
onChange?: React.ChangeEventHandler<HTMLInputElement>;
|
||||
}
|
||||
|
||||
function Filename({ children, className, value, onChange, ...props }: FilenameProps) {
|
||||
return (
|
||||
<div className={cn('text-foreground space-y-1', className)}>
|
||||
<label className="block text-base">{children}</label>
|
||||
<Input
|
||||
{...props}
|
||||
className={cn('w-full', className)}
|
||||
value={value}
|
||||
onChange={onChange ?? (() => {})}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Filetype subcomponent */
|
||||
|
||||
interface FiletypeProps {
|
||||
selected: string;
|
||||
/** Handler is optional. If not provided, we do nothing. */
|
||||
onSelect?: (val: string) => void;
|
||||
className?: string;
|
||||
/** Array of file type options */
|
||||
options?: Array<{ value: string; label: string }>;
|
||||
}
|
||||
|
||||
function Filetype({ selected, onSelect, className, options = [] }: FiletypeProps) {
|
||||
const defaultOptions = [
|
||||
{ value: 'jpg', label: 'JPG' },
|
||||
{ value: 'png', label: 'PNG' },
|
||||
];
|
||||
|
||||
const fileTypeOptions = options.length ? options : defaultOptions;
|
||||
|
||||
return (
|
||||
<Select
|
||||
value={selected}
|
||||
onValueChange={val => onSelect?.(val)}
|
||||
>
|
||||
<SelectTrigger
|
||||
aria-label="File type"
|
||||
className={cn('w-[5.5rem] sm:w-24', className)}
|
||||
>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{fileTypeOptions.map(option => (
|
||||
<SelectItem
|
||||
key={option.value}
|
||||
value={option.value}
|
||||
>
|
||||
{option.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ImageSize subcomponent */
|
||||
|
||||
interface ImageSizeProps {
|
||||
children: React.ReactNode;
|
||||
width: string;
|
||||
height: string;
|
||||
/** Handlers optional. If not provided, default no‐op. */
|
||||
onWidthChange?: React.ChangeEventHandler<HTMLInputElement>;
|
||||
onHeightChange?: React.ChangeEventHandler<HTMLInputElement>;
|
||||
className?: string;
|
||||
maxWidth?: string;
|
||||
maxHeight?: string;
|
||||
}
|
||||
|
||||
function ImageSize({
|
||||
children,
|
||||
width,
|
||||
height,
|
||||
onWidthChange,
|
||||
onHeightChange,
|
||||
className,
|
||||
maxWidth,
|
||||
maxHeight,
|
||||
}: ImageSizeProps) {
|
||||
return (
|
||||
<div className={cn('text-foreground space-y-1', className)}>
|
||||
<label className="block text-base">{children}</label>
|
||||
|
||||
{/* Flex container for width/height inputs */}
|
||||
<div className="flex items-center space-x-4">
|
||||
{/* Width group */}
|
||||
<div className="flex items-center space-x-2">
|
||||
<span className="text-foreground text-base">W</span>
|
||||
<Input
|
||||
value={width}
|
||||
onChange={onWidthChange ?? (() => {})}
|
||||
placeholder="Width"
|
||||
className="w-20"
|
||||
max={maxWidth}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Height group */}
|
||||
<div className="text-foreground flex items-center space-x-2 text-base">
|
||||
<span className="text-foreground text-base">H</span>
|
||||
<Input
|
||||
value={height}
|
||||
onChange={onHeightChange ?? (() => {})}
|
||||
placeholder="Height"
|
||||
className="w-20"
|
||||
max={maxHeight}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* SwitchOption subcomponent */
|
||||
|
||||
interface SwitchOptionProps {
|
||||
children: React.ReactNode;
|
||||
checked?: boolean;
|
||||
defaultChecked?: boolean;
|
||||
onCheckedChange?: (checked: boolean) => void;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
function SwitchOption({
|
||||
children,
|
||||
checked,
|
||||
defaultChecked,
|
||||
onCheckedChange,
|
||||
className,
|
||||
}: SwitchOptionProps) {
|
||||
return (
|
||||
<div className={cn('text-foreground flex items-center space-x-2', className)}>
|
||||
<Switch
|
||||
checked={checked}
|
||||
defaultChecked={defaultChecked}
|
||||
onCheckedChange={val => onCheckedChange?.(val)}
|
||||
/>
|
||||
<span className="text-base">{children}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Attach subcomponents onto the main ImageModal function. */
|
||||
|
||||
ImageModal.Body = ImageBody;
|
||||
ImageModal.ImageVisual = ImageVisual;
|
||||
ImageModal.ImageOptions = ImageOptions;
|
||||
ImageModal.Filename = Filename;
|
||||
ImageModal.Filetype = Filetype;
|
||||
ImageModal.ImageSize = ImageSize;
|
||||
ImageModal.SwitchOption = SwitchOption;
|
||||
@@ -0,0 +1,120 @@
|
||||
import * as React from 'react';
|
||||
import { Label } from '../Label';
|
||||
import { Input } from '../Input';
|
||||
import { cn } from '../../lib/utils';
|
||||
|
||||
interface UserPreferencesModalProps {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function UserPreferencesModal({ children, className }: UserPreferencesModalProps) {
|
||||
return (
|
||||
<div className={cn('flex max-h-[80vh] w-full max-w-4xl flex-col overflow-hidden', className)}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Body
|
||||
* Automatically wraps content in a scrollable area.
|
||||
*/
|
||||
interface BodyProps {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
function Body({ children, className }: BodyProps) {
|
||||
return (
|
||||
<div className={cn('flex-1 overflow-y-auto', className)}>
|
||||
<div className={cn('mt-1 mb-4 flex flex-col space-y-4', className)}>{children}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Subheading
|
||||
* Section labels
|
||||
*/
|
||||
interface SubHeadingProps {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
function SubHeading({ children, className }: SubHeadingProps) {
|
||||
return <span className={cn('text-muted-foreground text-lg', className)}>{children}</span>;
|
||||
}
|
||||
|
||||
/** Responsive 3-column grid for hotkeys, etc. */
|
||||
interface HotkeysGridProps {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
function HotkeysGrid({ children, className }: HotkeysGridProps) {
|
||||
return (
|
||||
<div className={cn('grid grid-cols-1 gap-3 gap-x-16 md:grid-cols-2 lg:grid-cols-3', className)}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** A single hotkey row: label + input */
|
||||
interface HotkeyProps {
|
||||
label: string;
|
||||
placeholder?: string;
|
||||
className?: string;
|
||||
value?: string;
|
||||
onChange?: (value: string) => void;
|
||||
hotkeys?: {
|
||||
record: (callback: (sequence: string[]) => void) => void;
|
||||
pause: () => void;
|
||||
unpause: () => void;
|
||||
startRecording: () => void;
|
||||
};
|
||||
}
|
||||
|
||||
function Hotkey({ label, placeholder, className, value, onChange, hotkeys }: HotkeyProps) {
|
||||
const [isRecording, setIsRecording] = React.useState(false);
|
||||
|
||||
const onInputKeyDown = (event: React.KeyboardEvent) => {
|
||||
event.preventDefault();
|
||||
hotkeys?.record((sequence: string[]) => {
|
||||
const keys = sequence.join('+');
|
||||
hotkeys?.unpause();
|
||||
setIsRecording(false);
|
||||
onChange?.(keys);
|
||||
});
|
||||
};
|
||||
|
||||
const onFocus = () => {
|
||||
setIsRecording(true);
|
||||
hotkeys?.pause();
|
||||
hotkeys?.startRecording();
|
||||
};
|
||||
|
||||
const onBlur = () => {
|
||||
setIsRecording(false);
|
||||
hotkeys?.unpause();
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={cn('flex items-center justify-between space-x-2', className)}>
|
||||
<Label className="whitespace-nowrap">{label}</Label>
|
||||
<Input
|
||||
className={cn(
|
||||
'w-16 text-center transition-colors',
|
||||
isRecording && 'bg-accent text-accent-foreground caret-accent-foreground'
|
||||
)}
|
||||
placeholder={isRecording ? 'Press keys...' : placeholder}
|
||||
value={value}
|
||||
onKeyDown={onInputKeyDown}
|
||||
onFocus={onFocus}
|
||||
onBlur={onBlur}
|
||||
readOnly={!isRecording}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Attach subcomponents as static properties for a nicer API */
|
||||
UserPreferencesModal.Body = Body;
|
||||
UserPreferencesModal.HotkeysGrid = HotkeysGrid;
|
||||
UserPreferencesModal.Hotkey = Hotkey;
|
||||
UserPreferencesModal.SubHeading = SubHeading;
|
||||
@@ -0,0 +1,3 @@
|
||||
export { UserPreferencesModal } from './UserPreferencesModal';
|
||||
export { ImageModal } from './ImageModal';
|
||||
export { AboutModal } from './AboutModal';
|
||||
Reference in new issue
Block a user