Skip to content

Refactor: Form elements #1315

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

Merged
merged 19 commits into from
May 19, 2022
Merged

Refactor: Form elements #1315

merged 19 commits into from
May 19, 2022

Conversation

arielj
Copy link
Collaborator

@arielj arielj commented May 15, 2022

This PR is a refactor around how we use selects, text inputs, and the toggle switch tags.

There were some issues:

  • we had to copy some extra tags with specific classes in specific order for things to work properly (like to add a text field we had to add a span.setting, then a label with a specific code for RTL, then another element and so on), now each tag has it's own component so to add a select field (with a label and some extra stuff) we can use SelectField, similar with TextInputField, also each component handles the RTL variable
  • the css for those elements was a big hacky and elements were not all the same width (which was driving me crazy xD)
  • responsiveness was not asking properly in some cases
  • for the ToggleSwitch, I removed some elements to make it simpler relying a big more in CSS instead of code
  • The FormControl element is doing to much and still requires specific html, these new components are more focused

I'll add more comments in the diff


Use the following Checklist if you have changed something on the Backend or Frontend:

  • Tested the feature and it's working on a current and clean install.
  • Tested the main App features and they are still working on a current and clean install. (Login, Install, Play, Uninstall, Move games, etc.)
  • Created / Updated Tests (If necessary)
  • Created / Updated documentation (If necessary)

showWeblateLink?: boolean
}

const languageLabels: { [key: string]: string } = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

moved these 2 constants outside the component so they are not initialized in every call to the function

dataTestId = 'toggleSwitch'
} = props
// TODO fixes errors in the console, but the props may not be necessary at all
const checkmarkProps = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was able to remove the need of the .checkmark element completely so we don't need this anymore

.switch input:checked ~ .checkmark:after {
display: block;
.toggleSwitchWrapper.checked:before {
content: '\2713';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

replaced the hacky check done using css borders and rotation with a real check character

@@ -3,29 +3,36 @@ input[type='range'] {
max-width: 513px;
}

.Accessibility > .settingsWrapper > .setting > .is-drop-down {
background-position: calc(100% - 20px) calc(1em + -4px),
calc(100% - 15px) calc(1em + -4px), calc(101% - 2.5em) calc(0.5em + -8px);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed the main background properties so it works in smaller and bigger selects so this is not needed

const handleChangeLanguage = (language: string) => {
storage.setItem('language', language)
i18n.changeLanguage(language)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

language changes are handled by the LanguageSelector component directly

@arielj arielj added the pr:ready-for-review Feature-complete, ready for the grind! :P label May 15, 2022
@@ -185,17 +185,10 @@ html,
}

.material-icons.settings.folder {
Copy link
Member

Choose a reason for hiding this comment

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

One thing, not really related with the PR.
Have you noticed that we are using two different folder icons? one on the settings and another on the InstallModal.
I think we should pick one, maybe the one that we are using on the InstallModal looks a bit better imo.
But we can do that in another task if you think this could increase the scope of this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah, I didn't know the reason so I just skipped that, I agree that a single icon in all palces would look better

I'm also thinking about adding another component PathInputField that would take care of the input with the folder icon, we use that in a lot of places, I think it's a good opportunity to simplify that

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I extracted a TextInputWithIconField component instead, maybe we can extract a PathInputField in the future, but not all path inputs behave the same so decided to go with a more generic input with icon

flavioislima
flavioislima previously approved these changes May 17, 2022
Copy link
Member

@flavioislima flavioislima left a comment

Choose a reason for hiding this comment

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

Looks pretty good!
I can see all settings finally are well aligned :)

just a question, the ToggleSwitch checkmark background should not be using transparent, or the same color as the setting's background? 🤔
Screenshot 2022-05-17 at 09 31 06

@flavioislima
Copy link
Member

Another bug I just found was tha the settings are not working for RTL anymore, a param for that would be necessary to change the layout for those languages.
Screenshot 2022-05-17 at 09 54 07

@flavioislima flavioislima dismissed their stale review May 17, 2022 07:55

will ask changes

@arielj
Copy link
Collaborator Author

arielj commented May 17, 2022

Looks pretty good! I can see all settings finally are well aligned :)

just a question, the ToggleSwitch checkmark background should not be using transparent, or the same color as the setting's background? thinking Screenshot 2022-05-17 at 09 31 06

I have to check this, I had an issue with hidding the original input and I was covering it setting the background of the check box, but I fixed that problem and forgot to remove that extra background

@arielj
Copy link
Collaborator Author

arielj commented May 17, 2022

Another bug I just found was tha the settings are not working for RTL anymore, a param for that would be necessary to change the layout for those languages. Screenshot 2022-05-17 at 09 54 07

weird, the compontents itself now gets the isRTL from the context so the prop is not needed, maybe I'm not setting that properly, I'll check that in a moment

@arielj arielj added pr:wip WIP, don't merge. and removed pr:ready-for-review Feature-complete, ready for the grind! :P labels May 17, 2022
@arielj
Copy link
Collaborator Author

arielj commented May 17, 2022

Fixed the RTL language style (I also improved some elements to do full RTL alignment and not just the label

image

@arielj arielj added pr:ready-for-review Feature-complete, ready for the grind! :P and removed pr:wip WIP, don't merge. labels May 17, 2022
@arielj
Copy link
Collaborator Author

arielj commented May 17, 2022

Also added an extra TextFieldWithIconField component so we don't need to pass specific markup for the icon, we just pass the icon and the click handler and it will create the correct html.

Finally, I replaced all uses of a Folder icon with the one in the InstallDialog component

Copy link
Member

@flavioislima flavioislima left a comment

Choose a reason for hiding this comment

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

I think that looks great now!
Ready to merge! ⚔️

@flavioislima flavioislima added pr:ready-to-merge This PR is fully ready for merge. and removed pr:ready-for-review Feature-complete, ready for the grind! :P labels May 18, 2022
@arielj arielj merged commit d005767 into main May 19, 2022
@arielj arielj deleted the refactor/form-elements branch May 19, 2022 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:ready-to-merge This PR is fully ready for merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants