@droppii-org/chat-sdk
Version:
Droppii React Chat SDK
26 lines (25 loc) • 1.93 kB
JavaScript
"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Select } from "antd";
import { Icon } from "../icon";
import clsx from "clsx";
import { useTranslation } from "react-i18next";
const SelectSession = ({ options, value, onChange, excludeOptions, placeholder, }) => {
const { t } = useTranslation();
const selectedOption = options.find((option) => option.value === value);
// Filter out excluded options
const filteredOptions = options.filter((option) => !(excludeOptions === null || excludeOptions === void 0 ? void 0 : excludeOptions.includes(option.value)));
// Transform options for Ant Design Select
const selectOptions = filteredOptions.map((option) => ({
label: (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("div", { className: clsx("w-2 h-2 rounded-full", option.tintColorClassnameBg) }), _jsx("span", { className: clsx("text-xs truncate flex-1", option.tintColorClassname), children: option.label })] })),
value: option.value,
}));
// Handle selection change
const handleSelect = (val) => {
onChange(val);
};
return (_jsx("div", { className: "relative", children: _jsx(Select, { className: `${selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.bgTintColorClassname} custom-select min-w-[100px]`, placement: "bottomLeft", placeholder: placeholder, options: selectOptions, value: selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value, onSelect: handleSelect, suffixIcon: _jsx(Icon, { icon: "angle-down-o", className: `${selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.tintColorClassname} mt-[2px]`, size: 14 }), menuItemSelectedIcon: null, labelRender: (option) => ["NONE", ""].includes(option.value)
? placeholder
: option.label }) }));
};
export default SelectSession;