UNPKG

wix-style-react

Version:
152 lines (131 loc) 6.02 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; var _excluded = ["selected", "hovered"]; 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; } } import React from 'react'; import PropTypes from 'prop-types'; import ListItemSelect from '../ListItemSelect'; import Text from '../Text'; import Box from '../Box'; import LocationIcon from 'wix-ui-icons-common/Location'; import { st, classes } from './AddressInputItem.st.css'; /** This component is used to display an address item mainly in <AddressInput/> component. */ var AddressInputItem = /*#__PURE__*/function (_React$PureComponent) { _inherits(AddressInputItem, _React$PureComponent); var _super = _createSuper(AddressInputItem); function AddressInputItem() { _classCallCheck(this, AddressInputItem); return _super.apply(this, arguments); } _createClass(AddressInputItem, [{ key: "render", value: function render() { var _this$props = this.props, dataHook = _this$props.dataHook, className = _this$props.className, secondaryLabel = _this$props.secondaryLabel, optionLayout = _this$props.optionLayout, mainLabel = _this$props.mainLabel, suffix = _this$props.suffix, prefix = _this$props.prefix, disabled = _this$props.disabled, selected = _this$props.selected, highlighted = _this$props.highlighted, onClick = _this$props.onClick; var textProps = { tagName: 'div', ellipsis: true, skin: disabled ? 'disabled' : 'standard', light: selected }; return /*#__PURE__*/React.createElement(ListItemSelect, { dataHook: dataHook, className: st(classes.root, { optionLayout: optionLayout }, className), subtitle: secondaryLabel, title: /*#__PURE__*/React.createElement(Text, textProps, mainLabel), suffix: /*#__PURE__*/React.createElement(Box, null, suffix), prefix: /*#__PURE__*/React.createElement(Box, null, prefix), ellipsis: true, disabled: disabled, selected: selected, highlighted: highlighted, onClick: onClick }); } }]); return AddressInputItem; }(React.PureComponent); export var addressInputItemBuilder = function addressInputItemBuilder(_ref) { var id = _ref.id, className = _ref.className, prefix = _ref.prefix, mainLabel = _ref.mainLabel, secondaryLabel = _ref.secondaryLabel, suffix = _ref.suffix, disabled = _ref.disabled, dataHook = _ref.dataHook, optionLayout = _ref.optionLayout, onClick = _ref.onClick, displayLabel = _ref.displayLabel; return { id: id, disabled: disabled, overrideOptionStyle: true, label: displayLabel, value: function value(_ref2) { var selected = _ref2.selected, hovered = _ref2.hovered, rest = _objectWithoutProperties(_ref2, _excluded); return /*#__PURE__*/React.createElement(AddressInputItem, _extends({ optionLayout: optionLayout, dataHook: dataHook, className: className, prefix: prefix, mainLabel: mainLabel, secondaryLabel: secondaryLabel, suffix: suffix, selected: selected, highlighted: hovered, onClick: onClick }, rest)); } }; }; AddressInputItem.displayName = 'AddressInputItem'; AddressInputItem.propTypes = { /** Applies a data-hook HTML attribute that can be used in the tests */ dataHook: PropTypes.string, /** Specifies a CSS class name to be appended to the component’s root element */ className: PropTypes.string, /** Sets the main label of an option. This label is a primary part that is matched to a search term or keyword. */ mainLabel: PropTypes.string, /** Sets the additional information of an address. Usually contains a region or a country. */ secondaryLabel: PropTypes.string, /** Sets the layout of mainLabel and secondaryLabel. Labels can be either side by side or stacked vertically. */ optionLayout: PropTypes.oneOf(['single-line', 'double-line']), /** Pass a component you want to show as the prefix of the input, e.g., text, icon. */ prefix: PropTypes.node, /** Pass a component you want to show as the suffix of the input, e.g., text, icon, button. */ suffix: PropTypes.node, /** Specifies whether the option is selected. */ selected: PropTypes.bool, /** Specifies whether option is highlighted */ highlighted: PropTypes.bool, /** Specifies whether option is disabled */ disabled: PropTypes.bool, /** Defines a callback function which is called every time option is clicked */ onClick: PropTypes.func }; AddressInputItem.defaultProps = { optionLayout: 'single-line', prefix: /*#__PURE__*/React.createElement(LocationIcon, null) }; export default AddressInputItem;