ToolJet/frontend/src/Editor/Components/Table/CustomSelect.jsx
Manish Kushare e3d4ef82f6
Columns multiple badge and badges dropdown should have proper width in table component (#5760)
* set min and max width of the custom select dropdown in th table widget

* Removed unwanted console

---------

Co-authored-by: Kavin Venkatachalam <kavin.saratha@gmail.com>
2023-03-22 15:50:21 +05:30

44 lines
1.4 KiB
JavaScript

import React from 'react';
import SelectSearch from 'react-select-search';
import { useTranslation } from 'react-i18next';
export const CustomSelect = ({ options, value, multiple, onChange, darkMode, isEditable, width }) => {
const { t } = useTranslation();
function renderValue(valueProps) {
if (!isEditable) {
const stringifyValue = String(valueProps.value);
const arrayOfValueProps = stringifyValue.includes(',') ? stringifyValue.split(', ') : stringifyValue.split(' ');
return arrayOfValueProps.map((value, index) => (
<span key={index} className="badge bg-blue-lt p-2 mx-1">
{value}
</span>
));
}
if (valueProps) {
const stringifyValue = String(valueProps.value);
const arrayOfValueProps = stringifyValue.includes(',') ? stringifyValue.split(', ') : stringifyValue.split(' ');
return arrayOfValueProps.map((value, index) => (
<span key={index} {...valueProps} className="badge bg-blue-lt p-2 mx-1">
{value}
</span>
));
}
}
return (
<div className="custom-select" style={{ width: width }}>
<SelectSearch
options={options}
printOptions="on-focus"
value={value}
renderValue={renderValue}
search={false}
onChange={onChange}
multiple={multiple}
placeholder={t('globals.select', 'Select') + '...'}
className={'select-search'}
/>
</div>
);
};