@atlaskit/editor-toolbar 0.1.1 → 0.2.1

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 (61) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/afm-passionfruit/tsconfig.json +54 -0
  3. package/dist/cjs/hooks/ui-context.js +35 -0
  4. package/dist/cjs/index.js +42 -2
  5. package/dist/cjs/ui/Toolbar.compiled.css +6 -2
  6. package/dist/cjs/ui/Toolbar.js +22 -3
  7. package/dist/cjs/ui/ToolbarButton.js +9 -1
  8. package/dist/cjs/ui/ToolbarDropdownMenu.js +5 -1
  9. package/dist/cjs/ui/ToolbarSection.js +4 -2
  10. package/dist/cjs/ui/icons/AlignTextCenterIcon.js +13 -0
  11. package/dist/cjs/ui/icons/AlignTextLeftIcon.js +13 -0
  12. package/dist/cjs/ui/icons/AlignTextRightIcon.js +13 -0
  13. package/dist/es2019/hooks/ui-context.js +28 -0
  14. package/dist/es2019/index.js +7 -3
  15. package/dist/es2019/ui/Toolbar.compiled.css +6 -2
  16. package/dist/es2019/ui/Toolbar.js +22 -2
  17. package/dist/es2019/ui/ToolbarButton.js +10 -1
  18. package/dist/es2019/ui/ToolbarDropdownMenu.js +6 -1
  19. package/dist/es2019/ui/ToolbarSection.js +4 -2
  20. package/dist/es2019/ui/icons/AlignTextCenterIcon.js +2 -0
  21. package/dist/es2019/ui/icons/AlignTextLeftIcon.js +2 -0
  22. package/dist/es2019/ui/icons/AlignTextRightIcon.js +2 -0
  23. package/dist/esm/hooks/ui-context.js +27 -0
  24. package/dist/esm/index.js +7 -3
  25. package/dist/esm/ui/Toolbar.compiled.css +6 -2
  26. package/dist/esm/ui/Toolbar.js +21 -2
  27. package/dist/esm/ui/ToolbarButton.js +9 -1
  28. package/dist/esm/ui/ToolbarDropdownMenu.js +5 -1
  29. package/dist/esm/ui/ToolbarSection.js +4 -2
  30. package/dist/esm/ui/icons/AlignTextCenterIcon.js +2 -0
  31. package/dist/esm/ui/icons/AlignTextLeftIcon.js +2 -0
  32. package/dist/esm/ui/icons/AlignTextRightIcon.js +2 -0
  33. package/dist/types/hooks/ui-context.d.ts +23 -0
  34. package/dist/types/index.d.ts +6 -2
  35. package/dist/types/types.d.ts +0 -1
  36. package/dist/types/ui/Toolbar.d.ts +7 -0
  37. package/dist/types/ui/ToolbarDropdownDivider.d.ts +0 -1
  38. package/dist/types/ui/ToolbarSection.d.ts +2 -1
  39. package/dist/types/ui/icons/AlignTextCenterIcon.d.ts +1 -0
  40. package/dist/types/ui/icons/AlignTextLeftIcon.d.ts +1 -0
  41. package/dist/types/ui/icons/AlignTextRightIcon.d.ts +1 -0
  42. package/dist/types-ts4.5/hooks/ui-context.d.ts +23 -0
  43. package/dist/types-ts4.5/index.d.ts +6 -2
  44. package/dist/types-ts4.5/types.d.ts +0 -1
  45. package/dist/types-ts4.5/ui/Toolbar.d.ts +7 -0
  46. package/dist/types-ts4.5/ui/ToolbarDropdownDivider.d.ts +0 -1
  47. package/dist/types-ts4.5/ui/ToolbarSection.d.ts +2 -1
  48. package/dist/types-ts4.5/ui/icons/AlignTextCenterIcon.d.ts +1 -0
  49. package/dist/types-ts4.5/ui/icons/AlignTextLeftIcon.d.ts +1 -0
  50. package/dist/types-ts4.5/ui/icons/AlignTextRightIcon.d.ts +1 -0
  51. package/examples/toolbar/examples/ExampleManuallyComposedToolbar.tsx +11 -11
  52. package/package.json +2 -2
  53. package/src/hooks/ui-context.tsx +51 -0
  54. package/src/index.ts +7 -2
  55. package/src/ui/Toolbar.tsx +31 -8
  56. package/src/ui/ToolbarButton.tsx +8 -0
  57. package/src/ui/ToolbarDropdownMenu.tsx +4 -0
  58. package/src/ui/ToolbarSection.tsx +7 -2
  59. package/src/ui/icons/AlignTextCenterIcon.tsx +2 -0
  60. package/src/ui/icons/AlignTextLeftIcon.tsx +2 -0
  61. package/src/ui/icons/AlignTextRightIcon.tsx +2 -0
@@ -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);
@@ -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
  var styles = {
8
9
  button: "_zulp12x7 _2rkoiti9 _1e0c1txw _bfhksm61 _o5721q9c _4cvr1h6o _1bah1h6o _1tke1f4h _syaz1gjq _k48p1wq8 _19bvu2gc _u5f3u2gc _1ah3idpf _g0pbkb7n _oh03h2mm",
9
10
  enabled: "_irr3166n _1di61dty",
@@ -29,6 +30,8 @@ export var ToolbarButton = /*#__PURE__*/forwardRef(function (_ref, ref) {
29
30
  isDisabled = _ref.isDisabled,
30
31
  ariaKeyshortcuts = _ref.ariaKeyshortcuts,
31
32
  label = _ref.label;
33
+ var _useToolbarUI = useToolbarUI(),
34
+ preventDefaultOnMouseDown = _useToolbarUI.preventDefaultOnMouseDown;
32
35
  return /*#__PURE__*/React.createElement(Pressable, {
33
36
  ref: ref,
34
37
  xcss: cx(styles.button, isDisabled ? styles.disabled : isSelected ? styles.selected : styles.enabled, groupLocation === 'start' && styles.groupStart, groupLocation === 'middle' && styles.groupMiddle, groupLocation === 'end' && styles.groupEnd),
@@ -43,6 +46,11 @@ export var ToolbarButton = /*#__PURE__*/forwardRef(function (_ref, ref) {
43
46
  onBlur: onBlur,
44
47
  onFocus: onFocus,
45
48
  testId: testId,
46
- isDisabled: isDisabled
49
+ isDisabled: isDisabled,
50
+ onMouseDown: function onMouseDown(event) {
51
+ if (preventDefaultOnMouseDown) {
52
+ event.preventDefault();
53
+ }
54
+ }
47
55
  }, iconBefore, children);
48
56
  });
@@ -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 var ToolbarDropdownMenu = function ToolbarDropdownMenu(_ref) {
5
6
  var iconBefore = _ref.iconBefore,
@@ -8,6 +9,8 @@ export var ToolbarDropdownMenu = function ToolbarDropdownMenu(_ref) {
8
9
  isDisabled = _ref.isDisabled,
9
10
  testId = _ref.testId,
10
11
  label = _ref.label;
12
+ var _useToolbarUI = useToolbarUI(),
13
+ onDropdownOpenChanged = _useToolbarUI.onDropdownOpenChanged;
11
14
  return /*#__PURE__*/React.createElement(DropdownMenu, {
12
15
  trigger: function trigger(triggerProps) {
13
16
  return /*#__PURE__*/React.createElement(ToolbarButton, {
@@ -25,6 +28,7 @@ export var ToolbarDropdownMenu = function ToolbarDropdownMenu(_ref) {
25
28
  isDisabled: isDisabled,
26
29
  label: label
27
30
  });
28
- }
31
+ },
32
+ onOpenChange: onDropdownOpenChanged
29
33
  }, children);
30
34
  };
@@ -7,8 +7,10 @@ var styles = {
7
7
  container: "_1e0c1txw _4cvr1h6o"
8
8
  };
9
9
  export var ToolbarSection = function ToolbarSection(_ref) {
10
- var children = _ref.children;
10
+ var children = _ref.children,
11
+ testId = _ref.testId;
11
12
  return /*#__PURE__*/React.createElement(Box, {
12
- xcss: styles.container
13
+ xcss: styles.container,
14
+ testId: testId
13
15
  }, children);
14
16
  };
@@ -0,0 +1,2 @@
1
+ /* eslint-disable @atlaskit/editor/no-re-export */
2
+ export { default as AlignTextCenterIcon } from '@atlaskit/icon/core/align-text-center';
@@ -0,0 +1,2 @@
1
+ /* eslint-disable @atlaskit/editor/no-re-export */
2
+ export { default as AlignTextLeftIcon } from '@atlaskit/icon/core/align-text-left';
@@ -0,0 +1,2 @@
1
+ /* eslint-disable @atlaskit/editor/no-re-export */
2
+ export { default as AlignTextRightIcon } from '@atlaskit/icon/core/align-text-right';
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import type { OnOpenChangeArgs } from '@atlaskit/dropdown-menu';
3
+ type ToolbarUIContextType = {
4
+ /**
5
+ * Callback for when the dropdown is open/closed. Receives an object with `isOpen` state.
6
+ *
7
+ * If the dropdown was closed programmatically, the `event` parameter will be `null`.
8
+ */
9
+ onDropdownOpenChanged: (args: OnOpenChangeArgs) => void;
10
+ /**
11
+ * Whether to prevent default behavior on mouse down events on ToolbarButton.
12
+ */
13
+ preventDefaultOnMouseDown?: boolean;
14
+ };
15
+ /**
16
+ * Access consumer specific config and state within a toolbar component
17
+ */
18
+ export declare const useToolbarUI: () => ToolbarUIContextType;
19
+ type ToolbarUIProviderProps = {
20
+ children: React.ReactNode;
21
+ } & ToolbarUIContextType;
22
+ export declare const ToolbarUIProvider: ({ children, onDropdownOpenChanged, preventDefaultOnMouseDown, }: ToolbarUIProviderProps) => React.JSX.Element;
23
+ export {};
@@ -1,13 +1,13 @@
1
- export { Toolbar } from './ui/Toolbar';
1
+ export { Toolbar, PrimaryToolbar } from './ui/Toolbar';
2
2
  export { ToolbarButton } from './ui/ToolbarButton';
3
3
  export { ToolbarButtonGroup } from './ui/ToolbarButtonGroup';
4
4
  export { ToolbarDropdownMenu } from './ui/ToolbarDropdownMenu';
5
5
  export { ToolbarDropdownItem } from './ui/ToolbarDropdownItem';
6
6
  export { ToolbarDropdownItemSection } from './ui/ToolbarDropdownItemSection';
7
+ export { ToolbarNestedDropdownMenu } from './ui/ToolbarNestedDropdownMenu';
7
8
  export { ToolbarKeyboardShortcutHint } from './ui/ToolbarKeyboardShortcutHint';
8
9
  export { ToolbarSection } from './ui/ToolbarSection';
9
10
  export { ToolbarTooltip } from './ui/ToolbarTooltip';
10
- export { ToolbarNestedDropdownMenu } from './ui/ToolbarNestedDropdownMenu';
11
11
  export { ToolbarDropdownDivider } from './ui/ToolbarDropdownDivider';
12
12
  export { ToolbarColorSwatch } from './ui/ToolbarColorSwatch';
13
13
  export { AIAdjustLengthIcon } from './ui/icons/AIAdjustLengthIcon';
@@ -50,4 +50,8 @@ export { CodeIcon } from './ui/icons/CodeIcon';
50
50
  export { SubscriptIcon } from './ui/icons/SubscriptIcon';
51
51
  export { SuperscriptIcon } from './ui/icons/SuperscriptIcon';
52
52
  export { ShowMoreHorizontalIcon } from './ui/icons/ShowMoreHorizontal';
53
+ export { AlignTextLeftIcon } from './ui/icons/AlignTextLeftIcon';
54
+ export { AlignTextCenterIcon } from './ui/icons/AlignTextCenterIcon';
55
+ export { AlignTextRightIcon } from './ui/icons/AlignTextRightIcon';
53
56
  export type { IconComponent, ToolbarButtonGroupLocation } from './types';
57
+ export { useToolbarUI, ToolbarUIProvider } from './hooks/ui-context';
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type NewCoreIconProps } from '@atlaskit/icon';
3
2
  export type ToolbarButtonGroupLocation = 'start' | 'middle' | 'end';
4
3
  export type IconComponent = (props: NewCoreIconProps) => JSX.Element;
@@ -3,5 +3,12 @@ type ToolbarProps = {
3
3
  children?: ReactNode;
4
4
  label: string;
5
5
  };
6
+ /**
7
+ * A simple component representing a toolbar with box shadows - used to represent a secondary/floating toolbar
8
+ */
6
9
  export declare const Toolbar: ({ children, label }: ToolbarProps) => React.JSX.Element;
10
+ /**
11
+ * A simple component representing a toolbar without box shadows - used to represent a primary toolbar
12
+ */
13
+ export declare const PrimaryToolbar: ({ children, label }: ToolbarProps) => React.JSX.Element;
7
14
  export {};
@@ -1,2 +1 @@
1
- /// <reference types="react" />
2
1
  export declare const ToolbarDropdownDivider: () => JSX.Element;
@@ -1,6 +1,7 @@
1
1
  import React, { type ReactNode } from 'react';
2
2
  type ToolbarSectionProps = {
3
3
  children?: ReactNode;
4
+ testId?: string;
4
5
  };
5
- export declare const ToolbarSection: ({ children }: ToolbarSectionProps) => React.JSX.Element;
6
+ export declare const ToolbarSection: ({ children, testId }: ToolbarSectionProps) => React.JSX.Element;
6
7
  export {};
@@ -0,0 +1 @@
1
+ export { default as AlignTextCenterIcon } from '@atlaskit/icon/core/align-text-center';
@@ -0,0 +1 @@
1
+ export { default as AlignTextLeftIcon } from '@atlaskit/icon/core/align-text-left';
@@ -0,0 +1 @@
1
+ export { default as AlignTextRightIcon } from '@atlaskit/icon/core/align-text-right';
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import type { OnOpenChangeArgs } from '@atlaskit/dropdown-menu';
3
+ type ToolbarUIContextType = {
4
+ /**
5
+ * Callback for when the dropdown is open/closed. Receives an object with `isOpen` state.
6
+ *
7
+ * If the dropdown was closed programmatically, the `event` parameter will be `null`.
8
+ */
9
+ onDropdownOpenChanged: (args: OnOpenChangeArgs) => void;
10
+ /**
11
+ * Whether to prevent default behavior on mouse down events on ToolbarButton.
12
+ */
13
+ preventDefaultOnMouseDown?: boolean;
14
+ };
15
+ /**
16
+ * Access consumer specific config and state within a toolbar component
17
+ */
18
+ export declare const useToolbarUI: () => ToolbarUIContextType;
19
+ type ToolbarUIProviderProps = {
20
+ children: React.ReactNode;
21
+ } & ToolbarUIContextType;
22
+ export declare const ToolbarUIProvider: ({ children, onDropdownOpenChanged, preventDefaultOnMouseDown, }: ToolbarUIProviderProps) => React.JSX.Element;
23
+ export {};
@@ -1,13 +1,13 @@
1
- export { Toolbar } from './ui/Toolbar';
1
+ export { Toolbar, PrimaryToolbar } from './ui/Toolbar';
2
2
  export { ToolbarButton } from './ui/ToolbarButton';
3
3
  export { ToolbarButtonGroup } from './ui/ToolbarButtonGroup';
4
4
  export { ToolbarDropdownMenu } from './ui/ToolbarDropdownMenu';
5
5
  export { ToolbarDropdownItem } from './ui/ToolbarDropdownItem';
6
6
  export { ToolbarDropdownItemSection } from './ui/ToolbarDropdownItemSection';
7
+ export { ToolbarNestedDropdownMenu } from './ui/ToolbarNestedDropdownMenu';
7
8
  export { ToolbarKeyboardShortcutHint } from './ui/ToolbarKeyboardShortcutHint';
8
9
  export { ToolbarSection } from './ui/ToolbarSection';
9
10
  export { ToolbarTooltip } from './ui/ToolbarTooltip';
10
- export { ToolbarNestedDropdownMenu } from './ui/ToolbarNestedDropdownMenu';
11
11
  export { ToolbarDropdownDivider } from './ui/ToolbarDropdownDivider';
12
12
  export { ToolbarColorSwatch } from './ui/ToolbarColorSwatch';
13
13
  export { AIAdjustLengthIcon } from './ui/icons/AIAdjustLengthIcon';
@@ -50,4 +50,8 @@ export { CodeIcon } from './ui/icons/CodeIcon';
50
50
  export { SubscriptIcon } from './ui/icons/SubscriptIcon';
51
51
  export { SuperscriptIcon } from './ui/icons/SuperscriptIcon';
52
52
  export { ShowMoreHorizontalIcon } from './ui/icons/ShowMoreHorizontal';
53
+ export { AlignTextLeftIcon } from './ui/icons/AlignTextLeftIcon';
54
+ export { AlignTextCenterIcon } from './ui/icons/AlignTextCenterIcon';
55
+ export { AlignTextRightIcon } from './ui/icons/AlignTextRightIcon';
53
56
  export type { IconComponent, ToolbarButtonGroupLocation } from './types';
57
+ export { useToolbarUI, ToolbarUIProvider } from './hooks/ui-context';
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type NewCoreIconProps } from '@atlaskit/icon';
3
2
  export type ToolbarButtonGroupLocation = 'start' | 'middle' | 'end';
4
3
  export type IconComponent = (props: NewCoreIconProps) => JSX.Element;
@@ -3,5 +3,12 @@ type ToolbarProps = {
3
3
  children?: ReactNode;
4
4
  label: string;
5
5
  };
6
+ /**
7
+ * A simple component representing a toolbar with box shadows - used to represent a secondary/floating toolbar
8
+ */
6
9
  export declare const Toolbar: ({ children, label }: ToolbarProps) => React.JSX.Element;
10
+ /**
11
+ * A simple component representing a toolbar without box shadows - used to represent a primary toolbar
12
+ */
13
+ export declare const PrimaryToolbar: ({ children, label }: ToolbarProps) => React.JSX.Element;
7
14
  export {};
@@ -1,2 +1 @@
1
- /// <reference types="react" />
2
1
  export declare const ToolbarDropdownDivider: () => JSX.Element;
@@ -1,6 +1,7 @@
1
1
  import React, { type ReactNode } from 'react';
2
2
  type ToolbarSectionProps = {
3
3
  children?: ReactNode;
4
+ testId?: string;
4
5
  };
5
- export declare const ToolbarSection: ({ children }: ToolbarSectionProps) => React.JSX.Element;
6
+ export declare const ToolbarSection: ({ children, testId }: ToolbarSectionProps) => React.JSX.Element;
6
7
  export {};
@@ -0,0 +1 @@
1
+ export { default as AlignTextCenterIcon } from '@atlaskit/icon/core/align-text-center';
@@ -0,0 +1 @@
1
+ export { default as AlignTextLeftIcon } from '@atlaskit/icon/core/align-text-left';
@@ -0,0 +1 @@
1
+ export { default as AlignTextRightIcon } from '@atlaskit/icon/core/align-text-right';
@@ -54,23 +54,23 @@ import { ToolbarTooltip } from '../../../src/ui/ToolbarTooltip';
54
54
  import { useExampleToolbarState } from './useExampleToolbarState';
55
55
 
56
56
  const headingSizeStylesMap = cssMap({
57
- xlarge: {
57
+ xlarge: {
58
58
  font: token('font.heading.xlarge'),
59
59
  },
60
- large: {
61
- font: token('font.heading.large')
60
+ large: {
61
+ font: token('font.heading.large'),
62
62
  },
63
- medium: {
64
- font: token('font.heading.medium')
63
+ medium: {
64
+ font: token('font.heading.medium'),
65
65
  },
66
- small: {
67
- font: token('font.heading.small')
66
+ small: {
67
+ font: token('font.heading.small'),
68
68
  },
69
- xsmall: {
70
- font: token('font.heading.xsmall')
69
+ xsmall: {
70
+ font: token('font.heading.xsmall'),
71
71
  },
72
- xxsmall: {
73
- font: token('font.heading.xxsmall')
72
+ xxsmall: {
73
+ font: token('font.heading.xxsmall'),
74
74
  },
75
75
  });
76
76
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "registry": "https://registry.npmjs.org/"
5
5
  },
6
- "version": "0.1.1",
6
+ "version": "0.2.1",
7
7
  "description": "Common UI for Toolbars across the platform",
8
8
  "atlassian": {
9
9
  "team": "Editor: Jenga",
@@ -28,7 +28,7 @@
28
28
  "@atlaskit/button": "^23.3.0",
29
29
  "@atlaskit/css": "^0.12.0",
30
30
  "@atlaskit/dropdown-menu": "^16.3.0",
31
- "@atlaskit/icon": "^27.10.0",
31
+ "@atlaskit/icon": "^27.11.0",
32
32
  "@atlaskit/icon-lab": "^5.4.0",
33
33
  "@atlaskit/logo": "^19.6.0",
34
34
  "@atlaskit/popup": "^4.3.0",
@@ -0,0 +1,51 @@
1
+ import React, { createContext, useContext } from 'react';
2
+
3
+ import type { OnOpenChangeArgs } from '@atlaskit/dropdown-menu';
4
+
5
+ type ToolbarUIContextType = {
6
+ /**
7
+ * Callback for when the dropdown is open/closed. Receives an object with `isOpen` state.
8
+ *
9
+ * If the dropdown was closed programmatically, the `event` parameter will be `null`.
10
+ */
11
+ onDropdownOpenChanged: (args: OnOpenChangeArgs) => void;
12
+
13
+ /**
14
+ * Whether to prevent default behavior on mouse down events on ToolbarButton.
15
+ */
16
+ preventDefaultOnMouseDown?: boolean;
17
+ };
18
+
19
+ const ToolbarUIContext = createContext<ToolbarUIContextType>({
20
+ onDropdownOpenChanged: () => {},
21
+ preventDefaultOnMouseDown: false,
22
+ });
23
+
24
+ /**
25
+ * Access consumer specific config and state within a toolbar component
26
+ */
27
+ export const useToolbarUI = () => {
28
+ const context = useContext(ToolbarUIContext);
29
+
30
+ if (!context) {
31
+ throw new Error('useToolbarUI must be used within ToolbarUIContext');
32
+ }
33
+
34
+ return context;
35
+ };
36
+
37
+ type ToolbarUIProviderProps = {
38
+ children: React.ReactNode;
39
+ } & ToolbarUIContextType;
40
+
41
+ export const ToolbarUIProvider = ({
42
+ children,
43
+ onDropdownOpenChanged,
44
+ preventDefaultOnMouseDown,
45
+ }: ToolbarUIProviderProps) => {
46
+ return (
47
+ <ToolbarUIContext.Provider value={{ onDropdownOpenChanged, preventDefaultOnMouseDown }}>
48
+ {children}
49
+ </ToolbarUIContext.Provider>
50
+ );
51
+ };
package/src/index.ts CHANGED
@@ -1,14 +1,14 @@
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';
6
6
  export { ToolbarDropdownItem } from './ui/ToolbarDropdownItem';
7
7
  export { ToolbarDropdownItemSection } from './ui/ToolbarDropdownItemSection';
8
+ export { ToolbarNestedDropdownMenu } from './ui/ToolbarNestedDropdownMenu';
8
9
  export { ToolbarKeyboardShortcutHint } from './ui/ToolbarKeyboardShortcutHint';
9
10
  export { ToolbarSection } from './ui/ToolbarSection';
10
11
  export { ToolbarTooltip } from './ui/ToolbarTooltip';
11
- export { ToolbarNestedDropdownMenu } from './ui/ToolbarNestedDropdownMenu';
12
12
  export { ToolbarDropdownDivider } from './ui/ToolbarDropdownDivider';
13
13
  export { ToolbarColorSwatch } from './ui/ToolbarColorSwatch';
14
14
 
@@ -52,5 +52,10 @@ export { CodeIcon } from './ui/icons/CodeIcon';
52
52
  export { SubscriptIcon } from './ui/icons/SubscriptIcon';
53
53
  export { SuperscriptIcon } from './ui/icons/SuperscriptIcon';
54
54
  export { ShowMoreHorizontalIcon } from './ui/icons/ShowMoreHorizontal';
55
+ export { AlignTextLeftIcon } from './ui/icons/AlignTextLeftIcon';
56
+ export { AlignTextCenterIcon } from './ui/icons/AlignTextCenterIcon';
57
+ export { AlignTextRightIcon } from './ui/icons/AlignTextRightIcon';
55
58
 
56
59
  export type { IconComponent, ToolbarButtonGroupLocation } from './types';
60
+
61
+ export { useToolbarUI, ToolbarUIProvider } from './hooks/ui-context';
@@ -1,21 +1,30 @@
1
1
  import React, { type ReactNode } from 'react';
2
2
 
3
- import { cssMap } from '@atlaskit/css';
3
+ import { cssMap, cx } from '@atlaskit/css';
4
4
  import { Box } from '@atlaskit/primitives/compiled';
5
5
  import { token } from '@atlaskit/tokens';
6
6
 
7
7
  const styles = cssMap({
8
- toolbar: {
8
+ toolbarBase: {
9
9
  backgroundColor: token('elevation.surface'),
10
- paddingRight: token('space.050'),
11
- paddingLeft: token('space.050'),
12
- boxShadow: token('elevation.shadow.overlay'),
13
10
  borderRadius: '6px',
14
- height: '36px',
15
- width: 'min-content',
16
11
  display: 'flex',
17
12
  alignItems: 'center',
18
13
  },
14
+ toolbar: {
15
+ height: '36px',
16
+ paddingRight: token('space.050'),
17
+ paddingLeft: token('space.050'),
18
+ boxShadow: token('elevation.shadow.overlay'),
19
+ },
20
+ primaryToolbar: {
21
+ backgroundColor: token('elevation.surface'),
22
+ minHeight: '32px',
23
+ paddingTop: token('space.075'),
24
+ paddingBottom: token('space.075'),
25
+ paddingLeft: token('space.150'),
26
+ paddingRight: token('space.150'),
27
+ },
19
28
  });
20
29
 
21
30
  type ToolbarProps = {
@@ -23,9 +32,23 @@ type ToolbarProps = {
23
32
  label: string;
24
33
  };
25
34
 
35
+ /**
36
+ * A simple component representing a toolbar with box shadows - used to represent a secondary/floating toolbar
37
+ */
26
38
  export const Toolbar = ({ children, label }: ToolbarProps) => {
27
39
  return (
28
- <Box xcss={styles.toolbar} role="toolbar" aria-label={label}>
40
+ <Box xcss={cx(styles.toolbarBase, styles.toolbar)} role="toolbar" aria-label={label}>
41
+ {children}
42
+ </Box>
43
+ );
44
+ };
45
+
46
+ /**
47
+ * A simple component representing a toolbar without box shadows - used to represent a primary toolbar
48
+ */
49
+ export const PrimaryToolbar = ({ children, label }: ToolbarProps) => {
50
+ return (
51
+ <Box xcss={cx(styles.toolbarBase, styles.primaryToolbar)} role="toolbar" aria-label={label}>
29
52
  {children}
30
53
  </Box>
31
54
  );
@@ -5,6 +5,7 @@ import { type TriggerProps } from '@atlaskit/popup';
5
5
  import { Pressable } from '@atlaskit/primitives/compiled';
6
6
  import { token } from '@atlaskit/tokens';
7
7
 
8
+ import { useToolbarUI } from '../hooks/ui-context';
8
9
  import { type ToolbarButtonGroupLocation } from '../types';
9
10
 
10
11
  const styles = cssMap({
@@ -108,6 +109,8 @@ export const ToolbarButton = forwardRef(
108
109
  }: ToolbarButtonProps,
109
110
  ref: Ref<HTMLButtonElement>,
110
111
  ) => {
112
+ const { preventDefaultOnMouseDown } = useToolbarUI();
113
+
111
114
  return (
112
115
  <Pressable
113
116
  ref={ref}
@@ -130,6 +133,11 @@ export const ToolbarButton = forwardRef(
130
133
  onFocus={onFocus}
131
134
  testId={testId}
132
135
  isDisabled={isDisabled}
136
+ onMouseDown={(event) => {
137
+ if (preventDefaultOnMouseDown) {
138
+ event.preventDefault();
139
+ }
140
+ }}
133
141
  >
134
142
  {iconBefore}
135
143
  {children}
@@ -2,6 +2,7 @@ import React, { type ReactNode } from 'react';
2
2
 
3
3
  import DropdownMenu from '@atlaskit/dropdown-menu';
4
4
 
5
+ import { useToolbarUI } from '../hooks/ui-context';
5
6
  import { type ToolbarButtonGroupLocation } from '../types';
6
7
 
7
8
  import { ToolbarButton } from './ToolbarButton';
@@ -23,6 +24,8 @@ export const ToolbarDropdownMenu = ({
23
24
  testId,
24
25
  label,
25
26
  }: ToolbarDropdownMenuProps) => {
27
+ const { onDropdownOpenChanged } = useToolbarUI();
28
+
26
29
  return (
27
30
  <DropdownMenu<HTMLButtonElement>
28
31
  trigger={(triggerProps) => (
@@ -42,6 +45,7 @@ export const ToolbarDropdownMenu = ({
42
45
  label={label}
43
46
  />
44
47
  )}
48
+ onOpenChange={onDropdownOpenChanged}
45
49
  >
46
50
  {children}
47
51
  </DropdownMenu>
@@ -12,8 +12,13 @@ const styles = cssMap({
12
12
 
13
13
  type ToolbarSectionProps = {
14
14
  children?: ReactNode;
15
+ testId?: string;
15
16
  };
16
17
 
17
- export const ToolbarSection = ({ children }: ToolbarSectionProps) => {
18
- return <Box xcss={styles.container}>{children}</Box>;
18
+ export const ToolbarSection = ({ children, testId }: ToolbarSectionProps) => {
19
+ return (
20
+ <Box xcss={styles.container} testId={testId}>
21
+ {children}
22
+ </Box>
23
+ );
19
24
  };
@@ -0,0 +1,2 @@
1
+ /* eslint-disable @atlaskit/editor/no-re-export */
2
+ export { default as AlignTextCenterIcon } from '@atlaskit/icon/core/align-text-center';
@@ -0,0 +1,2 @@
1
+ /* eslint-disable @atlaskit/editor/no-re-export */
2
+ export { default as AlignTextLeftIcon } from '@atlaskit/icon/core/align-text-left';
@@ -0,0 +1,2 @@
1
+ /* eslint-disable @atlaskit/editor/no-re-export */
2
+ export { default as AlignTextRightIcon } from '@atlaskit/icon/core/align-text-right';