@hig/rich-text
Advanced tools
Comparing version 2.1.0 to 2.1.1
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { css, cx } from 'emotion'; | ||
import { cx, css } from 'emotion'; | ||
import ThemeContext from '@hig/theme-context'; | ||
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; }; | ||
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 _objectSpread2(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; | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
function _objectWithoutProperties(source, excluded) { | ||
if (source == null) return {}; | ||
var target = _objectWithoutPropertiesLoose(source, excluded); | ||
var key, i; | ||
if (Object.getOwnPropertySymbols) { | ||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source); | ||
for (i = 0; i < sourceSymbolKeys.length; i++) { | ||
key = sourceSymbolKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; | ||
target[key] = source[key]; | ||
} | ||
} | ||
return target; | ||
} | ||
function stylesheet(props, themeData) { | ||
function typographyStyle(variant, margin) { | ||
return { | ||
color: themeData["typography." + variant + ".color"], | ||
color: themeData[`typography.${variant}.color`], | ||
display: "block", | ||
fontFamily: themeData["typography." + variant + ".fontFamily"], | ||
fontSize: themeData["typography." + variant + ".fontSize"], | ||
fontWeight: themeData["typography." + variant + ".fontWeight"], | ||
lineHeight: themeData["typography." + variant + ".lineHeight"], | ||
fontFamily: themeData[`typography.${variant}.fontFamily`], | ||
fontSize: themeData[`typography.${variant}.fontSize`], | ||
fontWeight: themeData[`typography.${variant}.fontWeight`], | ||
lineHeight: themeData[`typography.${variant}.lineHeight`], | ||
margin: margin || 0, | ||
@@ -22,12 +97,12 @@ textAlign: "initial" | ||
var customStylesheet = props.stylesheet; | ||
var baseStyles = typographyStyle("body", "0 0 " + themeData["density.spacings.small"] + " 0"); | ||
var listStyles = { | ||
"ul, ol": { paddingLeft: themeData["density.spacings.large"] }, | ||
const { | ||
stylesheet: customStylesheet | ||
} = props; | ||
const baseStyles = typographyStyle("body", "0"); | ||
const listStyles = { | ||
"ul, ol": { | ||
paddingLeft: themeData["density.spacings.large"] | ||
}, | ||
"ul li": { | ||
listStyle: "none", | ||
"&:before": { | ||
@@ -42,4 +117,3 @@ content: "'\\B7'", | ||
}; | ||
var headerStyles = { | ||
const headerStyles = { | ||
h1: typographyStyle("h1"), | ||
@@ -49,4 +123,3 @@ h2: typographyStyle("h2"), | ||
}; | ||
var anchorStyles = { | ||
const anchorStyles = { | ||
a: { | ||
@@ -57,3 +130,2 @@ textDecoration: "none", | ||
outline: "none", | ||
"&:hover": { | ||
@@ -64,56 +136,50 @@ color: themeData["textLink.primary.hover.fontColor"], | ||
}, | ||
"&:focus": { | ||
color: themeData["textLink.primary.focus.fontColor"], | ||
outline: "solid " + themeData["textLink.focus.haloWidth"] + " " + themeData["textLink.focus.haloColor"] | ||
outline: `solid ${themeData["textLink.focus.haloWidth"]} ${themeData["textLink.focus.haloColor"]}` | ||
} | ||
} | ||
}; | ||
var boldStyles = { | ||
"b, strong": { fontWeight: themeData["basics.fontWeights.bold"] } | ||
const boldStyles = { | ||
"b, strong": { | ||
fontWeight: themeData["basics.fontWeights.bold"] | ||
} | ||
}; | ||
var paragraphStyles = { | ||
p: typographyStyle("body", "0 0 " + themeData["density.spacings.small"] + " 0"), | ||
"h1 + p, h2 + p, h3 + p": typographyStyle("body", themeData["density.spacings.medium"] + " 0 " + themeData["density.spacings.small"] + " 0") | ||
const paragraphStyles = { | ||
p: typographyStyle("body", `0 0 ${themeData["density.spacings.small"]} 0`), | ||
"h1 + p, h2 + p, h3 + p": typographyStyle("body", `${themeData["density.spacings.medium"]} 0 ${themeData["density.spacings.small"]} 0`) | ||
}; | ||
var styles = { | ||
richText: _extends({}, baseStyles, listStyles, headerStyles, anchorStyles, paragraphStyles, boldStyles) | ||
const styles = { | ||
richText: _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, baseStyles), listStyles), headerStyles), anchorStyles), paragraphStyles), boldStyles) | ||
}; | ||
return customStylesheet ? customStylesheet(styles, props, themeData) : styles; | ||
} | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
const _excluded = ["children", "dangerouslySetInnerHTML"]; | ||
var RichText = function RichText(props) { | ||
return React.createElement( | ||
ThemeContext.Consumer, | ||
null, | ||
function (_ref) { | ||
var resolvedRoles = _ref.resolvedRoles; | ||
const RichText = props => /*#__PURE__*/React.createElement(ThemeContext.Consumer, null, _ref => { | ||
let { | ||
resolvedRoles | ||
} = _ref; | ||
var children = props.children, | ||
dangerouslySetInnerHTML = props.dangerouslySetInnerHTML, | ||
otherProps = _objectWithoutProperties(props, ["children", "dangerouslySetInnerHTML"]); | ||
const { | ||
children, | ||
dangerouslySetInnerHTML | ||
} = props, | ||
otherProps = _objectWithoutProperties(props, _excluded); | ||
var className = otherProps.className; | ||
const { | ||
className | ||
} = otherProps; | ||
const styles = stylesheet(props, resolvedRoles); | ||
return children ? /*#__PURE__*/React.createElement("div", { | ||
className: cx(css(styles.richText), className) | ||
}, children) : /*#__PURE__*/React.createElement("div", { | ||
className: cx(css(styles.richText), className), | ||
dangerouslySetInnerHTML: dangerouslySetInnerHTML // eslint-disable-line react/no-danger | ||
var styles = stylesheet(props, resolvedRoles); | ||
return children ? React.createElement( | ||
"div", | ||
{ className: cx(css(styles.richText), className) }, | ||
children | ||
) : React.createElement("div", { | ||
className: cx(css(styles.richText), className), | ||
dangerouslySetInnerHTML: dangerouslySetInnerHTML // eslint-disable-line react/no-danger | ||
}); | ||
} | ||
); | ||
}; | ||
}); | ||
}); | ||
RichText.displayName = "RichText"; | ||
RichText.propTypes = { | ||
@@ -124,2 +190,3 @@ /** | ||
children: PropTypes.node, | ||
/** | ||
@@ -131,2 +198,3 @@ * HTML string to be rendered and styled with HIG typography rules | ||
}), | ||
/** | ||
@@ -171,2 +239,2 @@ * Adds custom/overriding styles | ||
export default RichText; | ||
export { RichText as default }; |
@@ -5,20 +5,99 @@ 'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var React = _interopDefault(require('react')); | ||
var PropTypes = _interopDefault(require('prop-types')); | ||
var React = require('react'); | ||
var PropTypes = require('prop-types'); | ||
var emotion = require('emotion'); | ||
var ThemeContext = _interopDefault(require('@hig/theme-context')); | ||
var ThemeContext = require('@hig/theme-context'); | ||
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; }; | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var React__default = /*#__PURE__*/_interopDefaultLegacy(React); | ||
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes); | ||
var ThemeContext__default = /*#__PURE__*/_interopDefaultLegacy(ThemeContext); | ||
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 _objectSpread2(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; | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
function _objectWithoutProperties(source, excluded) { | ||
if (source == null) return {}; | ||
var target = _objectWithoutPropertiesLoose(source, excluded); | ||
var key, i; | ||
if (Object.getOwnPropertySymbols) { | ||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source); | ||
for (i = 0; i < sourceSymbolKeys.length; i++) { | ||
key = sourceSymbolKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; | ||
target[key] = source[key]; | ||
} | ||
} | ||
return target; | ||
} | ||
function stylesheet(props, themeData) { | ||
function typographyStyle(variant, margin) { | ||
return { | ||
color: themeData["typography." + variant + ".color"], | ||
color: themeData[`typography.${variant}.color`], | ||
display: "block", | ||
fontFamily: themeData["typography." + variant + ".fontFamily"], | ||
fontSize: themeData["typography." + variant + ".fontSize"], | ||
fontWeight: themeData["typography." + variant + ".fontWeight"], | ||
lineHeight: themeData["typography." + variant + ".lineHeight"], | ||
fontFamily: themeData[`typography.${variant}.fontFamily`], | ||
fontSize: themeData[`typography.${variant}.fontSize`], | ||
fontWeight: themeData[`typography.${variant}.fontWeight`], | ||
lineHeight: themeData[`typography.${variant}.lineHeight`], | ||
margin: margin || 0, | ||
@@ -29,12 +108,12 @@ textAlign: "initial" | ||
var customStylesheet = props.stylesheet; | ||
var baseStyles = typographyStyle("body", "0 0 " + themeData["density.spacings.small"] + " 0"); | ||
var listStyles = { | ||
"ul, ol": { paddingLeft: themeData["density.spacings.large"] }, | ||
const { | ||
stylesheet: customStylesheet | ||
} = props; | ||
const baseStyles = typographyStyle("body", "0"); | ||
const listStyles = { | ||
"ul, ol": { | ||
paddingLeft: themeData["density.spacings.large"] | ||
}, | ||
"ul li": { | ||
listStyle: "none", | ||
"&:before": { | ||
@@ -49,4 +128,3 @@ content: "'\\B7'", | ||
}; | ||
var headerStyles = { | ||
const headerStyles = { | ||
h1: typographyStyle("h1"), | ||
@@ -56,4 +134,3 @@ h2: typographyStyle("h2"), | ||
}; | ||
var anchorStyles = { | ||
const anchorStyles = { | ||
a: { | ||
@@ -64,3 +141,2 @@ textDecoration: "none", | ||
outline: "none", | ||
"&:hover": { | ||
@@ -71,56 +147,50 @@ color: themeData["textLink.primary.hover.fontColor"], | ||
}, | ||
"&:focus": { | ||
color: themeData["textLink.primary.focus.fontColor"], | ||
outline: "solid " + themeData["textLink.focus.haloWidth"] + " " + themeData["textLink.focus.haloColor"] | ||
outline: `solid ${themeData["textLink.focus.haloWidth"]} ${themeData["textLink.focus.haloColor"]}` | ||
} | ||
} | ||
}; | ||
var boldStyles = { | ||
"b, strong": { fontWeight: themeData["basics.fontWeights.bold"] } | ||
const boldStyles = { | ||
"b, strong": { | ||
fontWeight: themeData["basics.fontWeights.bold"] | ||
} | ||
}; | ||
var paragraphStyles = { | ||
p: typographyStyle("body", "0 0 " + themeData["density.spacings.small"] + " 0"), | ||
"h1 + p, h2 + p, h3 + p": typographyStyle("body", themeData["density.spacings.medium"] + " 0 " + themeData["density.spacings.small"] + " 0") | ||
const paragraphStyles = { | ||
p: typographyStyle("body", `0 0 ${themeData["density.spacings.small"]} 0`), | ||
"h1 + p, h2 + p, h3 + p": typographyStyle("body", `${themeData["density.spacings.medium"]} 0 ${themeData["density.spacings.small"]} 0`) | ||
}; | ||
var styles = { | ||
richText: _extends({}, baseStyles, listStyles, headerStyles, anchorStyles, paragraphStyles, boldStyles) | ||
const styles = { | ||
richText: _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, baseStyles), listStyles), headerStyles), anchorStyles), paragraphStyles), boldStyles) | ||
}; | ||
return customStylesheet ? customStylesheet(styles, props, themeData) : styles; | ||
} | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
const _excluded = ["children", "dangerouslySetInnerHTML"]; | ||
var RichText = function RichText(props) { | ||
return React.createElement( | ||
ThemeContext.Consumer, | ||
null, | ||
function (_ref) { | ||
var resolvedRoles = _ref.resolvedRoles; | ||
const RichText = props => /*#__PURE__*/React__default["default"].createElement(ThemeContext__default["default"].Consumer, null, _ref => { | ||
let { | ||
resolvedRoles | ||
} = _ref; | ||
var children = props.children, | ||
dangerouslySetInnerHTML = props.dangerouslySetInnerHTML, | ||
otherProps = _objectWithoutProperties(props, ["children", "dangerouslySetInnerHTML"]); | ||
const { | ||
children, | ||
dangerouslySetInnerHTML | ||
} = props, | ||
otherProps = _objectWithoutProperties(props, _excluded); | ||
var className = otherProps.className; | ||
const { | ||
className | ||
} = otherProps; | ||
const styles = stylesheet(props, resolvedRoles); | ||
return children ? /*#__PURE__*/React__default["default"].createElement("div", { | ||
className: emotion.cx(emotion.css(styles.richText), className) | ||
}, children) : /*#__PURE__*/React__default["default"].createElement("div", { | ||
className: emotion.cx(emotion.css(styles.richText), className), | ||
dangerouslySetInnerHTML: dangerouslySetInnerHTML // eslint-disable-line react/no-danger | ||
var styles = stylesheet(props, resolvedRoles); | ||
return children ? React.createElement( | ||
"div", | ||
{ className: emotion.cx(emotion.css(styles.richText), className) }, | ||
children | ||
) : React.createElement("div", { | ||
className: emotion.cx(emotion.css(styles.richText), className), | ||
dangerouslySetInnerHTML: dangerouslySetInnerHTML // eslint-disable-line react/no-danger | ||
}); | ||
} | ||
); | ||
}; | ||
}); | ||
}); | ||
RichText.displayName = "RichText"; | ||
RichText.propTypes = { | ||
@@ -130,13 +200,15 @@ /** | ||
*/ | ||
children: PropTypes.node, | ||
children: PropTypes__default["default"].node, | ||
/** | ||
* HTML string to be rendered and styled with HIG typography rules | ||
*/ | ||
dangerouslySetInnerHTML: PropTypes.shape({ | ||
__html: PropTypes.string | ||
dangerouslySetInnerHTML: PropTypes__default["default"].shape({ | ||
__html: PropTypes__default["default"].string | ||
}), | ||
/** | ||
* Adds custom/overriding styles | ||
*/ | ||
stylesheet: PropTypes.func | ||
stylesheet: PropTypes__default["default"].func | ||
}; | ||
@@ -177,2 +249,2 @@ RichText.__docgenInfo = { | ||
exports.default = RichText; | ||
exports["default"] = RichText; |
@@ -0,1 +1,8 @@ | ||
# [@hig/rich-text-v2.1.1](https://github.com/Autodesk/hig/compare/@hig/rich-text@2.1.0...@hig/rich-text@2.1.1) (2022-04-10) | ||
### Bug Fixes | ||
* margin bottom of the rich-text component deleted ([9db610c](https://github.com/Autodesk/hig/commit/9db610c)) | ||
# [@hig/rich-text-v2.1.0](https://github.com/Autodesk/hig/compare/@hig/rich-text@2.0.0...@hig/rich-text@2.1.0) (2022-01-24) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "@hig/rich-text", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "HIG RichText", | ||
@@ -35,3 +35,3 @@ "author": "Autodesk Inc.", | ||
"@hig/theme-context": "^4.1.0", | ||
"@hig/theme-data": "^2.23.0", | ||
"@hig/theme-data": "^2.25.0", | ||
"react": "^17.0.0" | ||
@@ -38,0 +38,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21446
416