Skip to content
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

Merged

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';
Copy link
Member

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';
Copy link
Member

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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
toggleFields.forEach((toggleField) => toggleField.addEventListener('click', toggleState));
toggleFields.forEach((toggleField) => toggleField.addEventListener('click', toggleState, false));


&__input {
opacity: 0;
height: 1px;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calculateRem

{% set inputs %}
{% endset %}


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

</span>
{% endif %}
</div>
{%- endblock -%}
Copy link
Member

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

@GrabowskiM GrabowskiM force-pushed the IBX-617-as-an-editor-i-want-to-see-the-redesigned-toggle-button branch from 61210d3 to d97052a Compare July 12, 2021 10:39
@GrabowskiM GrabowskiM requested a review from dew326 July 12, 2021 12:48
position: absolute;
top: calculateRem(3px);
left: 0;
transition: all 0.3s $ibexa-admin-transition;
Copy link
Contributor

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

Comment on lines 11 to 13
event.currentTarget.classList.toggle('ibexa-toggle--is-checked');

const isChecked = event.currentTarget.classList.contains('ibexa-toggle--is-checked');
Copy link
Contributor

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:

Suggested change
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;
Copy link
Contributor

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;

Comment on lines 14 to 17
const valueToSet = isChecked ? 1 : 0;

if (event.currentTarget.classList.contains('ibexa-toggle--radio')) {
event.currentTarget.querySelector(`.form-check input[value="${valueToSet}"]`).checked = true;
Copy link
Contributor

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.

Suggested change
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');
Copy link
Contributor

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')) {
Copy link
Contributor

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. :)

Suggested change
if (event.currentTarget.classList.contains('ibexa-toggle--is-disabled')) {
const isTogglerDisabled = event.currentTarget.classList.contains('ibexa-toggle--is-disabled');
if (isTogglerDisabled) {

@GrabowskiM GrabowskiM force-pushed the IBX-617-as-an-editor-i-want-to-see-the-redesigned-toggle-button branch from d66f52f to ce62098 Compare July 14, 2021 10:43
@GrabowskiM GrabowskiM force-pushed the IBX-617-as-an-editor-i-want-to-see-the-redesigned-toggle-button branch from ce62098 to 947bbb9 Compare July 15, 2021 07:38
@GrabowskiM GrabowskiM force-pushed the IBX-617-as-an-editor-i-want-to-see-the-redesigned-toggle-button branch from 947bbb9 to 5c2bd8f Compare July 15, 2021 08:54
@GrabowskiM GrabowskiM requested a review from dew326 July 15, 2021 10:36
@GrabowskiM GrabowskiM force-pushed the IBX-617-as-an-editor-i-want-to-see-the-redesigned-toggle-button branch from 5c04e52 to 15d9afd Compare July 20, 2021 13:16
@sonarcloud
Copy link

sonarcloud bot commented Jul 20, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@dew326 dew326 merged commit c579183 into master Jul 21, 2021
@dew326 dew326 deleted the IBX-617-as-an-editor-i-want-to-see-the-redesigned-toggle-button branch July 21, 2021 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants