foxit-component 1.0.4 → 1.0.5-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import './accordion.css';
3
+ export interface AccordionItem {
4
+ key: string;
5
+ label: React.ReactNode;
6
+ children: React.ReactNode;
7
+ disabled?: boolean;
8
+ }
9
+ export interface AccordionProps {
10
+ items: AccordionItem[];
11
+ title?: React.ReactNode;
12
+ subTitle?: React.ReactNode;
13
+ align?: 'left' | 'center' | 'right';
14
+ activeKey?: string | string[];
15
+ defaultActiveKey?: string | string[];
16
+ accordion?: boolean;
17
+ destroyInactivePanel?: boolean;
18
+ onChange?: (keys: string[]) => void;
19
+ className?: string;
20
+ }
21
+ declare const Accordion: React.FC<AccordionProps>;
22
+ export { Accordion };
@@ -0,0 +1,60 @@
1
+ import { __spreadArray, __assign } from '../node_modules/tslib/tslib.es6.js';
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import { useId, useState, useCallback } from 'react';
4
+ import classNames from 'classnames';
5
+
6
+ var ChevronIcon = function (_a) {
7
+ var className = _a.className;
8
+ return (jsx("svg", __assign({ className: className, width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" }, { children: jsx("path", { d: "M4 6L8 10L12 6", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) })));
9
+ };
10
+ var AccordionPanel = function (_a) {
11
+ var item = _a.item, isOpen = _a.isOpen, onToggle = _a.onToggle, headerId = _a.headerId, contentId = _a.contentId, _b = _a.destroyInactivePanel, destroyInactivePanel = _b === void 0 ? false : _b;
12
+ var handleClick = function () {
13
+ if (!item.disabled) {
14
+ onToggle(item.key);
15
+ }
16
+ };
17
+ var handleKeyDown = function (e) {
18
+ if (e.key === 'Enter' || e.key === ' ') {
19
+ e.preventDefault();
20
+ handleClick();
21
+ }
22
+ };
23
+ return (jsxs("div", __assign({ className: classNames('foxit-accordion-item', {
24
+ 'foxit-accordion-item-active': isOpen,
25
+ 'foxit-accordion-item-disabled': item.disabled
26
+ }) }, { children: [jsxs("button", __assign({ id: headerId, type: "button", className: "foxit-accordion-header", "aria-expanded": isOpen, "aria-controls": contentId, onClick: handleClick, onKeyDown: handleKeyDown, disabled: item.disabled }, { children: [jsx("span", __assign({ className: "foxit-accordion-label" }, { children: item.label })), jsx(ChevronIcon, { className: "foxit-accordion-icon" })] })), jsx("div", __assign({ id: contentId, role: "region", "aria-labelledby": headerId, className: classNames('foxit-accordion-content-wrapper', {
27
+ 'foxit-accordion-content-wrapper-open': isOpen
28
+ }) }, { children: (!destroyInactivePanel || isOpen) && (jsx("div", __assign({ className: "foxit-accordion-content" }, { children: item.children }))) }))] })));
29
+ };
30
+ var normalizeKeys = function (keys) {
31
+ if (keys === undefined || keys === null)
32
+ return [];
33
+ return Array.isArray(keys) ? keys : [keys];
34
+ };
35
+ var Accordion = function (_a) {
36
+ var items = _a.items, title = _a.title, subTitle = _a.subTitle, _b = _a.align, align = _b === void 0 ? 'left' : _b, activeKey = _a.activeKey, defaultActiveKey = _a.defaultActiveKey, _c = _a.accordion, accordion = _c === void 0 ? false : _c, _d = _a.destroyInactivePanel, destroyInactivePanel = _d === void 0 ? false : _d, onChange = _a.onChange, className = _a.className;
37
+ var uid = useId();
38
+ var isControlled = activeKey !== undefined;
39
+ var _e = useState(function () {
40
+ return normalizeKeys(defaultActiveKey);
41
+ }), internalOpenKeys = _e[0], setInternalOpenKeys = _e[1];
42
+ var openKeys = isControlled ? normalizeKeys(activeKey) : internalOpenKeys;
43
+ var handleToggle = useCallback(function (key) {
44
+ var isCurrentlyOpen = openKeys.includes(key);
45
+ var nextKeys;
46
+ if (isCurrentlyOpen) {
47
+ nextKeys = openKeys.filter(function (k) { return k !== key; });
48
+ }
49
+ else {
50
+ nextKeys = accordion ? [key] : __spreadArray(__spreadArray([], openKeys, true), [key], false);
51
+ }
52
+ if (!isControlled) {
53
+ setInternalOpenKeys(nextKeys);
54
+ }
55
+ onChange === null || onChange === void 0 ? void 0 : onChange(nextKeys);
56
+ }, [openKeys, accordion, isControlled, onChange]);
57
+ return (jsxs("div", __assign({ className: classNames('foxit-accordion', className) }, { children: [(title || subTitle) && (jsxs("div", __assign({ className: "foxit-accordion-head", style: { textAlign: align } }, { children: [title && jsx("h2", __assign({ className: "foxit-accordion-title" }, { children: title })), subTitle && jsx("p", __assign({ className: "foxit-accordion-subtitle" }, { children: subTitle }))] }))), items.map(function (item, index) { return (jsx(AccordionPanel, { item: item, isOpen: openKeys.includes(item.key), onToggle: handleToggle, headerId: "".concat(uid, "-header-").concat(index), contentId: "".concat(uid, "-content-").concat(index), destroyInactivePanel: destroyInactivePanel }, item.key)); })] })));
58
+ };
59
+
60
+ export { Accordion };
@@ -6,8 +6,9 @@ import './alert.css';
6
6
  interface AlertProps {
7
7
  message: string | React.ReactNode;
8
8
  showIcon?: boolean;
9
- type?: 'success' | 'warning' | 'error' | 'gradient';
9
+ type?: 'success' | 'warning' | 'error' | 'gradient' | 'arrows';
10
10
  className?: string;
11
+ arrowPosition?: 'left' | 'right';
11
12
  }
12
13
  declare const Alert: React.FC<AlertProps>;
13
14
  export { Alert };
package/es/Alert/Alert.js CHANGED
@@ -4,7 +4,8 @@ import { Icon } from '../Icon/index.js';
4
4
  import classNames from 'classnames';
5
5
 
6
6
  var Alert = function (_a) {
7
- var message = _a.message, _b = _a.showIcon, showIcon = _b === void 0 ? true : _b, _c = _a.type, type = _c === void 0 ? 'success' : _c, className = _a.className;
7
+ var _b;
8
+ var message = _a.message, _c = _a.showIcon, showIcon = _c === void 0 ? true : _c, _d = _a.type, type = _d === void 0 ? 'success' : _d, className = _a.className, _e = _a.arrowPosition, arrowPosition = _e === void 0 ? 'left' : _e;
8
9
  var getIconName = function (type) {
9
10
  switch (type) {
10
11
  case 'success':
@@ -19,7 +20,9 @@ var Alert = function (_a) {
19
20
  return 'WarningColoursOutlined';
20
21
  }
21
22
  };
22
- return (jsxs("div", __assign({ className: classNames('foxit-alert', "foxit-alert-".concat(type), className) }, { children: [showIcon && (jsx("div", __assign({ className: "foxit-alert-icon-container" }, { children: jsx(Icon, { name: getIconName(type), className: "foxit-alert-icon" }) }))), jsx("div", __assign({ className: "foxit-alert-message" }, { children: message }))] })));
23
+ return (jsxs("div", __assign({ className: classNames('foxit-alert', "foxit-alert-".concat(type), (_b = {},
24
+ _b["foxit-alert-arrows-".concat(arrowPosition)] = type === 'arrows',
25
+ _b), className) }, { children: [showIcon && type !== 'arrows' && (jsx("div", __assign({ className: "foxit-alert-icon-container" }, { children: jsx(Icon, { name: getIconName(type), className: "foxit-alert-icon" }) }))), jsx("div", __assign({ className: "foxit-alert-message" }, { children: message }))] })));
23
26
  };
24
27
 
25
28
  export { Alert };
@@ -10,5 +10,6 @@ export interface ButtonProps {
10
10
  style?: React.CSSProperties;
11
11
  [key: string]: unknown;
12
12
  loading?: boolean;
13
+ link?: boolean;
13
14
  }
14
- export declare const Button: ({ primary, size, shape, children, className, style, loading, ...props }: ButtonProps) => import("react/jsx-runtime").JSX.Element;
15
+ export declare const Button: ({ primary, size, shape, children, className, style, loading, link, ...props }: ButtonProps) => import("react/jsx-runtime").JSX.Element;
@@ -4,9 +4,9 @@ import classNames from 'classnames';
4
4
  import { Icon } from '../Icon/index.js';
5
5
 
6
6
  var Button = function (_a) {
7
- var _b = _a.primary, primary = _b === void 0 ? false : _b, _c = _a.size, size = _c === void 0 ? 'large' : _c, _d = _a.shape, shape = _d === void 0 ? 'default' : _d, _e = _a.children, children = _e === void 0 ? '' : _e, className = _a.className, style = _a.style, loading = _a.loading, props = __rest(_a, ["primary", "size", "shape", "children", "className", "style", "loading"]);
7
+ var _b = _a.primary, primary = _b === void 0 ? false : _b, _c = _a.size, size = _c === void 0 ? 'large' : _c, _d = _a.shape, shape = _d === void 0 ? 'default' : _d, _e = _a.children, children = _e === void 0 ? '' : _e, className = _a.className, style = _a.style, loading = _a.loading, _f = _a.link, link = _f === void 0 ? false : _f, props = __rest(_a, ["primary", "size", "shape", "children", "className", "style", "loading", "link"]);
8
8
  var mode = primary ? 'foxit-button-primary' : 'foxit-button-secondary';
9
- return (jsxs("button", __assign({ type: "button", className: classNames('foxit-button', "foxit-button-".concat(size), shape === 'circle' && 'foxit-button-circle', mode, className, loading && 'foxit-button-prevent-click'), style: style }, props, { children: [loading && jsx(Icon, { name: "LoadingOutlined", className: "foxit-button-loading" }), children] })));
9
+ return (jsxs("button", __assign({ type: "button", className: classNames('foxit-button', !link && "foxit-button-".concat(size), shape === 'circle' && 'foxit-button-circle', !link && mode, link && 'foxit-button-link', className, loading && 'foxit-button-prevent-click'), style: style }, props, { children: [loading && jsx(Icon, { name: "LoadingOutlined", className: "foxit-button-loading" }), children] })));
10
10
  };
11
11
 
12
12
  export { Button };
@@ -5,7 +5,9 @@ interface CheckboxProps {
5
5
  checked?: boolean;
6
6
  disabled?: boolean;
7
7
  value?: string;
8
- children: React.ReactNode;
8
+ children?: React.ReactNode;
9
+ size?: 'default' | 'small';
10
+ indeterminate?: boolean;
9
11
  }
10
12
  interface CheckboxGroupProps {
11
13
  value?: string[];
@@ -1,17 +1,23 @@
1
1
  import { __assign, __spreadArray } from '../node_modules/tslib/tslib.es6.js';
2
2
  import { jsxs, jsx } from 'react/jsx-runtime';
3
- import { createContext, useContext, useState, useEffect } from 'react';
3
+ import { createContext, useContext, useState, useRef, useEffect } from 'react';
4
4
 
5
5
  var CheckboxGroupContext = createContext(null);
6
6
  var Checkbox = function (_a) {
7
- var onChange = _a.onChange, checked = _a.checked, _b = _a.disabled, disabled = _b === void 0 ? false : _b, value = _a.value, children = _a.children;
7
+ var onChange = _a.onChange, checked = _a.checked, _b = _a.disabled, disabled = _b === void 0 ? false : _b, value = _a.value, children = _a.children, _c = _a.size, size = _c === void 0 ? 'default' : _c, _d = _a.indeterminate, indeterminate = _d === void 0 ? false : _d;
8
8
  var groupContext = useContext(CheckboxGroupContext);
9
- var _c = useState(checked || false), internalChecked = _c[0], setInternalChecked = _c[1];
9
+ var _e = useState(checked || false), internalChecked = _e[0], setInternalChecked = _e[1];
10
+ var inputRef = useRef(null);
10
11
  useEffect(function () {
11
12
  if (checked !== undefined) {
12
13
  setInternalChecked(checked);
13
14
  }
14
15
  }, [checked]);
16
+ useEffect(function () {
17
+ if (inputRef.current) {
18
+ inputRef.current.indeterminate = indeterminate;
19
+ }
20
+ }, [indeterminate]);
15
21
  var handleChange = function (e) {
16
22
  var newChecked = e.target.checked;
17
23
  setInternalChecked(newChecked);
@@ -23,7 +29,7 @@ var Checkbox = function (_a) {
23
29
  }
24
30
  };
25
31
  var isChecked = groupContext ? groupContext.value.includes(value || '') : internalChecked;
26
- return (jsxs("label", __assign({ className: "foxit-checkbox-container ".concat(disabled ? 'disabled' : '') }, { children: [jsx("input", { type: "checkbox", checked: isChecked, disabled: disabled, onChange: handleChange }), jsx("span", { className: "foxit-checkbox-checkmark ".concat(disabled ? 'disabled' : '') }), jsx("span", __assign({ className: "foxit-checkbox-content" }, { children: children }))] })));
32
+ return (jsxs("label", __assign({ className: "foxit-checkbox-container ".concat(disabled ? 'disabled' : '', " ").concat(size === 'small' ? 'small' : '') }, { children: [jsx("input", { ref: inputRef, type: "checkbox", checked: isChecked, disabled: disabled, onChange: handleChange }), jsx("span", { className: "foxit-checkbox-checkmark ".concat(disabled ? 'disabled' : '') }), jsx("span", __assign({ className: "foxit-checkbox-content" }, { children: children }))] })));
27
33
  };
28
34
  var CheckboxGroup = function (_a) {
29
35
  var value = _a.value, onChange = _a.onChange, children = _a.children;
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ export interface ConfigProviderProps {
3
+ dir?: 'ltr' | 'rtl';
4
+ children?: React.ReactNode;
5
+ }
6
+ interface ConfigContextType {
7
+ dir: 'ltr' | 'rtl';
8
+ }
9
+ export declare const useConfig: () => ConfigContextType;
10
+ declare const ConfigProvider: React.FC<ConfigProviderProps>;
11
+ export { ConfigProvider };
@@ -0,0 +1,19 @@
1
+ import { __assign } from '../node_modules/tslib/tslib.es6.js';
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import { createContext, useContext } from 'react';
4
+
5
+ var ConfigContext = createContext({
6
+ dir: 'ltr'
7
+ });
8
+ var useConfig = function () {
9
+ return useContext(ConfigContext);
10
+ };
11
+ var ConfigProvider = function (_a) {
12
+ var _b = _a.dir, dir = _b === void 0 ? 'ltr' : _b, children = _a.children;
13
+ var value = {
14
+ dir: dir
15
+ };
16
+ return (jsx(ConfigContext.Provider, __assign({ value: value }, { children: jsx("div", __assign({ dir: dir }, { children: children })) })));
17
+ };
18
+
19
+ export { ConfigProvider, useConfig };
@@ -11,5 +11,10 @@ interface SearchInputProps extends InputProps {
11
11
  }
12
12
  declare const SearchInput: React.FC<SearchInputProps>;
13
13
  declare const PasswordInput: React.FC<InputProps>;
14
+ export interface TextAreaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
15
+ className?: string;
16
+ rows?: number;
17
+ }
18
+ declare const TextArea: React.FC<TextAreaProps>;
14
19
  export default Input;
15
- export { SearchInput, PasswordInput };
20
+ export { SearchInput, PasswordInput, TextArea };
package/es/Input/Input.js CHANGED
@@ -25,5 +25,9 @@ var PasswordInput = function (props) {
25
25
  };
26
26
  return (jsx(Input, __assign({}, props, { type: visible ? 'text' : 'password', addonAfter: jsx("div", __assign({ style: { display: 'flex' }, onClick: toggleVisibility }, { children: jsx(Icon, { name: visible ? 'EyeOutlined' : 'EyeInvisibleOutlined' }) })) })));
27
27
  };
28
+ var TextArea = function (_a) {
29
+ var className = _a.className, _b = _a.rows, rows = _b === void 0 ? 3 : _b, rest = __rest(_a, ["className", "rows"]);
30
+ return (jsx("div", __assign({ className: "foxit-input-wrapper foxit-input-wrapper-textarea" }, { children: jsx("textarea", __assign({ className: classNames('foxit-input-element foxit-textarea-element', rest.disabled && 'foxit-input-wrapper-disabled', className), rows: rows }, rest)) })));
31
+ };
28
32
 
29
- export { PasswordInput, SearchInput, Input as default };
33
+ export { PasswordInput, SearchInput, TextArea, Input as default };
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import { InputProps } from './Input';
3
+ import { AreaCodeOption } from './areaCodeData';
4
+ import './input.css';
5
+ export interface PhoneInputValue {
6
+ areaCode: string;
7
+ dialCode: string;
8
+ name: string;
9
+ phoneNumber: string;
10
+ }
11
+ export type PhoneInputFieldValue = Partial<PhoneInputValue>;
12
+ export interface PhoneInputProps extends Omit<InputProps, 'addonBefore' | 'value' | 'defaultValue' | 'onChange'> {
13
+ value?: PhoneInputFieldValue;
14
+ defaultValue?: PhoneInputFieldValue;
15
+ areaCodeOptions?: AreaCodeOption[];
16
+ flagBaseUrl?: string;
17
+ onChange?: (value: PhoneInputValue) => void;
18
+ }
19
+ declare const PhoneInput: React.FC<PhoneInputProps>;
20
+ export default PhoneInput;
@@ -0,0 +1,145 @@
1
+ import { __assign, __rest, __spreadArray } from '../node_modules/tslib/tslib.es6.js';
2
+ import { jsx, jsxs } from 'react/jsx-runtime';
3
+ import React, { useCallback, useRef, useState, useEffect, useMemo } from 'react';
4
+ import classNames from 'classnames';
5
+ import Select from '../Select/Select.js';
6
+ import Input from './Input.js';
7
+ import { US_FLAG_DATA_URI, areaCodeOptions, AREA_FLAG_BASE_URL } from './areaCodeData.js';
8
+
9
+ var getFlagUrl = function (baseUrl, countryCode) {
10
+ return baseUrl ? "".concat(baseUrl.replace(/\/$/, ''), "/").concat(countryCode.toLowerCase(), ".svg") : '';
11
+ };
12
+ var getPhoneInputValue = function (option, phoneNumber) { return ({
13
+ areaCode: option.value,
14
+ dialCode: option.dialCode,
15
+ name: option.name,
16
+ phoneNumber: phoneNumber
17
+ }); };
18
+ var LazyFlag = function (_a) {
19
+ var src = _a.src, alt = _a.alt, _b = _a.lazy, lazy = _b === void 0 ? true : _b;
20
+ var imgRef = useRef(null);
21
+ var _c = useState(!lazy), shouldLoad = _c[0], setShouldLoad = _c[1];
22
+ useEffect(function () {
23
+ var img = imgRef.current;
24
+ if (!lazy) {
25
+ setShouldLoad(true);
26
+ return;
27
+ }
28
+ if (!img || shouldLoad) {
29
+ return;
30
+ }
31
+ if (typeof IntersectionObserver === 'undefined') {
32
+ setShouldLoad(true);
33
+ return;
34
+ }
35
+ var observer = new IntersectionObserver(function (_a) {
36
+ var entry = _a[0];
37
+ if (entry.isIntersecting) {
38
+ setShouldLoad(true);
39
+ observer.disconnect();
40
+ }
41
+ }, { rootMargin: '80px' });
42
+ observer.observe(img);
43
+ return function () { return observer.disconnect(); };
44
+ }, [lazy, shouldLoad]);
45
+ return (jsx("img", { ref: imgRef, className: "foxit-area-code-flag", src: shouldLoad && src ? src : undefined, alt: alt, loading: "lazy" }));
46
+ };
47
+ var AreaCodeOptionLabel = function (_a) {
48
+ var option = _a.option, flagBaseUrl = _a.flagBaseUrl, isMenu = _a.isMenu;
49
+ // SSR 时 flagBaseUrl 为空,选中值展示兜底使用 US 国旗;菜单项不展示图片(不会影响交互)
50
+ var flagSrc = flagBaseUrl
51
+ ? getFlagUrl(flagBaseUrl, option.value)
52
+ : !isMenu
53
+ ? US_FLAG_DATA_URI
54
+ : '';
55
+ return (jsxs("div", __assign({ className: classNames('foxit-area-code-option', !isMenu && 'foxit-area-code-option-value') }, { children: [jsxs("div", __assign({ className: "foxit-area-code-option-main" }, { children: [jsx(LazyFlag, { src: flagSrc, alt: option.name, lazy: isMenu }), isMenu && jsx("span", __assign({ className: "foxit-area-code-name" }, { children: option.name })), !isMenu && jsx("span", __assign({ className: "foxit-area-code-dial" }, { children: option.dialCode }))] })), isMenu && jsx("span", __assign({ className: "foxit-area-code-dial" }, { children: option.dialCode }))] })));
56
+ };
57
+ var phoneAreaCodeSelectStyles = {
58
+ control: {
59
+ minHeight: 24,
60
+ height: 24,
61
+ border: 'none',
62
+ paddingLeft: 0,
63
+ backgroundColor: 'transparent'
64
+ },
65
+ singleValue: {
66
+ margin: 0
67
+ },
68
+ input: {
69
+ margin: 0,
70
+ padding: 0
71
+ },
72
+ menu: function (base, state) { return (__assign(__assign({}, base), { transform: "translate(-12px, ".concat(state.placement === 'top' ? -8 : 10, "px)") })); }
73
+ };
74
+ var filterAreaCodeOption = function (candidate, inputValue) {
75
+ var keyword = inputValue.trim().toLowerCase();
76
+ if (!keyword) {
77
+ return true;
78
+ }
79
+ var option = candidate.data;
80
+ var normalizedDialCode = option.dialCode.replace('+', '');
81
+ var normalizedKeyword = keyword.replace('+', '');
82
+ return (option.value.toLowerCase().includes(keyword) ||
83
+ option.name.toLowerCase().includes(keyword) ||
84
+ option.dialCode.includes(keyword) ||
85
+ normalizedDialCode.includes(normalizedKeyword));
86
+ };
87
+ var PhoneAreaCodeSelectBase = function (_a) {
88
+ var options = _a.options, value = _a.value, disabled = _a.disabled, flagBaseUrl = _a.flagBaseUrl, onChange = _a.onChange;
89
+ var handleChange = useCallback(function (option) {
90
+ var nextOption = option;
91
+ if (!nextOption) {
92
+ return;
93
+ }
94
+ onChange(nextOption);
95
+ }, [onChange]);
96
+ var formatOptionLabel = useCallback(function (option, meta) { return (jsx(AreaCodeOptionLabel, { option: option, flagBaseUrl: flagBaseUrl, isMenu: meta.context === 'menu' })); }, [flagBaseUrl]);
97
+ return (jsx(Select, { className: "foxit-phone-input-select", classNamePrefix: "foxit-phone-input-select", options: options, value: value, onChange: handleChange, isDisabled: disabled, isSearchable: true, showSelectedIcon: false, placeholder: "", filterOption: filterAreaCodeOption, formatOptionLabel: formatOptionLabel, styles: phoneAreaCodeSelectStyles }));
98
+ };
99
+ var PhoneAreaCodeSelect = React.memo(PhoneAreaCodeSelectBase);
100
+ var PhoneInput = function (_a) {
101
+ var _b;
102
+ var value = _a.value, defaultValue = _a.defaultValue, _c = _a.areaCodeOptions, passAreaCodeOptions = _c === void 0 ? areaCodeOptions : _c, flagBaseUrl = _a.flagBaseUrl, onChange = _a.onChange, className = _a.className, rest = __rest(_a, ["value", "defaultValue", "areaCodeOptions", "flagBaseUrl", "onChange", "className"]);
103
+ var resolvedFlagBaseUrl = flagBaseUrl || AREA_FLAG_BASE_URL();
104
+ var selectOptions = useMemo(function () {
105
+ return __spreadArray([], passAreaCodeOptions, true).sort(function (a, b) {
106
+ var dialCodeDiff = Number(a.dialCode.replace(/\D/g, '')) - Number(b.dialCode.replace(/\D/g, ''));
107
+ if (dialCodeDiff !== 0) {
108
+ return dialCodeDiff;
109
+ }
110
+ return a.value.localeCompare(b.value);
111
+ })
112
+ .map(function (option) { return (__assign(__assign({}, option), { label: option.dialCode })); });
113
+ }, [passAreaCodeOptions]);
114
+ var _d = useState((defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.areaCode) || 'US'), innerAreaCode = _d[0], setInnerAreaCode = _d[1];
115
+ var _e = useState((defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.phoneNumber) || ''), innerPhoneNumber = _e[0], setInnerPhoneNumber = _e[1];
116
+ var selectedAreaCode = (_b = value === null || value === void 0 ? void 0 : value.areaCode) !== null && _b !== void 0 ? _b : innerAreaCode;
117
+ var phoneNumber = value === undefined ? innerPhoneNumber : value.phoneNumber || '';
118
+ var phoneNumberRef = useRef(phoneNumber);
119
+ phoneNumberRef.current = phoneNumber;
120
+ var selectedOption = selectOptions.find(function (option) { return option.value === selectedAreaCode; }) || selectOptions[0];
121
+ var isControlled = value !== undefined;
122
+ var onChangeRef = useRef(onChange);
123
+ var isControlledRef = useRef(isControlled);
124
+ onChangeRef.current = onChange;
125
+ isControlledRef.current = isControlled;
126
+ var handleAreaCodeChange = useCallback(function (nextOption) {
127
+ var _a;
128
+ if (!isControlledRef.current) {
129
+ setInnerAreaCode(nextOption.value);
130
+ }
131
+ (_a = onChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onChangeRef, getPhoneInputValue(nextOption, phoneNumberRef.current));
132
+ }, []);
133
+ var handlePhoneNumberChange = function (e) {
134
+ var nextPhoneNumber = e.target.value.replace(/\D/g, '');
135
+ if (value === undefined) {
136
+ setInnerPhoneNumber(nextPhoneNumber);
137
+ }
138
+ if (selectedOption) {
139
+ onChange === null || onChange === void 0 ? void 0 : onChange(getPhoneInputValue(selectedOption, nextPhoneNumber));
140
+ }
141
+ };
142
+ return (jsx(Input, __assign({}, rest, { inputMode: rest.inputMode || 'numeric', pattern: rest.pattern || '[0-9]*', value: phoneNumber, onChange: handlePhoneNumberChange, className: classNames('foxit-phone-input', className), addonBefore: jsx(PhoneAreaCodeSelect, { options: selectOptions, value: selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value, disabled: rest.disabled, flagBaseUrl: resolvedFlagBaseUrl, onChange: handleAreaCodeChange }) })));
143
+ };
144
+
145
+ export { PhoneInput as default };
@@ -0,0 +1,8 @@
1
+ export interface AreaCodeOption {
2
+ value: string;
3
+ dialCode: string;
4
+ name: string;
5
+ }
6
+ export declare const AREA_FLAG_BASE_URL: () => string;
7
+ export declare const US_FLAG_DATA_URI: string;
8
+ export declare const areaCodeOptions: AreaCodeOption[];