@easyv/react-components 0.0.5 → 0.0.6

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/README.md CHANGED
@@ -7,7 +7,53 @@ a react component library base on arco design
7
7
 
8
8
  ## Usage
9
9
 
10
- TODO
10
+ ### 安装包
11
+
12
+ 基础包
13
+
14
+ ```shell
15
+ pnpm add @arco-design/web-react @arco-plugins/vite-react
16
+ ```
17
+
18
+ 主题包,例如 `@arco-themes/react-easytwin`
19
+
20
+ ```shell
21
+ pnpm add @arco-themes/react-easytwin
22
+ ```
23
+
24
+ ### 配置
25
+
26
+ 以 vite 为例
27
+
28
+ 配置 `vite.config.ts`
29
+
30
+ ```js
31
+ import { vitePluginForArco } from '@arco-plugins/vite-react';
32
+
33
+ export default defineConfig({
34
+ // ...
35
+ plugins: [
36
+ // ...
37
+ vitePluginForArco({
38
+ theme: '@arco-themes/react-easytwin',
39
+ }),
40
+ ],
41
+ });
42
+ ```
43
+
44
+ 如果是应用的暗色主题,请在 `index.html` 的 body 上添加 `arco-theme="dark"`,如果是亮色的,可以不加。
45
+
46
+ ### 使用
47
+
48
+ 可以统一在 `components` 目录下新建一个 `ui.ts` 文件,这个文件的主要作用就是从 `@easyv/react-components` 中导入组件并导出
49
+
50
+ ```ts
51
+ export { Input } from '@easyv/react-components';
52
+ ```
53
+
54
+ 这样方便统一管理,后面如果要迁移组件库,只需要修改这个文件即可。
55
+
56
+ 注意:不要引 `@arco-design/web-react`,这是依赖的基础库,但不是直接使用的库。`@easyv/react-components` 会基于它做一些定制。
11
57
 
12
58
  ## Options
13
59
 
@@ -6,35 +6,72 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
6
6
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
7
7
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
8
8
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
9
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
10
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
12
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
13
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
14
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
9
15
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
10
16
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
11
- import React, { forwardRef } from 'react';
17
+ import React, { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
12
18
  import { Input } from '@arco-design/web-react';
13
19
  import classNames from 'classnames';
14
20
  import { SearchCircleOutlined } from '@easyv/react-icons';
15
21
  import "./index.less";
16
22
  import { jsx as _jsx } from "react/jsx-runtime";
17
- var XInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
18
- var _ref$bordered = _ref.bordered,
19
- bordered = _ref$bordered === void 0 ? true : _ref$bordered,
20
- className = _ref.className,
21
- restProps = _objectWithoutProperties(_ref, _excluded);
22
- return /*#__PURE__*/_jsx(Input, _objectSpread({
23
+ var XInput = /*#__PURE__*/forwardRef(function (props, ref) {
24
+ var _props$bordered = props.bordered,
25
+ bordered = _props$bordered === void 0 ? true : _props$bordered,
26
+ className = props.className,
27
+ restProps = _objectWithoutProperties(props, _excluded);
28
+ var isHalfControll = ('onBlurChange' in props);
29
+ var _useState = useState('value' in props ? props.value : undefined),
30
+ _useState2 = _slicedToArray(_useState, 2),
31
+ localValue = _useState2[0],
32
+ setLocalValue = _useState2[1];
33
+ var refValue = useRef(localValue);
34
+ refValue.current = localValue;
35
+ useEffect(function () {
36
+ if (isHalfControll && props.value !== localValue) {
37
+ setLocalValue(props.value);
38
+ }
39
+ }, [props.value, isHalfControll]);
40
+ var handlePressEnter = useCallback(function (e) {
41
+ return e.currentTarget.blur();
42
+ }, []);
43
+ var handleChange = useCallback(function (value) {
44
+ setLocalValue(value);
45
+ }, []);
46
+ var handleBlur = useCallback(function () {
47
+ if (refValue.current !== undefined && refValue.current !== props.value) {
48
+ if (props.enableEmpty) {
49
+ var _props$onBlurChange;
50
+ (_props$onBlurChange = props.onBlurChange) === null || _props$onBlurChange === void 0 ? void 0 : _props$onBlurChange.call(props, refValue.current);
51
+ } else {
52
+ setLocalValue(props.value);
53
+ }
54
+ }
55
+ }, []);
56
+ var halfControlledProps = {
57
+ value: localValue,
58
+ onChange: handleChange,
59
+ onBlur: handleBlur
60
+ };
61
+ return /*#__PURE__*/_jsx(Input, _objectSpread(_objectSpread({
23
62
  ref: ref,
24
63
  className: classNames(className, {
25
64
  'arco-input-borderless': !bordered
26
65
  }),
27
- onPressEnter: function onPressEnter(e) {
28
- e.target.blur();
29
- }
30
- }, restProps));
66
+ onPressEnter: handlePressEnter
67
+ }, isHalfControll ? halfControlledProps : {}), restProps));
31
68
  });
32
- var InputSearch = /*#__PURE__*/forwardRef(function (_ref2, ref) {
33
- var _ref2$bordered = _ref2.bordered,
34
- bordered = _ref2$bordered === void 0 ? true : _ref2$bordered,
35
- className = _ref2.className,
36
- onSearch = _ref2.onSearch,
37
- restProps = _objectWithoutProperties(_ref2, _excluded2);
69
+ var InputSearch = /*#__PURE__*/forwardRef(function (_ref, ref) {
70
+ var _ref$bordered = _ref.bordered,
71
+ bordered = _ref$bordered === void 0 ? true : _ref$bordered,
72
+ className = _ref.className,
73
+ onSearch = _ref.onSearch,
74
+ restProps = _objectWithoutProperties(_ref, _excluded2);
38
75
  return /*#__PURE__*/_jsx(Input, _objectSpread({
39
76
  ref: ref,
40
77
  className: classNames(className, {
@@ -1,7 +1,9 @@
1
1
  import type { InputProps } from '@arco-design/web-react';
2
2
  import type { InputSearchProps, RefInputType } from '@arco-design/web-react/es/Input';
3
3
  interface XInputProps extends InputProps {
4
+ enableEmpty?: boolean;
4
5
  bordered?: boolean;
6
+ onBlurChange?: (value: string) => void;
5
7
  }
6
8
  interface XInputSearchProps extends InputSearchProps {
7
9
  bordered?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/react-components",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "a react component library base on arco design",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",