diff --git a/packages/ui/counter/src/use-counter.ts b/packages/ui/counter/src/use-counter.ts index b9a99885f..05b926d1b 100644 --- a/packages/ui/counter/src/use-counter.ts +++ b/packages/ui/counter/src/use-counter.ts @@ -266,17 +266,17 @@ export const useCounter = ({ } }, [ prefixCls, + value, minProp, maxProp, - value, inputValue, tabIndex, autoFocus, disabled, onInputChange, + onInputFocus, onInputBlur, onInputKeyDown, - onInputFocus, onInputWheel, ]) diff --git a/packages/ui/hiui/package.json b/packages/ui/hiui/package.json index 69e7ce2c4..c7e299bec 100644 --- a/packages/ui/hiui/package.json +++ b/packages/ui/hiui/package.json @@ -92,6 +92,7 @@ "@hi-ui/select": "^4.0.6", "@hi-ui/slider": "^4.0.5", "@hi-ui/space": "^4.0.6", + "@hi-ui/spinner": "^4.0.4", "@hi-ui/stepper": "^4.0.4", "@hi-ui/svg-icon": "^4.0.4", "@hi-ui/switch": "^4.0.4", diff --git a/packages/ui/hiui/src/index.ts b/packages/ui/hiui/src/index.ts index 4e4e3e19f..186fab474 100644 --- a/packages/ui/hiui/src/index.ts +++ b/packages/ui/hiui/src/index.ts @@ -151,7 +151,8 @@ export { default as Slider } from '@hi-ui/slider' export * from '@hi-ui/space' export { default as Space } from '@hi-ui/space' -// export * from '@hi-ui/spinner' +export * from '@hi-ui/spinner' +export { default as Spinner } from '@hi-ui/spinner' export * from '@hi-ui/stepper' export { default as Stepper } from '@hi-ui/stepper' diff --git a/packages/ui/loading/src/Loading.tsx b/packages/ui/loading/src/Loading.tsx index 2d9759e24..44bd30da1 100644 --- a/packages/ui/loading/src/Loading.tsx +++ b/packages/ui/loading/src/Loading.tsx @@ -1,18 +1,10 @@ -import React, { - useState, - useEffect, - useImperativeHandle, - useCallback, - forwardRef, - useRef, -} from 'react' -import { debounce } from '@hi-ui/func-utils' -import type { DebounceReturn } from '@hi-ui/func-utils' +import React, { useImperativeHandle, forwardRef, ReactNode } from 'react' import { CSSTransition } from 'react-transition-group' import { cx, getPrefixCls } from '@hi-ui/classname' import { __DEV__ } from '@hi-ui/env' import { Portal } from '@hi-ui/portal' import { HiBaseHTMLProps, HiBaseSizeEnum } from '@hi-ui/core' +import { useLoading } from './use-loading' const _role = 'loading' export const _prefix = getPrefixCls('loading') @@ -34,47 +26,12 @@ export const Loading = forwardRef( disabledPortal = false, innerRef, timeout = 300, + indicator, ...restProps }, ref ) => { - const [internalVisible, setInternalVisible] = useState(false) - - // Real trigger loading update - const updateLoadingStatus = useCallback(() => { - if (internalVisible === visible) return - setInternalVisible(visible) - }, [internalVisible, visible]) - - const prevDebouncedUpdateRef = useRef(null) - - const cancelWaitingLoading = () => { - prevDebouncedUpdateRef.current?.cancel() - } - - const shouldDelay = visible && delay >= 0 - - const debouncedLoadingUpdater = useCallback(() => { - cancelWaitingLoading() - - if (shouldDelay) { - const debouncedUpdateLoading = debounce(updateLoadingStatus, delay) - prevDebouncedUpdateRef.current = debouncedUpdateLoading - - debouncedUpdateLoading() - } else { - updateLoadingStatus() - prevDebouncedUpdateRef.current = null - } - }, [delay, shouldDelay, updateLoadingStatus]) - - useEffect(() => { - debouncedLoadingUpdater() - - return () => { - cancelWaitingLoading() - } - }, [debouncedLoadingUpdater]) + const { internalVisible, setInternalVisible } = useLoading({ visible, delay }) useImperativeHandle(innerRef, () => ({ close: () => setInternalVisible(false), @@ -98,10 +55,12 @@ export const Loading = forwardRef(
-
-
-
-
+ {indicator || ( +
+
+
+
+ )}
{content ? {content} : null}
@@ -173,6 +132,10 @@ export interface LoadingProps extends HiBaseHTMLProps<'div'> { * @private */ part?: boolean + /** + * 自定义加载指示符 + */ + indicator?: ReactNode } if (__DEV__) { diff --git a/packages/ui/loading/src/use-loading.ts b/packages/ui/loading/src/use-loading.ts new file mode 100644 index 000000000..ea45f3bc1 --- /dev/null +++ b/packages/ui/loading/src/use-loading.ts @@ -0,0 +1,55 @@ +import { useCallback, useEffect, useRef, useState } from 'react' +import { debounce } from '@hi-ui/func-utils' +import type { DebounceReturn } from '@hi-ui/func-utils' + +export const useLoading = ({ visible = true, delay = -1 }: UseLoadingProps) => { + const [internalVisible, setInternalVisible] = useState(false) + + // Real trigger loading update + const updateLoadingStatus = useCallback(() => { + if (internalVisible === visible) return + setInternalVisible(visible) + }, [internalVisible, visible]) + + const prevDebouncedUpdateRef = useRef(null) + + const cancelWaitingLoading = () => { + prevDebouncedUpdateRef.current?.cancel() + } + + const shouldDelay = visible && delay >= 0 + + const debouncedLoadingUpdater = useCallback(() => { + cancelWaitingLoading() + + if (shouldDelay) { + const debouncedUpdateLoading = debounce(updateLoadingStatus, delay) + prevDebouncedUpdateRef.current = debouncedUpdateLoading + + debouncedUpdateLoading() + } else { + updateLoadingStatus() + prevDebouncedUpdateRef.current = null + } + }, [delay, shouldDelay, updateLoadingStatus]) + + useEffect(() => { + debouncedLoadingUpdater() + + return () => { + cancelWaitingLoading() + } + }, [debouncedLoadingUpdater]) + + return { + internalVisible, + setInternalVisible, + } +} + +export interface UseLoadingProps { + visible?: boolean + delay?: number +} + +export type useInputReturn = ReturnType diff --git a/packages/ui/loading/stories/index.stories.tsx b/packages/ui/loading/stories/index.stories.tsx index 53cf51336..3cb11b92d 100644 --- a/packages/ui/loading/stories/index.stories.tsx +++ b/packages/ui/loading/stories/index.stories.tsx @@ -4,6 +4,7 @@ import Loading from '../src' export * from './basic.stories' export * from './duration.stories' export * from './visible.stories' +export * from './indicator.stories' export default { title: 'FeedBack/Loading', diff --git a/packages/ui/loading/stories/indicator.stories.tsx b/packages/ui/loading/stories/indicator.stories.tsx new file mode 100644 index 000000000..e7dcf997a --- /dev/null +++ b/packages/ui/loading/stories/indicator.stories.tsx @@ -0,0 +1,31 @@ +import React from 'react' +import Spinner from '@hi-ui/spinner' +import Loading from '../src' + +/** + * @title 设置加载指示符 + */ +export const Indicator = () => { + return ( + <> +

Indicator

+
+ }> +
+ +
+ + ) +} diff --git a/packages/ui/spinner/src/Spinner.tsx b/packages/ui/spinner/src/Spinner.tsx index 26ee76279..749a49f6c 100644 --- a/packages/ui/spinner/src/Spinner.tsx +++ b/packages/ui/spinner/src/Spinner.tsx @@ -9,14 +9,11 @@ const SPINNER_PREFIX = getPrefixCls('spinner') * TODO: What is Spinner */ export const Spinner = forwardRef( - ( - { prefixCls = SPINNER_PREFIX, role = 'spinner', className, children, size = 14, ...rest }, - ref - ) => { + ({ prefixCls = SPINNER_PREFIX, role = 'spinner', className, style, size = 14 }, ref) => { const cls = cx(prefixCls, className) return ( - + ( ) export interface SpinnerProps extends HiBaseHTMLProps<'i'> { - size?: string + /** + * 自定义尺寸 + */ + size?: number } if (__DEV__) { diff --git a/packages/ui/spinner/src/styles/spinner.scss b/packages/ui/spinner/src/styles/spinner.scss index 19306b24d..d420862c3 100644 --- a/packages/ui/spinner/src/styles/spinner.scss +++ b/packages/ui/spinner/src/styles/spinner.scss @@ -1,13 +1,13 @@ -@import '~@hi-ui/core-css/lib/index.scss'; +@import "~@hi-ui/core-css/lib/index.scss"; -$prefix: '#{$component-prefix}-spinner' !default; +$prefix: "#{$component-prefix}-spinner" !default; .#{$prefix} { width: 1em; height: 1em; display: inline-block; cursor: default; - color: use-color-mode('primary'); + color: use-color-mode("primary"); svg.#{$prefix}__icon { @keyframes #{$component-prefix}-rotate { @@ -16,8 +16,8 @@ $prefix: '#{$component-prefix}-spinner' !default; } } - width: 0.8rem; - height: 0.8rem; + width: 1em; + height: 1em; stroke: none; fill: currentColor; animation-name: #{$component-prefix}-rotate; diff --git a/packages/ui/spinner/stories/basic.stories.tsx b/packages/ui/spinner/stories/basic.stories.tsx index eb2df3fe9..5ccc6d3de 100644 --- a/packages/ui/spinner/stories/basic.stories.tsx +++ b/packages/ui/spinner/stories/basic.stories.tsx @@ -9,7 +9,7 @@ export const Basic = () => { <>

Basic

- +
) diff --git a/packages/ui/spinner/stories/index.stories.tsx b/packages/ui/spinner/stories/index.stories.tsx index 17fab6cda..7cd9cc648 100644 --- a/packages/ui/spinner/stories/index.stories.tsx +++ b/packages/ui/spinner/stories/index.stories.tsx @@ -1,8 +1,11 @@ import React from 'react' +import Spinner from '../src' export * from './basic.stories' +export * from './size.stories' export default { - title: 'Private(暂不对外)/Spinner', + title: 'FeedBack/Spinner', + component: Spinner, decorators: [(story: Function) =>
{story()}
], } diff --git a/packages/ui/spinner/stories/size.stories.tsx b/packages/ui/spinner/stories/size.stories.tsx new file mode 100644 index 000000000..ee7b8933b --- /dev/null +++ b/packages/ui/spinner/stories/size.stories.tsx @@ -0,0 +1,21 @@ +import React from 'react' +import Space from '@hi-ui/space' +import Spinner from '../src' + +/** + * @title 设置大小 + */ +export const Size = () => { + return ( + <> +

Size

+
+ + + + + +
+ + ) +}