UNPKG

@atlaskit/editor-plugin-highlight

Version:

Highlight plugin for @atlaskit/editor-core

80 lines (78 loc) 3.94 kB
import React, { useMemo } from 'react'; import { ColorPalette, REMOVE_HIGHLIGHT_COLOR, getSelectedRowAndColumnFromPalette, highlightColorPalette, highlightColorPaletteNew } from '@atlaskit/editor-common/ui-color'; import { ArrowKeyNavigationType, DropdownContainer as Dropdown } from '@atlaskit/editor-common/ui-menu'; import { hexToEditorTextBackgroundPaletteColor } from '@atlaskit/editor-palette'; import { akEditorMenuZIndex } from '@atlaskit/editor-shared-styles'; import { fg } from '@atlaskit/platform-feature-flags'; import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals'; var HIGHLIGHT_COLOR_PICKER_COLUMNS = 8; var HIGHLIGHT_COLOR_PICKER_COLUMNS_NEW = 10; export var PaletteDropdown = function PaletteDropdown(props) { var popupsMountPoint = props.popupsMountPoint, popupsBoundariesElement = props.popupsBoundariesElement, popupsScrollableElement = props.popupsScrollableElement, isOpen = props.isOpen, activeColor = props.activeColor, trigger = props.trigger, onColorChange = props.onColorChange, isOpenedByKeyboard = props.isOpenedByKeyboard, handleClickOutside = props.handleClickOutside, handleEscapeKeydown = props.handleEscapeKeydown; var isNewColorPaletteEnabled = expValEquals('platform_editor_lovability_text_bg_color', 'isEnabled', true); var isRedHighlightEnabled = fg('platform_editor_lovability_text_bg_color_patch_1'); var highlightPalette = useMemo(function () { if (isNewColorPaletteEnabled) { return highlightColorPaletteNew.filter(function (color) { if (isRedHighlightEnabled) { return color.value !== REMOVE_HIGHLIGHT_COLOR; } return color.label !== 'Red'; }); } return highlightColorPalette; }, [isNewColorPaletteEnabled, isRedHighlightEnabled]); var colorPickerColumns = isNewColorPaletteEnabled ? HIGHLIGHT_COLOR_PICKER_COLUMNS_NEW : HIGHLIGHT_COLOR_PICKER_COLUMNS; // pixels, used to determine where to horizontally position the dropdown when space is limited // this should reflect the width of the dropdown when fully populated with colors, including translations due to layering var fitWidth = isNewColorPaletteEnabled ? 338 : 274; // 8 cols: 272 = (32 * 8) + (8 + 8) // 10 cols: 336 = (32 * 10) + (8 + 8) // Not sure where the extra 2px comes from var selectedColor = activeColor || (isNewColorPaletteEnabled ? REMOVE_HIGHLIGHT_COLOR : null); var _getSelectedRowAndCol = getSelectedRowAndColumnFromPalette(highlightPalette, selectedColor, colorPickerColumns), selectedRowIndex = _getSelectedRowAndCol.selectedRowIndex, selectedColumnIndex = _getSelectedRowAndCol.selectedColumnIndex; return /*#__PURE__*/React.createElement(Dropdown, { mountTo: popupsMountPoint, boundariesElement: popupsBoundariesElement, scrollableElement: popupsScrollableElement, isOpen: isOpen, handleClickOutside: handleClickOutside, handleEscapeKeydown: handleEscapeKeydown, zIndex: akEditorMenuZIndex, fitWidth: fitWidth, closeOnTab: true // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed) , arrowKeyNavigationProviderOptions: { type: ArrowKeyNavigationType.COLOR, selectedRowIndex: selectedRowIndex, selectedColumnIndex: selectedColumnIndex, isOpenedByKeyboard: isOpenedByKeyboard, isPopupPositioned: true }, trigger: trigger }, /*#__PURE__*/React.createElement("div", { "data-testid": "highlight-color-palette" }, /*#__PURE__*/React.createElement(ColorPalette, { cols: colorPickerColumns, onClick: onColorChange, selectedColor: selectedColor // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed) , paletteOptions: { palette: highlightPalette, hexToPaletteColor: hexToEditorTextBackgroundPaletteColor } }))); };