office-ui-fabric-react
Version:
Reusable React components for building experiences for Office 365.
142 lines • 6.74 kB
JavaScript
import * as tslib_1 from "tslib";
import { parseGap, parsePadding } from './StackUtils';
import { getGlobalClassNames } from '../../Styling';
var nameMap = {
start: 'flex-start',
end: 'flex-end'
};
var GlobalClassNames = {
root: 'ms-Stack',
inner: 'ms-Stack-inner'
};
export var styles = function (props, theme, tokens) {
var verticalFill = props.verticalFill, maxWidth = props.maxWidth, maxHeight = props.maxHeight, horizontal = props.horizontal, reversed = props.reversed, gap = props.gap, grow = props.grow, wrap = props.wrap, padding = props.padding, horizontalAlign = props.horizontalAlign, verticalAlign = props.verticalAlign, disableShrink = props.disableShrink, className = props.className;
var classNames = getGlobalClassNames(GlobalClassNames, theme);
var childrenGap = tokens && tokens.childrenGap ? tokens.childrenGap : gap;
var _a = parseGap(childrenGap, theme), rowGap = _a.rowGap, columnGap = _a.columnGap;
var horizontalMargin = "" + -0.5 * columnGap.value + columnGap.unit;
var verticalMargin = "" + -0.5 * rowGap.value + rowGap.unit;
// styles to be applied to all direct children regardless of wrap or direction
var childStyles = {
textOverflow: 'ellipsis'
};
// selectors to be applied regardless of wrap or direction
var commonSelectors = {
// flexShrink styles are applied by the StackItem
'> *:not(.ms-StackItem)': {
flexShrink: disableShrink ? 0 : 1
}
};
if (wrap) {
return {
root: [
classNames.root,
{
flexWrap: 'wrap',
maxWidth: maxWidth,
maxHeight: maxHeight,
width: 'auto',
overflow: 'visible',
height: '100%'
},
horizontalAlign && (_b = {},
_b[horizontal ? 'justifyContent' : 'alignItems'] = nameMap[horizontalAlign] || horizontalAlign,
_b),
verticalAlign && (_c = {},
_c[horizontal ? 'alignItems' : 'justifyContent'] = nameMap[verticalAlign] || verticalAlign,
_c),
className,
{
// not allowed to be overridden by className
// since this is necessary in order to prevent collapsing margins
display: 'flex'
},
horizontal && {
height: verticalFill ? '100%' : 'auto'
}
],
inner: [
classNames.inner,
{
display: 'flex',
flexWrap: 'wrap',
marginLeft: horizontalMargin,
marginRight: horizontalMargin,
marginTop: verticalMargin,
marginBottom: verticalMargin,
overflow: 'visible',
boxSizing: 'border-box',
padding: parsePadding(padding, theme),
// avoid unnecessary calc() calls if horizontal gap is 0
width: columnGap.value === 0 ? '100%' : "calc(100% + " + columnGap.value + columnGap.unit + ")",
maxWidth: '100vw',
selectors: tslib_1.__assign({ '> *': tslib_1.__assign({ margin: "" + 0.5 * rowGap.value + rowGap.unit + " " + 0.5 * columnGap.value + columnGap.unit }, childStyles) }, commonSelectors)
},
horizontalAlign && (_d = {},
_d[horizontal ? 'justifyContent' : 'alignItems'] = nameMap[horizontalAlign] || horizontalAlign,
_d),
verticalAlign && (_e = {},
_e[horizontal ? 'alignItems' : 'justifyContent'] = nameMap[verticalAlign] || verticalAlign,
_e),
horizontal && {
flexDirection: reversed ? 'row-reverse' : 'row',
// avoid unnecessary calc() calls if vertical gap is 0
height: rowGap.value === 0 ? '100%' : "calc(100% + " + rowGap.value + rowGap.unit + ")",
selectors: {
'> *': {
maxWidth: columnGap.value === 0 ? '100%' : "calc(100% - " + columnGap.value + columnGap.unit + ")"
}
}
},
!horizontal && {
flexDirection: reversed ? 'column-reverse' : 'column',
height: "calc(100% + " + rowGap.value + rowGap.unit + ")",
selectors: {
'> *': {
maxHeight: rowGap.value === 0 ? '100%' : "calc(100% - " + rowGap.value + rowGap.unit + ")"
}
}
}
]
};
}
return {
root: [
classNames.root,
{
display: 'flex',
flexDirection: horizontal ? (reversed ? 'row-reverse' : 'row') : reversed ? 'column-reverse' : 'column',
flexWrap: 'nowrap',
width: 'auto',
height: verticalFill ? '100%' : 'auto',
maxWidth: maxWidth,
maxHeight: maxHeight,
padding: parsePadding(padding, theme),
boxSizing: 'border-box',
selectors: tslib_1.__assign((_f = { '> *': childStyles }, _f[reversed ? '> *:not(:last-child)' : '> *:not(:first-child)'] = [
horizontal && {
marginLeft: "" + columnGap.value + columnGap.unit
},
!horizontal && {
marginTop: "" + rowGap.value + rowGap.unit
}
], _f), commonSelectors)
},
grow && {
flexGrow: grow === true ? 1 : grow,
overflow: 'hidden'
},
horizontalAlign && (_g = {},
_g[horizontal ? 'justifyContent' : 'alignItems'] = nameMap[horizontalAlign] || horizontalAlign,
_g),
verticalAlign && (_h = {},
_h[horizontal ? 'alignItems' : 'justifyContent'] = nameMap[verticalAlign] || verticalAlign,
_h),
className
]
// TODO: this cast may be hiding some potential issues with styling and name
// lookups and should be removed
};
var _b, _c, _d, _e, _f, _g, _h;
};
//# sourceMappingURL=Stack.styles.js.map