@atlaskit/editor-toolbar 0.3.8 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @atlaskit/editor-toolbar
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`1eba43a7b680d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1eba43a7b680d) -
8
+ [ux] ED-29000 - Address paper cut issues in ColorPalette
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies
13
+
3
14
  ## 0.3.8
4
15
 
5
16
  ### Patch Changes
package/dist/cjs/index.js CHANGED
@@ -412,6 +412,12 @@ Object.defineProperty(exports, "UndoIcon", {
412
412
  return _UndoIcon.UndoIcon;
413
413
  }
414
414
  });
415
+ Object.defineProperty(exports, "getContrastingBackgroundColor", {
416
+ enumerable: true,
417
+ get: function get() {
418
+ return _utils.getContrastingBackgroundColor;
419
+ }
420
+ });
415
421
  Object.defineProperty(exports, "useToolbarDropdownMenu", {
416
422
  enumerable: true,
417
423
  get: function get() {
@@ -491,4 +497,5 @@ var _UndoIcon = require("./ui/icons/UndoIcon");
491
497
  var _RedoIcon = require("./ui/icons/RedoIcon");
492
498
  var _HistoryIcon = require("./ui/icons/HistoryIcon");
493
499
  var _ColorPalette = _interopRequireDefault(require("./ui/ColorPalette"));
500
+ var _utils = require("./ui/ColorPalette/utils");
494
501
  var _uiContext = require("./hooks/ui-context");
@@ -1,6 +1,5 @@
1
1
 
2
2
  ._19itcf40{border:var(--_1wr0y6w)}
3
- ._2rko1hkb{border-radius:var(--ds-border-radius-050,4px)}
4
3
  ._2rkoiti9{border-radius:var(--ds-border-radius-100,4px)}._189et94y{border-width:1px}
5
4
  ._1dqonqa1{border-style:solid}
6
5
  ._1h6d1j28{border-color:transparent}
@@ -62,7 +62,7 @@ var Color = exports.Color = /*#__PURE__*/(0, _react.memo)(function (_ref) {
62
62
  onMouseDown: handleMouseDown,
63
63
  tabIndex: tabIndex,
64
64
  autoFocus: autoFocus,
65
- className: (0, _runtime.ax)(["_ca0qidpf _u5f3idpf _n3tdidpf _19bvidpf _2rko1hkb _19itcf40 _4t3icr4y _1bsbcr4y _bfhkm7j4 _80omtlke _1e0c1ule _kqswh2mm _y2mv12j9 _1bg4v77o"]),
65
+ className: (0, _runtime.ax)(["_ca0qidpf _u5f3idpf _n3tdidpf _19bvidpf _2rkoiti9 _19itcf40 _4t3icr4y _1bsbcr4y _bfhkm7j4 _80omtlke _1e0c1ule _kqswh2mm _y2mv12j9 _1bg4v77o"]),
66
66
  style: {
67
67
  backgroundColor: colorStyle || "var(--ds-background-input, #FFFFFF)",
68
68
  border: "1px solid ".concat(borderColor),
@@ -70,6 +70,7 @@ var Color = exports.Color = /*#__PURE__*/(0, _react.memo)(function (_ref) {
70
70
  "--_toyvsf": (0, _runtime.ix)("2px solid ".concat("var(--ds-border-focused, #388BFF)"))
71
71
  }
72
72
  }, !decorator && isSelected && /*#__PURE__*/_react.default.createElement(_checkMarkEditorDone.default, {
73
+ color: checkMarkColor,
73
74
  LEGACY_primaryColor: checkMarkColor,
74
75
  label: ""
75
76
  }), decorator)));
@@ -1,13 +1,16 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.DEFAULT_COLOR_PICKER_COLUMNS = void 0;
7
8
  exports.getColorsPerRowFromPalette = getColorsPerRowFromPalette;
9
+ exports.getContrastingBackgroundColor = getContrastingBackgroundColor;
8
10
  exports.getSelectedRowAndColumn = getSelectedRowAndColumn;
9
11
  exports.getSelectedRowAndColumnFromPalette = getSelectedRowAndColumnFromPalette;
10
12
  exports.getTokenCSSVariableValue = void 0;
13
+ var _chromatism = _interopRequireDefault(require("chromatism"));
11
14
  /**
12
15
  * Default number of columns in the color picker
13
16
  */
@@ -91,4 +94,40 @@ var getTokenCSSVariableValue = exports.getTokenCSSVariableValue = function getTo
91
94
  return value || fallback;
92
95
  }
93
96
  return '';
94
- };
97
+ };
98
+
99
+ /**
100
+ * Get the best contrasting background color for a given text color
101
+ * Ensures WCAG AA compliance for accessibility
102
+ *
103
+ * @param textColor - The text color to find a contrasting background for (supports HEX, RGB, RGBA etc.)
104
+ * @param useTokens - Whether to return design tokens instead of raw hex values
105
+ * @returns The best contrasting background color (hex value or design token)
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * // Get contrasting color for white text
110
+ * const bgForWhite = getContrastingBackgroundColor('#FFFFFF', false);
111
+ * // Returns: '#42526E' (dark gray)
112
+ *
113
+ * // Get contrasting color for black text with design tokens
114
+ * const bgForBlack = getContrastingBackgroundColor('#000000', true);
115
+ * // Returns: token('elevation.surface', '#FFFFFF')
116
+ * ```
117
+ */
118
+ function getContrastingBackgroundColor(textColor) {
119
+ var candidates = ['#FFFFFF',
120
+ // white - surface
121
+ '#172B4D' // dark blue-gray - text color
122
+ ];
123
+
124
+ // Extract actual color value if it's a CSS variable
125
+ var tokenVal = getTokenCSSVariableValue(textColor);
126
+ var colorValue = !!tokenVal ? tokenVal : textColor;
127
+
128
+ // Find the color with the highest contrast ratio
129
+ var bestContrast = candidates.sort(function (a, b) {
130
+ return _chromatism.default.difference(b, colorValue) - _chromatism.default.difference(a, colorValue);
131
+ })[0];
132
+ return bestContrast;
133
+ }
@@ -66,4 +66,5 @@ export { UndoIcon } from './ui/icons/UndoIcon';
66
66
  export { RedoIcon } from './ui/icons/RedoIcon';
67
67
  export { HistoryIcon } from './ui/icons/HistoryIcon';
68
68
  export { default as ColorPalette } from './ui/ColorPalette';
69
+ export { getContrastingBackgroundColor } from './ui/ColorPalette/utils';
69
70
  export { useToolbarUI, ToolbarUIProvider } from './hooks/ui-context';
@@ -1,6 +1,5 @@
1
1
 
2
2
  ._19itv4vr{border:1px solid var(--ds-border-inverse,#fff)}
3
- ._2rko1hkb{border-radius:var(--ds-border-radius-050,4px)}
4
3
  ._2rkoiti9{border-radius:var(--ds-border-radius-100,4px)}._189et94y{border-width:1px}
5
4
  ._1dqonqa1{border-style:solid}
6
5
  ._1h6d1j28{border-color:transparent}
@@ -57,8 +57,9 @@ export const Color = /*#__PURE__*/memo(({
57
57
  border: `1px solid ${borderColor}`
58
58
  },
59
59
  autoFocus: autoFocus,
60
- className: ax(["_ca0qidpf _u5f3idpf _n3tdidpf _19bvidpf _2rko1hkb _19itv4vr _4t3icr4y _1bsbcr4y _bfhkm7j4 _80omtlke _1e0c1ule _kqswh2mm _y2mvugt7 _1bg4v77o"])
60
+ className: ax(["_ca0qidpf _u5f3idpf _n3tdidpf _19bvidpf _2rkoiti9 _19itv4vr _4t3icr4y _1bsbcr4y _bfhkm7j4 _80omtlke _1e0c1ule _kqswh2mm _y2mvugt7 _1bg4v77o"])
61
61
  }, !decorator && isSelected && /*#__PURE__*/React.createElement(EditorDoneIcon, {
62
+ color: checkMarkColor,
62
63
  LEGACY_primaryColor: checkMarkColor,
63
64
  label: ""
64
65
  }), decorator)));
@@ -1,3 +1,4 @@
1
+ import chromatism from 'chromatism';
1
2
  /**
2
3
  * Default number of columns in the color picker
3
4
  */
@@ -80,4 +81,38 @@ export const getTokenCSSVariableValue = variableExpression => {
80
81
  return value || fallback;
81
82
  }
82
83
  return '';
83
- };
84
+ };
85
+
86
+ /**
87
+ * Get the best contrasting background color for a given text color
88
+ * Ensures WCAG AA compliance for accessibility
89
+ *
90
+ * @param textColor - The text color to find a contrasting background for (supports HEX, RGB, RGBA etc.)
91
+ * @param useTokens - Whether to return design tokens instead of raw hex values
92
+ * @returns The best contrasting background color (hex value or design token)
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * // Get contrasting color for white text
97
+ * const bgForWhite = getContrastingBackgroundColor('#FFFFFF', false);
98
+ * // Returns: '#42526E' (dark gray)
99
+ *
100
+ * // Get contrasting color for black text with design tokens
101
+ * const bgForBlack = getContrastingBackgroundColor('#000000', true);
102
+ * // Returns: token('elevation.surface', '#FFFFFF')
103
+ * ```
104
+ */
105
+ export function getContrastingBackgroundColor(textColor) {
106
+ const candidates = ['#FFFFFF',
107
+ // white - surface
108
+ '#172B4D' // dark blue-gray - text color
109
+ ];
110
+
111
+ // Extract actual color value if it's a CSS variable
112
+ const tokenVal = getTokenCSSVariableValue(textColor);
113
+ const colorValue = !!tokenVal ? tokenVal : textColor;
114
+
115
+ // Find the color with the highest contrast ratio
116
+ const bestContrast = candidates.sort((a, b) => chromatism.difference(b, colorValue) - chromatism.difference(a, colorValue))[0];
117
+ return bestContrast;
118
+ }
package/dist/esm/index.js CHANGED
@@ -66,4 +66,5 @@ export { UndoIcon } from './ui/icons/UndoIcon';
66
66
  export { RedoIcon } from './ui/icons/RedoIcon';
67
67
  export { HistoryIcon } from './ui/icons/HistoryIcon';
68
68
  export { default as ColorPalette } from './ui/ColorPalette';
69
+ export { getContrastingBackgroundColor } from './ui/ColorPalette/utils';
69
70
  export { useToolbarUI, ToolbarUIProvider } from './hooks/ui-context';
@@ -1,6 +1,5 @@
1
1
 
2
2
  ._19itcf40{border:var(--_1wr0y6w)}
3
- ._2rko1hkb{border-radius:var(--ds-border-radius-050,4px)}
4
3
  ._2rkoiti9{border-radius:var(--ds-border-radius-100,4px)}._189et94y{border-width:1px}
5
4
  ._1dqonqa1{border-style:solid}
6
5
  ._1h6d1j28{border-color:transparent}
@@ -53,7 +53,7 @@ export var Color = /*#__PURE__*/memo(function (_ref) {
53
53
  onMouseDown: handleMouseDown,
54
54
  tabIndex: tabIndex,
55
55
  autoFocus: autoFocus,
56
- className: ax(["_ca0qidpf _u5f3idpf _n3tdidpf _19bvidpf _2rko1hkb _19itcf40 _4t3icr4y _1bsbcr4y _bfhkm7j4 _80omtlke _1e0c1ule _kqswh2mm _y2mv12j9 _1bg4v77o"]),
56
+ className: ax(["_ca0qidpf _u5f3idpf _n3tdidpf _19bvidpf _2rkoiti9 _19itcf40 _4t3icr4y _1bsbcr4y _bfhkm7j4 _80omtlke _1e0c1ule _kqswh2mm _y2mv12j9 _1bg4v77o"]),
57
57
  style: {
58
58
  backgroundColor: colorStyle || "var(--ds-background-input, #FFFFFF)",
59
59
  border: "1px solid ".concat(borderColor),
@@ -61,6 +61,7 @@ export var Color = /*#__PURE__*/memo(function (_ref) {
61
61
  "--_toyvsf": ix("2px solid ".concat("var(--ds-border-focused, #388BFF)"))
62
62
  }
63
63
  }, !decorator && isSelected && /*#__PURE__*/React.createElement(EditorDoneIcon, {
64
+ color: checkMarkColor,
64
65
  LEGACY_primaryColor: checkMarkColor,
65
66
  label: ""
66
67
  }), decorator)));
@@ -1,3 +1,4 @@
1
+ import chromatism from 'chromatism';
1
2
  /**
2
3
  * Default number of columns in the color picker
3
4
  */
@@ -81,4 +82,40 @@ export var getTokenCSSVariableValue = function getTokenCSSVariableValue(variable
81
82
  return value || fallback;
82
83
  }
83
84
  return '';
84
- };
85
+ };
86
+
87
+ /**
88
+ * Get the best contrasting background color for a given text color
89
+ * Ensures WCAG AA compliance for accessibility
90
+ *
91
+ * @param textColor - The text color to find a contrasting background for (supports HEX, RGB, RGBA etc.)
92
+ * @param useTokens - Whether to return design tokens instead of raw hex values
93
+ * @returns The best contrasting background color (hex value or design token)
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * // Get contrasting color for white text
98
+ * const bgForWhite = getContrastingBackgroundColor('#FFFFFF', false);
99
+ * // Returns: '#42526E' (dark gray)
100
+ *
101
+ * // Get contrasting color for black text with design tokens
102
+ * const bgForBlack = getContrastingBackgroundColor('#000000', true);
103
+ * // Returns: token('elevation.surface', '#FFFFFF')
104
+ * ```
105
+ */
106
+ export function getContrastingBackgroundColor(textColor) {
107
+ var candidates = ['#FFFFFF',
108
+ // white - surface
109
+ '#172B4D' // dark blue-gray - text color
110
+ ];
111
+
112
+ // Extract actual color value if it's a CSS variable
113
+ var tokenVal = getTokenCSSVariableValue(textColor);
114
+ var colorValue = !!tokenVal ? tokenVal : textColor;
115
+
116
+ // Find the color with the highest contrast ratio
117
+ var bestContrast = candidates.sort(function (a, b) {
118
+ return chromatism.difference(b, colorValue) - chromatism.difference(a, colorValue);
119
+ })[0];
120
+ return bestContrast;
121
+ }
@@ -65,5 +65,6 @@ export { UndoIcon } from './ui/icons/UndoIcon';
65
65
  export { RedoIcon } from './ui/icons/RedoIcon';
66
66
  export { HistoryIcon } from './ui/icons/HistoryIcon';
67
67
  export { default as ColorPalette } from './ui/ColorPalette';
68
+ export { getContrastingBackgroundColor } from './ui/ColorPalette/utils';
68
69
  export type { IconComponent } from './types';
69
70
  export { useToolbarUI, ToolbarUIProvider, type ToolbarUIContextType } from './hooks/ui-context';
@@ -38,3 +38,23 @@ export declare function getSelectedRowAndColumnFromPalette(palette: PaletteColor
38
38
  * @returns The resolved color value or empty string if not found
39
39
  */
40
40
  export declare const getTokenCSSVariableValue: (variableExpression: string) => string;
41
+ /**
42
+ * Get the best contrasting background color for a given text color
43
+ * Ensures WCAG AA compliance for accessibility
44
+ *
45
+ * @param textColor - The text color to find a contrasting background for (supports HEX, RGB, RGBA etc.)
46
+ * @param useTokens - Whether to return design tokens instead of raw hex values
47
+ * @returns The best contrasting background color (hex value or design token)
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * // Get contrasting color for white text
52
+ * const bgForWhite = getContrastingBackgroundColor('#FFFFFF', false);
53
+ * // Returns: '#42526E' (dark gray)
54
+ *
55
+ * // Get contrasting color for black text with design tokens
56
+ * const bgForBlack = getContrastingBackgroundColor('#000000', true);
57
+ * // Returns: token('elevation.surface', '#FFFFFF')
58
+ * ```
59
+ */
60
+ export declare function getContrastingBackgroundColor(textColor: string): string;
@@ -65,5 +65,6 @@ export { UndoIcon } from './ui/icons/UndoIcon';
65
65
  export { RedoIcon } from './ui/icons/RedoIcon';
66
66
  export { HistoryIcon } from './ui/icons/HistoryIcon';
67
67
  export { default as ColorPalette } from './ui/ColorPalette';
68
+ export { getContrastingBackgroundColor } from './ui/ColorPalette/utils';
68
69
  export type { IconComponent } from './types';
69
70
  export { useToolbarUI, ToolbarUIProvider, type ToolbarUIContextType } from './hooks/ui-context';
@@ -38,3 +38,23 @@ export declare function getSelectedRowAndColumnFromPalette(palette: PaletteColor
38
38
  * @returns The resolved color value or empty string if not found
39
39
  */
40
40
  export declare const getTokenCSSVariableValue: (variableExpression: string) => string;
41
+ /**
42
+ * Get the best contrasting background color for a given text color
43
+ * Ensures WCAG AA compliance for accessibility
44
+ *
45
+ * @param textColor - The text color to find a contrasting background for (supports HEX, RGB, RGBA etc.)
46
+ * @param useTokens - Whether to return design tokens instead of raw hex values
47
+ * @returns The best contrasting background color (hex value or design token)
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * // Get contrasting color for white text
52
+ * const bgForWhite = getContrastingBackgroundColor('#FFFFFF', false);
53
+ * // Returns: '#42526E' (dark gray)
54
+ *
55
+ * // Get contrasting color for black text with design tokens
56
+ * const bgForBlack = getContrastingBackgroundColor('#000000', true);
57
+ * // Returns: token('elevation.surface', '#FFFFFF')
58
+ * ```
59
+ */
60
+ export declare function getContrastingBackgroundColor(textColor: string): string;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "registry": "https://registry.npmjs.org/"
5
5
  },
6
- "version": "0.3.8",
6
+ "version": "0.4.0",
7
7
  "description": "Common UI for Toolbars across the platform",
8
8
  "atlassian": {
9
9
  "team": "Editor: Jenga",
@@ -20,20 +20,17 @@
20
20
  "*.compiled.css"
21
21
  ],
22
22
  "atlaskit:src": "src/index.ts",
23
- "af:exports": {
24
- ".": "./src/index.ts"
25
- },
26
23
  "dependencies": {
27
24
  "@atlaskit/badge": "^18.1.0",
28
25
  "@atlaskit/button": "^23.4.0",
29
26
  "@atlaskit/css": "^0.12.0",
30
27
  "@atlaskit/dropdown-menu": "^16.3.0",
31
- "@atlaskit/icon": "^28.0.0",
32
- "@atlaskit/icon-lab": "^5.6.0",
28
+ "@atlaskit/icon": "^28.1.0",
29
+ "@atlaskit/icon-lab": "^5.7.0",
33
30
  "@atlaskit/logo": "^19.7.0",
34
31
  "@atlaskit/popup": "^4.3.0",
35
- "@atlaskit/primitives": "^14.11.0",
36
- "@atlaskit/tokens": "^6.0.0",
32
+ "@atlaskit/primitives": "^14.12.0",
33
+ "@atlaskit/tokens": "^6.1.0",
37
34
  "@atlaskit/tooltip": "^20.4.0",
38
35
  "@babel/runtime": "^7.0.0",
39
36
  "@compiled/react": "^0.18.3",