Skip to content
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

Merged
merged 4 commits into from
Apr 14, 2020
Merged

global: add prefix and suffix props #106

merged 4 commits into from
Apr 14, 2020

Conversation

KonstantinaStoikou
Copy link
Contributor

@KonstantinaStoikou KonstantinaStoikou commented Apr 13, 2020

Closes #104

Example:
Selection_001

Copy link
Contributor

@ntarocco ntarocco left a 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.

return (
<ShouldRender condition={!loading && totalResults > 0}>
{this.renderSpanWithMargin(prefix, 'right')}
Copy link
Contributor

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')}
Copy link
Contributor

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;
Copy link
Member

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 })}>
Copy link
Member

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 :)

this.onChange
)}
{suffix && this.renderSpanWithMargin(suffix)}
<span style={({ marginLeft: size }, { marginRight: size })}>
Copy link
Member

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(currentSortBy, this.options, this.onChange)}
{suffix && this.renderSpanWithMargin(suffix)}
<span style={({ marginLeft: size }, { marginRight: size })}>
Copy link
Member

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 })}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, sorry :)


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</>} />`
Copy link
Member

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 :)

Copy link
Contributor

@ntarocco ntarocco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add "prefix" and "suffix" props to components
3 participants