Skip to content

Commit

Permalink
refactor Selection to use downshift. Implement option group feature -…
Browse files Browse the repository at this point in the history
… STCOM-1278
  • Loading branch information
JohnC-80 committed May 10, 2024
1 parent 6b8b2c0 commit b9c5fde
Show file tree
Hide file tree
Showing 11 changed files with 491 additions and 1,147 deletions.
8 changes: 3 additions & 5 deletions lib/Selection/DefaultOptionFormatter.js
Expand Up @@ -8,11 +8,9 @@ const propTypes = {
};

const DefaultOptionFormatter = ({ option, searchTerm }) => {
if (option) {
return <OptionSegment searchTerm={searchTerm}>{option.label}</OptionSegment>;
}

return null;
return option ?
<OptionSegment searchTerm={searchTerm}>{option.label}</OptionSegment> :
null;
};

DefaultOptionFormatter.propTypes = propTypes;
Expand Down
18 changes: 8 additions & 10 deletions lib/Selection/OptionSegment.js
Expand Up @@ -14,30 +14,28 @@ const propTypes = {
searchTerm: PropTypes.string,
};

const render = ({ ...props }) => {
const { searchTerm, innerText, children } = props; /* eslint-disable-line react/prop-types */
const OptionSegment = ({ searchTerm, innerText, children }) => {
const text = innerText || children;

let rendered;
if (!searchTerm || searchTerm === '' || typeof text !== 'string') {
return text;
rendered = text;
}

return (
rendered = (
<Highlighter
searchWords={searchTerm.split(' ')} // eslint-disable-line react/prop-types
searchWords={searchTerm.split(' ')}
text={text}
/>
);
};

const OptionSegment = ({ searchTerm, innerText, children }) => (
return (
<div
data-test-selection-option-segment
className={css.optionSegment}
>
{render({ searchTerm, innerText, children })}
{rendered}
</div>
);
)};

OptionSegment.propTypes = propTypes;

Expand Down
311 changes: 0 additions & 311 deletions lib/Selection/SelectList.js

This file was deleted.

9 changes: 9 additions & 0 deletions lib/Selection/Selection.css
Expand Up @@ -154,6 +154,15 @@
}
}

.groupLabel {
padding: 0.5rem;
cursor: default;
display: flex;
justify-content: space-between;
color: var(--color-text);
background-color: var(--color-fill-disabled);
}

.optionSegment {
padding: 0 2px;
text-align: initial;
Expand Down

0 comments on commit b9c5fde

Please sign in to comment.