@_nu/react-button
Advanced tools
+63
-42
@@ -1,8 +0,10 @@ | ||
| var _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; }; | ||
| var _this = this, | ||
| _jsxFileName = "/Users/ziven27/Pro/@_nu/react-button/src/index.js"; | ||
| function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
| 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); } | ||
| function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
| import React, { Fragment } from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| /** | ||
@@ -14,6 +16,12 @@ * [get new classNames] | ||
| */ | ||
| export var getClassNames = function getClassNames() { | ||
| var classDefault = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
| var classIn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
| export var getClassNames = function getClassNames(classDefault, classIn) { | ||
| if (classDefault === void 0) { | ||
| classDefault = []; | ||
| } | ||
| if (classIn === void 0) { | ||
| classIn = []; | ||
| } | ||
| var arrClassDefault = classDefault && classDefault.split ? classDefault.split(' ') : classDefault || []; | ||
@@ -28,4 +36,5 @@ var arrClassIn = classIn && classIn.split ? classIn.split(' ') : classIn || []; | ||
| return; | ||
| } | ||
| // find last in arrClassVariant | ||
| } // find last in arrClassVariant | ||
| if (arrClassVariant.includes(item)) { | ||
@@ -37,24 +46,23 @@ variantClass = item; | ||
| } | ||
| }); | ||
| // push the variant class back | ||
| }); // push the variant class back | ||
| !!variantClass && arrClassNew.push(variantClass); | ||
| return arrClassNew.join(' '); | ||
| }; | ||
| var Button = function Button(_ref) { | ||
| var Button = React.forwardRef(function (_ref, ref) { | ||
| var _ref$className = _ref.className, | ||
| className = _ref$className === undefined ? '' : _ref$className, | ||
| className = _ref$className === void 0 ? '' : _ref$className, | ||
| _ref$classNameDefault = _ref.classNameDefault, | ||
| classNameDefault = _ref$classNameDefault === undefined ? 'nu_btn _fill' : _ref$classNameDefault, | ||
| classNameDefault = _ref$classNameDefault === void 0 ? 'nu_btn _fill' : _ref$classNameDefault, | ||
| _ref$children = _ref.children, | ||
| children = _ref$children === undefined ? null : _ref$children, | ||
| children = _ref$children === void 0 ? null : _ref$children, | ||
| _ref$Component = _ref.Component, | ||
| Component = _ref$Component === undefined ? null : _ref$Component, | ||
| Component = _ref$Component === void 0 ? null : _ref$Component, | ||
| _ref$ComponentSub = _ref.ComponentSub, | ||
| ComponentSub = _ref$ComponentSub === undefined ? 'span' : _ref$ComponentSub, | ||
| ComponentSub = _ref$ComponentSub === void 0 ? 'span' : _ref$ComponentSub, | ||
| _ref$href = _ref.href, | ||
| href = _ref$href === undefined ? null : _ref$href, | ||
| href = _ref$href === void 0 ? null : _ref$href, | ||
| _ref$disabled = _ref.disabled, | ||
| disabled = _ref$disabled === undefined ? false : _ref$disabled, | ||
| otherProps = _objectWithoutProperties(_ref, ['className', 'classNameDefault', 'children', 'Component', 'ComponentSub', 'href', 'disabled']); | ||
| disabled = _ref$disabled === void 0 ? false : _ref$disabled, | ||
| otherProps = _objectWithoutPropertiesLoose(_ref, ["className", "classNameDefault", "children", "Component", "ComponentSub", "href", "disabled"]); | ||
@@ -64,30 +72,36 @@ // if exist Component use component | ||
| var ComponentTag = Component ? Component : !!href ? 'a' : 'button'; | ||
| var classNames = getClassNames(classNameDefault, className); | ||
| // only button got button type | ||
| var classNames = getClassNames(classNameDefault, className); // only button got button type | ||
| if (ComponentTag === 'button' && !otherProps.type) { | ||
| otherProps.type = 'button'; | ||
| } | ||
| // set the title of button | ||
| } // set the title of button | ||
| if (!otherProps.title && typeof children === 'string') { | ||
| otherProps.title = children; | ||
| } | ||
| } // subItem | ||
| // subItem | ||
| var ComponentSubTag = ComponentSub && typeof children === 'string' ? ComponentSub : Fragment; | ||
| return React.createElement( | ||
| ComponentTag, | ||
| _extends({ | ||
| href: href, | ||
| disabled: disabled, | ||
| className: classNames | ||
| }, otherProps), | ||
| React.createElement( | ||
| ComponentSubTag, | ||
| null, | ||
| children | ||
| ) | ||
| ); | ||
| }; | ||
| return /*#__PURE__*/React.createElement(ComponentTag, _extends({ | ||
| ref: ref, | ||
| href: href, | ||
| disabled: disabled, | ||
| className: classNames | ||
| }, otherProps, { | ||
| __self: _this, | ||
| __source: { | ||
| fileName: _jsxFileName, | ||
| lineNumber: 70, | ||
| columnNumber: 7 | ||
| } | ||
| }), /*#__PURE__*/React.createElement(ComponentSubTag, { | ||
| __self: _this, | ||
| __source: { | ||
| fileName: _jsxFileName, | ||
| lineNumber: 77, | ||
| columnNumber: 9 | ||
| } | ||
| }, children)); | ||
| }); | ||
| Button.propTypes = process.env.NODE_ENV !== "production" ? { | ||
@@ -98,2 +112,3 @@ /** | ||
| title: PropTypes.string, | ||
| /** | ||
@@ -103,2 +118,3 @@ * children of component | ||
| children: PropTypes.node, | ||
| /** | ||
@@ -108,2 +124,3 @@ * just className | ||
| className: PropTypes.oneOfType([PropTypes.string, PropTypes.array]), | ||
| /** | ||
@@ -113,2 +130,3 @@ * just className base | ||
| classNameDefault: PropTypes.oneOfType([PropTypes.string, PropTypes.array]), | ||
| /** | ||
@@ -118,2 +136,3 @@ * href for tag a | ||
| href: PropTypes.string, | ||
| /** | ||
@@ -123,2 +142,3 @@ * shell of button | ||
| Component: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.object]), | ||
| /** | ||
@@ -128,2 +148,3 @@ * subComponent of button | ||
| ComponentSub: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.object]), | ||
| /** | ||
@@ -130,0 +151,0 @@ * status of disabled |
+81
-55
@@ -1,20 +0,23 @@ | ||
| 'use strict'; | ||
| "use strict"; | ||
| exports.__esModule = true; | ||
| exports.getClassNames = undefined; | ||
| exports["default"] = exports.getClassNames = void 0; | ||
| var _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; }; | ||
| var _react = _interopRequireWildcard(require("react")); | ||
| var _react = require('react'); | ||
| var _propTypes = _interopRequireDefault(require("prop-types")); | ||
| var _react2 = _interopRequireDefault(_react); | ||
| var _this = void 0, | ||
| _jsxFileName = "/Users/ziven27/Pro/@_nu/react-button/src/index.js"; | ||
| var _propTypes = require('prop-types'); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
| var _propTypes2 = _interopRequireDefault(_propTypes); | ||
| function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
| function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
| 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); } | ||
| function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
| /** | ||
@@ -26,6 +29,11 @@ * [get new classNames] | ||
| */ | ||
| var getClassNames = exports.getClassNames = function getClassNames() { | ||
| var classDefault = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
| var classIn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
| var getClassNames = function getClassNames(classDefault, classIn) { | ||
| if (classDefault === void 0) { | ||
| classDefault = []; | ||
| } | ||
| if (classIn === void 0) { | ||
| classIn = []; | ||
| } | ||
| var arrClassDefault = classDefault && classDefault.split ? classDefault.split(' ') : classDefault || []; | ||
@@ -40,4 +48,5 @@ var arrClassIn = classIn && classIn.split ? classIn.split(' ') : classIn || []; | ||
| return; | ||
| } | ||
| // find last in arrClassVariant | ||
| } // find last in arrClassVariant | ||
| if (arrClassVariant.includes(item)) { | ||
@@ -49,4 +58,4 @@ variantClass = item; | ||
| } | ||
| }); | ||
| // push the variant class back | ||
| }); // push the variant class back | ||
| !!variantClass && arrClassNew.push(variantClass); | ||
@@ -56,18 +65,20 @@ return arrClassNew.join(' '); | ||
| var Button = function Button(_ref) { | ||
| exports.getClassNames = getClassNames; | ||
| var Button = _react["default"].forwardRef(function (_ref, ref) { | ||
| var _ref$className = _ref.className, | ||
| className = _ref$className === undefined ? '' : _ref$className, | ||
| className = _ref$className === void 0 ? '' : _ref$className, | ||
| _ref$classNameDefault = _ref.classNameDefault, | ||
| classNameDefault = _ref$classNameDefault === undefined ? 'nu_btn _fill' : _ref$classNameDefault, | ||
| classNameDefault = _ref$classNameDefault === void 0 ? 'nu_btn _fill' : _ref$classNameDefault, | ||
| _ref$children = _ref.children, | ||
| children = _ref$children === undefined ? null : _ref$children, | ||
| children = _ref$children === void 0 ? null : _ref$children, | ||
| _ref$Component = _ref.Component, | ||
| Component = _ref$Component === undefined ? null : _ref$Component, | ||
| Component = _ref$Component === void 0 ? null : _ref$Component, | ||
| _ref$ComponentSub = _ref.ComponentSub, | ||
| ComponentSub = _ref$ComponentSub === undefined ? 'span' : _ref$ComponentSub, | ||
| ComponentSub = _ref$ComponentSub === void 0 ? 'span' : _ref$ComponentSub, | ||
| _ref$href = _ref.href, | ||
| href = _ref$href === undefined ? null : _ref$href, | ||
| href = _ref$href === void 0 ? null : _ref$href, | ||
| _ref$disabled = _ref.disabled, | ||
| disabled = _ref$disabled === undefined ? false : _ref$disabled, | ||
| otherProps = _objectWithoutProperties(_ref, ['className', 'classNameDefault', 'children', 'Component', 'ComponentSub', 'href', 'disabled']); | ||
| disabled = _ref$disabled === void 0 ? false : _ref$disabled, | ||
| otherProps = _objectWithoutPropertiesLoose(_ref, ["className", "classNameDefault", "children", "Component", "ComponentSub", "href", "disabled"]); | ||
@@ -77,30 +88,37 @@ // if exist Component use component | ||
| var ComponentTag = Component ? Component : !!href ? 'a' : 'button'; | ||
| var classNames = getClassNames(classNameDefault, className); | ||
| // only button got button type | ||
| var classNames = getClassNames(classNameDefault, className); // only button got button type | ||
| if (ComponentTag === 'button' && !otherProps.type) { | ||
| otherProps.type = 'button'; | ||
| } | ||
| // set the title of button | ||
| } // set the title of button | ||
| if (!otherProps.title && typeof children === 'string') { | ||
| otherProps.title = children; | ||
| } | ||
| } // subItem | ||
| // subItem | ||
| var ComponentSubTag = ComponentSub && typeof children === 'string' ? ComponentSub : _react.Fragment; | ||
| return /*#__PURE__*/_react["default"].createElement(ComponentTag, _extends({ | ||
| ref: ref, | ||
| href: href, | ||
| disabled: disabled, | ||
| className: classNames | ||
| }, otherProps, { | ||
| __self: _this, | ||
| __source: { | ||
| fileName: _jsxFileName, | ||
| lineNumber: 70, | ||
| columnNumber: 7 | ||
| } | ||
| }), /*#__PURE__*/_react["default"].createElement(ComponentSubTag, { | ||
| __self: _this, | ||
| __source: { | ||
| fileName: _jsxFileName, | ||
| lineNumber: 77, | ||
| columnNumber: 9 | ||
| } | ||
| }, children)); | ||
| }); | ||
| return _react2.default.createElement( | ||
| ComponentTag, | ||
| _extends({ | ||
| href: href, | ||
| disabled: disabled, | ||
| className: classNames | ||
| }, otherProps), | ||
| _react2.default.createElement( | ||
| ComponentSubTag, | ||
| null, | ||
| children | ||
| ) | ||
| ); | ||
| }; | ||
| Button.propTypes = process.env.NODE_ENV !== "production" ? { | ||
@@ -110,33 +128,41 @@ /** | ||
| */ | ||
| title: _propTypes2.default.string, | ||
| title: _propTypes["default"].string, | ||
| /** | ||
| * children of component | ||
| */ | ||
| children: _propTypes2.default.node, | ||
| children: _propTypes["default"].node, | ||
| /** | ||
| * just className | ||
| */ | ||
| className: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.array]), | ||
| className: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].array]), | ||
| /** | ||
| * just className base | ||
| */ | ||
| classNameDefault: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.array]), | ||
| classNameDefault: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].array]), | ||
| /** | ||
| * href for tag a | ||
| */ | ||
| href: _propTypes2.default.string, | ||
| href: _propTypes["default"].string, | ||
| /** | ||
| * shell of button | ||
| */ | ||
| Component: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func, _propTypes2.default.object]), | ||
| Component: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].func, _propTypes["default"].object]), | ||
| /** | ||
| * subComponent of button | ||
| */ | ||
| ComponentSub: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func, _propTypes2.default.object]), | ||
| ComponentSub: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].func, _propTypes["default"].object]), | ||
| /** | ||
| * status of disabled | ||
| */ | ||
| disabled: _propTypes2.default.bool | ||
| disabled: _propTypes["default"].bool | ||
| } : {}; | ||
| Button.defaultProps = {}; | ||
| exports.default = Button; | ||
| var _default = Button; | ||
| exports["default"] = _default; |
+1
-1
| { | ||
| "name": "@_nu/react-button", | ||
| "version": "0.1.1", | ||
| "version": "0.1.2", | ||
| "description": "No UI dependency Button of react", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
18380
11.31%258
10.26%