@atlaskit/editor-toolbar 0.1.0 → 0.2.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.
Files changed (51) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/cjs/hooks/ui-context.js +35 -0
  3. package/dist/cjs/index.js +27 -1
  4. package/dist/cjs/ui/Toolbar.compiled.css +6 -2
  5. package/dist/cjs/ui/Toolbar.js +22 -3
  6. package/dist/cjs/ui/ToolbarButton.js +9 -1
  7. package/dist/cjs/ui/ToolbarDropdownItem.compiled.css +0 -7
  8. package/dist/cjs/ui/ToolbarDropdownItem.js +2 -13
  9. package/dist/cjs/ui/ToolbarDropdownMenu.js +5 -1
  10. package/dist/cjs/ui/ToolbarSection.js +4 -2
  11. package/dist/es2019/hooks/ui-context.js +28 -0
  12. package/dist/es2019/index.js +4 -2
  13. package/dist/es2019/ui/Toolbar.compiled.css +6 -2
  14. package/dist/es2019/ui/Toolbar.js +22 -2
  15. package/dist/es2019/ui/ToolbarButton.js +10 -1
  16. package/dist/es2019/ui/ToolbarDropdownItem.compiled.css +0 -7
  17. package/dist/es2019/ui/ToolbarDropdownItem.js +3 -13
  18. package/dist/es2019/ui/ToolbarDropdownMenu.js +6 -1
  19. package/dist/es2019/ui/ToolbarSection.js +4 -2
  20. package/dist/esm/hooks/ui-context.js +27 -0
  21. package/dist/esm/index.js +4 -2
  22. package/dist/esm/ui/Toolbar.compiled.css +6 -2
  23. package/dist/esm/ui/Toolbar.js +21 -2
  24. package/dist/esm/ui/ToolbarButton.js +9 -1
  25. package/dist/esm/ui/ToolbarDropdownItem.compiled.css +0 -7
  26. package/dist/esm/ui/ToolbarDropdownItem.js +3 -14
  27. package/dist/esm/ui/ToolbarDropdownMenu.js +5 -1
  28. package/dist/esm/ui/ToolbarSection.js +4 -2
  29. package/dist/types/hooks/ui-context.d.ts +23 -0
  30. package/dist/types/index.d.ts +3 -1
  31. package/dist/types/types.d.ts +0 -1
  32. package/dist/types/ui/Toolbar.d.ts +7 -0
  33. package/dist/types/ui/ToolbarDropdownDivider.d.ts +0 -1
  34. package/dist/types/ui/ToolbarDropdownItem.d.ts +1 -1
  35. package/dist/types/ui/ToolbarSection.d.ts +2 -1
  36. package/dist/types-ts4.5/hooks/ui-context.d.ts +23 -0
  37. package/dist/types-ts4.5/index.d.ts +3 -1
  38. package/dist/types-ts4.5/types.d.ts +0 -1
  39. package/dist/types-ts4.5/ui/Toolbar.d.ts +7 -0
  40. package/dist/types-ts4.5/ui/ToolbarDropdownDivider.d.ts +0 -1
  41. package/dist/types-ts4.5/ui/ToolbarDropdownItem.d.ts +1 -1
  42. package/dist/types-ts4.5/ui/ToolbarSection.d.ts +2 -1
  43. package/examples/toolbar/examples/ExampleManuallyComposedToolbar.tsx +28 -13
  44. package/package.json +2 -2
  45. package/src/hooks/ui-context.tsx +51 -0
  46. package/src/index.ts +4 -1
  47. package/src/ui/Toolbar.tsx +31 -8
  48. package/src/ui/ToolbarButton.tsx +8 -0
  49. package/src/ui/ToolbarDropdownItem.tsx +2 -24
  50. package/src/ui/ToolbarDropdownMenu.tsx +4 -0
  51. package/src/ui/ToolbarSection.tsx +7 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # @atlaskit/editor-toolbar
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#199353](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/199353)
8
+ [`22cab8325fc62`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/22cab8325fc62) -
9
+ [ux] [ED-28760] Fix editor lose focus and hence editing flow is interrupted. This is done for 2
10
+ components
11
+
12
+ - Dropdown
13
+ - Create context ToolbarUIContext for toolbar consumers to access consumer specific state and
14
+ callbacks
15
+ - Define onDropdownOpenChanged callback for selection toolbars so that editor regains focus
16
+ after dropdown is closed
17
+ - Button
18
+ - Call preventDefault on mouseDown to prevent button takes away focus
19
+
20
+ - [#199487](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/199487)
21
+ [`54098ba4cc83c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/54098ba4cc83c) -
22
+ Add new PrimaryToolbar export which removes box shadows, export toolbar types
23
+
24
+ ## 0.1.1
25
+
26
+ ### Patch Changes
27
+
28
+ - [`428e4e6ff8ac9`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/428e4e6ff8ac9) -
29
+ ED-28683 remove textStyle option from ToolbarDropdownItem, apply this style from the children
30
+ instead
31
+ - [#197017](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/197017)
32
+ [`5ef01d09bada1`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/5ef01d09bada1) -
33
+ [ux] ED-28687 [Register] Text colour + highlight
34
+
3
35
  ## 0.1.0
4
36
 
5
37
  ### Minor Changes
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.useToolbarUI = exports.ToolbarUIProvider = void 0;
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ 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); }
10
+ var ToolbarUIContext = /*#__PURE__*/(0, _react.createContext)({
11
+ onDropdownOpenChanged: function onDropdownOpenChanged() {},
12
+ preventDefaultOnMouseDown: false
13
+ });
14
+
15
+ /**
16
+ * Access consumer specific config and state within a toolbar component
17
+ */
18
+ var useToolbarUI = exports.useToolbarUI = function useToolbarUI() {
19
+ var context = (0, _react.useContext)(ToolbarUIContext);
20
+ if (!context) {
21
+ throw new Error('useToolbarUI must be used within ToolbarUIContext');
22
+ }
23
+ return context;
24
+ };
25
+ var ToolbarUIProvider = exports.ToolbarUIProvider = function ToolbarUIProvider(_ref) {
26
+ var children = _ref.children,
27
+ onDropdownOpenChanged = _ref.onDropdownOpenChanged,
28
+ preventDefaultOnMouseDown = _ref.preventDefaultOnMouseDown;
29
+ return /*#__PURE__*/_react.default.createElement(ToolbarUIContext.Provider, {
30
+ value: {
31
+ onDropdownOpenChanged: onDropdownOpenChanged,
32
+ preventDefaultOnMouseDown: preventDefaultOnMouseDown
33
+ }
34
+ }, children);
35
+ };
package/dist/cjs/index.js CHANGED
@@ -195,6 +195,12 @@ Object.defineProperty(exports, "PinnedIcon", {
195
195
  return _PinnedIcon.PinnedIcon;
196
196
  }
197
197
  });
198
+ Object.defineProperty(exports, "PrimaryToolbar", {
199
+ enumerable: true,
200
+ get: function get() {
201
+ return _Toolbar.PrimaryToolbar;
202
+ }
203
+ });
198
204
  Object.defineProperty(exports, "QuoteIcon", {
199
205
  enumerable: true,
200
206
  get: function get() {
@@ -255,6 +261,12 @@ Object.defineProperty(exports, "ToolbarButtonGroup", {
255
261
  return _ToolbarButtonGroup.ToolbarButtonGroup;
256
262
  }
257
263
  });
264
+ Object.defineProperty(exports, "ToolbarColorSwatch", {
265
+ enumerable: true,
266
+ get: function get() {
267
+ return _ToolbarColorSwatch.ToolbarColorSwatch;
268
+ }
269
+ });
258
270
  Object.defineProperty(exports, "ToolbarDropdownDivider", {
259
271
  enumerable: true,
260
272
  get: function get() {
@@ -303,12 +315,24 @@ Object.defineProperty(exports, "ToolbarTooltip", {
303
315
  return _ToolbarTooltip.ToolbarTooltip;
304
316
  }
305
317
  });
318
+ Object.defineProperty(exports, "ToolbarUIProvider", {
319
+ enumerable: true,
320
+ get: function get() {
321
+ return _uiContext.ToolbarUIProvider;
322
+ }
323
+ });
306
324
  Object.defineProperty(exports, "UnderlineIcon", {
307
325
  enumerable: true,
308
326
  get: function get() {
309
327
  return _UnderlineIcon.UnderlineIcon;
310
328
  }
311
329
  });
330
+ Object.defineProperty(exports, "useToolbarUI", {
331
+ enumerable: true,
332
+ get: function get() {
333
+ return _uiContext.useToolbarUI;
334
+ }
335
+ });
312
336
  var _Toolbar = require("./ui/Toolbar");
313
337
  var _ToolbarButton = require("./ui/ToolbarButton");
314
338
  var _ToolbarButtonGroup = require("./ui/ToolbarButtonGroup");
@@ -320,6 +344,7 @@ var _ToolbarSection = require("./ui/ToolbarSection");
320
344
  var _ToolbarTooltip = require("./ui/ToolbarTooltip");
321
345
  var _ToolbarNestedDropdownMenu = require("./ui/ToolbarNestedDropdownMenu");
322
346
  var _ToolbarDropdownDivider = require("./ui/ToolbarDropdownDivider");
347
+ var _ToolbarColorSwatch = require("./ui/ToolbarColorSwatch");
323
348
  var _AIAdjustLengthIcon = require("./ui/icons/AIAdjustLengthIcon");
324
349
  var _AIChatIcon = require("./ui/icons/AIChatIcon");
325
350
  var _AIProfessionalIcon = require("./ui/icons/AIProfessionalIcon");
@@ -359,4 +384,5 @@ var _StrikeThroughIcon = require("./ui/icons/StrikeThroughIcon");
359
384
  var _CodeIcon = require("./ui/icons/CodeIcon");
360
385
  var _SubscriptIcon = require("./ui/icons/SubscriptIcon");
361
386
  var _SuperscriptIcon = require("./ui/icons/SuperscriptIcon");
362
- var _ShowMoreHorizontal = require("./ui/icons/ShowMoreHorizontal");
387
+ var _ShowMoreHorizontal = require("./ui/icons/ShowMoreHorizontal");
388
+ var _uiContext = require("./hooks/ui-context");
@@ -1,9 +1,13 @@
1
1
 
2
2
  ._2rkoi2wt{border-radius:6px}._16qs1cd0{box-shadow:var(--ds-shadow-overlay,0 8px 9pt #091e4226,0 0 1px #091e424f)}
3
3
  ._19bv1b66{padding-left:var(--ds-space-050,4px)}
4
- ._1bsb184x{width:min-content}
4
+ ._19bvutpp{padding-left:var(--ds-space-150,9pt)}
5
5
  ._1e0c1txw{display:flex}
6
+ ._1tkezwfg{min-height:2pc}
6
7
  ._4cvr1h6o{align-items:center}
7
8
  ._4t3i14no{height:36px}
8
9
  ._bfhkvuon{background-color:var(--ds-surface,#fff)}
9
- ._u5f31b66{padding-right:var(--ds-space-050,4px)}
10
+ ._ca0q12x7{padding-top:var(--ds-space-075,6px)}
11
+ ._n3td12x7{padding-bottom:var(--ds-space-075,6px)}
12
+ ._u5f31b66{padding-right:var(--ds-space-050,4px)}
13
+ ._u5f3utpp{padding-right:var(--ds-space-150,9pt)}
@@ -5,19 +5,38 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.Toolbar = void 0;
8
+ exports.Toolbar = exports.PrimaryToolbar = void 0;
9
9
  require("./Toolbar.compiled.css");
10
10
  var _runtime = require("@compiled/react/runtime");
11
11
  var _react = _interopRequireDefault(require("react"));
12
+ var _css = require("@atlaskit/css");
12
13
  var _compiled = require("@atlaskit/primitives/compiled");
13
14
  var styles = {
14
- toolbar: "_2rkoi2wt _bfhkvuon _u5f31b66 _19bv1b66 _16qs1cd0 _4t3i14no _1bsb184x _1e0c1txw _4cvr1h6o"
15
+ toolbarBase: "_2rkoi2wt _bfhkvuon _1e0c1txw _4cvr1h6o",
16
+ toolbar: "_4t3i14no _u5f31b66 _19bv1b66 _16qs1cd0",
17
+ primaryToolbar: "_bfhkvuon _1tkezwfg _ca0q12x7 _n3td12x7 _19bvutpp _u5f3utpp"
15
18
  };
19
+ /**
20
+ * A simple component representing a toolbar with box shadows - used to represent a secondary/floating toolbar
21
+ */
16
22
  var Toolbar = exports.Toolbar = function Toolbar(_ref) {
17
23
  var children = _ref.children,
18
24
  label = _ref.label;
19
25
  return /*#__PURE__*/_react.default.createElement(_compiled.Box, {
20
- xcss: styles.toolbar,
26
+ xcss: (0, _css.cx)(styles.toolbarBase, styles.toolbar),
27
+ role: "toolbar",
28
+ "aria-label": label
29
+ }, children);
30
+ };
31
+
32
+ /**
33
+ * A simple component representing a toolbar without box shadows - used to represent a primary toolbar
34
+ */
35
+ var PrimaryToolbar = exports.PrimaryToolbar = function PrimaryToolbar(_ref2) {
36
+ var children = _ref2.children,
37
+ label = _ref2.label;
38
+ return /*#__PURE__*/_react.default.createElement(_compiled.Box, {
39
+ xcss: (0, _css.cx)(styles.toolbarBase, styles.primaryToolbar),
21
40
  role: "toolbar",
22
41
  "aria-label": label
23
42
  }, children);
@@ -11,6 +11,7 @@ var _runtime = require("@compiled/react/runtime");
11
11
  var _react = _interopRequireWildcard(require("react"));
12
12
  var _css = require("@atlaskit/css");
13
13
  var _compiled = require("@atlaskit/primitives/compiled");
14
+ var _uiContext = require("../hooks/ui-context");
14
15
  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); }
15
16
  var styles = {
16
17
  button: "_zulp12x7 _2rkoiti9 _1e0c1txw _bfhksm61 _o5721q9c _4cvr1h6o _1bah1h6o _1tke1f4h _syaz1gjq _k48p1wq8 _19bvu2gc _u5f3u2gc _1ah3idpf _g0pbkb7n _oh03h2mm",
@@ -37,6 +38,8 @@ var ToolbarButton = exports.ToolbarButton = /*#__PURE__*/(0, _react.forwardRef)(
37
38
  isDisabled = _ref.isDisabled,
38
39
  ariaKeyshortcuts = _ref.ariaKeyshortcuts,
39
40
  label = _ref.label;
41
+ var _useToolbarUI = (0, _uiContext.useToolbarUI)(),
42
+ preventDefaultOnMouseDown = _useToolbarUI.preventDefaultOnMouseDown;
40
43
  return /*#__PURE__*/_react.default.createElement(_compiled.Pressable, {
41
44
  ref: ref,
42
45
  xcss: (0, _css.cx)(styles.button, isDisabled ? styles.disabled : isSelected ? styles.selected : styles.enabled, groupLocation === 'start' && styles.groupStart, groupLocation === 'middle' && styles.groupMiddle, groupLocation === 'end' && styles.groupEnd),
@@ -51,6 +54,11 @@ var ToolbarButton = exports.ToolbarButton = /*#__PURE__*/(0, _react.forwardRef)(
51
54
  onBlur: onBlur,
52
55
  onFocus: onFocus,
53
56
  testId: testId,
54
- isDisabled: isDisabled
57
+ isDisabled: isDisabled,
58
+ onMouseDown: function onMouseDown(event) {
59
+ if (preventDefaultOnMouseDown) {
60
+ event.preventDefault();
61
+ }
62
+ }
55
63
  }, iconBefore, children);
56
64
  });
@@ -1,10 +1,3 @@
1
- ._11c8140y{font:var(--ds-font-heading-xsmall,normal 600 14px/1pc ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
2
- ._11c81c04{font:var(--ds-font-heading-xlarge,normal 600 29px/2pc ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
3
- ._11c81vhk{font:var(--ds-font-heading-xxsmall,normal 600 9pt/1pc ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
4
- ._11c82smr{font:var(--ds-font-body,normal 400 14px/20px ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
5
- ._11c8lodh{font:var(--ds-font-heading-medium,normal 500 20px/24px ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
6
- ._11c8nbxd{font:var(--ds-font-heading-small,normal 600 1pc/20px ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
7
- ._11c8nf1z{font:var(--ds-font-heading-large,normal 500 24px/28px ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
8
1
  ._19bvutpp{padding-left:var(--ds-space-150,9pt)}
9
2
  ._1bsb1osq{width:100%}
10
3
  ._1tke14no{min-height:36px}
@@ -17,14 +17,7 @@ var styles = {
17
17
  toolbarDropdownItem: "_kqswh2mm _bfhksm61 _1bsb1osq _1tke14no _19bvutpp _u5f3utpp _1basglpi _1ah31i6y",
18
18
  enabled: "_irr3166n _1di61dty",
19
19
  disabled: "_syaz1lh4 _80om13gf",
20
- selected: "_bfhkfg4m _syazaqb7 _irr3i1yw _1di619ru",
21
- normal: "_11c82smr",
22
- heading1: "_11c81c04",
23
- heading2: "_11c8nf1z",
24
- heading3: "_11c8lodh",
25
- heading4: "_11c8nbxd",
26
- heading5: "_11c8140y",
27
- heading6: "_11c81vhk"
20
+ selected: "_bfhkfg4m _syazaqb7 _irr3i1yw _1di619ru"
28
21
  };
29
22
  var CustomDropdownMenuItemButton = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
30
23
  var children = _ref.children,
@@ -54,8 +47,6 @@ var ToolbarDropdownItem = exports.ToolbarDropdownItem = function ToolbarDropdown
54
47
  elemAfter = _ref2.elemAfter,
55
48
  isSelected = _ref2.isSelected,
56
49
  children = _ref2.children,
57
- _ref2$textStyle = _ref2.textStyle,
58
- textStyle = _ref2$textStyle === void 0 ? 'normal' : _ref2$textStyle,
59
50
  isDisabled = _ref2.isDisabled,
60
51
  hasNestedDropdownMenu = _ref2.hasNestedDropdownMenu,
61
52
  triggerRef = _ref2.triggerRef,
@@ -73,7 +64,5 @@ var ToolbarDropdownItem = exports.ToolbarDropdownItem = function ToolbarDropdown
73
64
  ref: triggerRef,
74
65
  component: CustomDropdownMenuItemButton,
75
66
  testId: testId
76
- }, /*#__PURE__*/_react.default.createElement(_compiled.Box, {
77
- xcss: styles[textStyle]
78
- }, children));
67
+ }, children);
79
68
  };
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.ToolbarDropdownMenu = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _dropdownMenu = _interopRequireDefault(require("@atlaskit/dropdown-menu"));
10
+ var _uiContext = require("../hooks/ui-context");
10
11
  var _ToolbarButton = require("./ToolbarButton");
11
12
  var ToolbarDropdownMenu = exports.ToolbarDropdownMenu = function ToolbarDropdownMenu(_ref) {
12
13
  var iconBefore = _ref.iconBefore,
@@ -15,6 +16,8 @@ var ToolbarDropdownMenu = exports.ToolbarDropdownMenu = function ToolbarDropdown
15
16
  isDisabled = _ref.isDisabled,
16
17
  testId = _ref.testId,
17
18
  label = _ref.label;
19
+ var _useToolbarUI = (0, _uiContext.useToolbarUI)(),
20
+ onDropdownOpenChanged = _useToolbarUI.onDropdownOpenChanged;
18
21
  return /*#__PURE__*/_react.default.createElement(_dropdownMenu.default, {
19
22
  trigger: function trigger(triggerProps) {
20
23
  return /*#__PURE__*/_react.default.createElement(_ToolbarButton.ToolbarButton, {
@@ -32,6 +35,7 @@ var ToolbarDropdownMenu = exports.ToolbarDropdownMenu = function ToolbarDropdown
32
35
  isDisabled: isDisabled,
33
36
  label: label
34
37
  });
35
- }
38
+ },
39
+ onOpenChange: onDropdownOpenChanged
36
40
  }, children);
37
41
  };
@@ -14,8 +14,10 @@ var styles = {
14
14
  container: "_1e0c1txw _4cvr1h6o"
15
15
  };
16
16
  var ToolbarSection = exports.ToolbarSection = function ToolbarSection(_ref) {
17
- var children = _ref.children;
17
+ var children = _ref.children,
18
+ testId = _ref.testId;
18
19
  return /*#__PURE__*/_react.default.createElement(_compiled.Box, {
19
- xcss: styles.container
20
+ xcss: styles.container,
21
+ testId: testId
20
22
  }, children);
21
23
  };
@@ -0,0 +1,28 @@
1
+ import React, { createContext, useContext } from 'react';
2
+ const ToolbarUIContext = /*#__PURE__*/createContext({
3
+ onDropdownOpenChanged: () => {},
4
+ preventDefaultOnMouseDown: false
5
+ });
6
+
7
+ /**
8
+ * Access consumer specific config and state within a toolbar component
9
+ */
10
+ export const useToolbarUI = () => {
11
+ const context = useContext(ToolbarUIContext);
12
+ if (!context) {
13
+ throw new Error('useToolbarUI must be used within ToolbarUIContext');
14
+ }
15
+ return context;
16
+ };
17
+ export const ToolbarUIProvider = ({
18
+ children,
19
+ onDropdownOpenChanged,
20
+ preventDefaultOnMouseDown
21
+ }) => {
22
+ return /*#__PURE__*/React.createElement(ToolbarUIContext.Provider, {
23
+ value: {
24
+ onDropdownOpenChanged,
25
+ preventDefaultOnMouseDown
26
+ }
27
+ }, children);
28
+ };
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @atlaskit/editor/no-re-export */
2
- export { Toolbar } from './ui/Toolbar';
2
+ export { Toolbar, PrimaryToolbar } from './ui/Toolbar';
3
3
  export { ToolbarButton } from './ui/ToolbarButton';
4
4
  export { ToolbarButtonGroup } from './ui/ToolbarButtonGroup';
5
5
  export { ToolbarDropdownMenu } from './ui/ToolbarDropdownMenu';
@@ -10,6 +10,7 @@ export { ToolbarSection } from './ui/ToolbarSection';
10
10
  export { ToolbarTooltip } from './ui/ToolbarTooltip';
11
11
  export { ToolbarNestedDropdownMenu } from './ui/ToolbarNestedDropdownMenu';
12
12
  export { ToolbarDropdownDivider } from './ui/ToolbarDropdownDivider';
13
+ export { ToolbarColorSwatch } from './ui/ToolbarColorSwatch';
13
14
  export { AIAdjustLengthIcon } from './ui/icons/AIAdjustLengthIcon';
14
15
  export { AIChatIcon } from './ui/icons/AIChatIcon';
15
16
  export { AIBriefcaseIcon } from './ui/icons/AIProfessionalIcon';
@@ -49,4 +50,5 @@ export { StrikeThroughIcon } from './ui/icons/StrikeThroughIcon';
49
50
  export { CodeIcon } from './ui/icons/CodeIcon';
50
51
  export { SubscriptIcon } from './ui/icons/SubscriptIcon';
51
52
  export { SuperscriptIcon } from './ui/icons/SuperscriptIcon';
52
- export { ShowMoreHorizontalIcon } from './ui/icons/ShowMoreHorizontal';
53
+ export { ShowMoreHorizontalIcon } from './ui/icons/ShowMoreHorizontal';
54
+ export { useToolbarUI, ToolbarUIProvider } from './hooks/ui-context';
@@ -1,9 +1,13 @@
1
1
 
2
2
  ._2rkoi2wt{border-radius:6px}._16qs1cd0{box-shadow:var(--ds-shadow-overlay,0 8px 9pt #091e4226,0 0 1px #091e424f)}
3
3
  ._19bv1b66{padding-left:var(--ds-space-050,4px)}
4
- ._1bsb184x{width:min-content}
4
+ ._19bvutpp{padding-left:var(--ds-space-150,9pt)}
5
5
  ._1e0c1txw{display:flex}
6
+ ._1tkezwfg{min-height:2pc}
6
7
  ._4cvr1h6o{align-items:center}
7
8
  ._4t3i14no{height:36px}
8
9
  ._bfhkvuon{background-color:var(--ds-surface,#fff)}
9
- ._u5f31b66{padding-right:var(--ds-space-050,4px)}
10
+ ._ca0q12x7{padding-top:var(--ds-space-075,6px)}
11
+ ._n3td12x7{padding-bottom:var(--ds-space-075,6px)}
12
+ ._u5f31b66{padding-right:var(--ds-space-050,4px)}
13
+ ._u5f3utpp{padding-right:var(--ds-space-150,9pt)}
@@ -2,16 +2,36 @@
2
2
  import "./Toolbar.compiled.css";
3
3
  import { ax, ix } from "@compiled/react/runtime";
4
4
  import React from 'react';
5
+ import { cx } from '@atlaskit/css';
5
6
  import { Box } from '@atlaskit/primitives/compiled';
6
7
  const styles = {
7
- toolbar: "_2rkoi2wt _bfhkvuon _u5f31b66 _19bv1b66 _16qs1cd0 _4t3i14no _1bsb184x _1e0c1txw _4cvr1h6o"
8
+ toolbarBase: "_2rkoi2wt _bfhkvuon _1e0c1txw _4cvr1h6o",
9
+ toolbar: "_4t3i14no _u5f31b66 _19bv1b66 _16qs1cd0",
10
+ primaryToolbar: "_bfhkvuon _1tkezwfg _ca0q12x7 _n3td12x7 _19bvutpp _u5f3utpp"
8
11
  };
12
+ /**
13
+ * A simple component representing a toolbar with box shadows - used to represent a secondary/floating toolbar
14
+ */
9
15
  export const Toolbar = ({
10
16
  children,
11
17
  label
12
18
  }) => {
13
19
  return /*#__PURE__*/React.createElement(Box, {
14
- xcss: styles.toolbar,
20
+ xcss: cx(styles.toolbarBase, styles.toolbar),
21
+ role: "toolbar",
22
+ "aria-label": label
23
+ }, children);
24
+ };
25
+
26
+ /**
27
+ * A simple component representing a toolbar without box shadows - used to represent a primary toolbar
28
+ */
29
+ export const PrimaryToolbar = ({
30
+ children,
31
+ label
32
+ }) => {
33
+ return /*#__PURE__*/React.createElement(Box, {
34
+ xcss: cx(styles.toolbarBase, styles.primaryToolbar),
15
35
  role: "toolbar",
16
36
  "aria-label": label
17
37
  }, children);
@@ -4,6 +4,7 @@ import { ax, ix } from "@compiled/react/runtime";
4
4
  import React, { forwardRef } from 'react';
5
5
  import { cx } from '@atlaskit/css';
6
6
  import { Pressable } from '@atlaskit/primitives/compiled';
7
+ import { useToolbarUI } from '../hooks/ui-context';
7
8
  const styles = {
8
9
  button: "_zulp12x7 _2rkoiti9 _1e0c1txw _bfhksm61 _o5721q9c _4cvr1h6o _1bah1h6o _1tke1f4h _syaz1gjq _k48p1wq8 _19bvu2gc _u5f3u2gc _1ah3idpf _g0pbkb7n _oh03h2mm",
9
10
  enabled: "_irr3166n _1di61dty",
@@ -30,6 +31,9 @@ export const ToolbarButton = /*#__PURE__*/forwardRef(({
30
31
  ariaKeyshortcuts,
31
32
  label
32
33
  }, ref) => {
34
+ const {
35
+ preventDefaultOnMouseDown
36
+ } = useToolbarUI();
33
37
  return /*#__PURE__*/React.createElement(Pressable, {
34
38
  ref: ref,
35
39
  xcss: cx(styles.button, isDisabled ? styles.disabled : isSelected ? styles.selected : styles.enabled, groupLocation === 'start' && styles.groupStart, groupLocation === 'middle' && styles.groupMiddle, groupLocation === 'end' && styles.groupEnd),
@@ -44,6 +48,11 @@ export const ToolbarButton = /*#__PURE__*/forwardRef(({
44
48
  onBlur: onBlur,
45
49
  onFocus: onFocus,
46
50
  testId: testId,
47
- isDisabled: isDisabled
51
+ isDisabled: isDisabled,
52
+ onMouseDown: event => {
53
+ if (preventDefaultOnMouseDown) {
54
+ event.preventDefault();
55
+ }
56
+ }
48
57
  }, iconBefore, children);
49
58
  });
@@ -1,10 +1,3 @@
1
- ._11c8140y{font:var(--ds-font-heading-xsmall,normal 600 14px/1pc ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
2
- ._11c81c04{font:var(--ds-font-heading-xlarge,normal 600 29px/2pc ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
3
- ._11c81vhk{font:var(--ds-font-heading-xxsmall,normal 600 9pt/1pc ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
4
- ._11c82smr{font:var(--ds-font-body,normal 400 14px/20px ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
5
- ._11c8lodh{font:var(--ds-font-heading-medium,normal 500 20px/24px ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
6
- ._11c8nbxd{font:var(--ds-font-heading-small,normal 600 1pc/20px ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
7
- ._11c8nf1z{font:var(--ds-font-heading-large,normal 500 24px/28px ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
8
1
  ._19bvutpp{padding-left:var(--ds-space-150,9pt)}
9
2
  ._1bsb1osq{width:100%}
10
3
  ._1tke14no{min-height:36px}
@@ -4,19 +4,12 @@ import { ax, ix } from "@compiled/react/runtime";
4
4
  import React, { forwardRef } from 'react';
5
5
  import { cx } from '@atlaskit/css';
6
6
  import { DropdownItem } from '@atlaskit/dropdown-menu';
7
- import { Box, Pressable } from '@atlaskit/primitives/compiled';
7
+ import { Pressable } from '@atlaskit/primitives/compiled';
8
8
  const styles = {
9
9
  toolbarDropdownItem: "_kqswh2mm _bfhksm61 _1bsb1osq _1tke14no _19bvutpp _u5f3utpp _1basglpi _1ah31i6y",
10
10
  enabled: "_irr3166n _1di61dty",
11
11
  disabled: "_syaz1lh4 _80om13gf",
12
- selected: "_bfhkfg4m _syazaqb7 _irr3i1yw _1di619ru",
13
- normal: "_11c82smr",
14
- heading1: "_11c81c04",
15
- heading2: "_11c8nf1z",
16
- heading3: "_11c8lodh",
17
- heading4: "_11c8nbxd",
18
- heading5: "_11c8140y",
19
- heading6: "_11c81vhk"
12
+ selected: "_bfhkfg4m _syazaqb7 _irr3i1yw _1di619ru"
20
13
  };
21
14
  const CustomDropdownMenuItemButton = /*#__PURE__*/forwardRef(({
22
15
  children,
@@ -45,7 +38,6 @@ export const ToolbarDropdownItem = ({
45
38
  elemAfter,
46
39
  isSelected,
47
40
  children,
48
- textStyle = 'normal',
49
41
  isDisabled,
50
42
  hasNestedDropdownMenu,
51
43
  triggerRef,
@@ -63,6 +55,4 @@ export const ToolbarDropdownItem = ({
63
55
  ref: triggerRef,
64
56
  component: CustomDropdownMenuItemButton,
65
57
  testId: testId
66
- }, /*#__PURE__*/React.createElement(Box, {
67
- xcss: styles[textStyle]
68
- }, children));
58
+ }, children);
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import DropdownMenu from '@atlaskit/dropdown-menu';
3
+ import { useToolbarUI } from '../hooks/ui-context';
3
4
  import { ToolbarButton } from './ToolbarButton';
4
5
  export const ToolbarDropdownMenu = ({
5
6
  iconBefore,
@@ -9,6 +10,9 @@ export const ToolbarDropdownMenu = ({
9
10
  testId,
10
11
  label
11
12
  }) => {
13
+ const {
14
+ onDropdownOpenChanged
15
+ } = useToolbarUI();
12
16
  return /*#__PURE__*/React.createElement(DropdownMenu, {
13
17
  trigger: triggerProps => /*#__PURE__*/React.createElement(ToolbarButton, {
14
18
  ref: triggerProps.triggerRef,
@@ -24,6 +28,7 @@ export const ToolbarDropdownMenu = ({
24
28
  groupLocation: groupLocation,
25
29
  isDisabled: isDisabled,
26
30
  label: label
27
- })
31
+ }),
32
+ onOpenChange: onDropdownOpenChanged
28
33
  }, children);
29
34
  };
@@ -7,9 +7,11 @@ const styles = {
7
7
  container: "_1e0c1txw _4cvr1h6o"
8
8
  };
9
9
  export const ToolbarSection = ({
10
- children
10
+ children,
11
+ testId
11
12
  }) => {
12
13
  return /*#__PURE__*/React.createElement(Box, {
13
- xcss: styles.container
14
+ xcss: styles.container,
15
+ testId: testId
14
16
  }, children);
15
17
  };
@@ -0,0 +1,27 @@
1
+ import React, { createContext, useContext } from 'react';
2
+ var ToolbarUIContext = /*#__PURE__*/createContext({
3
+ onDropdownOpenChanged: function onDropdownOpenChanged() {},
4
+ preventDefaultOnMouseDown: false
5
+ });
6
+
7
+ /**
8
+ * Access consumer specific config and state within a toolbar component
9
+ */
10
+ export var useToolbarUI = function useToolbarUI() {
11
+ var context = useContext(ToolbarUIContext);
12
+ if (!context) {
13
+ throw new Error('useToolbarUI must be used within ToolbarUIContext');
14
+ }
15
+ return context;
16
+ };
17
+ export var ToolbarUIProvider = function ToolbarUIProvider(_ref) {
18
+ var children = _ref.children,
19
+ onDropdownOpenChanged = _ref.onDropdownOpenChanged,
20
+ preventDefaultOnMouseDown = _ref.preventDefaultOnMouseDown;
21
+ return /*#__PURE__*/React.createElement(ToolbarUIContext.Provider, {
22
+ value: {
23
+ onDropdownOpenChanged: onDropdownOpenChanged,
24
+ preventDefaultOnMouseDown: preventDefaultOnMouseDown
25
+ }
26
+ }, children);
27
+ };
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @atlaskit/editor/no-re-export */
2
- export { Toolbar } from './ui/Toolbar';
2
+ export { Toolbar, PrimaryToolbar } from './ui/Toolbar';
3
3
  export { ToolbarButton } from './ui/ToolbarButton';
4
4
  export { ToolbarButtonGroup } from './ui/ToolbarButtonGroup';
5
5
  export { ToolbarDropdownMenu } from './ui/ToolbarDropdownMenu';
@@ -10,6 +10,7 @@ export { ToolbarSection } from './ui/ToolbarSection';
10
10
  export { ToolbarTooltip } from './ui/ToolbarTooltip';
11
11
  export { ToolbarNestedDropdownMenu } from './ui/ToolbarNestedDropdownMenu';
12
12
  export { ToolbarDropdownDivider } from './ui/ToolbarDropdownDivider';
13
+ export { ToolbarColorSwatch } from './ui/ToolbarColorSwatch';
13
14
  export { AIAdjustLengthIcon } from './ui/icons/AIAdjustLengthIcon';
14
15
  export { AIChatIcon } from './ui/icons/AIChatIcon';
15
16
  export { AIBriefcaseIcon } from './ui/icons/AIProfessionalIcon';
@@ -49,4 +50,5 @@ export { StrikeThroughIcon } from './ui/icons/StrikeThroughIcon';
49
50
  export { CodeIcon } from './ui/icons/CodeIcon';
50
51
  export { SubscriptIcon } from './ui/icons/SubscriptIcon';
51
52
  export { SuperscriptIcon } from './ui/icons/SuperscriptIcon';
52
- export { ShowMoreHorizontalIcon } from './ui/icons/ShowMoreHorizontal';
53
+ export { ShowMoreHorizontalIcon } from './ui/icons/ShowMoreHorizontal';
54
+ export { useToolbarUI, ToolbarUIProvider } from './hooks/ui-context';
@@ -1,9 +1,13 @@
1
1
 
2
2
  ._2rkoi2wt{border-radius:6px}._16qs1cd0{box-shadow:var(--ds-shadow-overlay,0 8px 9pt #091e4226,0 0 1px #091e424f)}
3
3
  ._19bv1b66{padding-left:var(--ds-space-050,4px)}
4
- ._1bsb184x{width:min-content}
4
+ ._19bvutpp{padding-left:var(--ds-space-150,9pt)}
5
5
  ._1e0c1txw{display:flex}
6
+ ._1tkezwfg{min-height:2pc}
6
7
  ._4cvr1h6o{align-items:center}
7
8
  ._4t3i14no{height:36px}
8
9
  ._bfhkvuon{background-color:var(--ds-surface,#fff)}
9
- ._u5f31b66{padding-right:var(--ds-space-050,4px)}
10
+ ._ca0q12x7{padding-top:var(--ds-space-075,6px)}
11
+ ._n3td12x7{padding-bottom:var(--ds-space-075,6px)}
12
+ ._u5f31b66{padding-right:var(--ds-space-050,4px)}
13
+ ._u5f3utpp{padding-right:var(--ds-space-150,9pt)}
@@ -2,15 +2,34 @@
2
2
  import "./Toolbar.compiled.css";
3
3
  import { ax, ix } from "@compiled/react/runtime";
4
4
  import React from 'react';
5
+ import { cx } from '@atlaskit/css';
5
6
  import { Box } from '@atlaskit/primitives/compiled';
6
7
  var styles = {
7
- toolbar: "_2rkoi2wt _bfhkvuon _u5f31b66 _19bv1b66 _16qs1cd0 _4t3i14no _1bsb184x _1e0c1txw _4cvr1h6o"
8
+ toolbarBase: "_2rkoi2wt _bfhkvuon _1e0c1txw _4cvr1h6o",
9
+ toolbar: "_4t3i14no _u5f31b66 _19bv1b66 _16qs1cd0",
10
+ primaryToolbar: "_bfhkvuon _1tkezwfg _ca0q12x7 _n3td12x7 _19bvutpp _u5f3utpp"
8
11
  };
12
+ /**
13
+ * A simple component representing a toolbar with box shadows - used to represent a secondary/floating toolbar
14
+ */
9
15
  export var Toolbar = function Toolbar(_ref) {
10
16
  var children = _ref.children,
11
17
  label = _ref.label;
12
18
  return /*#__PURE__*/React.createElement(Box, {
13
- xcss: styles.toolbar,
19
+ xcss: cx(styles.toolbarBase, styles.toolbar),
20
+ role: "toolbar",
21
+ "aria-label": label
22
+ }, children);
23
+ };
24
+
25
+ /**
26
+ * A simple component representing a toolbar without box shadows - used to represent a primary toolbar
27
+ */
28
+ export var PrimaryToolbar = function PrimaryToolbar(_ref2) {
29
+ var children = _ref2.children,
30
+ label = _ref2.label;
31
+ return /*#__PURE__*/React.createElement(Box, {
32
+ xcss: cx(styles.toolbarBase, styles.primaryToolbar),
14
33
  role: "toolbar",
15
34
  "aria-label": label
16
35
  }, children);