|
| 1 | +import React from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import RBStack from 'react-bootstrap/Stack'; |
| 4 | +import {omit} from 'ramda'; |
| 5 | + |
| 6 | +/** |
| 7 | + * Stacks are shorthand helpers that build on top of existing flexbox |
| 8 | + * utilities to make component layout faster and easier than ever. |
| 9 | + */ |
| 10 | +const Stack = props => { |
| 11 | + const {children, loading_state, className, class_name, ...otherProps} = props; |
| 12 | + return ( |
| 13 | + <RBStack |
| 14 | + className={class_name || className} |
| 15 | + {...omit(['setProps'], otherProps)} |
| 16 | + data-dash-is-loading={ |
| 17 | + (loading_state && loading_state.is_loading) || undefined |
| 18 | + } |
| 19 | + > |
| 20 | + {children} |
| 21 | + </RBStack> |
| 22 | + ); |
| 23 | +}; |
| 24 | + |
| 25 | +Stack.defaultPropTypes = { |
| 26 | + direction: 'vertical' |
| 27 | +}; |
| 28 | + |
| 29 | +Stack.propTypes = { |
| 30 | + /** |
| 31 | + * The ID of this component, used to identify dash components |
| 32 | + * in callbacks. The ID needs to be unique across all of the |
| 33 | + * components in an app. |
| 34 | + */ |
| 35 | + id: PropTypes.string, |
| 36 | + |
| 37 | + /** |
| 38 | + * The children of this component |
| 39 | + */ |
| 40 | + children: PropTypes.node, |
| 41 | + |
| 42 | + /** |
| 43 | + * Defines CSS styles which will override styles previously set. |
| 44 | + */ |
| 45 | + style: PropTypes.object, |
| 46 | + |
| 47 | + /** |
| 48 | + * Often used with CSS to style elements with common properties. |
| 49 | + */ |
| 50 | + class_name: PropTypes.string, |
| 51 | + |
| 52 | + /** |
| 53 | + * **DEPRECATED** Use `class_name` instead. |
| 54 | + * |
| 55 | + * Often used with CSS to style elements with common properties. |
| 56 | + */ |
| 57 | + className: PropTypes.string, |
| 58 | + |
| 59 | + /** |
| 60 | + * A unique identifier for the component, used to improve |
| 61 | + * performance by React.js while rendering components |
| 62 | + * See https://reactjs.org/docs/lists-and-keys.html for more info |
| 63 | + */ |
| 64 | + key: PropTypes.string, |
| 65 | + |
| 66 | + /** |
| 67 | + * Object that holds the loading state object coming from dash-renderer |
| 68 | + */ |
| 69 | + loading_state: PropTypes.shape({ |
| 70 | + /** |
| 71 | + * Determines if the component is loading or not |
| 72 | + */ |
| 73 | + is_loading: PropTypes.bool, |
| 74 | + /** |
| 75 | + * Holds which property is loading |
| 76 | + */ |
| 77 | + prop_name: PropTypes.string, |
| 78 | + /** |
| 79 | + * Holds the name of the component that is loading |
| 80 | + */ |
| 81 | + component_name: PropTypes.string |
| 82 | + }), |
| 83 | + |
| 84 | + /** |
| 85 | + * Which direction to stack the objects in |
| 86 | + */ |
| 87 | + direction: PropTypes.oneOf(['vertical', 'horizontal']), |
| 88 | + |
| 89 | + /** |
| 90 | + * Set the spacing between each item (0 - 5) |
| 91 | + */ |
| 92 | + gap: PropTypes.number |
| 93 | +}; |
| 94 | + |
| 95 | +export default Stack; |
0 commit comments