Skip to content

Commit

Permalink
feat: add trbl, default:0
Browse files Browse the repository at this point in the history
  • Loading branch information
afeiship committed Oct 15, 2021
1 parent f572832 commit 88eaa45
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
], "@babel/react"],
"plugins": [
[ "@babel/plugin-proposal-decorators", { "legacy": true } ],
[ "@babel/plugin-proposal-class-properties", { "loose": true } ],
[ "@babel/plugin-proposal-class-properties", { "loose": false } ],
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-transform-parameters"
]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@
"access": "public",
"registry": "https://registry.npmjs.org"
}
}
}
2 changes: 1 addition & 1 deletion public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class App extends React.Component {
<ReactDemokit
className="p-3 app-container"
url="https://github.com/afeiship/react-absolute-rect">
<ReactAbsoluteRect>
<ReactAbsoluteRect trbl={20}>
<h1>ReactAbsoluteRect</h1>
<p>
<img src="http://himg.bdimg.com/sys/portrait/item/be10475f686d6c73db00.jpg" />
Expand Down
38 changes: 22 additions & 16 deletions src/components/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import objectAssign from 'object-assign';

const CLASS_NAME = 'react-absolute-rect';
const val = (value, defaults) => {
return typeof value === 'undefined' ? defaults : value;
};

export default class ReactAbsoluteRect extends Component {
static displayName = CLASS_NAME;
Expand All @@ -29,32 +31,36 @@ export default class ReactAbsoluteRect extends Component {
* Css style.left(number).
*/
left: PropTypes.number,
/**
* Css style for top, right, bottom, left.
*/
trbl: PropTypes.number,
/**
* If open css-behavior smooth.
*/
smooth: PropTypes.bool
};

static defaultProps = {
top: 0,
right: 0,
bottom: 0,
left: 0,
trbl: 0,
smooth: false
};

get trblStyle() {
const { top, right, bottom, left, trbl } = this.props;

return {
top: val(top, trbl),
right: val(right, trbl),
bottom: val(bottom, trbl),
left: val(left, trbl)
};
}

render() {
const {
className,
top,
right,
bottom,
left,
style,
smooth,
...props
} = this.props;
const _style = objectAssign({ top, right, bottom, left }, style);
const { className, top, right, bottom, left, style, smooth, ...props } =
this.props;
const _style = { ...this.trblStyle, ...style };

return (
<section
Expand Down

0 comments on commit 88eaa45

Please sign in to comment.