@yuntijs/ui 1.0.0-beta.14 → 1.0.0-beta.15
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/es/FormHelper/autoFocus.d.ts +10 -0
- package/es/FormHelper/autoFocus.js +38 -0
- package/es/FormHelper/index.d.ts +13 -0
- package/es/FormHelper/index.js +41 -0
- package/es/index.d.ts +2 -1
- package/es/index.js +2 -1
- package/package.json +1 -1
- package/umd/index.min.js +1 -1
- package/umd/index.min.js.map +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
type RefOrDomOrId<T> = HTMLElement | string | React.Ref<T>;
|
|
3
|
+
type F = any;
|
|
4
|
+
/**
|
|
5
|
+
* Passing a ref, id, or DOM element to obtain and set the focus state of the first non-disabled and non-readonly input or textarea.
|
|
6
|
+
* @param {RefOrDomOrId} refOrDomOrId - 支持类型 HTMLElement | string | React.Ref<T>
|
|
7
|
+
* @returns void
|
|
8
|
+
*/
|
|
9
|
+
export declare const useAutoFocus: (refOrDomOrId?: RefOrDomOrId<F>) => void;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
|
+
var getDom = function getDom(refOrDomOrId) {
|
|
4
|
+
return typeof refOrDomOrId === 'string' ? document.querySelector("#".concat(refOrDomOrId)) : (refOrDomOrId === null || refOrDomOrId === void 0 ? void 0 : refOrDomOrId.current) || refOrDomOrId;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/input#input_%E7%B1%BB%E5%9E%8B
|
|
8
|
+
var disabled = ':not([disabled]):not([readonly])';
|
|
9
|
+
var queryInputTypes = ['text', 'password', 'search', 'tel', 'url', 'number', 'email', ''].map(function (item) {
|
|
10
|
+
return "input[type=\"".concat(item, "\"]").concat(disabled);
|
|
11
|
+
}).join(', ') + ", input:not([type])".concat(disabled, ", textarea").concat(disabled);
|
|
12
|
+
var setAutoFocus = function setAutoFocus(refOrDomOrId) {
|
|
13
|
+
var _dom$querySelector;
|
|
14
|
+
var dom = getDom(refOrDomOrId);
|
|
15
|
+
if (!dom) return;
|
|
16
|
+
var input = (_dom$querySelector = dom.querySelector) === null || _dom$querySelector === void 0 ? void 0 : _dom$querySelector.call(dom, queryInputTypes);
|
|
17
|
+
if (!(input !== null && input !== void 0 && input.focus)) return;
|
|
18
|
+
input.focus();
|
|
19
|
+
return true;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Passing a ref, id, or DOM element to obtain and set the focus state of the first non-disabled and non-readonly input or textarea.
|
|
24
|
+
* @param {RefOrDomOrId} refOrDomOrId - 支持类型 HTMLElement | string | React.Ref<T>
|
|
25
|
+
* @returns void
|
|
26
|
+
*/
|
|
27
|
+
export var useAutoFocus = function useAutoFocus(refOrDomOrId) {
|
|
28
|
+
var _useState = useState(false),
|
|
29
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
30
|
+
focused = _useState2[0],
|
|
31
|
+
setFocused = _useState2[1];
|
|
32
|
+
React.useEffect(function () {
|
|
33
|
+
if (focused || !refOrDomOrId) return;
|
|
34
|
+
var setRes = setAutoFocus(refOrDomOrId);
|
|
35
|
+
if (!setRes) return;
|
|
36
|
+
setFocused(true);
|
|
37
|
+
}, [refOrDomOrId, focused, setFocused]);
|
|
38
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React, { ComponentType, FC } from 'react';
|
|
2
|
+
export { useAutoFocus } from './autoFocus';
|
|
3
|
+
export type FormHelperProps = {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
autoFocus?: boolean;
|
|
6
|
+
id?: string;
|
|
7
|
+
className?: string;
|
|
8
|
+
style?: React.CSSProperties;
|
|
9
|
+
};
|
|
10
|
+
declare const FormHelper: React.FC<FormHelperProps>;
|
|
11
|
+
type FormHelperConfig = Omit<FormHelperProps, 'children'>;
|
|
12
|
+
export declare const withFormHelper: (formHelperConfig?: FormHelperConfig) => <P extends Record<string, never>>(WrappedComponent: React.ComponentType<P>) => React.FC<P>;
|
|
13
|
+
export { FormHelper };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
import React, { useRef } from 'react';
|
|
5
|
+
import { useAutoFocus } from "./autoFocus";
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
export { useAutoFocus } from "./autoFocus";
|
|
8
|
+
// Component
|
|
9
|
+
|
|
10
|
+
var FormHelper = function FormHelper(props) {
|
|
11
|
+
var _props$style;
|
|
12
|
+
var _props$autoFocus = props.autoFocus,
|
|
13
|
+
autoFocus = _props$autoFocus === void 0 ? true : _props$autoFocus;
|
|
14
|
+
var ref = useRef(null);
|
|
15
|
+
useAutoFocus(autoFocus ? ref : undefined);
|
|
16
|
+
return /*#__PURE__*/_jsx("div", {
|
|
17
|
+
className: props.className,
|
|
18
|
+
id: props.id,
|
|
19
|
+
ref: ref,
|
|
20
|
+
style: (_props$style = props.style) !== null && _props$style !== void 0 ? _props$style : {
|
|
21
|
+
display: props.className ? undefined : 'contents'
|
|
22
|
+
},
|
|
23
|
+
children: props.children
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// HOC
|
|
28
|
+
|
|
29
|
+
export var withFormHelper = function withFormHelper(formHelperConfig) {
|
|
30
|
+
return function (WrappedComponent) {
|
|
31
|
+
var HocComponent = function HocComponent(props) {
|
|
32
|
+
return /*#__PURE__*/_jsx(FormHelper, _objectSpread(_objectSpread({}, formHelperConfig || {}), {}, {
|
|
33
|
+
children: /*#__PURE__*/_jsx(WrappedComponent, _objectSpread({}, props))
|
|
34
|
+
}));
|
|
35
|
+
};
|
|
36
|
+
var displayName = WrappedComponent.displayName || WrappedComponent.name || 'Component';
|
|
37
|
+
HocComponent.displayName = "withFormHelper(".concat(displayName, ")");
|
|
38
|
+
return HocComponent;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export { FormHelper };
|
package/es/index.d.ts
CHANGED
|
@@ -9,10 +9,11 @@ export * from './Card';
|
|
|
9
9
|
export * from './Descriptions';
|
|
10
10
|
export * from './Divider';
|
|
11
11
|
export * from './Drawer';
|
|
12
|
+
export * from './FormHelper';
|
|
12
13
|
export * from './Modal';
|
|
13
14
|
export { Affix, type AffixProps, Anchor, type AnchorProps, App, type AppProps, AutoComplete, type AutoCompleteProps, Avatar, type AvatarProps, BackTop, type BackTopProps, Badge, // @todo composed type
|
|
14
15
|
type BadgeProps, Button, // @todo dependence unifiedLink. link type, hover primary color, back button
|
|
15
16
|
type ButtonProps, Calendar, type CalendarProps, Carousel, type CarouselProps, Cascader, type CascaderProps, Checkbox, type CheckboxProps, Col, Collapse, type CollapseProps, ColorPicker, type ColorPickerProps, type ColProps, // @todo center style
|
|
16
|
-
DatePicker, type DatePickerProps, Dropdown, type DropDownProps, Empty, type EmptyProps, Flex, type FlexProps, FloatButton, type FloatButtonProps, Form, type FormInstance, type FormItemProps, type FormListFieldData, type FormListOperation, type FormProps, type FormRule, Grid, Image, ImageProps, Input, InputNumber, type InputNumberProps, type InputProps, type InputRef, Layout, type LayoutProps, List, type ListProps, type MentionProps, Mentions, Menu, type MenuItemProps, type MenuProps, type MenuRef, type MenuTheme, message, type MessageArgsProps, Space, type SpaceProps, type SubMenuProps, } from 'antd';
|
|
17
|
+
DatePicker, type DatePickerProps, Dropdown, type DropDownProps, Empty, type EmptyProps, Flex, type FlexProps, FloatButton, type FloatButtonProps, Form, type FormInstance, type FormItemProps, type FormListFieldData, type FormListOperation, type FormProps, type FormRule, Grid, Image, type ImageProps, Input, InputNumber, type InputNumberProps, type InputProps, type InputRef, Layout, type LayoutProps, List, type ListProps, type MentionProps, Mentions, Menu, type MenuItemProps, type MenuProps, type MenuRef, type MenuTheme, message, type MessageArgsProps, Space, type SpaceProps, type SubMenuProps, } from 'antd';
|
|
17
18
|
export { Highlighter, type HighlighterProps, Markdown, type MarkdownProps, SyntaxHighlighter, type SyntaxHighlighterProps, } from '@lobehub/ui';
|
|
18
19
|
export { useResponsive, useTheme, useThemeMode } from 'antd-style';
|
package/es/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export * from "./Card";
|
|
|
11
11
|
export * from "./Descriptions";
|
|
12
12
|
export * from "./Divider";
|
|
13
13
|
export * from "./Drawer";
|
|
14
|
+
export * from "./FormHelper";
|
|
14
15
|
export * from "./Modal";
|
|
15
16
|
|
|
16
17
|
// ~ antd
|
|
@@ -18,7 +19,7 @@ export { Affix, Anchor, App, AutoComplete, Avatar, BackTop, Badge // @todo compo
|
|
|
18
19
|
, Button // @todo dependence unifiedLink. link type, hover primary color, back button
|
|
19
20
|
, Calendar, Carousel, Cascader, Checkbox, Col, Collapse, ColorPicker,
|
|
20
21
|
// @todo center style
|
|
21
|
-
DatePicker, Dropdown, Empty, Flex, FloatButton, Form, Grid, Image,
|
|
22
|
+
DatePicker, Dropdown, Empty, Flex, FloatButton, Form, Grid, Image, Input, InputNumber, Layout, List, Mentions, Menu, message, Space } from 'antd';
|
|
22
23
|
|
|
23
24
|
// ~ @lobehub/ui
|
|
24
25
|
export { Highlighter, Markdown, SyntaxHighlighter } from '@lobehub/ui';
|