UNPKG

@atlaskit/adf-schema

Version:

Shared package that contains the ADF-schema (json) and ProseMirror node/mark specs

27 lines (26 loc) 1.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hexToEditorBackgroundPaletteRawValue = hexToEditorBackgroundPaletteRawValue; var _editorPalette = require("./editor-palette"); /** * Takes an ADF hex color and returns the rendered hex code for the associated background palette design token using getTokenValue. * If the provided color does not exist in the Editor color palette, this function returns undefined. * * This should only be used when rendering content where CSS variables are not feasible, such as a non-CSS environment * or to enable cross-app copy/paste. * * WARNING: If the rendered theme changes (such as from light -> dark mode) the value returned here will no longer match * the surrounding UI and will need to be re-fetched. * In addition, the values of tokens will differ between themes and the value for a given theme can and will change. * - **DO NOT**: store the output of these functions in any user-generated content or back-end. * - **DO**: store the ADF hex color, and use these utilities at render time to display the themed version of the color. */ function hexToEditorBackgroundPaletteRawValue(hexColor) { // Ts ignore was used to allow use of conditional return type // (preferencing better type on consumption over safety in implementation) var tokenData = hexColor ? _editorPalette.editorBackgroundPalette[hexColor.toUpperCase()] : undefined; // @ts-expect-error return tokenData ? tokenData.getValue(hexColor) : undefined; }