feat: status creating
This commit is contained in:
@ -12,7 +12,7 @@ import {
|
||||
horizontalListSortingStrategy,
|
||||
SortableContext,
|
||||
} from "@dnd-kit/sortable";
|
||||
import { Group, ScrollArea } from "@mantine/core";
|
||||
import { Group } from "@mantine/core";
|
||||
import useDndSensors from "@/app/deals/hooks/useSensors";
|
||||
import SortableItem from "@/components/dnd/SortableItem";
|
||||
import { BaseDraggable } from "@/components/dnd/types/types";
|
||||
@ -59,67 +59,63 @@ const FunnelDnd = <
|
||||
const sensors = useDndSensors();
|
||||
|
||||
return (
|
||||
<ScrollArea
|
||||
offsetScrollbars="x"
|
||||
scrollbarSize="0.5rem">
|
||||
<DndContext
|
||||
sensors={sensors}
|
||||
collisionDetection={closestCorners}
|
||||
onDragStart={onDragStart}
|
||||
onDragOver={onDragOver}
|
||||
onDragEnd={onDragEnd}>
|
||||
<SortableContext
|
||||
items={containers.map(getContainerId)}
|
||||
strategy={horizontalListSortingStrategy}>
|
||||
<Group
|
||||
gap="xs"
|
||||
wrap="nowrap"
|
||||
align="start">
|
||||
{containers.map(container => {
|
||||
const containerItems = getItemsByContainer(
|
||||
container,
|
||||
items
|
||||
);
|
||||
const containerId = getContainerId(container);
|
||||
return (
|
||||
<SortableItem
|
||||
key={containerId}
|
||||
id={containerId}>
|
||||
{renderContainer(
|
||||
container,
|
||||
<FunnelColumn
|
||||
id={containerId}
|
||||
items={containerItems}
|
||||
renderItem={renderItem}
|
||||
/>
|
||||
)}
|
||||
</SortableItem>
|
||||
);
|
||||
})}
|
||||
<FunnelOverlay
|
||||
activeContainer={activeContainer}
|
||||
activeItem={activeItem}
|
||||
renderContainer={container => {
|
||||
const containerItems = getItemsByContainer(
|
||||
container,
|
||||
items
|
||||
);
|
||||
const containerId = getContainerId(container);
|
||||
return renderContainerOverlay(
|
||||
<DndContext
|
||||
sensors={sensors}
|
||||
collisionDetection={closestCorners}
|
||||
onDragStart={onDragStart}
|
||||
onDragOver={onDragOver}
|
||||
onDragEnd={onDragEnd}>
|
||||
<SortableContext
|
||||
items={containers.map(getContainerId)}
|
||||
strategy={horizontalListSortingStrategy}>
|
||||
<Group
|
||||
gap="xs"
|
||||
wrap="nowrap"
|
||||
align="start">
|
||||
{containers.map(container => {
|
||||
const containerItems = getItemsByContainer(
|
||||
container,
|
||||
items
|
||||
);
|
||||
const containerId = getContainerId(container);
|
||||
return (
|
||||
<SortableItem
|
||||
key={containerId}
|
||||
id={containerId}>
|
||||
{renderContainer(
|
||||
container,
|
||||
<FunnelColumn
|
||||
id={containerId}
|
||||
items={containerItems}
|
||||
renderItem={renderItem}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
renderItem={renderItemOverlay}
|
||||
/>
|
||||
</Group>
|
||||
</SortableContext>
|
||||
</DndContext>
|
||||
</ScrollArea>
|
||||
)}
|
||||
</SortableItem>
|
||||
);
|
||||
})}
|
||||
<FunnelOverlay
|
||||
activeContainer={activeContainer}
|
||||
activeItem={activeItem}
|
||||
renderContainer={container => {
|
||||
const containerItems = getItemsByContainer(
|
||||
container,
|
||||
items
|
||||
);
|
||||
const containerId = getContainerId(container);
|
||||
return renderContainerOverlay(
|
||||
container,
|
||||
<FunnelColumn
|
||||
id={containerId}
|
||||
items={containerItems}
|
||||
renderItem={renderItem}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
renderItem={renderItemOverlay}
|
||||
/>
|
||||
</Group>
|
||||
</SortableContext>
|
||||
</DndContext>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
85
src/components/ui/InPlaceInput/InPlaceInput.tsx
Normal file
85
src/components/ui/InPlaceInput/InPlaceInput.tsx
Normal file
@ -0,0 +1,85 @@
|
||||
import React, { FC, ReactNode, useEffect, useRef, useState } from "react";
|
||||
import { TextInput } from "@mantine/core";
|
||||
import { Styles } from "@mantine/core/lib/core/styles-api/styles-api.types";
|
||||
|
||||
type Props = {
|
||||
defaultValue?: string;
|
||||
onComplete: (value: string) => void;
|
||||
placeholder?: string;
|
||||
getChildren: (startEditing: () => void) => ReactNode;
|
||||
inputStyles?: Styles<any>;
|
||||
};
|
||||
|
||||
const InPlaceInput: FC<Props> = ({
|
||||
onComplete,
|
||||
placeholder,
|
||||
inputStyles,
|
||||
getChildren,
|
||||
defaultValue = "",
|
||||
}) => {
|
||||
const [isWriting, setIsWriting] = useState<boolean>(false);
|
||||
const [value, setValue] = useState<string>(defaultValue);
|
||||
console.log(value);
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (isWriting && inputRef.current) {
|
||||
inputRef.current.focus();
|
||||
}
|
||||
}, [isWriting]);
|
||||
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
if (
|
||||
isWriting &&
|
||||
inputRef.current &&
|
||||
!inputRef.current.contains(event.target as Node)
|
||||
) {
|
||||
onCompleteCreating();
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener("mousedown", handleClickOutside);
|
||||
return () =>
|
||||
document.removeEventListener("mousedown", handleClickOutside);
|
||||
}, [isWriting, value]);
|
||||
|
||||
const onStartCreating = () => {
|
||||
setValue(defaultValue);
|
||||
setIsWriting(true);
|
||||
};
|
||||
|
||||
const onCancelCreating = () => {
|
||||
setValue(defaultValue);
|
||||
setIsWriting(false);
|
||||
};
|
||||
|
||||
const onCompleteCreating = () => {
|
||||
const localValue = value.trim();
|
||||
if (localValue) {
|
||||
onComplete(localValue);
|
||||
}
|
||||
setIsWriting(false);
|
||||
};
|
||||
|
||||
if (isWriting) {
|
||||
return (
|
||||
<TextInput
|
||||
ref={inputRef}
|
||||
placeholder={placeholder}
|
||||
variant={"unstyled"}
|
||||
value={value}
|
||||
onChange={e => setValue(e.target.value)}
|
||||
onKeyDown={e => {
|
||||
if (e.key === "Enter") onCompleteCreating();
|
||||
if (e.key === "Escape") onCancelCreating();
|
||||
}}
|
||||
styles={inputStyles}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return getChildren(onStartCreating);
|
||||
};
|
||||
|
||||
export default InPlaceInput;
|
||||
Reference in New Issue
Block a user