UNPKG

1.37 kBJavaScriptView Raw
1import classNames from 'classnames';
2export const flexWrapValues = ['wrap', 'nowrap', 'wrap-reverse'];
3export const justifyContentValues = ['flex-start', 'flex-end', 'start', 'end', 'center', 'space-between', 'space-around', 'space-evenly', 'stretch', 'normal', 'left', 'right'];
4export const alignItemsValues = ['center', 'start', 'end', 'flex-start', 'flex-end', 'self-start', 'self-end', 'baseline', 'normal', 'stretch'];
5const genClsWrap = (prefixCls, props) => {
6 const wrap = props.wrap === true ? 'wrap' : props.wrap;
7 return {
8 [`${prefixCls}-wrap-${wrap}`]: wrap && flexWrapValues.includes(wrap)
9 };
10};
11const genClsAlign = (prefixCls, props) => {
12 const alignCls = {};
13 alignItemsValues.forEach(cssKey => {
14 alignCls[`${prefixCls}-align-${cssKey}`] = props.align === cssKey;
15 });
16 alignCls[`${prefixCls}-align-stretch`] = !props.align && !!props.vertical;
17 return alignCls;
18};
19const genClsJustify = (prefixCls, props) => {
20 const justifyCls = {};
21 justifyContentValues.forEach(cssKey => {
22 justifyCls[`${prefixCls}-justify-${cssKey}`] = props.justify === cssKey;
23 });
24 return justifyCls;
25};
26function createFlexClassNames(prefixCls, props) {
27 return classNames(Object.assign(Object.assign(Object.assign({}, genClsWrap(prefixCls, props)), genClsAlign(prefixCls, props)), genClsJustify(prefixCls, props)));
28}
29export default createFlexClassNames;
\No newline at end of file