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

[DS-497] - Create dropdown input component 🚀 #586

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

mavericardo
Copy link
Contributor

@mavericardo mavericardo commented Dec 8, 2022

JIRA Issue

Description 📄

Context:

(WHAT) What does this component do?

  • Allows the user to choose a country and add secondary information. (Company name for example)

(WHY) That's been required by some teams.

Platforms 📲

  • Web
  • Mobile

Type of change 🔍

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested? 🧪

  • Unit Test - work in progress
  • Snapshot Test

Checklist: 🔍

  • My code follows the contribution guide of this project Contributing Guide
  • Layout matches design prototype: FIGMA
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Screenshots 📸

dropdowninput.mov

Copy link
Contributor

@guilhermecardoso-gympass guilhermecardoso-gympass left a comment

Choose a reason for hiding this comment

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

This component is used only countries ? For me OK! Just fix the spacing and sizes with a Yoga Theming spacing e all done! Congrats for that contrib.

packages/yoga/src/DropdownInput/web/DropdownInput.jsx Outdated Show resolved Hide resolved
packages/yoga/src/DropdownInput/web/DropdownInput.jsx Outdated Show resolved Hide resolved
packages/yoga/src/DropdownInput/web/DropdownInput.jsx Outdated Show resolved Hide resolved
packages/yoga/src/DropdownInput/web/DropdownInput.jsx Outdated Show resolved Hide resolved
packages/yoga/src/DropdownInput/web/DropdownInput.jsx Outdated Show resolved Hide resolved
packages/yoga/src/DropdownInput/web/DropdownInput.jsx Outdated Show resolved Hide resolved
packages/yoga/src/DropdownInput/web/DropdownInput.jsx Outdated Show resolved Hide resolved
packages/yoga/src/DropdownInput/web/DropdownInput.jsx Outdated Show resolved Hide resolved
packages/yoga/src/DropdownInput/web/DropdownInput.jsx Outdated Show resolved Hide resolved
Comment on lines 200 to 235
const renderListCountries = () => {
return countries.map(country => {
const isCountrySelected = selectedCountry.id === country.id;

return (
<ItemDropDown
d="flex"
alignItems="center"
justifyContent="flex-start"
alignContent="center"
key={country.id}
onClick={changeSelectedCountry(country)}
>
<ContainerName>
<Box>
<Icon
as={country.icon}
width="medium"
height="medium"
marginRight={4}
/>
</Box>
<Text.Small
fw={isCountrySelected ? 'medium' : 'regular'}
color={isCountrySelected ? 'primary' : 'secondary'}
>
{country.name}
</Text.Small>
</ContainerName>
{isCountrySelected && (
<Icon as={Check} width="medium" height="medium" fill="vibin" />
)}
</ItemDropDown>
);
});
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Creating this renderListCountries function is an anti-pattern.

It's better to do the .map directly and (optionally) extract <IterDropDown... to a new component outside render.

Copy link
Contributor

Choose a reason for hiding this comment

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

dont' forget the solution we've discussed offline

Copy link
Contributor Author

Choose a reason for hiding this comment

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


const ContainerName = styled.div``;

const DropdownInput = ({
Copy link
Contributor

Choose a reason for hiding this comment

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

The name of this component is too the generic, considering we have this one:

https://gympass.github.io/yoga/components/dropdown

So, WDYT of?

Suggested change
const DropdownInput = ({
const CountryDropdownInput = ({

value,
selectedCountry,
onChangeSelectedCountry,
countries,
Copy link
Contributor

Choose a reason for hiding this comment

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

If you choose the path of specifying this components in only to work with countries this list can be static instead of a prop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This way, whoever uses the component will not be able to specify the countries that should be displayed.
What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Currently gympass only supports the countries we have flags for. If you want to keep this property, then you should make it optional and have a default list...

Comment on lines 200 to 235
const renderListCountries = () => {
return countries.map(country => {
const isCountrySelected = selectedCountry.id === country.id;

return (
<ItemDropDown
d="flex"
alignItems="center"
justifyContent="flex-start"
alignContent="center"
key={country.id}
onClick={changeSelectedCountry(country)}
>
<ContainerName>
<Box>
<Icon
as={country.icon}
width="medium"
height="medium"
marginRight={4}
/>
</Box>
<Text.Small
fw={isCountrySelected ? 'medium' : 'regular'}
color={isCountrySelected ? 'primary' : 'secondary'}
>
{country.name}
</Text.Small>
</ContainerName>
{isCountrySelected && (
<Icon as={Check} width="medium" height="medium" fill="vibin" />
)}
</ItemDropDown>
);
});
};
Copy link
Contributor

Choose a reason for hiding this comment

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

dont' forget the solution we've discussed offline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants