Skip to content

Commit

Permalink
feat(Box): add propTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
WB01081293 committed Jan 5, 2024
1 parent 3c60de7 commit bb1fefb
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
58 changes: 57 additions & 1 deletion components/box/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as React from 'react';
import * as cx from 'classnames';
import * as PropTypes from 'prop-types';
import ConfigProvider from '../config-provider';
import { obj } from '../util';
import { BoxProps } from './types';
import createStyle, {
getMargin,
Expand All @@ -11,6 +13,8 @@ import createStyle, {
filterOuterStyle,
} from '../responsive-grid/create-style';

const { pickOthers } = obj;

type ChildElement = React.ReactElement<
BoxProps,
(string | React.JSXElementConstructor<BoxProps>) & { _typeMark: string }
Expand Down Expand Up @@ -104,6 +108,58 @@ const getInnerStyle: typeof getStyle = (style, styleProps) => {
* Box
*/
class Box extends React.Component<BoxProps> {
static propTypes = {
prefix: PropTypes.string,
style: PropTypes.object,
className: PropTypes.any,
/**
* 布局属性
*/
flex: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])),
PropTypes.number,
]),
/**
* 布局方向,默认为 column ,一个元素占据一整行
* @defaultValue column
*/
direction: PropTypes.oneOf(['row', 'column', 'row-reverse']),
/**
* 是否折行 支持IE11+
*/
wrap: PropTypes.bool,
/**
* 元素之间的间距 [bottom&top, right&left]
*/
spacing: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.number]),
/**
* 设置 margin [bottom&top, right&left]
*/
margin: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.number]),
/**
* 设置 padding [bottom&top, right&left]
*/
padding: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.number]),
/**
* 沿着主轴方向,子元素们的排布关系 (兼容性同 justify-content )
*/
justify: PropTypes.oneOf([
'flex-start',
'center',
'flex-end',
'space-between',
'space-around',
]),
/**
* 垂直主轴方向,子元素们的排布关系 (兼容性同 align-items )
*/
align: PropTypes.oneOf(['flex-start', 'center', 'flex-end', 'baseline', 'stretch']),
device: PropTypes.oneOf(['phone', 'tablet', 'desktop']),
/**
* 定制标签名, 例如section等
*/
component: PropTypes.string,
};
static defaultProps = {
prefix: 'next-',
direction: 'column',
Expand All @@ -127,7 +183,6 @@ class Box extends React.Component<BoxProps> {
children,
device,
component,
...others
} = this.props;

const styleProps: BoxProps = {
Expand All @@ -141,6 +196,7 @@ class Box extends React.Component<BoxProps> {
margin,
};
const View = component as React.ElementType;
const others = pickOthers(Object.keys(Box.propTypes), this.props);
const styleSheet = getStyle(style, styleProps);

const boxs = createChildren(children, {
Expand Down
4 changes: 4 additions & 0 deletions components/box/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as React from 'react';
import { CommonProps } from '../util';

/**
* Box
* @api
*/
export interface BoxProps extends React.HTMLAttributes<HTMLElement>, CommonProps {
/**
* 布局属性
Expand Down

0 comments on commit bb1fefb

Please sign in to comment.