Skip to content

v1.18.0 #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions components/KernDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default function KernDropdown(props: KernDropdownProps) {
const [disabledOptions, setDisabledOptions] = useState<boolean[]>([]);
const [backgroundColors, setBackgroundColors] = useState<string[]>([]);
const [searchText, setSearchText] = useState('');
const [searchIndexes, setSearchIndexes] = useState<number[]>();
const [isOpen, setIsOpen_] = useState(false);
const [selectedCheckboxes, setSelectedCheckboxes] = useState<any[]>([]);
const [position, setPosition] = useState(null);
Expand Down Expand Up @@ -51,11 +52,15 @@ export default function KernDropdown(props: KernDropdownProps) {
useEffect(() => {
const prepareOptions = prepareDropdownOptionsToArray(props.options, props.hasSearchBar, props.valuePropertyPath);
if (props.hasSearchBar) {
setDropdownCaptions(setOptionsWithSearchBar(prepareOptions, searchText));
const [remaining, indexes] = setOptionsWithSearchBar(prepareOptions, searchText)
setDropdownCaptions(remaining);
setSearchIndexes(indexes);
} else if (props.hasCheckboxes) {
setOptionsWithCheckboxes(prepareOptions);
setSearchIndexes(null);
} else {
setDropdownCaptions(prepareOptions);
setSearchIndexes(null);
}
}, [props.options, searchText, selectedCheckboxes, props.hasSearchBar, props.hasCheckboxes, props.selectedCheckboxes, props.hasSelectAll, props.valuePropertyPath]);

Expand Down Expand Up @@ -167,10 +172,12 @@ export default function KernDropdown(props: KernDropdownProps) {
return;
}
if (props.selectedOption) {
props.selectedOption(props.options[index]);
if (props.hoverBoxList) setHoverBoxPosition(null);
if (props.hasSearchBar) {
setSearchText(option);
props.selectedOption(props.options[searchIndexes[index]]);
} else {
props.selectedOption(props.options[index]);
}
setIsOpen(false);
}
Expand Down
10 changes: 8 additions & 2 deletions components/SVGIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IconBolt, IconChevronDown, IconCode, IconDotsVertical, IconExternalLink, IconFileInfo, IconFilePencil, IconLoader, IconPlayerPlayFilled, IconSquare, IconSquareCheck, IconTrash } from '@tabler/icons-react';
import { IconBolt, IconChevronDown, IconCode, IconDotsVertical, IconEdit, IconExternalLink, IconFileInfo, IconFilePencil, IconLoader, IconPlayerPlayFilled, IconShieldCheckFilled, IconShieldFilled, IconSquare, IconSquareCheck, IconTrash } from '@tabler/icons-react';

export const SUPPORTED_ICONS = ['IconCode', 'IconBolt', 'IconSquareCheck', 'IconSquare', 'IconPlayerPlayFilled', 'IconTrash', 'IconExternalLink',
'IconLoader', 'IconFilePencil', 'IconFileInfo'
'IconLoader', 'IconFilePencil', 'IconFileInfo', 'IconEdit', 'IconShieldFilled', 'IconShieldCheckFilled'
]

type SVGIconProps = {
Expand Down Expand Up @@ -37,6 +37,12 @@ export default function SVGIcon(props: SVGIconProps) {
return <IconFilePencil size={props.size} strokeWidth={props.strokeWidth} className={`${props.useFillForIcons ? 'fill-gray-800' : ''}`} />
case 'IconFileInfo':
return <IconFileInfo size={props.size} strokeWidth={props.strokeWidth} className={`${props.useFillForIcons ? 'fill-gray-800' : ''}`} />
case 'IconEdit':
return <IconEdit size={props.size} strokeWidth={props.strokeWidth} className={`${props.useFillForIcons ? 'fill-gray-800' : ''}`} />
case 'IconShieldFilled':
return <IconShieldFilled size={props.size} strokeWidth={props.strokeWidth} className={`${props.useFillForIcons ? 'fill-gray-800' : ''}`} />
case 'IconShieldCheckFilled':
return <IconShieldCheckFilled size={props.size} strokeWidth={props.strokeWidth} className={`${props.useFillForIcons ? 'fill-gray-800' : ''}`} />
default: return <IconLoader size={props.size} strokeWidth={props.strokeWidth} className={`${props.useFillForIcons ? 'fill-gray-800' : ''}`} />
}

Expand Down
8 changes: 5 additions & 3 deletions helpers/dropdown-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ export function prepareDropdownOptionsToArray(options: string[] | any[], hasSear
else return getTextArray(options);
}

export function setOptionsWithSearchBar(options: string[], searchText: string) {
if (!searchText) return options;
return options.filter(option => option.toLowerCase().includes(searchText.toLowerCase()));
export function setOptionsWithSearchBar(options: string[], searchText: string): [string[], number[]] {
if (!searchText) return [options, options.map((_, i) => i)];
const withIdx = options.map((o, i) => ({ origIdx: i, text: o }));
const filtered = withIdx.filter(option => option.text.toLowerCase().includes(searchText.toLowerCase()));
return [filtered.map(f => f.text), filtered.map(f => f.origIdx)];
}

export function checkDropdownProps(props: KernDropdownProps) {
Expand Down