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

fix: change UI when restricting to only one country on PhoneInput #1816

Merged
merged 12 commits into from
Sep 21, 2020

Conversation

gtallesb
Copy link
Collaborator

fix: #1649

Changes proposed in this PR:

-add new conditional component VariantRenderIf
-replace one of the RenderIf components with VariantRenderIf on index.js
-add a new interactive example passing the countries prop on .md

@nexxtway/react-rainbow

@commit-lint
Copy link

commit-lint bot commented Sep 10, 2020

Bug Fixes

  • change UI when restricting to only one country on PhoneInput (a6a011d)
  • change UI when only one country on PhoneInput (2751710)
  • change UI when restricting to one country on PhoneInput (579ec06)
  • change UI when only one country on PhoneInput (8dd09e3)
  • remove empty lines (287a5c1)

Contributors

@gtallesb, @TahimiLeonBravo, @maxxgreene

Commit-Lint commands

You can trigger Commit-Lint actions by commenting on this PR:

  • @Commit-Lint merge patch will merge dependabot PR on "patch" versions (X.X.Y - Y change)
  • @Commit-Lint merge minor will merge dependabot PR on "minor" versions (X.Y.Y - Y change)
  • @Commit-Lint merge major will merge dependabot PR on "major" versions (Y.Y.Y - Y change)
  • @Commit-Lint merge disable will desactivate merge dependabot PR
  • @Commit-Lint review will approve dependabot PR
  • @Commit-Lint stop review will stop approve dependabot PR

import { StyledTrigger, StyledFlagContainer, StyledIndicator } from './styled';

export default function VariantRenderIf(props) {
const { isTrue, ref, onClick, onBlur, tabIndex, disabled, error, countries, flagIcon } = props;
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 4 locations. Consider refactoring.

Comment on lines 142 to 153
<VariantRenderIf
isTrue
ref={triggerRef}
onClick={handleClick}
onFocus={event => handleFocus(event, 0)}
onBlur={handleBlur}
tabIndex={tabIndex}
disabled={disabled}
error={error}
countries={countriesProps}
flagIcon={flagIcon}
/>
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 the solution can be simpler something like this:

    const isReadOnly = readOnly && !disabled;
    const hasTrigger = !isReadOnly && countries.length > 1;
    const isOnlyCountry = !isReadOnly && countries.length === 1;
    
    
    
    <RenderIf isTrue={isReadOnly}>
        <StyledFlagContainer readOnly>{flagIcon}</StyledFlagContainer>
    </RenderIf>

    <RenderIf isTrue={hasTrigger}>
        <StyledTrigger
            ref={triggerRef}
            onClick={handleClick}
            onFocus={event => handleFocus(event, 0)}
            onBlur={handleBlur}
            tabIndex={tabIndex}
            disabled={disabled}
        >
            <StyledFlagContainer disabled={disabled}>
                {flagIcon}
                <StyledIndicator error={error} disabled={disabled} />
            </StyledFlagContainer>
        </StyledTrigger>
    </RenderIf>

    <RenderIf isTrue={isOnlyCountry}>
        <StyledFlagContainer disabled={disabled}>{flagIcon}</StyledFlagContainer>
    </RenderIf>

placeholder="Enter your phone number"
onChange={setPhone}
value={phone}
countries=''
Copy link
Contributor

Choose a reason for hiding this comment

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

countries has to be an array

import { StyledTrigger, StyledFlagContainer, StyledIndicator } from './styled';

export default function VariantRenderIf(props) {
const { ref, onClick, onBlur, tabIndex, disabled, error, countries, flagIcon } = props;
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 10 locations. Consider refactoring.

);
}
return (
<StyledTrigger
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 2 locations. Consider refactoring.

<Form />
</Container>

```
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove unnecessary empty lines ^^

placeholder="Enter your phone number"
onChange={setPhone}
value={phone}
countries={[]}
Copy link
Collaborator

Choose a reason for hiding this comment

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

it's an example with a single selection, right?? I see empty array []

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think when the countries receive an empty array it should render all the countries

…to fix-changing-UI-one-country-on-PhoneInput
placeholder="Enter your phone number"
onChange={setPhone}
value={phone}
countries={[]}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think when the countries receive an empty array it should render all the countries

Copy link
Contributor

@maxxgreene maxxgreene left a comment

Choose a reason for hiding this comment

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

+1

@codeclimate
Copy link

codeclimate bot commented Sep 21, 2020

Code Climate has analyzed commit 287a5c1 and detected 0 issues on this pull request.

View more on Code Climate.

@TahimiLeonBravo TahimiLeonBravo merged commit 3b7d2bc into master Sep 21, 2020
@TahimiLeonBravo TahimiLeonBravo deleted the fix-changing-UI-one-country-on-PhoneInput branch September 21, 2020 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix: change UI when restricting to only one country on the PhoneInput
5 participants