mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-16 11:20:10 +01:00
- added checkbox for multy selection
This commit is contained in:
parent
40de9d7bd5
commit
a3c5480442
@ -1,7 +1,10 @@
|
|||||||
|
import { PaperPlaneRight } from "@phosphor-icons/react";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
const OptionSelect = ({ data, settings, submit, message, setMessage }) => {
|
const OptionSelect = ({ data, settings, submit, message, setMessage }) => {
|
||||||
|
const [selectedOptions, setSelectedOptions] = useState([]);
|
||||||
const [submitMessage, setSubmitMessage] = useState(false);
|
const [submitMessage, setSubmitMessage] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (submitMessage) {
|
if (submitMessage) {
|
||||||
submit();
|
submit();
|
||||||
@ -10,7 +13,20 @@ const OptionSelect = ({ data, settings, submit, message, setMessage }) => {
|
|||||||
}, [message]);
|
}, [message]);
|
||||||
|
|
||||||
const handleSelection = (value) => {
|
const handleSelection = (value) => {
|
||||||
setMessage(value);
|
const currentIndex = selectedOptions.indexOf(value);
|
||||||
|
const newSelectedOptions = [...selectedOptions];
|
||||||
|
|
||||||
|
if (currentIndex === -1) {
|
||||||
|
newSelectedOptions.push(value);
|
||||||
|
} else {
|
||||||
|
newSelectedOptions.splice(currentIndex, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
setSelectedOptions(newSelectedOptions);
|
||||||
|
setMessage(newSelectedOptions.join(", "));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = () => {
|
||||||
setSubmitMessage(true);
|
setSubmitMessage(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -24,14 +40,19 @@ const OptionSelect = ({ data, settings, submit, message, setMessage }) => {
|
|||||||
<button
|
<button
|
||||||
key={index}
|
key={index}
|
||||||
className="group relative shadow-lg hover:shadow-sm transition-all duration-200 ease-in-out text-left p-2.5 border rounded-xl border-white/20 bg-sidebar hover:bg-sidebar/50 overflow-hidden "
|
className="group relative shadow-lg hover:shadow-sm transition-all duration-200 ease-in-out text-left p-2.5 border rounded-xl border-white/20 bg-sidebar hover:bg-sidebar/50 overflow-hidden "
|
||||||
onClick={() => handleSelection(option.value)}
|
onClick={() => {
|
||||||
|
{
|
||||||
|
handleSelection(option.value);
|
||||||
|
handleSubmit();
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<p className="truncate max-w-xl group-hover:max-w-xl group-hover:truncate-0">
|
<p className="truncate max-w-xl group-hover:max-w-xl group-hover:truncate-0">
|
||||||
<span style={{ color: "grey" }}>{index + 1}.</span>{" "}
|
<span className="text-white/50 mr-1">{index + 1}.</span>{" "}
|
||||||
{option.label}
|
{option.label}
|
||||||
</p>
|
</p>
|
||||||
<span className="absolute invisible group-hover:visible bg-black text-white text-xs rounded-lg p-2 left-0 bottom-full mb-2">
|
<span className="absolute invisible group-hover:visible bg-black text-white text-xs rounded-lg p-2 left-0 bottom-full mb-2">
|
||||||
<span style={{ color: "grey" }}>{index + 1}.</span>{" "}
|
<span className="text-white/50 mr-1">{index + 1}.</span>{" "}
|
||||||
{option.label}
|
{option.label}
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
@ -51,10 +72,16 @@ const OptionSelect = ({ data, settings, submit, message, setMessage }) => {
|
|||||||
key={index}
|
key={index}
|
||||||
href={option.href} // assuming `href` is available in your option object
|
href={option.href} // assuming `href` is available in your option object
|
||||||
className="block p-2.5 border-b border-white/10 last:border-0 hover:bg-sidebar/50 cursor-pointer"
|
className="block p-2.5 border-b border-white/10 last:border-0 hover:bg-sidebar/50 cursor-pointer"
|
||||||
onClick={() => handleSelection(option.value)}
|
onClick={() => {
|
||||||
|
{
|
||||||
|
handleSelection(option.value);
|
||||||
|
handleSubmit();
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<p className="">
|
<p className="">
|
||||||
<span style={{ color: "grey" }}>{index + 1}.</span> {option.label}
|
<span className="text-white/50 mr-1">{index + 1}.</span>{" "}
|
||||||
|
{option.label}
|
||||||
</p>
|
</p>
|
||||||
</a>
|
</a>
|
||||||
))}
|
))}
|
||||||
@ -62,9 +89,45 @@ const OptionSelect = ({ data, settings, submit, message, setMessage }) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checkbox
|
||||||
|
if (settings.displayType === "checkbox") {
|
||||||
|
return (
|
||||||
|
<div className="w-full p-4 backdrop-blur-sm rounded-t-xl overflow-hidden py-4 px-6 border-l border-t border-r border-[#2f3238]">
|
||||||
|
<Label label={data?.label} />
|
||||||
|
<div className="pb-0 mt-2 grid grid-cols-1 md:grid-cols-2 gap-4 text-white/80 text-xs">
|
||||||
|
{data.options.map((option, index) => (
|
||||||
|
<label key={index} className="flex items-center space-x-2">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
value={option.value}
|
||||||
|
checked={selectedOptions.includes(option.value)}
|
||||||
|
onChange={() => {
|
||||||
|
handleSelection(option.value);
|
||||||
|
}}
|
||||||
|
className="checkbox"
|
||||||
|
/>
|
||||||
|
<span>{option.label}</span>
|
||||||
|
</label>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
{selectedOptions.length > 0 && (
|
||||||
|
<button
|
||||||
|
className="flex items-center justify-center p-2 mt-4 text-sm text-white/60 hover:text-white rounded"
|
||||||
|
onClick={() => {
|
||||||
|
handleSelection(selectedOptions.join(", "));
|
||||||
|
handleSubmit();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<PaperPlaneRight className="h-6 w-6 mr-2" /> Send
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Dropdown Menu
|
// Dropdown Menu
|
||||||
return (
|
return (
|
||||||
<div className="mt-5 mb-5 w-full backdrop-blur-sm rounded-t-xl overflow-hidden py-4 px-6 border-l border-t border-r border-[#2f3238]">
|
<div className="mt-5 mb-5 w-full backdrop-blur-sm rounded-t-xl py-4 px-6 border-l border-t border-r border-[#2f3238]">
|
||||||
<Label {...data} />
|
<Label {...data} />
|
||||||
<select
|
<select
|
||||||
name="optionSelect"
|
name="optionSelect"
|
||||||
@ -72,8 +135,11 @@ const OptionSelect = ({ data, settings, submit, message, setMessage }) => {
|
|||||||
multiple={settings.allowMultiple}
|
multiple={settings.allowMultiple}
|
||||||
required={true}
|
required={true}
|
||||||
disabled={settings.disabled}
|
disabled={settings.disabled}
|
||||||
className="shadow-xl bg-sidebar text-white text-xs rounded-xl p-2.5 w-full border border-white/20 focus:ring-blue-500 focus:border-blue-500"
|
className="shadow-xl mt-3 bg-sidebar text-white text-xs rounded-xl p-2.5 w-full border border-white/20 focus:ring-blue-500 focus:border-blue-500"
|
||||||
onChange={(e) => handleSelection(e.target.value)}
|
onChange={(e) => {
|
||||||
|
handleSelection(e.target.value);
|
||||||
|
handleSubmit();
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<option value="placeholder" disabled selected>
|
<option value="placeholder" disabled selected>
|
||||||
Select an option
|
Select an option
|
||||||
@ -85,7 +151,8 @@ const OptionSelect = ({ data, settings, submit, message, setMessage }) => {
|
|||||||
) : (
|
) : (
|
||||||
data.options.map((option, index) => (
|
data.options.map((option, index) => (
|
||||||
<option key={index} value={option.value}>
|
<option key={index} value={option.value}>
|
||||||
<span style={{ color: "grey" }}>{index + 1}.</span> {option.label}
|
<span className="text-white/50 mr-1">{index + 1}.</span>{" "}
|
||||||
|
{option.label}
|
||||||
</option>
|
</option>
|
||||||
))
|
))
|
||||||
)}
|
)}
|
||||||
|
@ -12,7 +12,7 @@ import PromptInput from "../PromptInput";
|
|||||||
// import Checkbox from './Checkbox';
|
// import Checkbox from './Checkbox';
|
||||||
|
|
||||||
const inputComponents = {
|
const inputComponents = {
|
||||||
// text: TextInput,
|
text: PromptInput,
|
||||||
options: OptionSelect,
|
options: OptionSelect,
|
||||||
// range: RangeSlider,
|
// range: RangeSlider,
|
||||||
// date: DatePicker,
|
// date: DatePicker,
|
||||||
@ -38,51 +38,50 @@ const DynamicInput = ({
|
|||||||
const [isForcedTextInput, setIsForcedTextInput] = useState(false);
|
const [isForcedTextInput, setIsForcedTextInput] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (inputs?.type !== "text") {
|
setIsForcedTextInput(inputs?.type === "text");
|
||||||
setIsForcedTextInput(false);
|
|
||||||
}
|
|
||||||
}, [inputs]);
|
}, [inputs]);
|
||||||
|
|
||||||
const InputComponent = inputComponents[inputs?.type] || null;
|
// Select the appropriate input component based on inputs.type or force text input
|
||||||
if (!InputComponent) {
|
const InputComponent =
|
||||||
return null; // or any fallback UI
|
inputs && (isForcedTextInput || inputs.type === "text")
|
||||||
}
|
? inputComponents["text"]
|
||||||
const renderPromptInput = () => {
|
: inputComponents[inputs?.type] || null;
|
||||||
if (inputs?.type === "text" || inputs === undefined || isForcedTextInput) {
|
|
||||||
return (
|
// Condition to show the dynamic input or the forced text input
|
||||||
<PromptInput
|
const shouldShowDynamicInput =
|
||||||
className={
|
isDynamicInput && inputs !== undefined && !isForcedTextInput;
|
||||||
inputs !== undefined ? "bottom-8 md:-bottom-5" : "-bottom-2"
|
|
||||||
}
|
|
||||||
workspace={workspace}
|
|
||||||
message={message}
|
|
||||||
submit={submit}
|
|
||||||
onChange={onChange}
|
|
||||||
inputDisabled={inputDisabled}
|
|
||||||
buttonDisabled={buttonDisabled}
|
|
||||||
sendCommand={sendCommand}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full md:px-4 fixed md:absolute bottom-10 left-0 z-10 md:z-0 flex justify-center items-center">
|
<div className="w-full md:px-4 fixed md:absolute bottom-10 left-0 z-10 md:z-0 flex justify-center items-center">
|
||||||
<div className="w-[600px]">
|
<div className="w-[600px]">
|
||||||
{inputs?.type !== "text" &&
|
{shouldShowDynamicInput ? (
|
||||||
isDynamicInput &&
|
|
||||||
inputs !== undefined &&
|
|
||||||
!isForcedTextInput ? (
|
|
||||||
<InputComponent
|
<InputComponent
|
||||||
submit={submit}
|
submit={submit}
|
||||||
setMessage={setMessage}
|
setMessage={setMessage}
|
||||||
message={message}
|
message={message}
|
||||||
|
workspace={workspace}
|
||||||
|
onChange={onChange}
|
||||||
|
inputDisabled={inputDisabled}
|
||||||
|
buttonDisabled={buttonDisabled}
|
||||||
|
sendCommand={sendCommand}
|
||||||
{...inputs}
|
{...inputs}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
renderPromptInput()
|
<PromptInput
|
||||||
|
className={
|
||||||
|
inputs === undefined ? "-bottom-2" : "bottom-8 md:-bottom-5"
|
||||||
|
}
|
||||||
|
workspace={workspace}
|
||||||
|
message={message}
|
||||||
|
submit={submit}
|
||||||
|
onChange={onChange}
|
||||||
|
inputDisabled={inputDisabled}
|
||||||
|
buttonDisabled={buttonDisabled}
|
||||||
|
sendCommand={sendCommand}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
{isDynamicInput && inputs != undefined && (
|
{isDynamicInput && inputs != undefined && (
|
||||||
<div className="w-full fixed absolute -bottom-8 left-0 z-10 md:z-0 flex justify-center items-center">
|
<div className="w-full absolute -bottom-8 left-0 z-10 md:z-0 flex justify-center items-center">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="transition-all w-fit duration-300 px-5 py-2.5 rounded-lg text-white/40 text-xs items-center flex gap-x-2 shadow-sm hover:text-white/60 focus:ring-gray-800"
|
className="transition-all w-fit duration-300 px-5 py-2.5 rounded-lg text-white/40 text-xs items-center flex gap-x-2 shadow-sm hover:text-white/60 focus:ring-gray-800"
|
||||||
|
Loading…
Reference in New Issue
Block a user