@atlaskit/renderer
Version:
Renderer component
77 lines (75 loc) • 4.41 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = BackgroundColor;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = _interopRequireWildcard(require("react"));
var _adfSchema = require("@atlaskit/adf-schema");
var _editorPalette = require("@atlaskit/editor-palette");
var _tokens = require("@atlaskit/tokens");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function BackgroundColor(props) {
var _useThemeObserver = (0, _tokens.useThemeObserver)(),
colorMode = _useThemeObserver.colorMode;
var paletteColorValue;
/**
* Documents can contain custom colors when content has been migrated from the old editor, or created via APIs.
*
* This behaviour predates the introduction of dark mode.
*
* Without the inversion logic below, text with custom colors, can be hard to read when the user loads the page in dark mode.
*
* This introduces inversion of the presentation of the custom text background colors when the user is in dark mode.
*
* This can be done without additional changes to account for users copying and pasting content inside the Editor, because of
* how we detect text background colors copied from external editor sources. Where we load the background color from a
* separate attribute (data-background-custom-color), instead of the inline style.
*
* See the following document for more details on this behaviour
* https://hello.atlassian.net/wiki/spaces/CCECO/pages/2908658046/Unsupported+custom+text+colors+in+dark+theme+Editor+Job+Story
*/
var tokenColor = (0, _editorPalette.hexToEditorTextBackgroundPaletteColor)(props.color);
if (tokenColor) {
paletteColorValue = tokenColor;
} else {
if (colorMode === 'dark') {
// if we have a custom color, we need to check if we are in dark mode
paletteColorValue = (0, _adfSchema.getDarkModeLCHColor)(props.color);
} else {
// if we are in light mode, we can just set the color
paletteColorValue = props.color;
}
}
var style = (0, _react.useMemo)(function () {
return (0, _defineProperty2.default)({}, '--custom-palette-color', paletteColorValue);
}, [paletteColorValue]);
if (props.isStandalone) {
return /*#__PURE__*/_react.default.createElement("span", {
"data-block-mark": props.dataAttributes['data-block-mark'],
"data-renderer-mark": props.dataAttributes['data-renderer-mark'],
"data-background-custom-color": props.color
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
,
className: "fabric-background-color-mark"
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
,
style: style
}, /*#__PURE__*/_react.default.createElement("span", {
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
className: "background-color-padding-left background-color-padding-right"
}, props.children));
}
return /*#__PURE__*/_react.default.createElement("span", (0, _extends2.default)({}, props.dataAttributes, {
"data-background-custom-color": props.color
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
,
className: "fabric-background-color-mark"
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
,
style: style
}), props.children);
}