diff --git a/packages/website/docs/components/utilities/delay.mdx b/packages/website/docs/components/utilities/delay.mdx new file mode 100644 index 00000000000..8894ff9b335 --- /dev/null +++ b/packages/website/docs/components/utilities/delay.mdx @@ -0,0 +1,139 @@ +--- +slug: /utilities/delay +id: utilities_delay +--- + +# Delay + +## Delay render + +**EuiDelayRender** is a component for conditionally toggling the visibility of a child component. It will ensure that the child is hidden for at least 500ms (default). This allows delay UI rendering. That is helpful when you need to update aria live region(s) repeatedly. + + +```tsx interactive +import React, { useState, Fragment } from 'react'; + +import { + EuiDelayRender, + EuiFlexItem, + EuiCheckbox, + EuiFormRow, + EuiFieldNumber, + EuiLoadingSpinner, +} from '@elastic/eui'; + +export default () => { + const [minimumDelay, setDelay] = useState(3000); + const [render, setRender] = useState(false); + + const onChangeMinimumDelay = (event) => { + setDelay(parseInt(event.target.value, 10)); + }; + + const onChangeHide = (event) => { + setRender(event.target.checked); + }; + + const status = render ? 'showing' : 'hidden'; + const label = `Child (${status})`; + + return ( + + + + + + + + + + {render ? ( + + + + ) : ( + + )} + + + + ); +}; +``` + + +## Delay hide + +**EuiDelayHide** is a component for conditionally toggling the visibility of a child component. It will ensure that the child is visible for at least 1000ms (default). This avoids UI glitches that are common with loading spinners and other elements that are rendered conditionally and potentially for a short amount of time. + + +```tsx interactive +import React, { useState, Fragment } from 'react'; + +import { + EuiDelayHide, + EuiFlexItem, + EuiCheckbox, + EuiFormRow, + EuiFieldNumber, + EuiLoadingSpinner, +} from '@elastic/eui'; + +export default () => { + const [minimumDuration, setDuration] = useState(3000); + const [hide, setHide] = useState(false); + + const onChangeMinimumDuration = (event) => { + setDuration(parseInt(event.target.value, 10)); + }; + + const onChangeHide = (event) => { + setHide(event.target.checked); + }; + + return ( + + + + + + + + + + } + /> + + + + ); +}; +``` + + +## Props + +import delayRenderDocgen from '@elastic/eui-docgen/dist/components/delay_render'; +import delayHideDocgen from '@elastic/eui-docgen/dist/components/delay_hide'; + + +