Spaces:
Sleeping
Sleeping
File size: 7,404 Bytes
56fda74 |
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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _typeof from "@babel/runtime/helpers/esm/typeof";
import _extends from "@babel/runtime/helpers/esm/extends";
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import deepmerge from '@mui/utils/deepmerge';
import generateUtilityClass from '@mui/utils/generateUtilityClass';
import composeClasses from '@mui/utils/composeClasses';
import systemStyled from '../styled';
import useThemePropsSystem from '../useThemeProps';
import { extendSxProp } from '../styleFunctionSx';
import createTheme from '../createTheme';
import { handleBreakpoints, mergeBreakpointsInOrder, resolveBreakpointValues } from '../breakpoints';
import { createUnarySpacing, getValue } from '../spacing';
import { jsx as _jsx } from "react/jsx-runtime";
var defaultTheme = createTheme();
// widening Theme to any so that the consumer can own the theme structure.
var defaultCreateStyledComponent = systemStyled('div', {
name: 'MuiStack',
slot: 'Root',
overridesResolver: function overridesResolver(props, styles) {
return styles.root;
}
});
function useThemePropsDefault(props) {
return useThemePropsSystem({
props: props,
name: 'MuiStack',
defaultTheme: defaultTheme
});
}
/**
* Return an array with the separator React element interspersed between
* each React node of the input children.
*
* > joinChildren([1,2,3], 0)
* [1,0,2,0,3]
*/
function joinChildren(children, separator) {
var childrenArray = React.Children.toArray(children).filter(Boolean);
return childrenArray.reduce(function (output, child, index) {
output.push(child);
if (index < childrenArray.length - 1) {
output.push( /*#__PURE__*/React.cloneElement(separator, {
key: "separator-".concat(index)
}));
}
return output;
}, []);
}
var getSideFromDirection = function getSideFromDirection(direction) {
return {
row: 'Left',
'row-reverse': 'Right',
column: 'Top',
'column-reverse': 'Bottom'
}[direction];
};
export var style = function style(_ref) {
var ownerState = _ref.ownerState,
theme = _ref.theme;
var styles = _extends({
display: 'flex',
flexDirection: 'column'
}, handleBreakpoints({
theme: theme
}, resolveBreakpointValues({
values: ownerState.direction,
breakpoints: theme.breakpoints.values
}), function (propValue) {
return {
flexDirection: propValue
};
}));
if (ownerState.spacing) {
var transformer = createUnarySpacing(theme);
var base = Object.keys(theme.breakpoints.values).reduce(function (acc, breakpoint) {
if (_typeof(ownerState.spacing) === 'object' && ownerState.spacing[breakpoint] != null || _typeof(ownerState.direction) === 'object' && ownerState.direction[breakpoint] != null) {
acc[breakpoint] = true;
}
return acc;
}, {});
var directionValues = resolveBreakpointValues({
values: ownerState.direction,
base: base
});
var spacingValues = resolveBreakpointValues({
values: ownerState.spacing,
base: base
});
if (_typeof(directionValues) === 'object') {
Object.keys(directionValues).forEach(function (breakpoint, index, breakpoints) {
var directionValue = directionValues[breakpoint];
if (!directionValue) {
var previousDirectionValue = index > 0 ? directionValues[breakpoints[index - 1]] : 'column';
directionValues[breakpoint] = previousDirectionValue;
}
});
}
var styleFromPropValue = function styleFromPropValue(propValue, breakpoint) {
if (ownerState.useFlexGap) {
return {
gap: getValue(transformer, propValue)
};
}
return {
// The useFlexGap={false} implement relies on each child to give up control of the margin.
// We need to reset the margin to avoid double spacing.
'& > :not(style):not(style)': {
margin: 0
},
'& > :not(style) ~ :not(style)': _defineProperty({}, "margin".concat(getSideFromDirection(breakpoint ? directionValues[breakpoint] : ownerState.direction)), getValue(transformer, propValue))
};
};
styles = deepmerge(styles, handleBreakpoints({
theme: theme
}, spacingValues, styleFromPropValue));
}
styles = mergeBreakpointsInOrder(theme.breakpoints, styles);
return styles;
};
export default function createStack() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var _options$createStyled = options.createStyledComponent,
createStyledComponent = _options$createStyled === void 0 ? defaultCreateStyledComponent : _options$createStyled,
_options$useThemeProp = options.useThemeProps,
useThemeProps = _options$useThemeProp === void 0 ? useThemePropsDefault : _options$useThemeProp,
_options$componentNam = options.componentName,
componentName = _options$componentNam === void 0 ? 'MuiStack' : _options$componentNam;
var useUtilityClasses = function useUtilityClasses() {
var slots = {
root: ['root']
};
return composeClasses(slots, function (slot) {
return generateUtilityClass(componentName, slot);
}, {});
};
var StackRoot = createStyledComponent(style);
var Stack = /*#__PURE__*/React.forwardRef(function Grid(inProps, ref) {
var themeProps = useThemeProps(inProps);
var props = extendSxProp(themeProps); // `color` type conflicts with html color attribute.
var _props$component = props.component,
component = _props$component === void 0 ? 'div' : _props$component,
_props$direction = props.direction,
direction = _props$direction === void 0 ? 'column' : _props$direction,
_props$spacing = props.spacing,
spacing = _props$spacing === void 0 ? 0 : _props$spacing,
divider = props.divider,
children = props.children,
className = props.className,
_props$useFlexGap = props.useFlexGap,
useFlexGap = _props$useFlexGap === void 0 ? false : _props$useFlexGap,
other = _objectWithoutProperties(props, ["component", "direction", "spacing", "divider", "children", "className", "useFlexGap"]);
var ownerState = {
direction: direction,
spacing: spacing,
useFlexGap: useFlexGap
};
var classes = useUtilityClasses();
return /*#__PURE__*/_jsx(StackRoot, _extends({
as: component,
ownerState: ownerState,
ref: ref,
className: clsx(classes.root, className)
}, other, {
children: divider ? joinChildren(children, divider) : children
}));
});
process.env.NODE_ENV !== "production" ? Stack.propTypes /* remove-proptypes */ = {
children: PropTypes.node,
direction: PropTypes.oneOfType([PropTypes.oneOf(['column-reverse', 'column', 'row-reverse', 'row']), PropTypes.arrayOf(PropTypes.oneOf(['column-reverse', 'column', 'row-reverse', 'row'])), PropTypes.object]),
divider: PropTypes.node,
spacing: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])), PropTypes.number, PropTypes.object, PropTypes.string]),
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
} : void 0;
return Stack;
} |