-
Notifications
You must be signed in to change notification settings - Fork 62
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
IBX-617: As an Editor, I want to see the redesigned toggle button #1798
IBX-617: As an Editor, I want to see the redesigned toggle button #1798
Conversation
const methodName = event.target.checked ? 'add' : 'remove'; | ||
|
||
event.target.closest('.ez-data-source__label').classList[methodName]('is-checked'); | ||
// const methodName = event.target.checked ? 'add' : 'remove'; |
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.
commented code
const label = event.currentTarget.closest(SELECTOR_LABEL); | ||
|
||
label.classList[methodName]('is-checked'); | ||
// const methodName = event.currentTarget.checked ? 'add' : 'remove'; |
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.
commented
event.currentTarget.closest('.ibexa-toggle').classList.remove('ibexa-toggle--is-focused'); | ||
}; | ||
|
||
toggleFields.forEach((toggleField) => toggleField.addEventListener('click', toggleState)); |
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.
toggleFields.forEach((toggleField) => toggleField.addEventListener('click', toggleState)); | |
toggleFields.forEach((toggleField) => toggleField.addEventListener('click', toggleState, false)); |
|
||
&__input { | ||
opacity: 0; | ||
height: 1px; |
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.
calculateRem
{% set inputs %} | ||
{% endset %} | ||
|
||
|
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.
</span> | ||
{% endif %} | ||
</div> | ||
{%- endblock -%} |
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.
new line at the end
61210d3
to
d97052a
Compare
position: absolute; | ||
top: calculateRem(3px); | ||
left: 0; | ||
transition: all 0.3s $ibexa-admin-transition; |
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.
use $ibexa-admin-transition-duration
instead 0.3
event.currentTarget.classList.toggle('ibexa-toggle--is-checked'); | ||
|
||
const isChecked = event.currentTarget.classList.contains('ibexa-toggle--is-checked'); |
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 if I like this change 🤔 but it can be done this way:
event.currentTarget.classList.toggle('ibexa-toggle--is-checked'); | |
const isChecked = event.currentTarget.classList.contains('ibexa-toggle--is-checked'); | |
const isChecked = event.currentTarget.classList.toggle('ibexa-toggle--is-checked'); |
ref. https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/toggle#return_value
if (event.currentTarget.classList.contains('ibexa-toggle--radio')) { | ||
event.currentTarget.querySelector(`.form-check input[value="${valueToSet}"]`).checked = true; | ||
} else { | ||
event.currentTarget.querySelector('.ibexa-toggle__input').checked = isChecked; |
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 have a lot of event.currentTarget
in this function. We can extract it to a variable at the beginning:
const toggler = event.currentTarget;
const valueToSet = isChecked ? 1 : 0; | ||
|
||
if (event.currentTarget.classList.contains('ibexa-toggle--radio')) { | ||
event.currentTarget.querySelector(`.form-check input[value="${valueToSet}"]`).checked = true; |
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 valueToSet
is only used in inside first if's execution block.
const valueToSet = isChecked ? 1 : 0; | |
if (event.currentTarget.classList.contains('ibexa-toggle--radio')) { | |
event.currentTarget.querySelector(`.form-check input[value="${valueToSet}"]`).checked = true; | |
if (event.currentTarget.classList.contains('ibexa-toggle--radio')) { | |
const valueToCheck = isChecked ? 1 : 0; | |
event.currentTarget.querySelector(`.form-check input[value="${valueToSet}"]`).checked = true; |
return; | ||
} | ||
|
||
event.currentTarget.closest('.ibexa-toggle').classList.add('ibexa-toggle--is-focused'); |
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 me, it looks a little bit complicated. I would split it into two lines.
const addFocus = (event) => { | ||
event.preventDefault(); | ||
|
||
if (event.currentTarget.classList.contains('ibexa-toggle--is-disabled')) { |
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 think its good to assign conditions to some variables to give them meaning. You can read code faster. :)
if (event.currentTarget.classList.contains('ibexa-toggle--is-disabled')) { | |
const isTogglerDisabled = event.currentTarget.classList.contains('ibexa-toggle--is-disabled'); | |
if (isTogglerDisabled) { |
src/bundle/Resources/views/themes/admin/ui/form_fields/toggle_widget.html.twig
Show resolved
Hide resolved
d66f52f
to
ce62098
Compare
ce62098
to
947bbb9
Compare
947bbb9
to
5c2bd8f
Compare
5c04e52
to
15d9afd
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
JIRa ref: https://issues.ibexa.co/browse/IBX-617
https://github.com/ezsystems/ezcommerce-shop/pull/326
#1798
https://github.com/ezsystems/ezplatform-form-builder/pull/287
https://github.com/ezsystems/ezplatform-page-builder/pull/783
https://github.com/ezsystems/ezplatform-site-factory/pull/128