@streetscape.gl/monochrome
Version:
A toolkit of React components for streetscape.gl
184 lines (159 loc) • 6.79 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import styled from '@emotion/styled';
import { evaluateStyle } from '../theme';
var RadioItem = styled.div(function (props) {
return _objectSpread({
outline: 'none',
cursor: 'pointer',
pointerEvents: props.isEnabled ? 'all' : 'none',
display: 'flex',
width: '100%',
alignItems: 'center',
justifyContent: 'space-between',
marginTop: props.theme.spacingTiny,
marginBottom: props.theme.spacingTiny
}, evaluateStyle(props.userStyle, props));
});
var RadioButton = styled.div(function (props) {
var color = props.theme.controlColorPrimary;
if (!props.isEnabled) {
color = props.theme.controlColorDisabled;
} else if (props.hasFocus) {
color = props.theme.controlColorActive;
} else if (props.isHovered) {
color = props.theme.controlColorHovered;
}
return _objectSpread({
position: 'relative',
boxSizing: 'border-box',
borderRadius: '50%',
width: props.size,
height: props.size,
marginLeft: props.theme.spacingSmall,
background: props.theme.background,
borderStyle: 'solid',
borderWidth: 2,
borderColor: color,
color: color,
flexShrink: 0
}, evaluateStyle(props.userStyle, props));
});
var RadioIcon = styled.div(function (props) {
return _objectSpread({
position: 'absolute',
left: '50%',
top: '50%',
transform: 'translate(-50%,-50%)',
width: 16,
height: 16,
textAlign: 'center',
lineHeight: '16px',
path: {
fill: 'currentColor'
}
}, evaluateStyle(props.userStyle, props));
});
var RadioBoxItem = function (_PureComponent) {
_inherits(RadioBoxItem, _PureComponent);
var _super = _createSuper(RadioBoxItem);
function RadioBoxItem() {
var _this;
_classCallCheck(this, RadioBoxItem);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _super.call.apply(_super, [this].concat(args));
_defineProperty(_assertThisInitialized(_this), "state", {
hasFocus: false,
isHovered: false
});
_defineProperty(_assertThisInitialized(_this), "_onMouseEnter", function () {
return _this.setState({
isHovered: true
});
});
_defineProperty(_assertThisInitialized(_this), "_onMouseLeave", function () {
return _this.setState({
isHovered: false
});
});
_defineProperty(_assertThisInitialized(_this), "_onFocus", function () {
return _this.setState({
hasFocus: true
});
});
_defineProperty(_assertThisInitialized(_this), "_onBlur", function () {
return _this.setState({
hasFocus: false
});
});
_defineProperty(_assertThisInitialized(_this), "_onKeyDown", function (evt) {
if (evt.keyCode === 32) {
_this.props.onClick(evt);
}
});
return _this;
}
_createClass(RadioBoxItem, [{
key: "render",
value: function render() {
var _this$props = this.props,
theme = _this$props.theme,
style = _this$props.style,
size = _this$props.size,
isSelected = _this$props.isSelected,
label = _this$props.label,
isEnabled = _this$props.isEnabled;
var styleProps = {
theme: theme,
size: size,
isSelected: isSelected,
hasFocus: this.state.hasFocus,
isHovered: this.state.isHovered,
isEnabled: isEnabled
};
return React.createElement(RadioItem, _extends({}, styleProps, {
userStyle: style.item,
tabIndex: isEnabled ? 0 : -1,
onMouseEnter: this._onMouseEnter,
onMouseLeave: this._onMouseLeave,
onFocus: this._onFocus,
onBlur: this._onBlur,
onKeyDown: this._onKeyDown,
onClick: this.props.onClick
}), label, React.createElement(RadioButton, _extends({}, styleProps, {
userStyle: style.button
}), React.createElement(RadioIcon, _extends({}, styleProps, {
userStyle: style.icon
}), isSelected ? style.iconSelected || '●' : null)));
}
}]);
return RadioBoxItem;
}(PureComponent);
_defineProperty(RadioBoxItem, "propTypes", {
onClick: PropTypes.func,
label: PropTypes.string,
style: PropTypes.object,
isEnabled: PropTypes.bool,
isSelected: PropTypes.bool
});
_defineProperty(RadioBoxItem, "defaultProps", {
style: {},
isEnabled: true,
onClick: function onClick() {}
});
export { RadioBoxItem as default };
//# sourceMappingURL=radio-box-item.js.map