{
+ if (delay > 0) {
+ setTimeout(() => {
+ setIsVisible(true);
+ }, delay);
+ }
+ }, []);
+
+ if (!isVisible) {
+ return null;
+ }
+
return (
= forwardRef((props: LoaderProps, ref: RefObject {
const wrapper = renderThemedComponent();
expect(wrapper).toMatchSnapshot();
});
+
+ test('with delay', () => {
+ const wrapper = renderThemedComponent();
+ expect(wrapper).toMatchSnapshot();
+ });
});
diff --git a/packages/main/src/components/Spinner/__snapshots__/Spinner.test.tsx.snap b/packages/main/src/components/Spinner/__snapshots__/Spinner.test.tsx.snap
index 3c010a975a8..c05baea20d1 100644
--- a/packages/main/src/components/Spinner/__snapshots__/Spinner.test.tsx.snap
+++ b/packages/main/src/components/Spinner/__snapshots__/Spinner.test.tsx.snap
@@ -59,3 +59,5 @@ exports[`Spinner with custom class name 1`] = `
Loading...
`;
+
+exports[`Spinner with delay 1`] = `null`;
diff --git a/packages/main/src/components/Spinner/demo.stories.tsx b/packages/main/src/components/Spinner/demo.stories.tsx
index 1d3b9c53151..761da6066e3 100644
--- a/packages/main/src/components/Spinner/demo.stories.tsx
+++ b/packages/main/src/components/Spinner/demo.stories.tsx
@@ -1,9 +1,22 @@
-import { select } from '@storybook/addon-knobs';
-import React from 'react';
+import { number, select } from '@storybook/addon-knobs';
import { Size } from '@ui5/webcomponents-react/lib/Size';
import { Spinner } from '@ui5/webcomponents-react/lib/Spinner';
+import React, { useMemo } from 'react';
-export const renderSpinner = () => ;
+let spinnerKey = 0;
+
+const Demo = (props) => {
+ const { delay } = props;
+
+ const spinner = useMemo(() => {
+ spinnerKey++;
+ return ;
+ }, [delay]);
+
+ return spinner;
+};
+
+export const renderSpinner = () => ;
renderSpinner.story = {
name: 'Default'
};
diff --git a/packages/main/src/components/Spinner/index.tsx b/packages/main/src/components/Spinner/index.tsx
index bcc196c9bd4..0fa6f6b3698 100644
--- a/packages/main/src/components/Spinner/index.tsx
+++ b/packages/main/src/components/Spinner/index.tsx
@@ -1,19 +1,24 @@
import { StyleClassHelper } from '@ui5/webcomponents-react-base/lib/StyleClassHelper';
-import React, { forwardRef, RefObject, FC } from 'react';
+import { Size } from '@ui5/webcomponents-react/lib/Size';
+import React, { FC, forwardRef, RefObject, useEffect, useState } from 'react';
import { createUseStyles } from 'react-jss';
import { CommonProps } from '../../interfaces/CommonProps';
-import { Size } from '@ui5/webcomponents-react/lib/Size';
import { styles } from './Spinner.jss';
export interface SpinnerProps extends CommonProps {
+ /*
+ * Delay in ms until the Spinner will be displayed
+ */
+ delay?: number;
size?: Size;
}
const useStyles = createUseStyles(styles, { name: 'Spinner' });
const Spinner: FC = forwardRef((props: SpinnerProps, ref: RefObject) => {
- const { className, size, tooltip, slot, style } = props;
+ const { className, size, tooltip, slot, style, delay } = props;
const classes = useStyles();
+ const [isVisible, setIsVisible] = useState(delay === 0);
const spinnerClasses = StyleClassHelper.of(classes.spinner);
if (className) {
@@ -22,6 +27,18 @@ const Spinner: FC = forwardRef((props: SpinnerProps, ref: RefObjec
spinnerClasses.put(classes[`spinner${size}`]);
+ useEffect(() => {
+ if (delay > 0) {
+ setTimeout(() => {
+ setIsVisible(true);
+ }, delay);
+ }
+ }, []);
+
+ if (!isVisible) {
+ return null;
+ }
+
return (
= forwardRef((props: SpinnerProps, ref: RefObjec
});
Spinner.defaultProps = {
+ delay: 0,
size: Size.Medium
};