-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Replace the usages of
react-phone-input-2
with `antd-phone-…
…input`" This reverts commit 31c0845.
- Loading branch information
Showing
4 changed files
with
87 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/components/BaseQuestionnaireResponseForm/widgets/PhoneInput/PhoneInput.styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import styled from 'styled-components/macro'; | ||
|
||
export const S = { | ||
Container: styled.div` | ||
display: flex; | ||
width: fit-content; | ||
.react-phone-input { | ||
border-color: ${({ theme }) => theme.antdTheme?.colorBorder}; | ||
height: 32px; | ||
box-shadow: none; | ||
border-radius: 6px; | ||
background-color: ${({ theme }) => theme.antdTheme?.colorBgContainer}; | ||
} | ||
.react-phone-input__button { | ||
background-color: ${({ theme }) => theme.antdTheme?.colorBgContainer}; | ||
border-color: ${({ theme }) => theme.antdTheme?.colorBorder}; | ||
} | ||
.flag-dropdown { | ||
border-radius: 6px 0 0 6px !important; | ||
background: 0 !important; | ||
} | ||
.selected-flag { | ||
background: 0 !important; | ||
} | ||
&:hover { | ||
.react-phone-input, | ||
.react-phone-input__button { | ||
border-color: ${({ theme }) => theme.primary}; | ||
} | ||
} | ||
.country-list { | ||
background-color: ${({ theme }) => theme.antdTheme?.colorBgContainer}; | ||
border-radius: 8px; | ||
padding: 4px; | ||
} | ||
.country { | ||
padding: 5px 12px !important; | ||
font-size: 14px; | ||
border-radius: 4px; | ||
transition: background 0.3s ease; | ||
cursor: pointer; | ||
color: ${({ theme }) => theme.antdTheme?.colorText}; | ||
&:hover { | ||
background-color: ${({ theme }) => theme.antdTheme?.controlItemBgHover} !important; | ||
} | ||
&.country.active { | ||
font-weight: 600; | ||
background-color: ${({ theme }) => theme.primaryPalette.bcp_1} !important; | ||
} | ||
} | ||
`, | ||
}; |
32 changes: 23 additions & 9 deletions
32
src/components/BaseQuestionnaireResponseForm/widgets/PhoneInput/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,38 @@ | ||
import { Form } from 'antd'; | ||
import PhoneInput from 'antd-phone-input'; | ||
import classNames from 'classnames'; | ||
import { useState } from 'react'; | ||
import PI, { PhoneInputProps } from 'react-phone-input-2'; | ||
import { QuestionItemProps } from 'sdc-qrf'; | ||
|
||
import { S } from './PhoneInput.styles'; | ||
import { useFieldController } from '../../hooks'; | ||
|
||
// https://github.com/bl00mber/react-phone-input-2/issues/533#issuecomment-1508211907 | ||
const PhoneInput: React.FC<PhoneInputProps> = (PI as any).default || PI; | ||
|
||
export function QuestionPhone({ parentPath, questionItem }: QuestionItemProps) { | ||
const { linkId } = questionItem; | ||
const fieldName = [...parentPath, linkId, 0, 'value', 'string']; | ||
const { value, onChange, disabled, formItem } = useFieldController(fieldName, questionItem); | ||
const [focused, setFocused] = useState(false); | ||
|
||
return ( | ||
<Form.Item {...formItem}> | ||
<PhoneInput | ||
country="us" | ||
value={value} | ||
disabled={disabled} | ||
onChange={({ countryCode, areaCode, phoneNumber }) => { | ||
onChange([countryCode, areaCode, phoneNumber].filter(Boolean).join('')); | ||
}} | ||
/> | ||
<S.Container> | ||
<PhoneInput | ||
country={'us'} | ||
value={value} | ||
onChange={(phone) => onChange(phone)} | ||
disabled={disabled} | ||
inputClass={'react-phone-input'} | ||
containerClass={classNames({ | ||
_focused: focused, | ||
})} | ||
buttonClass={'react-phone-input__button'} | ||
onFocus={() => setFocused(true)} | ||
onBlur={() => setFocused(false)} | ||
/> | ||
</S.Container> | ||
</Form.Item> | ||
); | ||
} |