UNPKG

backpack-ui

Version:

Lonely Planet's Components

149 lines (116 loc) 3.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); 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 = require("react"); var _react2 = _interopRequireDefault(_react); var _radium = require("radium"); var _radium2 = _interopRequireDefault(_radium); var _icon = require("../icon"); var _icon2 = _interopRequireDefault(_icon); var _providerLogo = require("../providerLogo"); var _providerLogo2 = _interopRequireDefault(_providerLogo); var _schema = require("../../utils/schema"); var _schema2 = _interopRequireDefault(_schema); var _font = require("../../utils/font"); var _font2 = _interopRequireDefault(_font); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function Rating(_ref) { var amount = _ref.amount; var max = _ref.max; var description = _ref.description; var provider = _ref.provider; var icon = _ref.icon; var styles = { container: { base: { fontFamily: (0, _font2.default)("benton"), fontSize: "11px", lineHeight: 1.5 } } }; var ratingMap = { 0: "RatingZero", 0.5: "RatingHalf", 1: "RatingOne", 1.5: "RatingOneHalf", 2: "RatingTwo", 2.5: "RatingTwoHalf", 3: "RatingThree", 3.5: "RatingThreeHalf", 4: "RatingFour", 4.5: "RatingFourHalf", 5: "RatingFive" }; var label = amount ? amount + " rating" : ""; var schemaProps = (0, _schema2.default)({ itemProp: "aggregateRating", itemType: "AggregateRating" }); var RatingIcon = _react2.default.createElement(_icon2.default[ratingMap[amount]], { height: "12px", label: label, width: "100px" }); return _react2.default.createElement( "div", _extends({ className: "Rating", title: label, style: styles.container.base }, schemaProps), amount && icon && ratingMap[amount] && _react2.default.createElement("meta", { itemProp: "ratingValue", content: amount }), amount && icon && RatingIcon, (amount && icon && !ratingMap[amount] || amount && !icon) && _react2.default.createElement( "div", { style: { display: "inline-block" } }, description && description + " ", _react2.default.createElement( "span", { itemProp: "ratingValue" }, amount ), max && " out of " + max ), provider && _react2.default.createElement(_providerLogo2.default, { provider: provider, style: { float: "right", height: "21px", marginTop: "-4px" } }) ); } Rating.propTypes = { /** * A numeric value, 0-5 */ amount: _react2.default.PropTypes.number, /** * A number that defines the maximum rating value */ max: _react2.default.PropTypes.number, /** * A word that describes the rating, i.e., excellent, great, poor, etc. */ description: _react2.default.PropTypes.string, /** * If the rating comes from a third-party */ provider: _react2.default.PropTypes.oneOf(["", "bdc", "hostelworld", "opentable", "gadventures", "viator"]), /** * Should the rating use an icon instead of text to describe the rating */ icon: _react2.default.PropTypes.bool }; Rating.defaultProps = { amount: "", max: 5, text: "", provider: "", icon: false }; exports.default = (0, _radium2.default)(Rating);