-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathCol.tsx
50 lines (46 loc) · 1.18 KB
/
Col.tsx
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
import React, { useContext } from 'react';
import classNames from 'classnames';
import { isNumber } from 'lodash';
import { usePrefixCls } from '@gio-design/utils';
import { ColProps } from './interface';
import { RowContext } from '../row';
const Col = ({
component: Component = 'div',
prefixCls: customizePrefixCls,
children,
className,
style,
order,
offset,
span = 1,
}: React.PropsWithChildren<ColProps>) => {
const prefixCls = usePrefixCls('col', customizePrefixCls);
const { gutters } = useContext(RowContext);
const mergedStyle: React.CSSProperties = {
...(gutters[0] > 0
? {
paddingLeft: gutters[0] / 2,
paddingRight: gutters[0] / 2,
}
: {}),
...(gutters[1] > 0
? {
paddingTop: gutters[1] / 2,
paddingBottom: gutters[1] / 2,
}
: {}),
...style,
};
return (
<Component
className={classNames(prefixCls, className, `${prefixCls}-span-${span}`, {
[`${prefixCls}-order-${order}`]: isNumber(order),
[`${prefixCls}-offset-${offset}`]: isNumber(offset),
})}
style={mergedStyle}
>
{children}
</Component>
);
};
export default Col;