@ohos-ports/s-ui-react-atom-input 5.51.0-beta.0
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/LICENSE.md +21 -0
- package/README.md +227 -0
- package/lib/Container/InputContainer.js +19 -0
- package/lib/Container/index.scss +25 -0
- package/lib/Input/Component/index.js +141 -0
- package/lib/Input/Component/index.scss +93 -0
- package/lib/Input/Component/settings.scss +30 -0
- package/lib/Input/Wrappers/Addons/InputAddons.js +32 -0
- package/lib/Input/Wrappers/Addons/config.js +12 -0
- package/lib/Input/Wrappers/Addons/index.scss +35 -0
- package/lib/Input/Wrappers/Addons/settings.scss +7 -0
- package/lib/Input/Wrappers/Button/InputButton.js +21 -0
- package/lib/Input/Wrappers/Button/config.js +2 -0
- package/lib/Input/Wrappers/Button/index.scss +13 -0
- package/lib/Input/Wrappers/Icons/InputIcons.js +34 -0
- package/lib/Input/Wrappers/Icons/config.js +12 -0
- package/lib/Input/Wrappers/Icons/index.scss +44 -0
- package/lib/Input/Wrappers/Icons/settings.scss +10 -0
- package/lib/Input/Wrappers/index.scss +3 -0
- package/lib/Input/Wrappers/settings.scss +2 -0
- package/lib/Input/index.js +49 -0
- package/lib/Mask/iMask.js +19 -0
- package/lib/Mask/index.js +48 -0
- package/lib/Password/config.js +5 -0
- package/lib/Password/index.js +60 -0
- package/lib/Password/index.scss +2 -0
- package/lib/Password/styles/index.scss +58 -0
- package/lib/Password/styles/settings.scss +3 -0
- package/lib/config.js +55 -0
- package/lib/helpers/getComponentAndProps.js +22 -0
- package/lib/helpers/isValidInputValue.js +16 -0
- package/lib/index.js +33 -0
- package/lib/index.scss +4 -0
- package/lib/mixins.scss +75 -0
- package/lib/settings.scss +5 -0
- package/lib/styles/index.scss +6 -0
- package/lib/styles/settings.scss +3 -0
- package/package.json +49 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import cx from 'classnames';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { BASE_CLASS_ICON, BASE_CLASS_ICON_COMPONENT, BASE_CLASS_ICON_COMPONENT_HANDLER, BASE_CLASS_ICON_COMPONENT_LEFT, BASE_CLASS_ICON_COMPONENT_RIGHT, BASE_CLASS_ICON_LEFT, BASE_CLASS_ICON_RIGHT } from './config.js';
|
|
4
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
|
+
var InputIcons = function InputIcons(_ref) {
|
|
6
|
+
var _cx, _cx2, _cx3;
|
|
7
|
+
var leftIcon = _ref.leftIcon,
|
|
8
|
+
rightIcon = _ref.rightIcon,
|
|
9
|
+
onClickLeftIcon = _ref.onClickLeftIcon,
|
|
10
|
+
onClickRightIcon = _ref.onClickRightIcon,
|
|
11
|
+
children = _ref.children;
|
|
12
|
+
if (!(leftIcon || rightIcon)) {
|
|
13
|
+
return children;
|
|
14
|
+
}
|
|
15
|
+
var handleLeftClick = function handleLeftClick(event) {
|
|
16
|
+
onClickLeftIcon && onClickLeftIcon(event);
|
|
17
|
+
};
|
|
18
|
+
var handleRightClick = function handleRightClick(event) {
|
|
19
|
+
onClickRightIcon && onClickRightIcon(event);
|
|
20
|
+
};
|
|
21
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
22
|
+
className: cx(BASE_CLASS_ICON, (_cx = {}, _cx[BASE_CLASS_ICON_LEFT] = leftIcon, _cx[BASE_CLASS_ICON_RIGHT] = rightIcon, _cx)),
|
|
23
|
+
children: [leftIcon && /*#__PURE__*/_jsx("span", {
|
|
24
|
+
className: cx(BASE_CLASS_ICON_COMPONENT, BASE_CLASS_ICON_COMPONENT_LEFT, (_cx2 = {}, _cx2[BASE_CLASS_ICON_COMPONENT_HANDLER] = onClickLeftIcon, _cx2)),
|
|
25
|
+
onClick: handleLeftClick,
|
|
26
|
+
children: leftIcon
|
|
27
|
+
}), children, rightIcon && /*#__PURE__*/_jsx("span", {
|
|
28
|
+
className: cx(BASE_CLASS_ICON_COMPONENT, BASE_CLASS_ICON_COMPONENT_RIGHT, (_cx3 = {}, _cx3[BASE_CLASS_ICON_COMPONENT_HANDLER] = onClickRightIcon, _cx3)),
|
|
29
|
+
onClick: handleRightClick,
|
|
30
|
+
children: rightIcon
|
|
31
|
+
})]
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
export default InputIcons;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BASE } from '../../../config.js';
|
|
2
|
+
export var ICON_TYPES = {
|
|
3
|
+
LEFT: 'left',
|
|
4
|
+
RIGHT: 'right'
|
|
5
|
+
};
|
|
6
|
+
export var BASE_CLASS_ICON = BASE + "--withIcon";
|
|
7
|
+
export var BASE_CLASS_ICON_LEFT = BASE_CLASS_ICON + "--" + ICON_TYPES.LEFT;
|
|
8
|
+
export var BASE_CLASS_ICON_RIGHT = BASE_CLASS_ICON + "--" + ICON_TYPES.RIGHT;
|
|
9
|
+
export var BASE_CLASS_ICON_COMPONENT = BASE_CLASS_ICON + "-icon";
|
|
10
|
+
export var BASE_CLASS_ICON_COMPONENT_HANDLER = BASE_CLASS_ICON_COMPONENT + "--withHandler";
|
|
11
|
+
export var BASE_CLASS_ICON_COMPONENT_LEFT = BASE_CLASS_ICON_COMPONENT + "--" + ICON_TYPES.LEFT;
|
|
12
|
+
export var BASE_CLASS_ICON_COMPONENT_RIGHT = BASE_CLASS_ICON_COMPONENT + "--" + ICON_TYPES.RIGHT;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#{$base-class}--withIcon {
|
|
2
|
+
position: relative;
|
|
3
|
+
width: 100%;
|
|
4
|
+
|
|
5
|
+
&--left #{$base-class-input} {
|
|
6
|
+
padding-left: $pl-atom-input-input;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
&--right #{$base-class-input} {
|
|
10
|
+
padding-right: $pr-atom-input-input;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
&-icon {
|
|
14
|
+
align-items: center;
|
|
15
|
+
color: $c-atom-input-icon;
|
|
16
|
+
display: flex;
|
|
17
|
+
fill: $c-atom-input-icon;
|
|
18
|
+
height: $w-atom-input-icon;
|
|
19
|
+
justify-content: center;
|
|
20
|
+
position: absolute;
|
|
21
|
+
top: $t-atom-input-icon;
|
|
22
|
+
transform: translateY($trf-ty-atom-input-icon);
|
|
23
|
+
width: $w-atom-input-icon;
|
|
24
|
+
pointer-events: none;
|
|
25
|
+
|
|
26
|
+
&--withHandler {
|
|
27
|
+
cursor: pointer;
|
|
28
|
+
pointer-events: auto;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
&--left {
|
|
32
|
+
left: $l-atom-input-icon;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
&--right {
|
|
36
|
+
right: $r-atom-input-icon;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
& > * {
|
|
40
|
+
height: 100%;
|
|
41
|
+
width: 100%;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
$l-atom-input-icon: $gutter !default;
|
|
2
|
+
$r-atom-input-icon: $gutter !default;
|
|
3
|
+
$w-atom-input-icon: $sz-icon-m !default;
|
|
4
|
+
$h-atom-input-icon: $sz-icon-m !default;
|
|
5
|
+
$t-atom-input-icon: 50% !default;
|
|
6
|
+
$trf-ty-atom-input-icon: -50% !default;
|
|
7
|
+
$pl-atom-input-icon: 50px !default;
|
|
8
|
+
$pl-atom-input-input: $w-atom-input-icon + $l-atom-input-icon + $p-s !default;
|
|
9
|
+
$pr-atom-input-input: $w-atom-input-icon + $r-atom-input-icon + $p-s !default;
|
|
10
|
+
$c-atom-input-icon: $c-primary !default;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
var _excluded = ["button", "leftAddon", "rightAddon", "leftIcon", "rightIcon", "children", "onClickLeftIcon", "onClickRightIcon", "size", "shape"];
|
|
4
|
+
import { forwardRef } from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import { INPUT_SHAPES, SIZES } from '../config.js';
|
|
7
|
+
import Input, { inputSizes, inputStates } from './Component/index.js';
|
|
8
|
+
import InputAddons from './Wrappers/Addons/InputAddons.js';
|
|
9
|
+
import InputButton from './Wrappers/Button/InputButton.js';
|
|
10
|
+
import InputIcons from './Wrappers/Icons/InputIcons.js';
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
var BaseInput = /*#__PURE__*/forwardRef(function (_ref, forwardedRef) {
|
|
13
|
+
var button = _ref.button,
|
|
14
|
+
leftAddon = _ref.leftAddon,
|
|
15
|
+
rightAddon = _ref.rightAddon,
|
|
16
|
+
leftIcon = _ref.leftIcon,
|
|
17
|
+
rightIcon = _ref.rightIcon,
|
|
18
|
+
children = _ref.children,
|
|
19
|
+
onClickLeftIcon = _ref.onClickLeftIcon,
|
|
20
|
+
onClickRightIcon = _ref.onClickRightIcon,
|
|
21
|
+
_ref$size = _ref.size,
|
|
22
|
+
size = _ref$size === void 0 ? SIZES.MEDIUM : _ref$size,
|
|
23
|
+
shape = _ref.shape,
|
|
24
|
+
inputProps = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
25
|
+
return /*#__PURE__*/_jsx(InputButton, {
|
|
26
|
+
button: button,
|
|
27
|
+
children: /*#__PURE__*/_jsx(InputAddons, {
|
|
28
|
+
leftAddon: leftAddon,
|
|
29
|
+
rightAddon: rightAddon,
|
|
30
|
+
shape: shape,
|
|
31
|
+
size: size,
|
|
32
|
+
children: /*#__PURE__*/_jsx(InputIcons, {
|
|
33
|
+
leftIcon: leftIcon,
|
|
34
|
+
rightIcon: rightIcon,
|
|
35
|
+
onClickLeftIcon: onClickLeftIcon,
|
|
36
|
+
onClickRightIcon: onClickRightIcon,
|
|
37
|
+
children: /*#__PURE__*/_jsx(Input, _extends({
|
|
38
|
+
ref: forwardedRef,
|
|
39
|
+
shape: shape
|
|
40
|
+
}, inputProps, {
|
|
41
|
+
size: size,
|
|
42
|
+
children: children
|
|
43
|
+
}))
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
export default BaseInput;
|
|
49
|
+
export { inputSizes, inputStates, BaseInput };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
var _excluded = ["inputRef", "value", "size"];
|
|
4
|
+
import { IMaskMixin } from 'react-imask';
|
|
5
|
+
import Input from '../Input/index.js';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
var IMask = IMaskMixin(function (_ref) {
|
|
8
|
+
var inputRef = _ref.inputRef,
|
|
9
|
+
value = _ref.value,
|
|
10
|
+
size = _ref.size,
|
|
11
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
12
|
+
return /*#__PURE__*/_jsx(Input, _extends({
|
|
13
|
+
type: "text",
|
|
14
|
+
ref: inputRef,
|
|
15
|
+
size: size,
|
|
16
|
+
value: value
|
|
17
|
+
}, props));
|
|
18
|
+
});
|
|
19
|
+
export default IMask;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
var _excluded = ["name", "onChange", "onComplete", "mask", "value", "defaultValue", "placeholder", "size"];
|
|
4
|
+
import { forwardRef } from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import { isFunction, SIZES } from '../config.js';
|
|
7
|
+
import IMask from './iMask.js';
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
var MaskInput = /*#__PURE__*/forwardRef(function (_ref, forwardedRef) {
|
|
10
|
+
var name = _ref.name,
|
|
11
|
+
onChange = _ref.onChange,
|
|
12
|
+
_onComplete = _ref.onComplete,
|
|
13
|
+
mask = _ref.mask,
|
|
14
|
+
value = _ref.value,
|
|
15
|
+
defaultValue = _ref.defaultValue,
|
|
16
|
+
placeholder = _ref.placeholder,
|
|
17
|
+
_ref$size = _ref.size,
|
|
18
|
+
size = _ref$size === void 0 ? SIZES.MEDIUM : _ref$size,
|
|
19
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
20
|
+
return /*#__PURE__*/_jsx(IMask, _extends({
|
|
21
|
+
name: name,
|
|
22
|
+
mask: mask == null ? void 0 : mask.mask,
|
|
23
|
+
value: value,
|
|
24
|
+
size: size,
|
|
25
|
+
ref: forwardedRef,
|
|
26
|
+
placeholder: placeholder,
|
|
27
|
+
onAccept: function onAccept(value, maskRef, event) {
|
|
28
|
+
for (var _len = arguments.length, args = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
|
|
29
|
+
args[_key - 3] = arguments[_key];
|
|
30
|
+
}
|
|
31
|
+
return isFunction(onChange) && onChange(event, _extends({
|
|
32
|
+
value: value,
|
|
33
|
+
maskRef: maskRef
|
|
34
|
+
}, args));
|
|
35
|
+
},
|
|
36
|
+
onComplete: function onComplete(value, maskRef, event) {
|
|
37
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
|
|
38
|
+
args[_key2 - 3] = arguments[_key2];
|
|
39
|
+
}
|
|
40
|
+
return isFunction(_onComplete) && _onComplete(event, _extends({
|
|
41
|
+
value: value,
|
|
42
|
+
maskRef: maskRef
|
|
43
|
+
}, args));
|
|
44
|
+
}
|
|
45
|
+
}, props));
|
|
46
|
+
});
|
|
47
|
+
MaskInput.displayName = 'MaskInput';
|
|
48
|
+
export default MaskInput;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
var _excluded = ["onChange", "shape", "pwShowLabel", "pwHideLabel", "toggleAriaLabel", "value", "defaultValue", "state"];
|
|
4
|
+
import { forwardRef, useState } from 'react';
|
|
5
|
+
import cx from 'classnames';
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
7
|
+
import useControlledState from '@s-ui/react-hooks/lib/useControlledState';
|
|
8
|
+
import { INPUT_SHAPES, INPUT_STATES } from '../config.js';
|
|
9
|
+
import Input from '../Input/index.js';
|
|
10
|
+
import { BASE_CLASS_PASSWORD, BASE_CLASS_PASSWORD_TOGGLE_BUTTON, PASSWORD, TEXT } from './config.js';
|
|
11
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
+
var Password = /*#__PURE__*/forwardRef(function (_ref, forwardedRef) {
|
|
13
|
+
var onChange = _ref.onChange,
|
|
14
|
+
shape = _ref.shape,
|
|
15
|
+
pwShowLabel = _ref.pwShowLabel,
|
|
16
|
+
pwHideLabel = _ref.pwHideLabel,
|
|
17
|
+
toggleAriaLabel = _ref.toggleAriaLabel,
|
|
18
|
+
value = _ref.value,
|
|
19
|
+
_ref$defaultValue = _ref.defaultValue,
|
|
20
|
+
defaultValue = _ref$defaultValue === void 0 ? '' : _ref$defaultValue,
|
|
21
|
+
state = _ref.state,
|
|
22
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
23
|
+
var _useState = useState(PASSWORD),
|
|
24
|
+
type = _useState[0],
|
|
25
|
+
setType = _useState[1];
|
|
26
|
+
var _useControlledState = useControlledState(value, defaultValue),
|
|
27
|
+
innerValue = _useControlledState[0],
|
|
28
|
+
setInnerValue = _useControlledState[1];
|
|
29
|
+
var toggle = function toggle() {
|
|
30
|
+
var inputType = type === PASSWORD ? TEXT : PASSWORD;
|
|
31
|
+
setType(inputType);
|
|
32
|
+
};
|
|
33
|
+
var handleChange = function handleChange(ev, _ref2) {
|
|
34
|
+
var value = _ref2.value;
|
|
35
|
+
setInnerValue(value);
|
|
36
|
+
typeof onChange === 'function' && onChange(ev, {
|
|
37
|
+
value: value
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
41
|
+
className: cx(BASE_CLASS_PASSWORD, shape && BASE_CLASS_PASSWORD + "-shape-" + shape, state && BASE_CLASS_PASSWORD + "--state-" + state),
|
|
42
|
+
children: [/*#__PURE__*/_jsx(Input, _extends({
|
|
43
|
+
ref: forwardedRef,
|
|
44
|
+
shape: shape
|
|
45
|
+
}, props, {
|
|
46
|
+
onChange: handleChange,
|
|
47
|
+
value: innerValue,
|
|
48
|
+
type: type,
|
|
49
|
+
noBorder: true
|
|
50
|
+
})), /*#__PURE__*/_jsx("button", {
|
|
51
|
+
onClick: toggle,
|
|
52
|
+
type: "button",
|
|
53
|
+
"aria-pressed": type !== PASSWORD,
|
|
54
|
+
"aria-label": toggleAriaLabel,
|
|
55
|
+
className: cx(BASE_CLASS_PASSWORD_TOGGLE_BUTTON, shape && BASE_CLASS_PASSWORD_TOGGLE_BUTTON + "-shape-" + shape),
|
|
56
|
+
children: type === PASSWORD ? pwShowLabel : pwHideLabel
|
|
57
|
+
})]
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
export default Password;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
$base-class-password: '#{$base-class-input}-password';
|
|
2
|
+
|
|
3
|
+
#{$base-class-password} {
|
|
4
|
+
position: relative;
|
|
5
|
+
width: 100%;
|
|
6
|
+
display: flex;
|
|
7
|
+
@include sui-atom-input-input;
|
|
8
|
+
padding-left: 0;
|
|
9
|
+
border-radius: $bdrs-atom-input;
|
|
10
|
+
|
|
11
|
+
& > input {
|
|
12
|
+
padding-right: $pr-atom-input-password;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
&-shape {
|
|
16
|
+
@each $shapeMapKey, $shapeMapValue in $bdrs-atom-input-shapes {
|
|
17
|
+
&-#{$shapeMapKey} {
|
|
18
|
+
border-radius: $shapeMapValue;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&--toggleButton {
|
|
24
|
+
&-shape {
|
|
25
|
+
@each $shapeMapKey, $shapeMapValue in $bdrs-atom-input-shapes {
|
|
26
|
+
&-#{$shapeMapKey} {
|
|
27
|
+
border-radius: $shapeMapValue;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
margin-top: 8px;
|
|
32
|
+
margin-bottom: 8px;
|
|
33
|
+
border: none;
|
|
34
|
+
background: $c-white;
|
|
35
|
+
color: $c-atom-input-password-toggle-button;
|
|
36
|
+
display: inline-block;
|
|
37
|
+
user-select: none;
|
|
38
|
+
border-radius: $bdrs-atom-input;
|
|
39
|
+
&:focus-visible {
|
|
40
|
+
outline-style: solid;
|
|
41
|
+
outline-color: transparentize($c-primary, 0.2);
|
|
42
|
+
outline-width: 2px;
|
|
43
|
+
outline-offset: 2px;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
&--state-error {
|
|
48
|
+
border-color: $c-atom-input--error;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
&--state-success {
|
|
52
|
+
border-color: $c-atom-input--success;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
&--state-alert {
|
|
56
|
+
border-color: $c-atom-input--alert;
|
|
57
|
+
}
|
|
58
|
+
}
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import cx from 'classnames';
|
|
2
|
+
export var PREFIX = 'sui';
|
|
3
|
+
export var CATEGORY = 'Atom';
|
|
4
|
+
export var COMPONENT = 'Input';
|
|
5
|
+
export var BASE = PREFIX + "-" + CATEGORY + COMPONENT;
|
|
6
|
+
export var BASE_CLASS = BASE + "-input";
|
|
7
|
+
|
|
8
|
+
// Enums
|
|
9
|
+
export var TYPES = {
|
|
10
|
+
DATE: 'date',
|
|
11
|
+
EMAIL: 'email',
|
|
12
|
+
MASK: 'mask',
|
|
13
|
+
NONE: 'none',
|
|
14
|
+
NUMBER: 'number',
|
|
15
|
+
PASSWORD: 'password',
|
|
16
|
+
SEARCH: 'search',
|
|
17
|
+
SUI_PASSWORD: 'sui-password',
|
|
18
|
+
TEL: 'tel',
|
|
19
|
+
TEXT: 'text'
|
|
20
|
+
};
|
|
21
|
+
export var SIZES = {
|
|
22
|
+
XLARGE: 'xl',
|
|
23
|
+
LARGE: 'l',
|
|
24
|
+
MEDIUM: 'm',
|
|
25
|
+
SMALL: 's',
|
|
26
|
+
XSMALL: 'xs'
|
|
27
|
+
};
|
|
28
|
+
export var INPUT_STATES = {
|
|
29
|
+
ERROR: 'error',
|
|
30
|
+
SUCCESS: 'success',
|
|
31
|
+
ALERT: 'alert'
|
|
32
|
+
};
|
|
33
|
+
export var INPUT_SHAPES = {
|
|
34
|
+
ROUNDED: 'rounded',
|
|
35
|
+
SQUARE: 'square',
|
|
36
|
+
CIRCLE: 'circle'
|
|
37
|
+
};
|
|
38
|
+
export var noop = function noop() {
|
|
39
|
+
return null;
|
|
40
|
+
};
|
|
41
|
+
export var isFunction = function isFunction(fn) {
|
|
42
|
+
return typeof fn === 'function';
|
|
43
|
+
};
|
|
44
|
+
export var getClassNames = function getClassNames(_ref) {
|
|
45
|
+
var size = _ref.size,
|
|
46
|
+
charsSize = _ref.charsSize,
|
|
47
|
+
hideInput = _ref.hideInput,
|
|
48
|
+
noBorder = _ref.noBorder,
|
|
49
|
+
readOnly = _ref.readOnly,
|
|
50
|
+
errorState = _ref.errorState,
|
|
51
|
+
state = _ref.state,
|
|
52
|
+
shape = _ref.shape,
|
|
53
|
+
className = _ref.className;
|
|
54
|
+
return cx(BASE_CLASS, size && BASE_CLASS + "-size-" + size, charsSize && BASE_CLASS + "--charsSize", hideInput && BASE_CLASS + "--hidden", noBorder && BASE_CLASS + "--noBorder", readOnly && BASE_CLASS + "--readOnly", errorState && BASE_CLASS + "--state-" + INPUT_STATES.ERROR, errorState === false && BASE_CLASS + "--state-" + INPUT_STATES.SUCCESS, state && BASE_CLASS + "--state-" + state, shape && BASE_CLASS + "-shape-" + shape, className);
|
|
55
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
var _excluded = ["type"];
|
|
4
|
+
import Input from '../Input/index.js';
|
|
5
|
+
import Mask from '../Mask/index.js';
|
|
6
|
+
import Password from '../Password/index.js';
|
|
7
|
+
export default (function (_ref) {
|
|
8
|
+
var type = _ref.type,
|
|
9
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
10
|
+
switch (type) {
|
|
11
|
+
case 'sui-password':
|
|
12
|
+
return [Password, _extends({}, rest, {
|
|
13
|
+
type: type
|
|
14
|
+
})];
|
|
15
|
+
case 'mask':
|
|
16
|
+
return [Mask, _extends({}, rest)];
|
|
17
|
+
default:
|
|
18
|
+
return [Input, _extends({}, rest, {
|
|
19
|
+
type: type
|
|
20
|
+
})];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TYPES } from '../config.js';
|
|
2
|
+
export default (function (event, _ref) {
|
|
3
|
+
var type = _ref.type,
|
|
4
|
+
onEnterKey = _ref.onEnterKey;
|
|
5
|
+
if (type === TYPES.NUMBER) {
|
|
6
|
+
// Check if input type number is valid as input type number doesn't currently work in browsers like Safari and Firefox
|
|
7
|
+
// Allowing: Integers | Backspace | Tab | Delete | Left & Right arrow keys
|
|
8
|
+
|
|
9
|
+
// const allowedCharacter =
|
|
10
|
+
// /(^\d*$)|(Backspace|Tab|Delete|ArrowLeft|ArrowRight|Enter)/
|
|
11
|
+
var onEnterKeyArray = Array.isArray(onEnterKey) ? onEnterKey : [onEnterKey];
|
|
12
|
+
var allowedCharacter = new RegExp("(^\\d*$)|(" + ['Backspace', 'Tab', 'Delete', 'ArrowLeft', 'ArrowRight'].concat(onEnterKeyArray).join('|') + ")");
|
|
13
|
+
return event.key.match(allowedCharacter);
|
|
14
|
+
}
|
|
15
|
+
return true;
|
|
16
|
+
});
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
var _excluded = ["type", "shape", "noBorder"];
|
|
4
|
+
import { forwardRef } from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import InputContainer from './Container/InputContainer.js';
|
|
7
|
+
import getComponentAndProps from './helpers/getComponentAndProps.js';
|
|
8
|
+
import { inputSizes, inputStates } from './Input/index.js';
|
|
9
|
+
import { INPUT_SHAPES, TYPES } from './config.js';
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
var AtomInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
12
|
+
var type = _ref.type,
|
|
13
|
+
shape = _ref.shape,
|
|
14
|
+
noBorder = _ref.noBorder,
|
|
15
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
16
|
+
var _getComponentAndProps = getComponentAndProps(_extends({
|
|
17
|
+
type: type
|
|
18
|
+
}, props)),
|
|
19
|
+
Component = _getComponentAndProps[0],
|
|
20
|
+
newProps = _getComponentAndProps[1];
|
|
21
|
+
return /*#__PURE__*/_jsx(InputContainer, {
|
|
22
|
+
shape: shape,
|
|
23
|
+
noBorder: noBorder,
|
|
24
|
+
children: /*#__PURE__*/_jsx(Component, _extends({}, newProps, {
|
|
25
|
+
shape: shape,
|
|
26
|
+
noBorder: noBorder,
|
|
27
|
+
ref: ref
|
|
28
|
+
}))
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
AtomInput.displayName = 'AtomInput';
|
|
32
|
+
export default AtomInput;
|
|
33
|
+
export { inputSizes, inputStates, TYPES as inputTypes, INPUT_SHAPES as inputShapes };
|
package/lib/index.scss
ADDED
package/lib/mixins.scss
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
@mixin atom-input-shape-wrapper(
|
|
2
|
+
$baseClass,
|
|
3
|
+
$baseClassName,
|
|
4
|
+
$shapeMap,
|
|
5
|
+
$sizesMap,
|
|
6
|
+
$bdrs-defaultValue,
|
|
7
|
+
$sz-defaultValue
|
|
8
|
+
) {
|
|
9
|
+
$this: &;
|
|
10
|
+
@if #{'sui-AtomInput-input'} == $baseClassName {
|
|
11
|
+
@each $shapeMapKey, $shapeMapValue in $shapeMap {
|
|
12
|
+
@if $shapeMapKey != 'circle' {
|
|
13
|
+
&#{$baseClassName}-shape-#{$shapeMapKey} {
|
|
14
|
+
border-radius: $shapeMapValue;
|
|
15
|
+
}
|
|
16
|
+
} @else {
|
|
17
|
+
@each $sizeKey, $sizeValue in $sizesMap {
|
|
18
|
+
&#{$baseClassName}-shape-#{$shapeMapKey}#{$baseClassName}-size-#{$sizeKey} {
|
|
19
|
+
border-radius: $sizeValue * 0.5;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
} @else {
|
|
25
|
+
> *,
|
|
26
|
+
#{$baseClass}-input {
|
|
27
|
+
border-radius: 0;
|
|
28
|
+
}
|
|
29
|
+
> *:first-child {
|
|
30
|
+
border-top-left-radius: $bdrs-defaultValue;
|
|
31
|
+
border-bottom-left-radius: $bdrs-defaultValue;
|
|
32
|
+
}
|
|
33
|
+
> *:last-child {
|
|
34
|
+
border-top-right-radius: $bdrs-defaultValue;
|
|
35
|
+
border-bottom-right-radius: $bdrs-defaultValue;
|
|
36
|
+
}
|
|
37
|
+
@each $shapeMapKey, $shapeMapValue in $shapeMap {
|
|
38
|
+
&#{$baseClassName}-shape-#{$shapeMapKey} {
|
|
39
|
+
> *,
|
|
40
|
+
#{$baseClass}-input {
|
|
41
|
+
border-radius: 0;
|
|
42
|
+
}
|
|
43
|
+
@if $shapeMapKey != 'circle' {
|
|
44
|
+
border-radius: $shapeMapValue;
|
|
45
|
+
> *:first-child {
|
|
46
|
+
border-top-left-radius: $shapeMapValue;
|
|
47
|
+
border-bottom-left-radius: $shapeMapValue;
|
|
48
|
+
}
|
|
49
|
+
> *:last-child {
|
|
50
|
+
border-top-right-radius: $shapeMapValue;
|
|
51
|
+
border-bottom-right-radius: $shapeMapValue;
|
|
52
|
+
}
|
|
53
|
+
} @else {
|
|
54
|
+
@each $sizeKey, $sizeValue in $sizesMap {
|
|
55
|
+
&#{$baseClassName}-shape-#{$shapeMapKey}#{$baseClassName}-size-#{$sizeKey} {
|
|
56
|
+
border-radius: $sizeValue * 0.5;
|
|
57
|
+
> *,
|
|
58
|
+
#{$baseClass}-input {
|
|
59
|
+
border-radius: 0;
|
|
60
|
+
}
|
|
61
|
+
> *:first-child {
|
|
62
|
+
border-top-left-radius: $sizeValue * 0.5;
|
|
63
|
+
border-bottom-left-radius: $sizeValue * 0.5;
|
|
64
|
+
}
|
|
65
|
+
> *:last-child {
|
|
66
|
+
border-top-right-radius: $sizeValue * 0.5;
|
|
67
|
+
border-bottom-right-radius: $sizeValue * 0.5;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ohos-ports/s-ui-react-atom-input",
|
|
3
|
+
"version": "5.51.0-beta.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"keywords": [
|
|
9
|
+
"@s-ui",
|
|
10
|
+
"react",
|
|
11
|
+
"component",
|
|
12
|
+
"atom",
|
|
13
|
+
"input"
|
|
14
|
+
],
|
|
15
|
+
"main": "lib/index.js",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"prepublishOnly": "rimraf ./lib && npm run build:js && npm run build:styles",
|
|
18
|
+
"build:js": "babel --presets sui ./src --out-dir ./lib",
|
|
19
|
+
"build:styles": "cpx './src/**/*.scss' ./lib"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@s-ui/react-hooks": "1",
|
|
23
|
+
"@s-ui/react-primitive-polymorphic-element": "1",
|
|
24
|
+
"react-imask": "6.4.3"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"@s-ui/component-dependencies": "1"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/ohos-ports/ohos-ports.git",
|
|
32
|
+
"directory": "ports/@s-ui/react-atom-input/5.51.0"
|
|
33
|
+
},
|
|
34
|
+
"config": {
|
|
35
|
+
"title": "input",
|
|
36
|
+
"category": "atom",
|
|
37
|
+
"type": "components"
|
|
38
|
+
},
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/ohos-ports/ohos-ports/issues"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://sui-components.vercel.app/",
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"files": [
|
|
45
|
+
"lib",
|
|
46
|
+
"README.md",
|
|
47
|
+
"LICENSE.md"
|
|
48
|
+
]
|
|
49
|
+
}
|