-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added dependency arrays; break popupmenu component to smaller ones
- Loading branch information
1 parent
08da0bc
commit 829825d
Showing
7 changed files
with
216 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/bundle/ui-dev/src/modules/common/popup-menu/popup.menu.group.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import PopupMenuItem from './popup.menu.item'; | ||
import { showItem } from './popup.menu.helper'; | ||
|
||
const PopupMenuGroup = ({ items, filterText, onItemClick }) => { | ||
const isAnyItemVisible = items.some((item) => showItem(item, filterText)); | ||
|
||
if (!isAnyItemVisible) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className="c-popup-menu__group"> | ||
{items.map((item) => ( | ||
<PopupMenuItem key={item.value} item={item} filterText={filterText} onItemClick={onItemClick} /> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
PopupMenuGroup.propTypes = { | ||
items: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
value: PropTypes.string.isRequired, | ||
}), | ||
), | ||
onItemClick: PropTypes.func.isRequired, | ||
filterText: PropTypes.string, | ||
}; | ||
|
||
PopupMenuGroup.defaultProps = { | ||
items: [], | ||
filterText: '', | ||
}; | ||
|
||
export default PopupMenuGroup; |
12 changes: 12 additions & 0 deletions
12
src/bundle/ui-dev/src/modules/common/popup-menu/popup.menu.helper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const MIN_SEARCH_LENGTH = 3; | ||
|
||
export const showItem = (item, filterText) => { | ||
if (filterText.length < MIN_SEARCH_LENGTH) { | ||
return true; | ||
} | ||
|
||
const itemLabelLowerCase = item.label.toLowerCase(); | ||
const filterTextLowerCase = filterText.toLowerCase(); | ||
|
||
return itemLabelLowerCase.indexOf(filterTextLowerCase) === 0; | ||
}; |
32 changes: 32 additions & 0 deletions
32
src/bundle/ui-dev/src/modules/common/popup-menu/popup.menu.item.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { showItem } from './popup.menu.helper'; | ||
|
||
const PopupMenuItem = ({ item, filterText, onItemClick }) => { | ||
if (!showItem(item, filterText)) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className="c-popup-menu__item"> | ||
<button type="button" className="c-popup-menu__item-content" onClick={() => onItemClick(item)}> | ||
<span className="c-popup-menu__item-label">{item.label}</span> | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
PopupMenuItem.propTypes = { | ||
item: PropTypes.shape({ | ||
label: PropTypes.string.isRequired, | ||
}).isRequired, | ||
onItemClick: PropTypes.func.isRequired, | ||
filterText: PropTypes.string, | ||
}; | ||
|
||
PopupMenuItem.defaultProps = { | ||
filterText: '', | ||
}; | ||
|
||
export default PopupMenuItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.