Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const BaseInternationalPhoneInput = forwardRef<
(
{
clearableCountryCode: clearableCountryCodeFromProps = true,
hideCountryFlag = false,
value,
country: countryProp,
filterFn,
Expand Down Expand Up @@ -235,21 +236,23 @@ export const BaseInternationalPhoneInput = forwardRef<
...inputProps,
onClear: handleClear,
onInput: handleInput,
leftAddons: renderCountrySelect(view === 'mobile'),
leftAddons: hideCountryFlag ? null : renderCountrySelect(view === 'mobile'),
}}
fieldProps={{
...(restProps.fieldProps as AnyObject),
className: inputProps.className,
addonsClassName: inputProps.addonsClassName,
...(view === 'mobile' ? { leftAddons: renderCountrySelect() } : null),
...(view === 'mobile'
? { leftAddons: hideCountryFlag ? null : renderCountrySelect() }
: null),
}}
/>
) : (
<Input
{...restProps}
{...inputProps}
onClear={inputProps.clear ? handleClear : undefined}
leftAddons={renderCountrySelect()}
leftAddons={hideCountryFlag ? null : renderCountrySelect()}
size={size}
onInput={handleInput}
value={value}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const international_phone_input: Story = {
)}
clear={boolean('clear', false)}
success={boolean('success', false)}
hideCountryFlag={boolean('options', true)}
/>
</div>
);
Expand Down
12 changes: 11 additions & 1 deletion packages/international-phone-input/src/docs/description.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ render(() => {

## Инпут без пикера страны

При необходимости можно отключить возможность явно выбирать код страны через селект. Инпут сам определит страну после ввода её кода.
При необходимости можно отключить возможность явно выбирать код страны через селект, или спрятать элемент флажка. Инпут сам определит страну после ввода её кода.

```jsx live mobileHeight={640}
render(() => {
const [value, setValue] = React.useState('');
const [selectedCountry, setSelectedCountry] = React.useState();
const [hideCountryFlag, setHideCountryFlag] = React.useState(false);

const handleChange = (phone) => setValue(phone);

Expand All @@ -84,11 +85,20 @@ render(() => {
onCountryChange={setSelectedCountry}
block={true}
countrySelectProps={{ hideCountrySelect: true }}
hideCountryFlag={hideCountryFlag}
/>
<Gap size='m' />
<Typography.Text color='secondary'>
Код выбранной страны: {selectedCountry && selectedCountry.iso2}
</Typography.Text>
<Gap size='m' />
<Switch
checked={hideCountryFlag}
label='Спрятать флажок'
onChange={() => {
setHideCountryFlag((prevState) => !prevState);
}}
/>
</div>
);
});
Expand Down
6 changes: 6 additions & 0 deletions packages/international-phone-input/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export type CommonPhoneInputProps = {
*/
clearableCountryCode?: boolean | 'preserve';

/**
* Скрывает компонент селекта
* @default false
*/
hideCountryFlag?: boolean;

/**
* Свойства селекта выбора стран
*/
Expand Down
Loading