-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[Slider] Add support for custom slider icon #12485
Conversation
This comment has been minimized.
This comment has been minimized.
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.
When you have added the requested block comments run yarn docs:api
.
Please add tests and examples to the documentation (see pages/lab/slider.js
).
@@ -434,6 +444,16 @@ class Slider extends React.Component { | |||
const inlineTrackAfterStyles = { [trackProperty]: this.calculateTrackAfterStyles(percent) }; | |||
const inlineThumbStyles = { [thumbProperty]: `${percent}%` }; | |||
|
|||
const Thumbnail = () => { | |||
if (React.isValidElement(Thumb)) { |
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'm not sure what the practice is in this package but if you would require the React.element
prop-type this check would be redundant.
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.
Changed prop type to React.element, and removed this extra flag.
@@ -454,7 +474,9 @@ class Slider extends React.Component { | |||
<div className={containerClasses}> | |||
<div className={trackBeforeClasses} style={inlineTrackBeforeStyles} /> | |||
<ButtonBase | |||
className={thumbClasses} | |||
className={ | |||
Thumbnail() ? classNames(thumbClasses, classes.thumbTransparent) : thumbClasses |
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.
Two possibilities:
- Wouldn't it be more "semantic" to add a
with-icon
class (something along the line) inthumbClasses
and letclassNames
to the conditional logic stuff? - Use
IconButton
if a thumb elment is provided instead ofButtonBase
(which I'd prefer).
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 went with option 1 here, updated thumbClasses.
if (React.isValidElement(Thumb)) { | ||
return React.cloneElement(Thumb, { | ||
...Thumb.props, | ||
className: classes.thumbIcon, |
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.
This overwrites existing classNames on the thumb. It should respect existing classNames.
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 have made changes now if the user adds classes to the thumb, it won't get over written.
@@ -463,7 +485,9 @@ class Slider extends React.Component { | |||
onTouchStartCapture={this.handleTouchStart} | |||
onTouchMove={this.handleMouseMove} | |||
onFocusVisible={this.handleFocus} | |||
/> | |||
> | |||
{Thumbnail()} |
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 change the Thumbnail
assignment so that you don't have to use this call syntax here. It's more in line with other components and also removes a second call to the function.
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.
Fixed.
@@ -524,6 +548,7 @@ Slider.propTypes = { | |||
* @ignore | |||
*/ | |||
theme: PropTypes.object.isRequired, | |||
thumb: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.object]), |
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.
Please add a block comment and document this property and use PropTypes.element
.
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.
Fixed.
thumbTransparent: { | ||
backgroundColor: 'transparent', | ||
}, | ||
thumbIcon: { |
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.
Please add a block comment to document this className
.
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 have added a small documentation to it.
@eps1lon first of all thank you so much for reviewing my PR, I have made changes as per your instructions. Do let me know if it still needs any tweaking. |
I think I made a mistake, I took a pull master and merged it in my feature-slider-thumbnail branch. And now there is a lot of code in the PR.. what should I do? Also I have no idea that why in |
The failing tests should've been resolve with #12535. Try rebasing or merging master again. Running For general advice about PR workflow I recommend https://gist.github.com/Chaser324/ce0505fbed06b947d962. |
@eps1lon I took a pull and merged this branch with master again, on running the tests after that merge all the tests where passing. But the Circleci build is failing. A bit information on how I ran the test, for Slider
It ran the test and gave an output for After that when the build failed, I in my root folder ran |
@adeelibr CircleCI is just broken at the moment (https://discuss.circleci.com/t/saving-cache-stopped-working-warning-skipping-this-step-disabled-in-configuration/24423/2). Nothing you can do about it but patiently wait for a fix. |
@eps1lon so does that mean my PR is okay, that it can be merged? |
Rebase/merge again to include #12573 and we'll see if everything is ok. |
One test is still failing |
The branch is just very messy due to all the merge commits. In general if any In this case |
I have ran |
Looks like you ran |
@eps1lon i don't know what's happening this is what I am doing right now
|
You are not running |
@eps1lon sorry, this is what i was doing
what i did was I updated, one of my props definition that I added in this PR ran |
still failed.. |
I'm pretty sure you have your line endings set to This should probably be mentioned in Perfect solution would be to run |
I did this
And ran I then saw the It is already configured for the use case that you have mentioned above, so back at square one I think.. |
It should be set to |
@eps1lon I have changed it from CRLF to LF, changed my git configuration's |
@oliviertassinari can we somehow change the regex https://github.com/mui-org/material-ui/blob/823fed03727bb6b52dbfc329472640b8e9da0e21/docs/scripts/buildApi.js#L112-L113 so that it is not dependent on the user side. |
@adeelibr I would try to replace the |
I have made another PR for this, to resolve this CRLF to LF issue. #12584 I have updated the regex, but it's still giving me the same error. @oliviertassinari |
This is what I did
Then I made some changes in only the files I wanted to be committed. Which were; After that
Isn't this how you wanted me to do it. @oliviertassinari But it committed those docs files as well. I am really bad at this.. sigh |
…o use classNames, class overirde issue resolved, changes Thumbnail assignment instead of call, added comments
a07aa25
to
432ed0b
Compare
I have added a new prop called
thumb
to the Slider component, which you can use like this.