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

Support for customizable static range labels #271

Merged
merged 3 commits into from
Jan 21, 2019

Conversation

mortargrind
Copy link
Contributor

@mortargrind mortargrind commented Jan 11, 2019

Types of changes

What types of changes does your code introduce?

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Description

renderStaticRangeLabel callback prop is added to DefinedRange component to enable custom component rendering for static range labels.

-react-test-renderer is added to dev dependencies.
-Initial DefinedRange tests are added.
-README is updated for renderStaticRangeLabel.
-eslintignore file is updated to ignore snapshot files.
-Existing demo is updated to display new renderStaticRangeLabel usage.

…nent to enable custom component rendering for static range labels.

-'react-test-renderer' is added to dev dependencies.
-README is updated for 'renderStaticRangeLabel'.
-eslintignore file is updated to ignore snapshot files.
-Existing demo is updated to display custom 'renderStaticRangeLabel' usage.
@mortargrind mortargrind self-assigned this Jan 11, 2019
Copy link
Collaborator

@mkg0 mkg0 left a comment

Choose a reason for hiding this comment

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

👍

return (
<div className={cx(styles.definedRangesWrapper, className)}>
{this.props.headerContent}
<div className={styles.staticRanges}>
{this.props.staticRanges.map((staticRange, i) => {
const { selectedRange, focusedRangeIndex } = this.getSelectedRange(ranges, staticRange);
let labelContent;

if (staticRange.hasCustomRendering) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's make hasCustomRendering true by default if renderStaticRangeLabel already defined. You can still add another property called renderLabel() to static range object for rendering custom range in order to render just for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

staticRange.label can already be rendered via a custom component (label: <MyComponent/>); there's no need for single renderLabel functions for individual staticRange on configuration object level. Whole point of having a render function on component level is let the callers specify custom props / logic to the label rendering logic on their own component's render phase. So yes; this means that if any of the staticRange configurations have hasCustomRendering; then the renderStaticRangeLabel prop should be present too. But the reverse is not true.

Having renderStaticRangeLabel prop provided does not mean that every staticRange object will be rendered in a custom way. So we cannot change hasCustomRendering to true by default if it's present. For example; in the original use-case we have right now is to be able to render a tooltip on one of the staticRange buttons while the others are continue to use staticRange.label.

src/components/DefinedRange.test.js Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
@keremciu keremciu merged commit a423741 into master Jan 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants