Skip to content

[G2M] Multiple search delete button #221

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

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
dropdown-multi-search - add delete button
  • Loading branch information
kc-leung committed Dec 2, 2024
commit e6c103d5fd5dfb4499543d45c7e2e76589801c71
24 changes: 23 additions & 1 deletion src/components/dropdown-multi-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'

import { DropdownSelect, TextField, makeStyles } from '..'
import { useComponentIsActive } from '../hooks'
import { Delete } from '../icons'


const DropdownMultiSearch = ({
Expand Down Expand Up @@ -31,6 +32,7 @@ const DropdownMultiSearch = ({
onOpenClose = () => {},
noOptionsMessage = '',
clearSearch = true,
deleteButton = true,
...rest
}) => {
const { ref, componentIsActive, setComponentIsActive } = useComponentIsActive()
Expand All @@ -46,6 +48,10 @@ const DropdownMultiSearch = ({
const styles = makeStyles({
root: {
position: 'relative',
heigh: '100%',
display: 'flex',
alignItems: 'center',

'.dropdown-multi-search-textfield-root': {
height: '2.35rem',
},
Expand Down Expand Up @@ -114,10 +120,20 @@ const DropdownMultiSearch = ({
}
}

const handleDelete = () => {
setSelectedFilters([])
}

useEffect(() => {
setFilteredOptions(data)
}, [data])

useEffect(() => {
if (value.length > 0) {
setSelectedFilters(value)
}
}, [value])

if (!componentIsActive && openMenu) {
setOpenMnu(false)
setSearchTerm('')
Expand Down Expand Up @@ -159,13 +175,18 @@ const DropdownMultiSearch = ({
limit={data?.length}
size={size}
defaultValue={defaultValue}
value={value}
value={selectedFilters}
onDelete={onDelete}
startIcon={startIcon}
endIcon={endIcon}
onOpenClose={onOpenClose}
{...rest}
/>
{deleteButton && selectedFilters.length > 0 &&
<div className={classes.endIcon} onMouseDown={handleDelete}>
<Delete className='ml-2 fill-current text-secondary-600 cursor-pointer' size={size}/>
</div>
}
</div>
)
}
Expand Down Expand Up @@ -193,6 +214,7 @@ DropdownMultiSearch.propTypes = {
disabled: PropTypes.bool,
noOptionsMessage: PropTypes.string,
clearSearch: PropTypes.bool,
deleteButton: PropTypes.bool,
}

DropdownMultiSearch.displayName = 'DropdownMultiSearch'
Expand Down
5 changes: 3 additions & 2 deletions src/components/dropdown-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const DropdownSelect = ({
contentHeader: `dropdown-select__content-header w-full flex flex-row items-center justify-between cursor-pointer ${classes.contentHeader}`,
type: `dropdown-select__type-container px-5px flex items-center font-semibold text-secondary-400 ${contentSize.type} ${classes.type}`,
description: `dropdown-select__description-container pt-5px font-normal text-secondary-500 ${contentSize.description} ${classes.description}`,
dividerContainer: `dropdown-select__divider-container px-2.5 flex flex-row items-center font-bold text-secondary-600 border-t border-secondary-300 cursor-pointer
dividerContainer: `dropdown-select__divider-container px-2.5 flex flex-row items-center font-bold text-secondary-600 border-b border-secondary-300 cursor-pointer
${contentSize.dividerContainer} ${classes.dividerContainer}`,
startIcon: 'dropdown-select__start-icon-container mr-2.5 fill-current stroke-current',
endIcon: 'dropdown-select__end-icon-container ml-2.5 fill-current stroke-current',
Expand Down Expand Up @@ -318,8 +318,8 @@ const DropdownSelect = ({
className={`list-container-${index} ${dropdownSelectClasses.listContainer}`}
>
{showType && el.type && <label className={`type-container-${index} ${dropdownSelectClasses.type}`} htmlFor="span">{renderListItem(el.type)}</label>}
{renderList(el)}
{el.divider && <div className={`divider-container-${index} ${dropdownSelectClasses.dividerContainer}`} onClick={el.divider.onClick}>{renderListItem(el.divider)}</div>}
{renderList(el)}
</Menu.Item>
)
})}
Expand Down Expand Up @@ -351,6 +351,7 @@ DropdownSelect.propTypes = {
title: PropTypes.string,
startIcon: PropTypes.node,
endIcon: PropTypes.node,
onClcik: PropTypes.func,
}),
}),
),
Expand Down
2 changes: 1 addition & 1 deletion stories/data/dropdown-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const sampleDataDivider = [
],
divider: {
title: 'Reset',
onClick: () => { console.log('click divider')}
onClick: () => {},
},
},
]
Expand Down
1 change: 1 addition & 0 deletions stories/dropdown.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export const Simple = () => {
* title: string, name of the dividir
* startIcon: node, icon on left side of divider title
* endIcon: node, icon on right side of divider title
* onClick: func, callback function onClick divider item
* }
* [button] - node, custom onClick element to trigger select/dropdown menu
* [size] - string, control component size - supported sizes ['md', 'lg'], default = 'md'
Expand Down