@_nu/react-switch
Advanced tools
| import * as React from 'react'; | ||
| export interface defaultClassT { | ||
| component?: string; | ||
| input?: string; | ||
| } | ||
| export interface ComponentProps extends React.HTMLAttributes<HTMLElement> { | ||
| Component?: React.ReactNode | React.Component; | ||
| Icon?: React.ReactNode | React.Component | any; | ||
| children?: React.ReactNode; | ||
| defaultClass?: defaultClassT; | ||
| classNameInput?: string; | ||
| type?: 'checkbox' | 'radio'; | ||
| } | ||
| declare const _default: (props?: ComponentProps) => JSX.Element; | ||
| export default _default; |
+108
| 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 _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
| function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | ||
| 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; } | ||
| /** | ||
| * Author: ziven27 | ||
| * Date: 7/6/2020 | ||
| * Desc: 开关的母版组件, radio,checkbox,switch 应该都基于这个组件 | ||
| */ | ||
| import React from 'react'; | ||
| import classNames from 'classnames'; | ||
| import PropTypes from 'prop-types'; | ||
| /** | ||
| * 渲染图标 | ||
| * @param Icon | ||
| * @param props | ||
| * @returns {*|null|React.DetailedReactHTMLElement<*, HTMLElement>} | ||
| * @constructor | ||
| */ | ||
| var RenderIcon = function RenderIcon(_ref) { | ||
| var Icon = _ref.Icon, | ||
| props = _objectWithoutProperties(_ref, ["Icon"]); | ||
| if (!Icon) { | ||
| return null; | ||
| } | ||
| return _typeof(Icon) === 'object' ? React.cloneElement(Icon, props) : /*#__PURE__*/React.createElement(Icon, props); | ||
| }; | ||
| /** | ||
| * On Off | ||
| * @param {node} Component | ||
| * @param {func | node} Icon | ||
| * @param {string} type | ||
| * @param {node} children | ||
| * @param {string} className | ||
| * @param {object} defaultClass | ||
| * @param otherProps | ||
| * @param ref | ||
| * @returns {*} | ||
| * @constructor | ||
| */ | ||
| var NuSwitch = React.forwardRef(function NuSwitch(_ref2, ref) { | ||
| var Component = _ref2.Component, | ||
| Icon = _ref2.Icon, | ||
| type = _ref2.type, | ||
| children = _ref2.children, | ||
| className = _ref2.className, | ||
| classNameInput = _ref2.classNameInput, | ||
| defaultClass = _ref2.defaultClass, | ||
| otherProps = _objectWithoutProperties(_ref2, ["Component", "Icon", "type", "children", "className", "classNameInput", "defaultClass"]); | ||
| return /*#__PURE__*/React.createElement(Component, { | ||
| className: classNames(defaultClass.component, className) | ||
| }, /*#__PURE__*/React.createElement("input", _extends({ | ||
| className: classNames(defaultClass.input, classNameInput), | ||
| ref: ref, | ||
| type: type | ||
| }, otherProps)), /*#__PURE__*/React.createElement(RenderIcon, { | ||
| Icon: Icon, | ||
| checked: otherProps.checked, | ||
| disabeld: otherProps.disabeld | ||
| }), children); | ||
| }); | ||
| NuSwitch.defaultProps = { | ||
| defaultClass: { | ||
| component: 'nu_switch', | ||
| input: '_input' | ||
| }, | ||
| Component: 'label', | ||
| Icon: /*#__PURE__*/React.createElement("i", { | ||
| className: "_icon" | ||
| }), | ||
| type: 'checkbox', | ||
| children: null, | ||
| className: '', | ||
| classNameInput: '' | ||
| }; | ||
| NuSwitch.propTypes = { | ||
| /** 默认class */ | ||
| defaultClass: PropTypes.shape({ | ||
| component: PropTypes.string, | ||
| input: PropTypes.string | ||
| }), | ||
| /** default class of input */ | ||
| classNameInput: PropTypes.string, | ||
| /** input types */ | ||
| type: PropTypes.oneOf(['checkbox', 'radio']), | ||
| /** 子元素 */ | ||
| children: PropTypes.node, | ||
| /** 容器组件,默认为 label */ | ||
| Component: PropTypes.node, | ||
| /** 图标 */ | ||
| Icon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]) | ||
| }; | ||
| export default NuSwitch; |
| import * as React from 'react'; | ||
| export interface defaultClassT { | ||
| component?: string; | ||
| input?: string; | ||
| } | ||
| export interface ComponentProps extends React.HTMLAttributes<HTMLElement> { | ||
| Component?: React.ReactNode | React.Component; | ||
| Icon?: React.ReactNode | React.Component | any; | ||
| children?: React.ReactNode; | ||
| defaultClass?: defaultClassT; | ||
| classNameInput?: string; | ||
| type?: 'checkbox' | 'radio'; | ||
| } | ||
| declare const _default: (props?: ComponentProps) => JSX.Element; | ||
| export default _default; |
+116
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.default = void 0; | ||
| var _react = _interopRequireDefault(require("react")); | ||
| var _classnames = _interopRequireDefault(require("classnames")); | ||
| var _propTypes = _interopRequireDefault(require("prop-types")); | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| 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 _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
| function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | ||
| 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; } | ||
| /** | ||
| * 渲染图标 | ||
| * @param Icon | ||
| * @param props | ||
| * @returns {*|null|React.DetailedReactHTMLElement<*, HTMLElement>} | ||
| * @constructor | ||
| */ | ||
| var RenderIcon = function RenderIcon(_ref) { | ||
| var Icon = _ref.Icon, | ||
| props = _objectWithoutProperties(_ref, ["Icon"]); | ||
| if (!Icon) { | ||
| return null; | ||
| } | ||
| return _typeof(Icon) === 'object' ? _react.default.cloneElement(Icon, props) : /*#__PURE__*/_react.default.createElement(Icon, props); | ||
| }; | ||
| /** | ||
| * On Off | ||
| * @param {node} Component | ||
| * @param {func | node} Icon | ||
| * @param {string} type | ||
| * @param {node} children | ||
| * @param {string} className | ||
| * @param {object} defaultClass | ||
| * @param otherProps | ||
| * @param ref | ||
| * @returns {*} | ||
| * @constructor | ||
| */ | ||
| var NuSwitch = _react.default.forwardRef(function NuSwitch(_ref2, ref) { | ||
| var Component = _ref2.Component, | ||
| Icon = _ref2.Icon, | ||
| type = _ref2.type, | ||
| children = _ref2.children, | ||
| className = _ref2.className, | ||
| classNameInput = _ref2.classNameInput, | ||
| defaultClass = _ref2.defaultClass, | ||
| otherProps = _objectWithoutProperties(_ref2, ["Component", "Icon", "type", "children", "className", "classNameInput", "defaultClass"]); | ||
| return /*#__PURE__*/_react.default.createElement(Component, { | ||
| className: (0, _classnames.default)(defaultClass.component, className) | ||
| }, /*#__PURE__*/_react.default.createElement("input", _extends({ | ||
| className: (0, _classnames.default)(defaultClass.input, classNameInput), | ||
| ref: ref, | ||
| type: type | ||
| }, otherProps)), /*#__PURE__*/_react.default.createElement(RenderIcon, { | ||
| Icon: Icon, | ||
| checked: otherProps.checked, | ||
| disabeld: otherProps.disabeld | ||
| }), children); | ||
| }); | ||
| NuSwitch.defaultProps = { | ||
| defaultClass: { | ||
| component: 'nu_switch', | ||
| input: '_input' | ||
| }, | ||
| Component: 'label', | ||
| Icon: /*#__PURE__*/_react.default.createElement("i", { | ||
| className: "_icon" | ||
| }), | ||
| type: 'checkbox', | ||
| children: null, | ||
| className: '', | ||
| classNameInput: '' | ||
| }; | ||
| NuSwitch.propTypes = { | ||
| /** 默认class */ | ||
| defaultClass: _propTypes.default.shape({ | ||
| component: _propTypes.default.string, | ||
| input: _propTypes.default.string | ||
| }), | ||
| /** default class of input */ | ||
| classNameInput: _propTypes.default.string, | ||
| /** input types */ | ||
| type: _propTypes.default.oneOf(['checkbox', 'radio']), | ||
| /** 子元素 */ | ||
| children: _propTypes.default.node, | ||
| /** 容器组件,默认为 label */ | ||
| Component: _propTypes.default.node, | ||
| /** 图标 */ | ||
| Icon: _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.func]) | ||
| }; | ||
| var _default = NuSwitch; | ||
| exports.default = _default; |
+11
-0
@@ -6,2 +6,13 @@ # Change Log | ||
| ## [0.1.2](https://github.com/nu-system/react/compare/@_nu/react-switch@0.1.1...@_nu/react-switch@0.1.2) (2020-07-12) | ||
| ### Bug Fixes | ||
| * build ([9a319d4](https://github.com/nu-system/react/commit/9a319d47d6c36cec100cc7a1c3d54b4864eb9ea8)) | ||
| ## [0.1.1](https://github.com/nu-system/react/compare/@_nu/react-switch@0.1.0...@_nu/react-switch@0.1.1) (2020-07-12) | ||
@@ -8,0 +19,0 @@ |
+2
-2
| { | ||
| "name": "@_nu/react-switch", | ||
| "version": "0.1.1", | ||
| "version": "0.1.2", | ||
| "description": "No UI dependency switch of react", | ||
@@ -47,3 +47,3 @@ "main": "lib/index.js", | ||
| }, | ||
| "gitHead": "bb73eae4ba2c74a1456001b6324b6e108b0da484" | ||
| "gitHead": "b56478e077ed2271fd1f2767074c372663d12ae2" | ||
| } |
18800
107.94%14
40%356
169.7%