feat(ui): add plain editable copy and visible media drag grips
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nodedc/ui-react",
|
||||
"version": "0.7.7",
|
||||
"version": "0.7.8",
|
||||
"type": "module",
|
||||
"files": [
|
||||
"dist"
|
||||
@@ -21,7 +21,7 @@
|
||||
"@dnd-kit/core": "^6.3.1",
|
||||
"@dnd-kit/sortable": "^10.0.0",
|
||||
"@dnd-kit/utilities": "^3.2.2",
|
||||
"@nodedc/ui-core": "0.7.2",
|
||||
"@nodedc/ui-core": "0.7.3",
|
||||
"lucide-react": "^0.468.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
||||
@@ -52,8 +52,9 @@ const copyRect = (rect: DragRect | null | undefined): DragRect | undefined => re
|
||||
height: rect.height,
|
||||
}) : undefined;
|
||||
|
||||
export function DragHandle({ label = "Перетащить", listeners, attributes, className }: {
|
||||
export function DragHandle({ label = "Перетащить", listeners, attributes, className, surface="none" }: {
|
||||
label?: string;
|
||||
surface?: "none" | "control";
|
||||
listeners?: ReturnType<typeof useDraggable>["listeners"];
|
||||
attributes?: ReturnType<typeof useDraggable>["attributes"];
|
||||
className?: string;
|
||||
@@ -62,6 +63,7 @@ export function DragHandle({ label = "Перетащить", listeners, attribut
|
||||
<button
|
||||
type="button"
|
||||
className={cn("nodedc-drag-handle", className)}
|
||||
data-surface={surface}
|
||||
aria-label={label}
|
||||
{...attributes}
|
||||
{...listeners}
|
||||
@@ -126,8 +128,9 @@ export function SortableScope({ ids, children, layout="list" }: { ids: string[];
|
||||
return <SortableLayoutContext.Provider value={layout}><SortableContext items={ids} strategy={layout==="grid"?rectSortingStrategy:verticalListSortingStrategy}>{children}</SortableContext></SortableLayoutContext.Provider>;
|
||||
}
|
||||
|
||||
export function SortableItem({ id, data, className, children }: {
|
||||
export function SortableItem({ id, data, className, children, handleSurface="none" }: {
|
||||
id: string;
|
||||
handleSurface?: "none" | "control";
|
||||
data?: NodedcDragData;
|
||||
className?: string;
|
||||
children: (state: { handle: ReactNode; isDragging: boolean }) => ReactNode;
|
||||
@@ -141,13 +144,14 @@ export function SortableItem({ id, data, className, children }: {
|
||||
className={cn(className, isDragging && "is-dragging")}
|
||||
style={{ transform: CSS.Transform.toString(verticalTransform), transition, opacity: isDragging ? 0.65 : undefined }}
|
||||
>
|
||||
{children({ handle: <DragHandle listeners={listeners} attributes={attributes} />, isDragging })}
|
||||
{children({ handle: <DragHandle surface={handleSurface} listeners={listeners} attributes={attributes} />, isDragging })}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function SortableList<T>({ items, getId, className, onReorder, children, layout="list" }: {
|
||||
export function SortableList<T>({ items, getId, className, onReorder, children, layout="list", handleSurface="none" }: {
|
||||
items: T[];
|
||||
handleSurface?: "none" | "control";
|
||||
layout?: "list" | "grid";
|
||||
getId: (item: T) => string;
|
||||
className?: string;
|
||||
@@ -165,7 +169,7 @@ export function SortableList<T>({ items, getId, className, onReorder, children,
|
||||
<SortableScope ids={ids} layout={layout}>
|
||||
<div className={className}>
|
||||
{items.map((item) => (
|
||||
<SortableItem key={getId(item)} id={getId(item)}>
|
||||
<SortableItem key={getId(item)} id={getId(item)} handleSurface={handleSurface}>
|
||||
{(state) => children(item, state)}
|
||||
</SortableItem>
|
||||
))}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useId, type InputHTMLAttributes, type ReactNode, type TextareaHTMLAttributes } from "react";
|
||||
import { useId, useLayoutEffect, useRef, type InputHTMLAttributes, type ReactNode, type TextareaHTMLAttributes } from "react";
|
||||
import { cn } from "./cn.js";
|
||||
|
||||
export interface FieldFrameProps {
|
||||
@@ -29,6 +29,8 @@ export interface TextFieldProps extends InputHTMLAttributes<HTMLInputElement> {
|
||||
hint?: string;
|
||||
description?: string;
|
||||
fieldClassName?: string;
|
||||
/** Plain text appearance for directly editable detail content. Keep an accessible name. */
|
||||
appearance?: "default" | "plain";
|
||||
}
|
||||
|
||||
export function TextField({
|
||||
@@ -36,6 +38,7 @@ export function TextField({
|
||||
hint,
|
||||
description,
|
||||
fieldClassName,
|
||||
appearance = "default",
|
||||
className,
|
||||
id,
|
||||
...props
|
||||
@@ -43,7 +46,7 @@ export function TextField({
|
||||
const generatedId = useId();
|
||||
const controlId = id ?? generatedId;
|
||||
return (
|
||||
<FieldFrame label={label} hint={hint} description={description} htmlFor={controlId} className={fieldClassName}>
|
||||
<FieldFrame label={label} hint={hint} description={description} htmlFor={controlId} className={cn(fieldClassName, appearance === "plain" && "nodedc-field--plain", !label && "nodedc-field--unlabelled")}>
|
||||
<input id={controlId} className={cn("nodedc-field__control", className)} {...props} />
|
||||
</FieldFrame>
|
||||
);
|
||||
@@ -54,6 +57,8 @@ export interface TextAreaFieldProps extends TextareaHTMLAttributes<HTMLTextAreaE
|
||||
hint?: string;
|
||||
description?: string;
|
||||
fieldClassName?: string;
|
||||
/** Plain text appearance for directly editable detail content. Keep an accessible name. */
|
||||
appearance?: "default" | "plain";
|
||||
}
|
||||
|
||||
export function TextAreaField({
|
||||
@@ -61,15 +66,29 @@ export function TextAreaField({
|
||||
hint,
|
||||
description,
|
||||
fieldClassName,
|
||||
appearance = "default",
|
||||
className,
|
||||
id,
|
||||
...props
|
||||
}: TextAreaFieldProps) {
|
||||
const generatedId = useId();
|
||||
const controlId = id ?? generatedId;
|
||||
const area = useRef<HTMLTextAreaElement>(null);
|
||||
useLayoutEffect(() => {
|
||||
const el = area.current;
|
||||
if (!el || appearance !== "plain") return;
|
||||
const resize = () => { el.style.height = "auto"; el.style.height = el.scrollHeight + "px"; };
|
||||
resize();
|
||||
let width = el.clientWidth;
|
||||
const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(() => {
|
||||
if (el.clientWidth !== width) { width = el.clientWidth; resize(); }
|
||||
});
|
||||
observer?.observe(el);
|
||||
return () => observer?.disconnect();
|
||||
}, [appearance, props.value]);
|
||||
return (
|
||||
<FieldFrame label={label} hint={hint} description={description} htmlFor={controlId} className={fieldClassName}>
|
||||
<textarea id={controlId} className={cn("nodedc-field__control", className)} {...props} />
|
||||
<FieldFrame label={label} hint={hint} description={description} htmlFor={controlId} className={cn(fieldClassName, appearance === "plain" && "nodedc-field--plain", !label && "nodedc-field--unlabelled")}>
|
||||
<textarea ref={area} id={controlId} className={cn("nodedc-field__control", className)} {...props} />
|
||||
</FieldFrame>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user