office-ui-fabric-react
Version:
Reusable React components for building experiences for Office 365.
44 lines • 1.67 kB
JavaScript
import * as tslib_1 from "tslib";
/** @jsx withSlots */
import * as React from 'react';
import { withSlots, createComponent, getSlots } from '../../Foundation';
import StackItem from './StackItem/StackItem';
import { styles } from './Stack.styles';
import { getNativeProps, htmlElementProperties } from '../../Utilities';
var StackItemType = withSlots(StackItem, null).type;
var view = function (props) {
var _a = props.as, RootType = _a === void 0 ? 'div' : _a, disableShrink = props.disableShrink, wrap = props.wrap, rest = tslib_1.__rest(props, ["as", "disableShrink", "wrap"]);
var stackChildren = React.Children.map(props.children, function (child, index) {
if (!child) {
return null;
}
if (child.type === StackItemType) {
var defaultItemProps = {
shrink: !disableShrink
};
return React.cloneElement(child, tslib_1.__assign({}, defaultItemProps, child.props));
}
return child;
});
var nativeProps = getNativeProps(rest, htmlElementProperties);
var Slots = getSlots(props, {
root: RootType,
inner: 'div'
});
if (wrap) {
return (withSlots(Slots.root, tslib_1.__assign({}, nativeProps),
withSlots(Slots.inner, null, stackChildren)));
}
return withSlots(Slots.root, tslib_1.__assign({}, nativeProps), stackChildren);
};
var StackStatics = {
Item: StackItem
};
export var Stack = createComponent({
displayName: 'Stack',
styles: styles,
view: view,
statics: StackStatics
});
export default Stack;
//# sourceMappingURL=Stack.js.map