utils.js 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import classNames from '../_util/classNames';
  3. export const flexWrapValues = ['wrap', 'nowrap', 'wrap-reverse'];
  4. export const justifyContentValues = ['flex-start', 'flex-end', 'start', 'end', 'center', 'space-between', 'space-around', 'space-evenly', 'stretch', 'normal', 'left', 'right'];
  5. export const alignItemsValues = ['center', 'start', 'end', 'flex-start', 'flex-end', 'self-start', 'self-end', 'baseline', 'normal', 'stretch'];
  6. const genClsWrap = (prefixCls, props) => {
  7. const wrapCls = {};
  8. flexWrapValues.forEach(cssKey => {
  9. wrapCls[`${prefixCls}-wrap-${cssKey}`] = props.wrap === cssKey;
  10. });
  11. return wrapCls;
  12. };
  13. const genClsAlign = (prefixCls, props) => {
  14. const alignCls = {};
  15. alignItemsValues.forEach(cssKey => {
  16. alignCls[`${prefixCls}-align-${cssKey}`] = props.align === cssKey;
  17. });
  18. alignCls[`${prefixCls}-align-stretch`] = !props.align && !!props.vertical;
  19. return alignCls;
  20. };
  21. const genClsJustify = (prefixCls, props) => {
  22. const justifyCls = {};
  23. justifyContentValues.forEach(cssKey => {
  24. justifyCls[`${prefixCls}-justify-${cssKey}`] = props.justify === cssKey;
  25. });
  26. return justifyCls;
  27. };
  28. function createFlexClassNames(prefixCls, props) {
  29. return classNames(_extends(_extends(_extends({}, genClsWrap(prefixCls, props)), genClsAlign(prefixCls, props)), genClsJustify(prefixCls, props)));
  30. }
  31. export default createFlexClassNames;