-
Notifications
You must be signed in to change notification settings - Fork 40
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
global: add prefix and suffix props #106
global: add prefix and suffix props #106
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes, and also for having updated the demo and documentation.
If you see the screenshot in the README of this repo, you might have it also for the Sort components, there are 3 of them. I would propose to add this suffix and prefix also to them.
src/lib/components/Count/Count.js
Outdated
return ( | ||
<ShouldRender condition={!loading && totalResults > 0}> | ||
{this.renderSpanWithMargin(prefix, 'right')} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefix or Suffix might be not defined, so the extra margin should not appear. I would change both to:
{prefix && this.renderSpanWithMargin(prefix, 'right')}
WDYT?
return ( | ||
<ShouldRender | ||
condition={!loading && totalResults > 0 && currentSize !== -1} | ||
> | ||
{this.renderSpanWithMargin(prefix, 'right')} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
render() { | ||
const { loading, currentSize, totalResults } = this.props; | ||
const { loading, currentSize, totalResults, prefix, suffix } = this.props; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May I suggest a change that IMHO it fits a bit better the purpose of the prefix/suffix props without making it too specific? As I understood, please correct me if I am wrong, the end goal is to apply a custom label that wraps the ResultsPerPage component. I would go then for a label prop that can be a function like this:
ResultsPerPage label={(cmp) => `Show {cmp} results per page`} />
then in the render function of the ResultsPerPage
component you could write something similar to this:
render() {
const { loading, currentSize, totalResults, label } = this.props;
...
{label && label(this.renderElement(currentSize, this.options, this.onChange))}
...
}
{prefix && this.renderSpanWithMargin(prefix, 'right')} | ||
{this.renderElement(currentSize, this.options, this.onChange)} | ||
{suffix && this.renderSpanWithMargin(suffix)} | ||
<span style={({ marginLeft: size }, { marginRight: size })}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this styling should go to the application that uses this component so as to keep the components here with minimal styling :)
src/lib/components/Sort/Sort.js
Outdated
this.onChange | ||
)} | ||
{suffix && this.renderSpanWithMargin(suffix)} | ||
<span style={({ marginLeft: size }, { marginRight: size })}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here for the styling!
src/lib/components/SortBy/SortBy.js
Outdated
{prefix && this.renderSpanWithMargin(prefix, 'right')} | ||
{this.renderElement(currentSortBy, this.options, this.onChange)} | ||
{suffix && this.renderSpanWithMargin(suffix)} | ||
<span style={({ marginLeft: size }, { marginRight: size })}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here for the styling!
{prefix && this.renderSpanWithMargin(prefix, 'right')} | ||
{this.renderElement(currentSortOrder, this.options, this.onChange)} | ||
{suffix && this.renderSpanWithMargin(suffix)} | ||
<span style={({ marginLeft: size }, { marginRight: size })}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, sorry :)
docs/docs/components/count.md
Outdated
|
||
An optional string to be displayed after the number of results. | ||
An optional function to wrap the component with a prefix and suffix string. <br /> | ||
E.g. `label={(val) => <> Found {val} results</>} />` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably change the val
to cmp
just to indicate that the passed argument is the component not just a value. This would make clear that the return value of the label
function needs to be a component and cannot be a string :) Please do the corresponding changes to the other places :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Closes #104
Example:
![Selection_001](https://user-images.githubusercontent.com/33685068/79227650-83b72700-7e60-11ea-8788-09fe12d3d928.png)