Skip to content
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

refactor(TagOverflowModal): add Typescript types to TagOverflowModal #5311

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// LICENSE file in the root directory of this source tree.
//

import React, { useState } from 'react';
import React, { ReactNode, useState } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';

Expand All @@ -30,6 +30,22 @@ const defaults = {
searchLabel: '',
};

interface TagType {
label: string;
}
type AllTags = (TagType & Omit<React.ComponentProps<Tag>, 'filter'>)[];
interface TagOverflowModalProps {
allTags?: AllTags;
className?: string;
onClose?: () => void;
open?: boolean;
overflowType?: 'default' | 'tag';
portalTarget?: ReactNode;
searchLabel?: string;
searchPlaceholder?: string;
title?: string;
}

export const TagOverflowModal = ({
// The component props, in alphabetical order (for consistency).

Expand All @@ -45,17 +61,17 @@ export const TagOverflowModal = ({

// Collect any other property values passed in.
...rest
}) => {
}: TagOverflowModalProps) => {
const [search, setSearch] = useState('');
const renderPortalUse = usePortalTarget(portalTargetIn);

const getFilteredItems = () => {
if (open && search) {
const getFilteredItems = (): AllTags => {
if (open && search && allTags) {
return allTags.filter((tag) =>
tag.label?.toLocaleLowerCase()?.includes(search.toLocaleLowerCase())
);
}
return allTags;
return allTags || [];
};

const handleSearch = (evt) => {
Expand Down
Loading