-
-
Notifications
You must be signed in to change notification settings - Fork 113
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
fix: change UI when restricting to only one country on PhoneInput #1816
Conversation
Bug Fixes
Contributors@gtallesb, @TahimiLeonBravo, @maxxgreene Commit-Lint commandsYou can trigger Commit-Lint actions by commenting on this PR:
|
import { StyledTrigger, StyledFlagContainer, StyledIndicator } from './styled'; | ||
|
||
export default function VariantRenderIf(props) { | ||
const { isTrue, ref, onClick, onBlur, tabIndex, disabled, error, countries, flagIcon } = props; |
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.
Similar blocks of code found in 4 locations. Consider refactoring.
src/components/PhoneInput/index.js
Outdated
<VariantRenderIf | ||
isTrue | ||
ref={triggerRef} | ||
onClick={handleClick} | ||
onFocus={event => handleFocus(event, 0)} | ||
onBlur={handleBlur} | ||
tabIndex={tabIndex} | ||
disabled={disabled} | ||
error={error} | ||
countries={countriesProps} | ||
flagIcon={flagIcon} | ||
/> |
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 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>
src/components/PhoneInput/readme.md
Outdated
placeholder="Enter your phone number" | ||
onChange={setPhone} | ||
value={phone} | ||
countries='' |
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.
countries has to be an array
…to fix-changing-UI-one-country-on-PhoneInput
…to fix-changing-UI-one-country-on-PhoneInput
…to fix-changing-UI-one-country-on-PhoneInput
import { StyledTrigger, StyledFlagContainer, StyledIndicator } from './styled'; | ||
|
||
export default function VariantRenderIf(props) { | ||
const { ref, onClick, onBlur, tabIndex, disabled, error, countries, flagIcon } = props; |
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.
Similar blocks of code found in 10 locations. Consider refactoring.
); | ||
} | ||
return ( | ||
<StyledTrigger |
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.
Similar blocks of code found in 2 locations. Consider refactoring.
<Form /> | ||
</Container> | ||
|
||
``` |
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.
remove unnecessary empty lines ^^
src/components/PhoneInput/readme.md
Outdated
placeholder="Enter your phone number" | ||
onChange={setPhone} | ||
value={phone} | ||
countries={[]} |
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.
it's an example with a single selection, right?? I see empty array []
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 when the countries
receive an empty array it should render all the countries
…to fix-changing-UI-one-country-on-PhoneInput
src/components/PhoneInput/readme.md
Outdated
placeholder="Enter your phone number" | ||
onChange={setPhone} | ||
value={phone} | ||
countries={[]} |
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 when the countries
receive an empty array it should render all the countries
…to fix-changing-UI-one-country-on-PhoneInput
…ithub.com/nexxtway/react-rainbow into fix-changing-UI-one-country-on-PhoneInput
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.
+1
Code Climate has analyzed commit 287a5c1 and detected 0 issues on this pull request. View more on Code Climate. |
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