-
Notifications
You must be signed in to change notification settings - Fork 6
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
Modernize polaris-color-picker components #493
Modernize polaris-color-picker components #493
Conversation
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.
@tomnez seems some tests are failing....can you please re-tag me once they pass
7330824
to
f7fa53d
Compare
f7fa53d
to
1c58f5f
Compare
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.
Generally looking good @tomnez, but for whatever reason there's an iffy error on CI 😭
} | ||
|
||
@computed('contentId') | ||
get 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.
Curious what @vladucu's thoughts are about this naming, mostly because I'm conflicted: part of me feels like we shouldn't be overwriting Ember's internal API, part of me feels like we should be able to overwrite because that's why we do inheritance. Basically I'm good with this as is but would also understand if we'd prefer to name it something else 😝
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.
hmm, tbh...I'm not sure I understand why we need 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.
@vladucu you're confused as to why it's a CP, or confused as to why we need to set the element?
I guess we could just set it in the init hook since that's the only place it's used. I was just trying to keep the same API that we were used to (having the use of this.element
) but I can get rid of it. If we ever end up needing it in multiple methods then we can refactor to a CP again.
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, why we need the CP....we get the element
explicitly as first parameter in the action called through did-insert
modifier....we could just set it here as a property on the component....but unless I'm wrong, it's only used in this one place
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.
update - was going through other files, and components like polaris-color-picker/slidable
call this.element
from multiple places, so maybe it's easiest to have it as a CP in this particular case?
If not we can call document.querySelector('#${this.contentId}')
each time. Pretty much the same thing IMO 🤷♂
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.
note: maybe I'm missing something and just talking non-sense...feel free to correct me
what I mean is....we can just keep it simple....why add a CP when you already have an action that set's contentId
and then have the CP compute what you call element
now
even more...could this just be? Not sure where the content
stuff comes from in this PR....
/**
* Polaris color picker component.
* See https://polaris.shopify.com/components/forms/color-picker
*/
@tagName('')
@templateLayout(layout)
export default class PolarisColorPicker extends Component {
....
// NO LONGER NEEDED
// didRender() {
// super.didRender(...arguments);
// let element = this.element;
// if (isNone(element)) {
// return;
// }
// Grab the size of the picker for positioning the draggable markers.
// const mainColorElement = element.querySelector(
// 'div.Polaris-ColorPicker__MainColor'
// );
// if (isNone(mainColorElement)) {
// return;
// }
// this.set('pickerSize', mainColorElement.clientWidth);
// }
@action
setPickerSize(element) {
// Grab the size of the picker for positioning the draggable markers.
const mainColorElement = element.querySelector(
'div.Polaris-ColorPicker__MainColor'
);
this.set('pickerSize', mainColorElement.clientWidth);
}
...
}
<div
id={{this.contentId}}
class="Polaris-ColorPicker"
{{did-insert this.setContentId}}
>
<div class="Polaris-ColorPicker__MainColor">
...
</div>
....
</div>
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.
^ Agreed, this works for polaris-color-picker
, but other components will have multiple methods that need to access the container element, so in other components we should at least set element
as a property on did-insert
(see slidable.js
, it accessing element
in other places besides the did-insert
method).
So I figure I'll refactor where I can, but some components might still have the element
property set.
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.
don't get me wrong Tom....in the same action you call from did-insert
, of course, keep a reference to the mainColorElement
or whatever you need by setting it on the component....if you need that for later use too
} | ||
|
||
@action | ||
setContentId(element, [value]) { |
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.
Reckon this, then contentId
property etc. are worth putting into a mixin? We're already using them 4 times in this PR alone 🤔
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.
we should probably stop using mixins going further, if we want to be able to use Glimmer components
what do you think about looking later into drying this up?
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.
Looking good so far...left a few comments though
} | ||
|
||
@action | ||
setContentId(element, [value]) { |
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.
we should probably stop using mixins going further, if we want to be able to use Glimmer components
what do you think about looking later into drying this up?
} | ||
|
||
@computed('contentId') | ||
get 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.
hmm, tbh...I'm not sure I understand why we need this
|
||
didRender() { | ||
this._super(...arguments); | ||
super.didRender(...arguments); |
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 don't think we need didRender
anymore...actually we want to stop using any other lifecycle hooks except init/destroy....instead we should have this logic inside the action you added setContentId
(renamed ofc)
pickerSize, | ||
color: { hue, alpha = 1 }, | ||
onChange, | ||
} = this.getProperties('pickerSize', 'color', 'onChange'); |
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.getProperties('pickerSize', 'color', 'onChange'); | |
} = this; |
const { | ||
color: { brightness, saturation, alpha = 1 }, | ||
onChange, | ||
} = this.getProperties('color', 'onChange'); |
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.getProperties('color', 'onChange'); | |
} = this; |
const { | ||
color: { hue, brightness, saturation }, | ||
onChange, | ||
} = this.getProperties('color', 'onChange'); |
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.getProperties('color', 'onChange'); | |
} = this; |
@@ -1,6 +1,8 @@ | |||
import { tagName, layout as templateLayout } from '@ember-decorators/component'; |
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.
same here (and other files), can we order this please
} | ||
|
||
@computed('contentId') | ||
get 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.
similar here like in main component
|
||
@action | ||
handleChange({ y }) { | ||
const { sliderHeight, onChange } = this.getProperties( |
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.
let's use ES6 destructuring
@vladucu @andrewpye updated - also, I ran the base branch locally and Seems like it would allow us to move a lot faster rather than finding failing tests and |
} | ||
|
||
@action | ||
setContentId(element, value) { |
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 this copied from somewhere? I don't understand where it's coming from, can't see it in the version prior to these changes
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's slighty different than the old version, it used to be
setContentId(element, [value])
because it used to get called from the on-insert
modifier, but now it gets called from within setContentIdAndTriggerHeightChanged
below.
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 you mind linking me to the old version here on github?
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's here in my first commit - this link doesn't seem to scroll to the line changes, but its slidable.js
, lines 150-153 - 0c66046#diff-160b5cb0d5fd7505911f238ca1295ee4R150-R153
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.
kk....do you think this is needed? why are we adding an ID attirbute to the new wrapping div
in the template that was added after making this component tag-less?
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 should be much simpler....please check ember-render-modifiers to understand it's usage....it's super simple: did-insert
will invoke your action with one param element
(the element on which did-insert
is added) and whatever else you're passing to it.....just set this element
argument you receive in your action and set it on this component
there's no need guidFor
and appending content
....etc (which is why I was confused)
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.
Ahh I did that originally, but got the error
Cannot set property element of [object Object] which has only a getter
I thought maybe it was something weird with the modifiers but it turns out it just doesn't want me using the key name "element"
.. 🤦♂ So yeah I can just do that.
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.
welp, element
is a reserved word in ember so makes sense
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, strange that it let me overwrite it with a CP tho.
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, strange that it let me overwrite it with a CP tho.
I guess overwriting replaces the entire setter/getter combo, while setting tries to access a non-existent setter on the existing element
property 🤷♂
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.
Not sure if you've missed to push the commit, but I still see in slidable
things we discussed yesterday to change...can you please take a look and re-tag once ready?
Ahhh yeah forgot to push 🤦♂ |
classic tom 😄 |
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.
Thanks for the updates, Tom!
👍
</div> | ||
<div | ||
class="Polaris-ColorPicker" | ||
{{did-insert this.setPickerSize}} |
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.
nit: let's add ...attributes
here too
Updates
PolarisColorPicker
to tagless component, ES6 classes, and angle bracket syntax.A lot of changes are just codemod changes - additional edits to the component worth pointing out are:
{{did-insert}}
and{{will-destroy}}
modifiers so we can set a unique ID on the tagless component since the component files made use ofthis.element
.get element()
computed property to return the container element, if we think this will be confusing we could rename to something specific per component, i.e.get alphaPickerElement()
template-lint-disable no-invalid-interactive
to the slider because it makes use ofonmousedown
andontouchstart
events.Dummy app demo: