Skip to content

Instantly share code, notes, and snippets.

@jm2242
Last active February 20, 2018 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jm2242/32fa639f7cb87c8edcc045d10e4ed5c5 to your computer and use it in GitHub Desktop.
Save jm2242/32fa639f7cb87c8edcc045d10e4ed5c5 to your computer and use it in GitHub Desktop.
Partial solution using many classes
//(contents of the React component, simplified)
render() { // render method of component
// ...
// count the number of truthy booleans
const numberOfButtons = [canAddColumns, canHideColumns, canRemoveColumns, canSearch, canSort].reduce(
(acc, showButton) => showButton ? acc+1 : acc,
0
)
<div className={
classNames(
{"column-icons-1": numberOfButtons === 1},
{"column-icons-2": numberOfButtons === 2},
{"column-icons-3": numberOfButtons === 3},
{"column-icons-4": numberOfButtons === 4},
{"column-icons-5": numberOfButtons === 5},
)
}>
{ canHideColumns && renderHideColumnsTrigger() }
{ canSort && renderSortingIndicator() }
{ canSearch && renderSearchTrigger() }
{ canRemoveColumns && <RemoveColumnButton /> }
{ canAddColumns && <AddColumnButton }
</div>
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment