wix-style-react
Version:
190 lines (168 loc) • 6.43 kB
JavaScript
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";
import _defineProperty from "@babel/runtime/helpers/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; } }
import React from 'react';
import PropTypes from 'prop-types';
import { st, classes } from './SocialPreview.st.css';
import Text from '../Text';
import Box from '../Box';
import { Link } from 'wix-ui-icons-common';
import { dataHooks } from './constants';
/**
* A displayer for a social post
*/
var SocialPreview = /*#__PURE__*/function (_React$Component) {
_inherits(SocialPreview, _React$Component);
var _super = _createSuper(SocialPreview);
function SocialPreview() {
_classCallCheck(this, SocialPreview);
return _super.apply(this, arguments);
}
_createClass(SocialPreview, [{
key: "_isTwitter",
value: function _isTwitter() {
var skin = this.props.skin;
return skin === 'twitter';
}
}, {
key: "_isTwitterSmall",
value: function _isTwitterSmall() {
var size = this.props.size;
return this._isTwitter() && size === 'small';
}
}, {
key: "_renderTitle",
value: function _renderTitle() {
var _this$props = this.props,
skin = _this$props.skin,
title = _this$props.title;
return /*#__PURE__*/React.createElement(Text, {
weight: "bold",
size: this._isTwitter() ? 'tiny' : 'small',
dataHook: dataHooks.socialPreviewTitle,
className: st(classes.socialPreviewTitle, {
skin: skin
}),
ellipsis: true
}, title);
}
}, {
key: "_renderDescription",
value: function _renderDescription() {
var _this$props2 = this.props,
skin = _this$props2.skin,
description = _this$props2.description;
return /*#__PURE__*/React.createElement(Text, {
weight: this._isTwitter() ? 'normal' : 'thin',
size: "tiny",
dataHook: dataHooks.socialPreviewDescription,
className: st(classes.socialPreviewDescription, {
skin: skin
}),
ellipsis: true,
maxLines: this._isTwitter() ? 2 : 1
}, description);
}
}, {
key: "_renderUrlText",
value: function _renderUrlText() {
var _this$props3 = this.props,
skin = _this$props3.skin,
previewUrl = _this$props3.previewUrl;
return /*#__PURE__*/React.createElement(Text, {
weight: "normal",
size: "tiny",
dataHook: dataHooks.socialPreviewUrl,
className: st(classes.socialPreviewUrl, {
skin: skin
}),
ellipsis: true
}, this._isTwitter() ? previewUrl : previewUrl && previewUrl.toUpperCase());
}
}, {
key: "_renderUrl",
value: function _renderUrl() {
var _this$props4 = this.props,
skin = _this$props4.skin,
previewUrl = _this$props4.previewUrl;
if (this._isTwitter()) {
return previewUrl && /*#__PURE__*/React.createElement("div", {
className: st(classes.socialPreviewUrlContainer, {
skin: skin
})
}, /*#__PURE__*/React.createElement(Link, {
size: "14px"
}), this._renderUrlText());
} else {
return this._renderUrlText();
}
}
}, {
key: "_renderMedia",
value: function _renderMedia() {
var _this$props5 = this.props,
skin = _this$props5.skin,
size = _this$props5.size,
media = _this$props5.media;
if (this._isTwitterSmall()) {
return /*#__PURE__*/React.createElement("div", {
className: st(classes.mediaContainer, {
skin: skin,
size: size
})
}, media);
}
return media;
}
}, {
key: "render",
value: function render() {
var _this$props6 = this.props,
skin = _this$props6.skin,
size = _this$props6.size;
return /*#__PURE__*/React.createElement("div", {
className: st(classes.root, {
skin: skin,
size: size
}),
"data-hook": this.props.dataHook,
"data-skin": skin,
"data-size": size
}, this._renderMedia(), /*#__PURE__*/React.createElement(Box, {
className: st(classes.container, {
skin: skin,
size: size
}),
direction: "vertical",
verticalAlign: this._isTwitterSmall() ? 'middle' : undefined
}, !this._isTwitter() && this._renderUrl(), this._renderTitle(), this._renderDescription(), this._isTwitter() && this._renderUrl()));
}
}]);
return SocialPreview;
}(React.Component);
_defineProperty(SocialPreview, "displayName", 'SocialPreview');
_defineProperty(SocialPreview, "propTypes", {
dataHook: PropTypes.string,
/** A social post link title */
title: PropTypes.string,
/** A social post link description */
description: PropTypes.string,
/** A url representation of the social post link */
previewUrl: PropTypes.string,
/** A slot to render a media item, most common will be the ImageViewer component */
media: PropTypes.node,
/** Changes the style of the preview */
skin: PropTypes.oneOf(['social', 'twitter']),
/** Specifies the size of the preview. Size small works only in combination with twitter skin */
size: PropTypes.oneOf(['small', 'large'])
});
_defineProperty(SocialPreview, "defaultProps", {
skin: 'social',
size: 'large'
});
export default SocialPreview;