UNPKG

kitten-components

Version:
151 lines (112 loc) 5.23 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.PasswordInput = undefined; 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 _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); var _radium = require('radium'); var _radium2 = _interopRequireDefault(_radium); var _colorsConfig = require('kitten/constants/colors-config'); var _colorsConfig2 = _interopRequireDefault(_colorsConfig); var _passwordIcon = require('kitten/components/icons/password-icon'); var _textInput = require('kitten/components/form/text-input'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var PasswordIcon = (0, _radium2.default)(_passwordIcon.PasswordIcon); var TextInput = (0, _radium2.default)(_textInput.TextInput); var PasswordInputBase = function (_Component) { _inherits(PasswordInputBase, _Component); function PasswordInputBase(props) { _classCallCheck(this, PasswordInputBase); var _this = _possibleConstructorReturn(this, (PasswordInputBase.__proto__ || Object.getPrototypeOf(PasswordInputBase)).call(this, props)); _this.handleClick = function () { _this.setState({ isHidden: !_this.state.isHidden }); }; _this.handleKeyDown = function (event) { var enterKeyCode = 13; if (event.keyCode == enterKeyCode) { _this.handleClick(); } }; _this.state = { isHidden: true }; return _this; } _createClass(PasswordInputBase, [{ key: 'render', value: function render() { var _props = this.props, name = _props.name, textInputProps = _props.textInputProps, iconLabel = _props.iconLabel, hiddenIconLabel = _props.hiddenIconLabel; var type = this.state.isHidden ? 'password' : 'text'; var iconStyle = [styles.icon.svg, !this.state.isHidden && styles.icon.svg.active]; var iconTitle = this.state.isHidden ? iconLabel : hiddenIconLabel; return _react2.default.createElement( 'div', { style: styles.textInput }, _react2.default.createElement(TextInput, _extends({}, textInputProps, { style: styles.input, name: name, type: type })), _react2.default.createElement( 'span', { style: styles.icon, title: iconTitle }, _react2.default.createElement(PasswordIcon, { tabIndex: '0', style: iconStyle, onClick: this.handleClick, onKeyDown: this.handleKeyDown, title: iconTitle }) ) ); } }]); return PasswordInputBase; }(_react.Component); PasswordInputBase.propTypes = { textInputProps: _propTypes2.default.shape({}), iconLabel: _propTypes2.default.string.isRequired, hiddenIconLabel: _propTypes2.default.string.isRequired, name: _propTypes2.default.string }; PasswordInputBase.defaultProps = { textInputProps: {}, name: 'password' }; var styles = { textInput: { position: 'relative', display: 'flex' }, input: { paddingRight: '40px' }, icon: { display: 'flex', position: 'absolute', zIndex: 1, marginRight: '11px', right: 0, top: 0, bottom: 0, svg: { cursor: 'pointer', active: { fill: _colorsConfig2.default.primary1 } } } }; var PasswordInput = exports.PasswordInput = (0, _radium2.default)(PasswordInputBase);