Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | 17x 17x 17x 17x 19x 19x 19x 19x 17x 17x 17x 17x 17x | import _ from 'lodash'; import React from 'react'; import PropTypes from 'prop-types'; import { lucidClassNames } from '../../util/style-helpers'; import { getFirst, rejectTypes } from '../../util/component-types'; import OverlayWrapper, { OverlayWrapperMessage, IOverlayWrapperProps, } from '../OverlayWrapper/OverlayWrapper'; import LoadingMessage from '../LoadingMessage/LoadingMessage'; const cx = lucidClassNames.bind('&-LoadingIndicator'); const { bool, node, oneOf, string } = PropTypes; export interface ILoadingIndicatorProps extends IOverlayWrapperProps { /** Set this to `false` if you don't want the semi-transparent overlay over the wrapped content */ hasOverlay: boolean; /** Controls the visibility of the `LoadingMessage` and overlay. */ isLoading: boolean; /** Positions the loading message near the top of the container. By default, * the loading message is vertically aligned to the middle of the container. */ anchorMessage: boolean; /** By default, the OverlayMessage is vertically aligned to the middle of the * OverlayWrapper, and the `OverlayWrapper` is the height of the entire content. * Set this to true to position the `OverlayMessage` near the center of the * `OverlayWrapper`, and fix the `OverlayWrapper` to the screen height and width. */ fixedMessage: boolean; /** Style variations for the overlay behind the loading indicator. */ overlayKind: 'light' | 'dark'; } const defaultProps = { hasOverlay: true, isLoading: false, anchorMessage: false, fixedMessage: false, overlayKind: 'light' as const, }; export const LoadingIndicator = ( props: ILoadingIndicatorProps ): React.ReactElement => { const { children, className, isLoading, anchorMessage, fixedMessage, ...passThroughs } = props; const messageElement = getFirst( props, LoadingIndicator.LoadingMessage, <LoadingMessage /> ); const otherChildren = rejectTypes(children, LoadingIndicator.LoadingMessage); return ( <OverlayWrapper {..._.omit(passThroughs, ['Message', 'initialState', 'callbackId'])} className={cx('&', className)} isVisible={isLoading} anchorMessage={anchorMessage} fixedMessage={fixedMessage} > {otherChildren} <OverlayWrapperMessage>{messageElement}</OverlayWrapperMessage> </OverlayWrapper> ); }; LoadingIndicator.LoadingMessage = LoadingMessage; LoadingIndicator.displayName = 'LoadingIndicator'; LoadingIndicator.peek = { description: `A loading indicator wrapper with optional overlay.`, notes: { overview: ` A visual indication that a section or component of the interface is loading. `, intendedUse: ` - Use in places where data takes time to load. LoadingIndicator lets users know that the information they expect to see will appear shortly. - Use the light overlay, \`overlayKind: "light"\` `, technicalRecommendations: ` If a page is displaying a lot of data coming from multiple sources, try as best as possible to load the individual parts of the UI, so as not to disrupt the user and block them from interacting with the entire page until all data is loaded. `, }, categories: ['Loading Indicator'], madeFrom: ['OverlayWrapper', 'LoadingMessage'], }; LoadingIndicator.propTypes = { /** Class names that are appended to the defaults. */ className: string, /** Any valid React children. */ children: node, /** Set this to \`false\` if you don't want the semi-transparent overlay over the wrapped content */ hasOverlay: bool, /** Controls the visibility of the \`LoadingMessage\` and overlay. */ isLoading: bool, /** Positions the loading message near the top of the container. By default, the loading message is vertically aligned to the middle of the container. */ anchorMessage: bool, /** By default, the OverlayMessage is vertically aligned to the middle of the \`OverlayWrapper\`, and the \`OverlayWrapper\` is the height of the entire content. Set this to true to position the \`OverlayMessage\` near the center of the \`OverlayWrapper\`, and fix the \`OverlayWrapper\` to the screen height and width. */ fixedMessage: bool, /** Style variations for the overlay behind the loading indicator. */ overlayKind: oneOf(['light', 'dark']), }; LoadingIndicator.defaultProps = defaultProps; export default LoadingIndicator; |