@_nu/react-button
Advanced tools
+11
-0
@@ -6,2 +6,13 @@ # Change Log | ||
| # [1.3.0](https://github.com/nu-system/react-button/compare/@_nu/react-button@1.2.0...@_nu/react-button@1.3.0) (2020-07-01) | ||
| ### Features | ||
| * update button api ([9f27c40](https://github.com/nu-system/react-button/commit/9f27c403791ab2c9b49b3398e4b1b74a1f708b5e)) | ||
| # [1.2.0](https://github.com/nu-system/react-button/compare/@_nu/react-button@1.1.2...@_nu/react-button@1.2.0) (2020-06-30) | ||
@@ -8,0 +19,0 @@ |
+26
-14
@@ -7,4 +7,4 @@ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import React from "react"; | ||
| import PropTypes from "prop-types"; | ||
| /** | ||
@@ -15,5 +15,6 @@ * Button | ||
| var Index = React.forwardRef(function (_ref, ref) { | ||
| var NuButton = React.forwardRef(function NuButton(_ref, ref) { | ||
| var component = _ref.component, | ||
| otherProps = _objectWithoutProperties(_ref, ["component"]); | ||
| onBeforeReturn = _ref.onBeforeReturn, | ||
| otherProps = _objectWithoutProperties(_ref, ["component", "onBeforeReturn"]); | ||
@@ -27,23 +28,34 @@ var href = otherProps.href, | ||
| var ComponentTag = component ? component : href ? 'a' : 'button'; // only button got button type | ||
| var ComponentTag = component ? component : href ? "a" : "button"; // only button got button type | ||
| if (ComponentTag === 'button' && !type) { | ||
| otherProps.type = 'button'; | ||
| if (ComponentTag === "button" && !type) { | ||
| otherProps.type = "button"; | ||
| } // Got role attr when ComponentTag is not button | ||
| if (ComponentTag !== 'button' && !role) { | ||
| otherProps.role = 'button'; | ||
| if (ComponentTag !== "button" && !role) { | ||
| otherProps.role = "button"; | ||
| } // set the title of button | ||
| if (typeof children === 'string' && !title) { | ||
| if (typeof children === "string" && !title) { | ||
| otherProps.title = children; | ||
| } | ||
| } // on before component return | ||
| var renderProps = onBeforeReturn(otherProps); | ||
| return /*#__PURE__*/React.createElement(ComponentTag, _extends({ | ||
| ref: ref | ||
| }, otherProps)); | ||
| }, renderProps)); | ||
| }); | ||
| Index.propTypes = { | ||
| NuButton.defaultProps = { | ||
| /** on before component return */ | ||
| onBeforeReturn: function onBeforeReturn(props) { | ||
| return props; | ||
| } | ||
| }; | ||
| NuButton.propTypes = { | ||
| /** on before component return */ | ||
| onBeforeReturn: PropTypes.func, | ||
| /** href for tag a */ | ||
@@ -55,2 +67,2 @@ href: PropTypes.string, | ||
| }; | ||
| export default Index; | ||
| export default NuButton; |
+24
-12
@@ -24,5 +24,6 @@ "use strict"; | ||
| */ | ||
| var Index = _react.default.forwardRef(function (_ref, ref) { | ||
| var NuButton = _react.default.forwardRef(function NuButton(_ref, ref) { | ||
| var component = _ref.component, | ||
| otherProps = _objectWithoutProperties(_ref, ["component"]); | ||
| onBeforeReturn = _ref.onBeforeReturn, | ||
| otherProps = _objectWithoutProperties(_ref, ["component", "onBeforeReturn"]); | ||
@@ -36,24 +37,35 @@ var href = otherProps.href, | ||
| var ComponentTag = component ? component : href ? 'a' : 'button'; // only button got button type | ||
| var ComponentTag = component ? component : href ? "a" : "button"; // only button got button type | ||
| if (ComponentTag === 'button' && !type) { | ||
| otherProps.type = 'button'; | ||
| if (ComponentTag === "button" && !type) { | ||
| otherProps.type = "button"; | ||
| } // Got role attr when ComponentTag is not button | ||
| if (ComponentTag !== 'button' && !role) { | ||
| otherProps.role = 'button'; | ||
| if (ComponentTag !== "button" && !role) { | ||
| otherProps.role = "button"; | ||
| } // set the title of button | ||
| if (typeof children === 'string' && !title) { | ||
| if (typeof children === "string" && !title) { | ||
| otherProps.title = children; | ||
| } | ||
| } // on before component return | ||
| var renderProps = onBeforeReturn(otherProps); | ||
| return /*#__PURE__*/_react.default.createElement(ComponentTag, _extends({ | ||
| ref: ref | ||
| }, otherProps)); | ||
| }, renderProps)); | ||
| }); | ||
| Index.propTypes = { | ||
| NuButton.defaultProps = { | ||
| /** on before component return */ | ||
| onBeforeReturn: function onBeforeReturn(props) { | ||
| return props; | ||
| } | ||
| }; | ||
| NuButton.propTypes = { | ||
| /** on before component return */ | ||
| onBeforeReturn: _propTypes.default.func, | ||
| /** href for tag a */ | ||
@@ -65,3 +77,3 @@ href: _propTypes.default.string, | ||
| }; | ||
| var _default = Index; | ||
| var _default = NuButton; | ||
| exports.default = _default; |
+2
-2
| { | ||
| "name": "@_nu/react-button", | ||
| "version": "1.2.0", | ||
| "version": "1.3.0", | ||
| "description": "No UI dependency Button of react", | ||
@@ -51,3 +51,3 @@ "main": "lib/index.js", | ||
| }, | ||
| "gitHead": "0ef2f0df3d2c45da3d8568c72017de1bcf233145" | ||
| "gitHead": "f054d4f623fe0e2fa5f01950261b3b03094119b6" | ||
| } |
+21
-17
@@ -42,10 +42,11 @@ # Button | ||
| import './style.css'; // custome style | ||
| export default from "@_nu/react-button"; | ||
| ``` | ||
| import NuButton from "@_nu/react-button"; // import | ||
| ```JSX | ||
| /* @components/Button/index.d.ts */ | ||
| import { ComponentProps } from "@_nu/react-button"; | ||
| declare const _default: (props?: ComponentProps) => JSX.Element; | ||
| export default _default; | ||
| // Add default class | ||
| NuButton.defaultProps.onBeforeReturn = ({className='', props})=> ({ | ||
| className:`nu_btn ${className}` | ||
| ...props | ||
| }); | ||
| export default NuButton; | ||
| ``` | ||
@@ -56,5 +57,5 @@ | ||
| ```JSX | ||
| <Button className="nu_btn _fill _primay">Button</Button> | ||
| <Button className="nu_btn _fill _primay" href="/nu-button">Link Button</Button> | ||
| <Button component="strong" className="nu_btn _fill _primay">Button</Button> | ||
| <Button className="_fill _primay">Button</Button> | ||
| <Button className="_fill _primay" href="/nu-button">Link Button</Button> | ||
| <Button component="strong" className="_fill _primay">Button</Button> | ||
| ``` | ||
@@ -70,8 +71,8 @@ | ||
| ```JSX | ||
| <Button className="nu_btn _fill">hello</Button> | ||
| <Button className="nu_btn _fill" component="strong">hello</Button> | ||
| <Button className="nu_btn _fill"><strong>hello</strong></Button> | ||
| <Button className="nu_btn _fill" disabled>hello</Button> | ||
| <Button className="nu_btn _fill _primary">hello</Button> | ||
| <Button className="nu_btn _fill _primary" href="." title="hello">hello</Button> | ||
| <Button className="_fill">hello</Button> | ||
| <Button className="_fill" component="strong">hello</Button> | ||
| <Button className="_fill"><strong>hello</strong></Button> | ||
| <Button className="_fill" disabled>hello</Button> | ||
| <Button className="_fill _primary">hello</Button> | ||
| <Button className="_fill _primary" href="." title="hello">hello</Button> | ||
| ``` | ||
@@ -86,3 +87,2 @@ | ||
| <button class="nu_btn _fill" type="button" disabled title="hello">hello</button> | ||
| <button class="nu_btn _primary _fill" type="button" title="hello">hello</button> | ||
| <button class="nu_btn _fill _primary" type="button" title="hello">hello</button> | ||
@@ -92,2 +92,6 @@ <a class="nu_btn _fill _primary" role="button" href="." title="hello">hello</a> | ||
| | defaultProps | type | Default | Function | | ||
| | :------------- | :------: | :---------------: | :---------------------------: | | ||
| | onBeforeReturn | function | `(props)=> props` | custom props on before return | | ||
| ## Custom style? | ||
@@ -94,0 +98,0 @@ |
13651
8.85%125
19.05%107
3.88%