-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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] Feature Custom Icon #12600
[Slider] Feature Custom Icon #12600
Conversation
@oliviertassinari I deleted the old PR, and created a new PR from scratch updated from upstream master, and I didn't run @eps1lon can you point me in the write direction? |
You need to in order to update the slider API docs |
No worries. BTW, no need to close one PR and open another - you can force push your fixed branch. Please could you make the customization examples a little more practical? The first looks like a glitch, and the third doesn't make much sense. Why would a slider have a trash-can icon for it's thumb? 😄 No need for the second example - we already know what it looks like when not customized. It also needs a heading "Custom thumb"? Not sure it warrants a description. |
I have added a better demo Along with the description, as instructed. Regarding the part
I tried doing it, tried for like 2 hours but I think I ended up messing the PR more, so created a new one. I'll spend some time tomorrow learning how to git reset, git revert and git reflog 💯 |
@eps1lon I have made changes to the thumb icon, is this the right approach? your suggestions. |
Regarding the |
`${withIcon ? '' : classes.thumb}`, | ||
commonClasses, | ||
`${withIcon ? classes.thumbTransparent : ''}`, | ||
); |
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.
You can leverage classNames
implementation here by passing an object with the classnames as keys and a truthy value.
Why not apply classes.thumb
always and classes.thumbIcon
if an icon is passed and style accordingly. This would make more sense in my opinion. thumbTransparent
just feels wrong. I'll always try to avoid naming my css classes after their look.
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.
You can leverage classNames implementation here by passing an object with the classnames as keys and a truthy value.
Done, I have made the changes. :)
Why not apply classes.thumb always and classes.thumbIcon if an icon is passed and style accordingly. This would make more sense in my opinion. thumbTransparent just feels wrong. I'll always try to avoid naming my css classes after their look.
Regarding why I am not using thumbIcon
is because I am using it for the Thumbnail
itself, so instead of thumbTransparent
I used thumbIconWrapper
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.
Also I can not use the classes.thumb
if there is a custom icon, because the recent issue you posted on active hovering state was because of this class.
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.
How would it look if you overwrite the conflicting styles? It might be confusing to users that this class is not always applied to the 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.
Understood, i'll do something about it.
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 enabled classes.thumb
even when it is used with a thumb icon.
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.
Also I just wanted to say thank you for taking the time out of your busy schedule, to review my code. This really means a lot. Thank you.
And now circleCI is failing again, because the docs needs to be updated using |
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.
It looks lime the position of the custom icon needs to be offset to the left by half its width. Also, there are no visible focus or click states.
const trackProperty = vertical ? 'height' : 'width'; | ||
const thumbProperty = vertical ? 'top' : 'left'; | ||
const inlineTrackBeforeStyles = { [trackProperty]: this.calculateTrackBeforeStyles(percent) }; | ||
const inlineTrackAfterStyles = { [trackProperty]: this.calculateTrackAfterStyles(percent) }; | ||
const inlineThumbStyles = { [thumbProperty]: `${percent}%` }; | ||
|
||
/** Start Thumbnail Icon Logic Here */ |
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.
Could you change references to Thumbnail to something less confusing? a thumbnail and a (Material) thumb are two different things.
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.
Should I change the prop thumb
to sliderIcon
would that be better?
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.
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.
thumbIcon sounds nice. Should this be the external prop too. e.g, right now it is only thumb
.
<Slider {...otherProps} thumb={} />
Should I change this to thumbIcon
too, along with inside the code as well.
And in Slider.js file
Instead of Thumbnail
use thumbIcon
as ThumbIcon
because I need to clone the element and pass some props to it.
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.
Done, I have made changes. Can you please review. Again thank you for taking your busy time out to review my code. This really means a lot.
thumb={ | ||
<img | ||
alt="slider thumb icon" | ||
src="/static/images/cards/live-from-space.jpg" |
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.
As previously mentioned, using a large image shrunk to the size of a thumb makes it look like a glitch (circular or not).
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.
Should I remove this image example?
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.
With this image, then yes.
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.
Okay, understood.
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.
Or if it's okay can I use a 50x50 image of a circle, to use here as thumb icon? Instead of removing it. I'll need to add a new file in the static/ folder for this.
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 ended up using another image, if that is not okay. Please do let me know. I'll just remove the image demo from the slider.
|
||
return ( | ||
<div className={classes.root}> | ||
<Typography id="label">Slider Image</Typography> |
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.
"Image thumb"
/> | ||
} | ||
/> | ||
<Typography id="label">Slider Icon</Typography> |
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.
"Icon thumb"
Makes sense to me. @eps1lon? |
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.
@eps1lon I think the tests passed successfully this time. |
@@ -122,6 +122,25 @@ export const styles = theme => { | |||
height: 17, | |||
}, | |||
}, | |||
/* Class applied to the thumb element if custom thumb icon provided` . */ |
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.
There seems to be a s stray back-tick and space before the full-stop.
@mbrookes since I updated the comment on style, the yarn docs:api command needs to be run again. I have an issue on windows. Can you please run the commands for this PR. |
@oliviertassinari this PR has no conflicts any more, can this be merged now? |
import { withStyles } from '@material-ui/core/styles'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import Slider from '@material-ui/lab/Slider'; | ||
import StarsIcon from '@material-ui/icons/Gamepad'; |
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.
GamepadIcon
?
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.
Oops! Updating it :P
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 updated it to Lens icon, which is basically a filled circle.
|
||
return ( | ||
<div className={classes.root}> | ||
<Typography id="label">Image thumb</Typography> |
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.
The id
s need to be unique.
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.
added different id's
'&$activated': { | ||
width: 22, | ||
height: 22, | ||
transition: 'none', |
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.
The thumb should grow and shrink.
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.
the thumb does grow and shrink.
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.
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 had some bloated styling, which was redundant. I removed it.
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.
That seems to have fixed it in Firefox
const trackProperty = vertical ? 'height' : 'width'; | ||
const thumbProperty = vertical ? 'top' : 'left'; | ||
const inlineTrackBeforeStyles = { [trackProperty]: this.calculateTrackBeforeStyles(percent) }; | ||
const inlineTrackAfterStyles = { [trackProperty]: this.calculateTrackAfterStyles(percent) }; | ||
const inlineThumbStyles = { [thumbProperty]: `${percent}%` }; | ||
|
||
/** Start Thumb Icon Logic Here */ | ||
const withIcon = !!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.
Is it necessary to convert thumbIcon
to an explicit boolean?
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.
can you suggest me a better approach, i'd love to do it that way. (always learning 😅 )
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.
If thumbIcon isn't provided, it will be undefined, so evaluate to false. You could still use !! for clarity if you prefer, but use it directly in the ternary and classNames
, rather than assigning to a variable.
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.
removed redundant !!
import { withStyles } from '@material-ui/core/styles'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import Slider from '@material-ui/lab/Slider'; | ||
import LensIcon from '@material-ui/icons/Lens'; |
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.
Would LensOutlined work so as so as to be distinct from the default?
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.
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 wondered about that. Not ideal...
What about "adjust"? Otherwise "favorite" with a step slider as a sort of rating slider.
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.
Should it have a default background color? e.g white?
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.
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.
That'll work (for the purpose of a demo)
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.
For this I have to change the thumbIconWrapper
in my slider.js file
thumbIconWrapper: {
backgroundColor: '#fff',
},
Or should i override it with classes
prop in the demo for this?
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 it in the demo, is that okay? 😅 @mbrookes
@eps1lon Could you have a last look please? |
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 👍
@adeelibr We got there in the end 😄 Thanks for working on it. |
I have added a new prop called thumb to the Slider component, which you can use like this.
This looks something like this
This is a clean version of #12485 which got messed up, I kept on trying for some hours. but I guess I messed that pr more. Lesson learnt at my end.