@via-profit/ui-kit 0.1.0-rc.87 → 0.1.0-rc.89
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.
- package/Color/index.d.ts +9 -0
- package/Color/index.js +25 -0
- package/Modal/BaseModal/ModalInner.js +7 -10
- package/Modal/BaseModal/ModalInnerContainer.d.ts +13 -0
- package/Modal/BaseModal/ModalInnerContainer.js +42 -0
- package/Modal/BaseModal/RenderModal.d.ts +2 -0
- package/Modal/BaseModal/RenderModal.js +4 -1
- package/Modal/BaseModal/index.d.ts +2 -0
- package/Modal/BaseModal/index.js +2 -0
- package/Modal/Dialog/DialogInner.js +4 -26
- package/Modal/Drawer/DrawerInner.js +19 -23
- package/Modal/Drawer/index.js +1 -1
- package/PhoneField/index.d.ts +11 -2
- package/PhoneField/index.js +3 -3
- package/package.json +1 -1
package/Color/index.d.ts
CHANGED
|
@@ -75,6 +75,15 @@ declare class Color {
|
|
|
75
75
|
* lum - 0-25
|
|
76
76
|
*/
|
|
77
77
|
private shade;
|
|
78
|
+
static stringToHashCode(str: string): number;
|
|
79
|
+
/**
|
|
80
|
+
* Convert the integer value to a string color value
|
|
81
|
+
*/
|
|
82
|
+
static intToRGB(i: number): string;
|
|
83
|
+
/**
|
|
84
|
+
* Convert GUID string value to a color string
|
|
85
|
+
*/
|
|
86
|
+
static uuidToColor(uuid: string): string;
|
|
78
87
|
/**
|
|
79
88
|
* Returns the current color as separate rgb channels
|
|
80
89
|
*/
|
package/Color/index.js
CHANGED
|
@@ -122,6 +122,31 @@ class Color {
|
|
|
122
122
|
__classPrivateFieldGet(this, _Color_color, "f").b = parseInt('0' + Math.min(255, Math.max(0, __classPrivateFieldGet(this, _Color_color, "f").b + lum)), 10);
|
|
123
123
|
return this;
|
|
124
124
|
}
|
|
125
|
+
static stringToHashCode(str) {
|
|
126
|
+
let hash = 0;
|
|
127
|
+
for (let i = 0; i < str.length; i++) {
|
|
128
|
+
const char = str.charCodeAt(i);
|
|
129
|
+
hash = (hash << 5) - hash + char;
|
|
130
|
+
hash |= 0; // Convert to a 32-bit integer
|
|
131
|
+
}
|
|
132
|
+
return hash;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Convert the integer value to a string color value
|
|
136
|
+
*/
|
|
137
|
+
static intToRGB(i) {
|
|
138
|
+
const red = (i >> 16) & 0xff;
|
|
139
|
+
const green = (i >> 8) & 0xff;
|
|
140
|
+
const blue = i & 0xff;
|
|
141
|
+
return `rgb(${red},${green},${blue})`;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Convert GUID string value to a color string
|
|
145
|
+
*/
|
|
146
|
+
static uuidToColor(uuid) {
|
|
147
|
+
const hash = Color.stringToHashCode(uuid);
|
|
148
|
+
return Color.intToRGB(hash);
|
|
149
|
+
}
|
|
125
150
|
/**
|
|
126
151
|
* Returns the current color as separate rgb channels
|
|
127
152
|
*/
|
|
@@ -20,24 +20,21 @@ const react_2 = require("@emotion/react");
|
|
|
20
20
|
const StyledModalInner = styled_1.default.div `
|
|
21
21
|
opacity: 0;
|
|
22
22
|
z-index: ${({ theme }) => theme.zIndex.modal};
|
|
23
|
-
position: fixed;
|
|
24
|
-
left: 50%;
|
|
25
|
-
top: 50%;
|
|
26
23
|
outline: none;
|
|
24
|
+
position: relative;
|
|
27
25
|
background-color: ${({ theme }) => theme.color.surface.toString()};
|
|
28
26
|
border-radius: ${({ theme }) => theme.shape.radiusFactor * 2}em;
|
|
29
|
-
|
|
27
|
+
margin-top: 2em;
|
|
30
28
|
transition:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
opacity 100ms ease-out,
|
|
30
|
+
margin-top 240ms ease-out;
|
|
34
31
|
${({ $isOpen }) => $isOpen &&
|
|
35
32
|
(0, react_2.css) `
|
|
33
|
+
margin-top: 0;
|
|
36
34
|
opacity: 1;
|
|
37
|
-
transform: translate(-50%, -50%);
|
|
38
35
|
transition:
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
opacity 100ms ease-out,
|
|
37
|
+
margin-top 240ms ease-out;
|
|
41
38
|
`}
|
|
42
39
|
`;
|
|
43
40
|
const ModalInner = (props, ref) => {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface ModalInnerContainerProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
3
|
+
/**
|
|
4
|
+
* The dialog will remain open as long as the value is true
|
|
5
|
+
*/
|
|
6
|
+
readonly isOpen: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* The function that will be called to close the dialog
|
|
9
|
+
*/
|
|
10
|
+
readonly onRequestClose: (event: React.MouseEvent<HTMLElement> | KeyboardEvent) => void;
|
|
11
|
+
}
|
|
12
|
+
declare const _default: React.ForwardRefExoticComponent<ModalInnerContainerProps & React.RefAttributes<HTMLDivElement>>;
|
|
13
|
+
export default _default;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
const react_1 = __importDefault(require("react"));
|
|
18
|
+
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
19
|
+
const react_2 = require("@emotion/react");
|
|
20
|
+
const StyledModalInnerContainer = styled_1.default.div `
|
|
21
|
+
opacity: 0;
|
|
22
|
+
z-index: ${({ theme }) => theme.zIndex.modal};
|
|
23
|
+
position: fixed;
|
|
24
|
+
inset: 0;
|
|
25
|
+
outline: none;
|
|
26
|
+
transition: opacity 100ms ease-out;
|
|
27
|
+
display: flex;
|
|
28
|
+
align-items: center;
|
|
29
|
+
justify-content: center;
|
|
30
|
+
flex-direction: column;
|
|
31
|
+
|
|
32
|
+
${({ $isOpen }) => $isOpen &&
|
|
33
|
+
(0, react_2.css) `
|
|
34
|
+
opacity: 1;
|
|
35
|
+
transition: opacity 100ms ease-out;
|
|
36
|
+
`}
|
|
37
|
+
`;
|
|
38
|
+
const ModalInnerContainer = (props, ref) => {
|
|
39
|
+
const { children, isOpen, onRequestClose } = props, restProps = __rest(props, ["children", "isOpen", "onRequestClose"]);
|
|
40
|
+
return (react_1.default.createElement(StyledModalInnerContainer, Object.assign({}, restProps, { "$isOpen": isOpen, ref: ref }), children));
|
|
41
|
+
};
|
|
42
|
+
exports.default = react_1.default.forwardRef(ModalInnerContainer);
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ModalOverlayProps } from './ModalOverlay';
|
|
3
3
|
import { ModalInnerProps } from './ModalInner';
|
|
4
|
+
import { ModalInnerContainerProps } from './ModalInnerContainer';
|
|
4
5
|
interface RenderModalProps {
|
|
5
6
|
readonly children: React.ReactNode | readonly React.ReactNode[];
|
|
6
7
|
readonly overrides: {
|
|
7
8
|
readonly Overlay?: React.ForwardRefExoticComponent<ModalOverlayProps & React.RefAttributes<HTMLDivElement>>;
|
|
8
9
|
readonly Inner?: React.ForwardRefExoticComponent<ModalInnerProps & React.RefAttributes<HTMLDivElement>>;
|
|
10
|
+
readonly InnerContainer?: React.ForwardRefExoticComponent<ModalInnerContainerProps & React.RefAttributes<HTMLDivElement>>;
|
|
9
11
|
};
|
|
10
12
|
}
|
|
11
13
|
declare const RenderModal: React.FC<RenderModalProps>;
|
|
@@ -7,6 +7,7 @@ const react_1 = __importDefault(require("react"));
|
|
|
7
7
|
const context_1 = require("./context");
|
|
8
8
|
const ModalOverlay_1 = __importDefault(require("./ModalOverlay"));
|
|
9
9
|
const ModalInner_1 = __importDefault(require("./ModalInner"));
|
|
10
|
+
const ModalInnerContainer_1 = __importDefault(require("./ModalInnerContainer"));
|
|
10
11
|
const RenderModal = props => {
|
|
11
12
|
const { children, overrides } = props;
|
|
12
13
|
const { state } = (0, context_1.useContext)();
|
|
@@ -14,9 +15,11 @@ const RenderModal = props => {
|
|
|
14
15
|
const overridesMap = react_1.default.useMemo(() => ({
|
|
15
16
|
Overlay: (overrides === null || overrides === void 0 ? void 0 : overrides.Overlay) || ModalOverlay_1.default,
|
|
16
17
|
Inner: (overrides === null || overrides === void 0 ? void 0 : overrides.Inner) || ModalInner_1.default,
|
|
18
|
+
InnerContainer: (overrides === null || overrides === void 0 ? void 0 : overrides.InnerContainer) || ModalInnerContainer_1.default,
|
|
17
19
|
}), [overrides]);
|
|
18
20
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
19
21
|
react_1.default.useMemo(() => (react_1.default.createElement(overridesMap.Overlay, { isOpen: isOpen, onRequestClose: onRequestClose, closeOnOverlayClick: closeOnOverlayClick })), [overridesMap, isOpen, closeOnOverlayClick, onRequestClose]),
|
|
20
|
-
react_1.default.useMemo(() => (react_1.default.createElement(overridesMap.
|
|
22
|
+
react_1.default.useMemo(() => (react_1.default.createElement(overridesMap.InnerContainer, { isOpen: isOpen, onRequestClose: onRequestClose },
|
|
23
|
+
react_1.default.createElement(overridesMap.Inner, { isOpen: isOpen, onRequestClose: onRequestClose }, children))), [children, isOpen, overridesMap, onRequestClose])));
|
|
21
24
|
};
|
|
22
25
|
exports.default = RenderModal;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ModalOverlayProps } from './ModalOverlay';
|
|
3
3
|
import { ModalInnerProps } from './ModalInner';
|
|
4
|
+
import { ModalInnerContainerProps } from './ModalInnerContainer';
|
|
4
5
|
export interface BaseModalProps {
|
|
5
6
|
/**
|
|
6
7
|
* The dialog will remain open as long as the value is true
|
|
@@ -46,6 +47,7 @@ export interface BaseModalProps {
|
|
|
46
47
|
export interface BaseModalOverrides {
|
|
47
48
|
readonly Overlay?: React.ForwardRefExoticComponent<ModalOverlayProps & React.RefAttributes<HTMLDivElement>>;
|
|
48
49
|
readonly Inner?: React.ForwardRefExoticComponent<ModalInnerProps & React.RefAttributes<HTMLDivElement>>;
|
|
50
|
+
readonly InnerContainer?: React.ForwardRefExoticComponent<ModalInnerContainerProps & React.RefAttributes<HTMLDivElement>>;
|
|
49
51
|
}
|
|
50
52
|
declare const BaseModal: React.FC<BaseModalProps>;
|
|
51
53
|
export default BaseModal;
|
package/Modal/BaseModal/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const react_dom_1 = __importDefault(require("react-dom"));
|
|
|
8
8
|
const context_1 = require("./context");
|
|
9
9
|
const ModalOverlay_1 = __importDefault(require("./ModalOverlay"));
|
|
10
10
|
const ModalInner_1 = __importDefault(require("./ModalInner"));
|
|
11
|
+
const ModalInnerContainer_1 = __importDefault(require("./ModalInnerContainer"));
|
|
11
12
|
const ModalWrapper_1 = __importDefault(require("./ModalWrapper"));
|
|
12
13
|
const RenderModal_1 = __importDefault(require("./RenderModal"));
|
|
13
14
|
const NoSSR_1 = __importDefault(require("../../NoSSR"));
|
|
@@ -18,6 +19,7 @@ const BaseModal = props => {
|
|
|
18
19
|
const overridesMap = react_1.default.useMemo(() => ({
|
|
19
20
|
Overlay: (overrides === null || overrides === void 0 ? void 0 : overrides.Overlay) || ModalOverlay_1.default,
|
|
20
21
|
Inner: (overrides === null || overrides === void 0 ? void 0 : overrides.Inner) || ModalInner_1.default,
|
|
22
|
+
InnerContainer: (overrides === null || overrides === void 0 ? void 0 : overrides.InnerContainer) || ModalInnerContainer_1.default,
|
|
21
23
|
}), [overrides]);
|
|
22
24
|
react_1.default.useEffect(() => {
|
|
23
25
|
/**
|
|
@@ -16,34 +16,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
const react_1 = __importDefault(require("react"));
|
|
18
18
|
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
19
|
-
const
|
|
20
|
-
const StyledDialogInner = styled_1.default.
|
|
21
|
-
flex: 1;
|
|
19
|
+
const ModalInner_1 = __importDefault(require("../BaseModal/ModalInner"));
|
|
20
|
+
const StyledDialogInner = (0, styled_1.default)(ModalInner_1.default) `
|
|
22
21
|
padding: 1em 1em;
|
|
23
|
-
opacity: 0;
|
|
24
|
-
z-index: ${({ theme }) => theme.zIndex.modal};
|
|
25
|
-
position: fixed;
|
|
26
|
-
left: 50%;
|
|
27
|
-
top: 50%;
|
|
28
|
-
outline: none;
|
|
29
|
-
background-color: ${({ theme }) => theme.color.surface.toString()};
|
|
30
|
-
border-radius: ${({ theme }) => theme.shape.radiusFactor * 2}em;
|
|
31
|
-
transform: translate(-50%, -30%);
|
|
32
|
-
transition:
|
|
33
|
-
transform 240ms ease-out,
|
|
34
|
-
opacity 100ms ease-out;
|
|
35
|
-
|
|
36
|
-
${({ $isOpen }) => $isOpen &&
|
|
37
|
-
(0, react_2.css) `
|
|
38
|
-
opacity: 1;
|
|
39
|
-
transform: translate(-50%, -50%);
|
|
40
|
-
ransition:
|
|
41
|
-
transform 240ms ease-out,
|
|
42
|
-
opacity 100ms ease-out;
|
|
43
|
-
`}
|
|
44
22
|
`;
|
|
45
23
|
const DialogInner = (props, ref) => {
|
|
46
|
-
const { children,
|
|
47
|
-
return (react_1.default.createElement(StyledDialogInner, Object.assign({
|
|
24
|
+
const { children, dialogID } = props, restProps = __rest(props, ["children", "dialogID"]);
|
|
25
|
+
return (react_1.default.createElement(StyledDialogInner, Object.assign({ id: `${dialogID}-description` }, restProps, { ref: ref }), children));
|
|
48
26
|
};
|
|
49
27
|
exports.default = react_1.default.forwardRef(DialogInner);
|
|
@@ -21,103 +21,99 @@ const StyledDrawerBottomInner = styled_1.default.div `
|
|
|
21
21
|
position: fixed;
|
|
22
22
|
left: 0;
|
|
23
23
|
right: 0;
|
|
24
|
-
bottom:
|
|
25
|
-
opacity: 0;
|
|
24
|
+
bottom: -100%;
|
|
26
25
|
max-height: 90%;
|
|
26
|
+
opacity: 0;
|
|
27
27
|
display: flex;
|
|
28
28
|
flex-direction: column;
|
|
29
|
-
transform: translate(0, 100%);
|
|
30
29
|
z-index: ${({ theme }) => theme.zIndex.modal};
|
|
31
30
|
background-color: ${({ theme }) => theme.color.surface.toString()};
|
|
32
31
|
border-top-left-radius: ${({ theme }) => theme.shape.radiusFactor * 2}em;
|
|
33
32
|
border-top-right-radius: ${({ theme }) => theme.shape.radiusFactor * 2}em;
|
|
34
33
|
transition:
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
opacity 120ms ease-out,
|
|
35
|
+
bottom 600ms ease-out;
|
|
37
36
|
${({ $isOpen }) => $isOpen &&
|
|
38
37
|
(0, react_2.css) `
|
|
39
38
|
opacity: 1;
|
|
40
|
-
|
|
39
|
+
bottom: 0;
|
|
41
40
|
transition:
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
opacity 100ms ease-out,
|
|
42
|
+
bottom 240ms ease-out;
|
|
44
43
|
`}
|
|
45
44
|
`;
|
|
46
45
|
const StyledDrawerTopInner = styled_1.default.div `
|
|
47
46
|
position: fixed;
|
|
48
47
|
left: 0;
|
|
49
48
|
right: 0;
|
|
50
|
-
top:
|
|
49
|
+
top: -100%;
|
|
51
50
|
opacity: 0;
|
|
52
51
|
max-height: 90%;
|
|
53
52
|
display: flex;
|
|
54
53
|
flex-direction: column;
|
|
55
|
-
transform: translate(0, -100%);
|
|
56
54
|
z-index: ${({ theme }) => theme.zIndex.modal};
|
|
57
55
|
background-color: ${({ theme }) => theme.color.surface.toString()};
|
|
58
56
|
border-bottom-left-radius: ${({ theme }) => theme.shape.radiusFactor * 2}em;
|
|
59
57
|
border-bottom-right-radius: ${({ theme }) => theme.shape.radiusFactor * 2}em;
|
|
60
58
|
transition:
|
|
61
|
-
|
|
59
|
+
top 600ms ease-out,
|
|
62
60
|
opacity 120ms ease-out;
|
|
63
61
|
${({ $isOpen }) => $isOpen &&
|
|
64
62
|
(0, react_2.css) `
|
|
65
63
|
opacity: 1;
|
|
66
|
-
|
|
64
|
+
top: 0;
|
|
67
65
|
transition:
|
|
68
|
-
|
|
66
|
+
top 240ms ease-out,
|
|
69
67
|
opacity 100ms ease-out;
|
|
70
68
|
`}
|
|
71
69
|
`;
|
|
72
70
|
const StyledDrawerRightInner = styled_1.default.div `
|
|
73
71
|
position: fixed;
|
|
74
|
-
right:
|
|
72
|
+
right: -100%;
|
|
75
73
|
top: 0;
|
|
76
74
|
bottom: 0;
|
|
77
75
|
opacity: 0;
|
|
78
76
|
max-width: 90%;
|
|
79
77
|
display: flex;
|
|
80
78
|
flex-direction: column;
|
|
81
|
-
transform: translate(100%, 0);
|
|
82
79
|
z-index: ${({ theme }) => theme.zIndex.modal};
|
|
83
80
|
background-color: ${({ theme }) => theme.color.surface.toString()};
|
|
84
81
|
border-top-left-radius: ${({ theme }) => theme.shape.radiusFactor * 2}em;
|
|
85
82
|
border-bottom-left-radius: ${({ theme }) => theme.shape.radiusFactor * 2}em;
|
|
86
83
|
transition:
|
|
87
|
-
|
|
84
|
+
right 600ms ease-out,
|
|
88
85
|
opacity 120ms ease-out;
|
|
89
86
|
${({ $isOpen }) => $isOpen &&
|
|
90
87
|
(0, react_2.css) `
|
|
91
88
|
opacity: 1;
|
|
92
|
-
|
|
89
|
+
right: 0;
|
|
93
90
|
transition:
|
|
94
|
-
|
|
91
|
+
right 240ms ease-out,
|
|
95
92
|
opacity 100ms ease-out;
|
|
96
93
|
`}
|
|
97
94
|
`;
|
|
98
95
|
const StyledDrawerLeftInner = styled_1.default.div `
|
|
99
96
|
position: fixed;
|
|
100
|
-
left:
|
|
97
|
+
left: -100%;
|
|
101
98
|
top: 0;
|
|
102
99
|
bottom: 0;
|
|
103
100
|
opacity: 0;
|
|
104
101
|
max-width: 90%;
|
|
105
102
|
display: flex;
|
|
106
103
|
flex-direction: column;
|
|
107
|
-
transform: translate(-100%, 0);
|
|
108
104
|
z-index: ${({ theme }) => theme.zIndex.modal};
|
|
109
105
|
background-color: ${({ theme }) => theme.color.surface.toString()};
|
|
110
106
|
border-top-right-radius: ${({ theme }) => theme.shape.radiusFactor * 2}em;
|
|
111
107
|
border-bottom-right-radius: ${({ theme }) => theme.shape.radiusFactor * 2}em;
|
|
112
108
|
transition:
|
|
113
|
-
|
|
109
|
+
left 600ms ease-out,
|
|
114
110
|
opacity 120ms ease-out;
|
|
115
111
|
${({ $isOpen }) => $isOpen &&
|
|
116
112
|
(0, react_2.css) `
|
|
117
113
|
opacity: 1;
|
|
118
|
-
|
|
114
|
+
left: 0;
|
|
119
115
|
transition:
|
|
120
|
-
|
|
116
|
+
left 240ms ease-out,
|
|
121
117
|
opacity 100ms ease-out;
|
|
122
118
|
`}
|
|
123
119
|
`;
|
package/Modal/Drawer/index.js
CHANGED
|
@@ -51,7 +51,7 @@ const Drawer = props => {
|
|
|
51
51
|
const hasHeader = React.useMemo(() => typeof header !== 'undefined' ||
|
|
52
52
|
typeof toolbar !== 'undefined' ||
|
|
53
53
|
typeof showCloseButton !== 'undefined', [showCloseButton, header, toolbar]);
|
|
54
|
-
const dialogID = React.useMemo(() => `drawer
|
|
54
|
+
const dialogID = React.useMemo(() => `drawer-${new Date().getTime()}`, []);
|
|
55
55
|
const overridesMap = React.useMemo(() => ({
|
|
56
56
|
Container: (overrides === null || overrides === void 0 ? void 0 : overrides.Container) || DrawerContainer_1.default,
|
|
57
57
|
Header: (overrides === null || overrides === void 0 ? void 0 : overrides.Header) || DrawerHeader_1.default,
|
package/PhoneField/index.d.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TextFieldProps } from '../TextField';
|
|
3
|
-
import type {
|
|
3
|
+
import type { CountryFlag, PhoneTemplate } from './templates';
|
|
4
4
|
export interface PhoneFieldProps extends Omit<TextFieldProps, 'value' | 'onChange'> {
|
|
5
5
|
/**
|
|
6
6
|
* Phone string format 79876543210 or +7 (987) 654-32-10
|
|
7
7
|
*/
|
|
8
8
|
readonly value: string;
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* On input change event
|
|
11
|
+
*/
|
|
10
12
|
readonly onChange: (event: React.ChangeEvent<HTMLInputElement>, payload: PhonePayload) => void;
|
|
13
|
+
/**
|
|
14
|
+
* Supported RegExp templates
|
|
15
|
+
*/
|
|
11
16
|
readonly templates: readonly PhoneTemplate[];
|
|
17
|
+
/**
|
|
18
|
+
* If truethen CountryFalg component will be hidden
|
|
19
|
+
*/
|
|
20
|
+
readonly withoutCountryFlag?: boolean;
|
|
12
21
|
}
|
|
13
22
|
export interface PhonePayload {
|
|
14
23
|
/**
|
package/PhoneField/index.js
CHANGED
|
@@ -33,7 +33,7 @@ const TextField_1 = __importDefault(require("../TextField"));
|
|
|
33
33
|
const usePhoneUtils_1 = require("./usePhoneUtils");
|
|
34
34
|
const CountryFlagComponent_1 = __importDefault(require("./CountryFlagComponent"));
|
|
35
35
|
const PhoneField = (props, ref) => {
|
|
36
|
-
const { value,
|
|
36
|
+
const { value, templates, inputRef, withoutCountryFlag, onChange } = props, textFieldProps = __rest(props, ["value", "templates", "inputRef", "withoutCountryFlag", "onChange"]);
|
|
37
37
|
const { formatParsedInput, parseInput, parseAndFormat } = (0, usePhoneUtils_1.usePhoneUtils)({ templates });
|
|
38
38
|
const textInputRef = react_1.default.useRef(null);
|
|
39
39
|
const initialValue = react_1.default.useRef(value);
|
|
@@ -80,12 +80,12 @@ const PhoneField = (props, ref) => {
|
|
|
80
80
|
(_a = textInputRef.current) === null || _a === void 0 ? void 0 : _a.setSelectionRange(caret, caret);
|
|
81
81
|
}, 15);
|
|
82
82
|
};
|
|
83
|
-
return (react_1.default.createElement(TextField_1.default, Object.assign({ ref: ref, startIcon: react_1.default.useMemo(() => (react_1.default.createElement(CountryFlagComponent_1.default, { flag: CountryFlag, onClick: () => {
|
|
83
|
+
return (react_1.default.createElement(TextField_1.default, Object.assign({ ref: ref, startIcon: react_1.default.useMemo(() => withoutCountryFlag ? undefined : (react_1.default.createElement(CountryFlagComponent_1.default, { flag: CountryFlag, onClick: () => {
|
|
84
84
|
if (textInputRef.current) {
|
|
85
85
|
textInputRef.current.select();
|
|
86
86
|
textInputRef.current.focus();
|
|
87
87
|
}
|
|
88
|
-
} })), [CountryFlag]) }, textFieldProps, { value: currentValue, placeholder: placeholder, onChange: handleChange, inputRef: input => {
|
|
88
|
+
} })), [CountryFlag, withoutCountryFlag]) }, textFieldProps, { value: currentValue, placeholder: placeholder, onChange: handleChange, inputRef: input => {
|
|
89
89
|
textInputRef.current = input;
|
|
90
90
|
if (typeof inputRef === 'function') {
|
|
91
91
|
inputRef(input);
|