-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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] Remove style-propable mixin and react-dom #3332
Conversation
[Slider] Fix css calc for calcDisabledSpacing [Slider] Fix css calc for calcDisabledSpacing [Slider] Copy this.props.style directly in the div that uses it
@@ -199,7 +193,7 @@ const Slider = React.createClass({ | |||
getStyles() { | |||
const fillGutter = this.getTheme().handleSize / 2; | |||
const disabledGutter = this.getTheme().trackSize + this.getTheme().handleSizeDisabled / 2; | |||
const calcDisabledSpacing = this.props.disabled ? ` -${disabledGutter}px` : ''; | |||
const calcDisabledSpacing = this.props.disabled ? ` - ${disabledGutter}px` : ''; |
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 wonder, when this is not disabled, does it matter if it's undefined
vs ''
. If not, we could write this as
this.props.disabled && `-{disabledGutter}px`
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 actually matters because the result of:
this.props.disabled && ` - {disabledGutter}px`
when this.props.disabled is false will be false. So in the string concatenation that happens after:
width: `calc(${(this.state.percent * 100)}%${calcDisabledSpacing})`
we would have the following string for example: 'calc(75% - false)'
I could change the code to behave as expected for that kind of assignment, but I would prefer not, because the advantage of a ternary is that we have the possibility to have a variable with the same type always (like in a functional approach), in that case a string. While, in the other case sometimes we have false and sometimes a string.
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.
Oh good catch! Thanks!
Good job @felipethome!
Good catch, yes we've been careful to make sure to not I left some comments that were unrelated to your changes that might improve code quality in other areas but so far this looks good. I forget to ask before, can you also move the |
Thanks @newoga . And I will gladly remove the I have a question, the slider has a lot of styles, some of them can be removed and I will do it soon, but most of them can't. A lot of these styles will me merged depending of state and prop variables. Right now, most of this merge computations are made in the |
I just realize that what I asked is not a good thing for the code. So, we don't need to change that. I will do the changes we talked about and remove getStyles to outside the class as you said, thanks! |
@felipethome Yeah give it a shot. The general patter we've been following is construct the style object in |
@newoga can you give a look? I am sorry I removed the clearValue function, I thought it was dead code since it is not being used inside the component and it doesn't seem to be in the docs, but maybe is some legacy code so I put the declaration back to its place.' Another thing, we are spreading all the props inside the root element:
Should I fix that to spread only the ones left? I mean, the ones the component doesn't explicitly use. Another thought, we call of "handle" the element that we drag, but it is really common to use the word handle in functions that are manipulating events, what do you think about change the name "handle" to "knob" or "thumb"? |
Looking good!
Yeah, it's probably better to leave it in for now. That being said, we should consider deprecating those methods for the next release since this component is controlled with
Yeah I think that's a good idea, let's add
Yeah I wondered the same thing, that's a good idea. Thumb seems like a good name based on the slider spec. |
Unfortunately, I think we will need to accept the name "handle", because there are variables in the muiTheme that use this name like: |
Yikes, yes you're right. That makes me said 😞. @alitaheri @oliviertassinari thoughts on this? |
It makes me sad too! Look this: |
overflow: 'visible', | ||
outline: 'none', | ||
}, | ||
handleWhenDisabled: { |
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 see what you mean with these:
handleWhenDisabled
, handledWhenPercentZero,
handleWhenPercentZeroAndDisabled`, etc. it would be nice if we could replace all of these wit ha single handle key so that the we didn't need Object.assign call below.
This can probably be solved by ternary for some keys or if there's too much, something like what we did with badge should work.
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.
They were already in the code actually. I will try hard to change that, but it will take some time because there are a lot of cases that need to be handled (pun intended 😄)
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.
Yeah I know! Not your fault. 😄
of cases that need to be handled (pun intended 😄)
😆
Yeah that's brutal. I really would like to fix that. Let me think about options... |
@newoga do you think the following code is too difficult to read? handle: {
boxSizing: props.disabled ? 'content-box' : 'border-box',
position: 'absolute',
cursor: props.disabled ? 'not-allowed' : 'pointer',
pointerEvents: 'inherit',
top: '0%',
left: state.percent === 0 ? '0%' : `${(state.percent * 100)}%`,
zIndex: 1,
margin: `${(slider.trackSize / 2)}px 0 0 0`,
width: props.disabled ? slider.handleSizeDisabled :
state.active ? slider.handleSizeActive : slider.handleSize,
height: props.disabled ? slider.handleSizeDisabled :
state.active ? slider.handleSizeActive : slider.handleSize,
backgroundColor: props.disabled ? slider.trackColor :
state.percent === 0 ? slider.handleFillColor : slider.selectionColor,
backgroundClip: 'padding-box',
borderRadius: '50%',
borderStyle: 'solid',
borderColor: (state.focused || state.hovered) ? slider.trackColorSelected : slider.handleColorZero,
borderWidth: state.percent === 0 && !props.disabled ? `${slider.trackSize}px` : 0,
transform: 'translate(-50%, -50%)',
transition:
`${Transitions.easeOut('450ms', 'background')}, ${
Transitions.easeOut('450ms', 'border-color')}, ${
Transitions.easeOut('450ms', 'width')}, ${
Transitions.easeOut('450ms', 'height')}`,
overflow: 'visible',
outline: 'none',
}, The slider can have a lot of different states: active, hovered, focused, disabled, percent zero. That is why I am thinking about ternaries instead of if-else generalizing all the states. Maybe the original way is more readable? |
Wow, you're not kidding 😆 Yeah maybe there's just too much state here to use ternarys for. Alright, let's leave it alone for now. I think there might be a way to break it up a bit still but let's see if we can get this merged now since we got style-prop and reactdom out. |
@oliviertassinari @alitaheri Can you take a look at this when you get a chance? |
That is a pity, but yes..would be too much for this PR. Can I at least move this piece of code:
To inside of the getStyles method()? Because then we get a Also, just something to point:
The this.props.styles are being applied two times, and should be just in the root element, right? But we probably would break some pages out there changing that right now. |
Yeah definitely, that makes sense
I didn't even catch that, that's a bug in my opinion. We ran into that with the AutoComplete component recently too. The style prop should really only be used for the root element. I want to fix this too... Looking at the code more closely, I wonder if the |
It doesn't offer anything at all for error and description. I think the slider component is more complex than what it seems when you just think about it. The material design specification also doesn't help us here because it has a lot of details about the design of this component.
I agree and If we had a directory just for the slider component, we would be able to break the implementation into pieces like: handle/thumb, track, errors, root. And that would simplify a lot.. Another awesome thing, would be a test case. Unfortunately, this test case isn't simple to write because of the amount of properties the user can set (that is the price we pay for customization). |
I agree, I think splitting this up is a good idea (and agree there is a lot more complexity to this than it seems, including functionality in the spec that we haven't implemented yet). Soon all the components will be put in directories (#3212) and we should be able to split it up. 😓 I wouldn't be totally opposed to starting to split of the thumb into a |
Awesome!
I would gladly be part of the discussion of how to split it, once you decide is time to do it. I added the last changes we talked about, now I think it is done. |
Okay awesome @felipethome, let's get some feedback from the other guys and we'll see what next steps are. Thanks so much, this is a huge help 👍 |
@felipethome That looks good 👍. Side note: I have noticed that |
Thanks @oliviertassinari ! The PR #3237 will solve this problem if you accept it. |
@felipethome Could you squash when you get a chance? @alitaheri If all is green for you, feel free to merge. We'll get the autoPrefix and other related improvements in future PRs. |
Actually only squash f392585 The rest of the commits are good for the history 👍 I'll review in a moment 👍 |
Let's continue this on the other PR. @oliviertassinari Feel free to merge, this looks good to me 👍 |
[Slider] Remove style-propable mixin and react-dom
@felipethome Thanks! 🎉 |
Awesome, thanks a lot @felipethome 👍 👍 👍 |
Great job! @felipethome 😄 |
Thank all of you too! 😄 |
This PR removes the style-propable mixin and react-dom from the slider source.
It, also, fixes the line:
There should be a space between '-' and '${disabledGutter}px', otherwise it will not be valid CSS.
Just to point it out, the following statement changed from:
to:
Since, the reference to this.props.style is kept outside the render() method would start to produce the warning from callOnce everytime we call the render method for styles that use this.props.style