@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
@@ -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,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
  var 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
  var CustomDropdownMenuItemButton = /*#__PURE__*/forwardRef(function (_ref, ref) {
22
15
  var children = _ref.children,
@@ -46,8 +39,6 @@ export var ToolbarDropdownItem = function ToolbarDropdownItem(_ref2) {
46
39
  elemAfter = _ref2.elemAfter,
47
40
  isSelected = _ref2.isSelected,
48
41
  children = _ref2.children,
49
- _ref2$textStyle = _ref2.textStyle,
50
- textStyle = _ref2$textStyle === void 0 ? 'normal' : _ref2$textStyle,
51
42
  isDisabled = _ref2.isDisabled,
52
43
  hasNestedDropdownMenu = _ref2.hasNestedDropdownMenu,
53
44
  triggerRef = _ref2.triggerRef,
@@ -65,7 +56,5 @@ export var ToolbarDropdownItem = function ToolbarDropdownItem(_ref2) {
65
56
  ref: triggerRef,
66
57
  component: CustomDropdownMenuItemButton,
67
58
  testId: testId
68
- }, /*#__PURE__*/React.createElement(Box, {
69
- xcss: styles[textStyle]
70
- }, children));
59
+ }, children);
71
60
  };
@@ -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,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,4 +1,4 @@
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';
@@ -9,6 +9,7 @@ export { ToolbarSection } from './ui/ToolbarSection';
9
9
  export { ToolbarTooltip } from './ui/ToolbarTooltip';
10
10
  export { ToolbarNestedDropdownMenu } from './ui/ToolbarNestedDropdownMenu';
11
11
  export { ToolbarDropdownDivider } from './ui/ToolbarDropdownDivider';
12
+ export { ToolbarColorSwatch } from './ui/ToolbarColorSwatch';
12
13
  export { AIAdjustLengthIcon } from './ui/icons/AIAdjustLengthIcon';
13
14
  export { AIChatIcon } from './ui/icons/AIChatIcon';
14
15
  export { AIBriefcaseIcon } from './ui/icons/AIProfessionalIcon';
@@ -50,3 +51,4 @@ export { SubscriptIcon } from './ui/icons/SubscriptIcon';
50
51
  export { SuperscriptIcon } from './ui/icons/SuperscriptIcon';
51
52
  export { ShowMoreHorizontalIcon } from './ui/icons/ShowMoreHorizontal';
52
53
  export type { IconComponent, ToolbarButtonGroupLocation } from './types';
54
+ 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;
@@ -20,5 +20,5 @@ type ToolbarDropdownItemProps = {
20
20
  testId?: string;
21
21
  ariaKeyshortcuts?: string;
22
22
  };
23
- export declare const ToolbarDropdownItem: ({ onClick, elemBefore, elemAfter, isSelected, children, textStyle, isDisabled, hasNestedDropdownMenu, triggerRef, testId, ariaKeyshortcuts, }: ToolbarDropdownItemProps) => React.JSX.Element;
23
+ export declare const ToolbarDropdownItem: ({ onClick, elemBefore, elemAfter, isSelected, children, isDisabled, hasNestedDropdownMenu, triggerRef, testId, ariaKeyshortcuts, }: ToolbarDropdownItemProps) => React.JSX.Element;
24
24
  export {};
@@ -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,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,4 +1,4 @@
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';
@@ -9,6 +9,7 @@ export { ToolbarSection } from './ui/ToolbarSection';
9
9
  export { ToolbarTooltip } from './ui/ToolbarTooltip';
10
10
  export { ToolbarNestedDropdownMenu } from './ui/ToolbarNestedDropdownMenu';
11
11
  export { ToolbarDropdownDivider } from './ui/ToolbarDropdownDivider';
12
+ export { ToolbarColorSwatch } from './ui/ToolbarColorSwatch';
12
13
  export { AIAdjustLengthIcon } from './ui/icons/AIAdjustLengthIcon';
13
14
  export { AIChatIcon } from './ui/icons/AIChatIcon';
14
15
  export { AIBriefcaseIcon } from './ui/icons/AIProfessionalIcon';
@@ -50,3 +51,4 @@ export { SubscriptIcon } from './ui/icons/SubscriptIcon';
50
51
  export { SuperscriptIcon } from './ui/icons/SuperscriptIcon';
51
52
  export { ShowMoreHorizontalIcon } from './ui/icons/ShowMoreHorizontal';
52
53
  export type { IconComponent, ToolbarButtonGroupLocation } from './types';
54
+ 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;
@@ -20,5 +20,5 @@ type ToolbarDropdownItemProps = {
20
20
  testId?: string;
21
21
  ariaKeyshortcuts?: string;
22
22
  };
23
- export declare const ToolbarDropdownItem: ({ onClick, elemBefore, elemAfter, isSelected, children, textStyle, isDisabled, hasNestedDropdownMenu, triggerRef, testId, ariaKeyshortcuts, }: ToolbarDropdownItemProps) => React.JSX.Element;
23
+ export declare const ToolbarDropdownItem: ({ onClick, elemBefore, elemAfter, isSelected, children, isDisabled, hasNestedDropdownMenu, triggerRef, testId, ariaKeyshortcuts, }: ToolbarDropdownItemProps) => React.JSX.Element;
24
24
  export {};
@@ -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 {};
@@ -1,5 +1,6 @@
1
1
  import React, { useState } from 'react';
2
2
 
3
+ import { cssMap } from '@atlaskit/css';
3
4
  import { Box } from '@atlaskit/primitives/compiled';
4
5
  import Toggle from '@atlaskit/toggle';
5
6
  import { token } from '@atlaskit/tokens';
@@ -52,6 +53,27 @@ import { ToolbarTooltip } from '../../../src/ui/ToolbarTooltip';
52
53
 
53
54
  import { useExampleToolbarState } from './useExampleToolbarState';
54
55
 
56
+ const headingSizeStylesMap = cssMap({
57
+ xlarge: {
58
+ font: token('font.heading.xlarge'),
59
+ },
60
+ large: {
61
+ font: token('font.heading.large'),
62
+ },
63
+ medium: {
64
+ font: token('font.heading.medium'),
65
+ },
66
+ small: {
67
+ font: token('font.heading.small'),
68
+ },
69
+ xsmall: {
70
+ font: token('font.heading.xsmall'),
71
+ },
72
+ xxsmall: {
73
+ font: token('font.heading.xxsmall'),
74
+ },
75
+ });
76
+
55
77
  export const ExampleManuallyComposedToolbar = () => {
56
78
  const {
57
79
  textStyle,
@@ -271,7 +293,6 @@ export const ExampleManuallyComposedToolbar = () => {
271
293
  elemAfter={<ToolbarKeyboardShortcutHint shortcut="⌘⌥0" />}
272
294
  onClick={onClick('Normal text', onSetTextStyle('normal'))}
273
295
  isSelected={textStyle === 'normal'}
274
- textStyle="normal"
275
296
  ariaKeyshortcuts="⌘⌥0"
276
297
  >
277
298
  Normal text
@@ -281,20 +302,18 @@ export const ExampleManuallyComposedToolbar = () => {
281
302
  elemAfter={<ToolbarKeyboardShortcutHint shortcut="⌘⌥1" />}
282
303
  onClick={onClick('Heading one', onSetTextStyle('heading1'))}
283
304
  isSelected={textStyle === 'heading1'}
284
- textStyle="heading1"
285
305
  ariaKeyshortcuts="⌘⌥1"
286
306
  >
287
- Heading 1
307
+ <Box xcss={headingSizeStylesMap.xlarge}>Heading 1</Box>
288
308
  </ToolbarDropdownItem>
289
309
  <ToolbarDropdownItem
290
310
  elemBefore={<HeadingTwoIcon label="Heading Two" />}
291
311
  elemAfter={<ToolbarKeyboardShortcutHint shortcut="⌘⌥2" />}
292
312
  onClick={onClick('Heading two', onSetTextStyle('heading2'))}
293
313
  isSelected={textStyle === 'heading2'}
294
- textStyle="heading2"
295
314
  ariaKeyshortcuts="⌘⌥2"
296
315
  >
297
- Heading 2
316
+ <Box xcss={headingSizeStylesMap.large}>Heading 2</Box>
298
317
  </ToolbarDropdownItem>
299
318
  <ToolbarDropdownItem
300
319
  elemBefore={<HeadingThreeIcon label="Heading Three" />}
@@ -304,44 +323,40 @@ export const ExampleManuallyComposedToolbar = () => {
304
323
  textStyle="heading3"
305
324
  ariaKeyshortcuts="⌘⌥3"
306
325
  >
307
- Heading 3
326
+ <Box xcss={headingSizeStylesMap.medium}>Heading 3</Box>
308
327
  </ToolbarDropdownItem>
309
328
  <ToolbarDropdownItem
310
329
  elemBefore={<HeadingFourIcon label="Heading Four" />}
311
330
  elemAfter={<ToolbarKeyboardShortcutHint shortcut="⌘⌥4" />}
312
331
  onClick={onClick('Heading four', onSetTextStyle('heading4'))}
313
332
  isSelected={textStyle === 'heading4'}
314
- textStyle="heading4"
315
333
  ariaKeyshortcuts="⌘⌥4"
316
334
  >
317
- Heading 4
335
+ <Box xcss={headingSizeStylesMap.small}>Heading 4</Box>
318
336
  </ToolbarDropdownItem>
319
337
  <ToolbarDropdownItem
320
338
  elemBefore={<HeadingFiveIcon label="Heading Five" />}
321
339
  elemAfter={<ToolbarKeyboardShortcutHint shortcut="⌘⌥5" />}
322
340
  onClick={onClick('Heading five', onSetTextStyle('heading5'))}
323
341
  isSelected={textStyle === 'heading5'}
324
- textStyle="heading5"
325
342
  ariaKeyshortcuts="⌘⌥5"
326
343
  >
327
- Heading 5
344
+ <Box xcss={headingSizeStylesMap.xsmall}>Heading 5</Box>
328
345
  </ToolbarDropdownItem>
329
346
  <ToolbarDropdownItem
330
347
  elemBefore={<HeadingSixIcon label="Heading Six" />}
331
348
  elemAfter={<ToolbarKeyboardShortcutHint shortcut="⌘⌥6" />}
332
349
  onClick={onClick('Heading six', onSetTextStyle('heading6'))}
333
350
  isSelected={textStyle === 'heading6'}
334
- textStyle="heading6"
335
351
  ariaKeyshortcuts="⌘⌥6"
336
352
  >
337
- Heading 6
353
+ <Box xcss={headingSizeStylesMap.xxsmall}>Heading 6</Box>
338
354
  </ToolbarDropdownItem>
339
355
  <ToolbarDropdownItem
340
356
  elemBefore={<QuoteIcon label="Quote" />}
341
357
  elemAfter={<ToolbarKeyboardShortcutHint shortcut="⌘⌥9" />}
342
358
  onClick={onClick('Quote', onSetTextStyle('quote'))}
343
359
  isSelected={textStyle === 'quote'}
344
- textStyle="normal"
345
360
  ariaKeyshortcuts="⌘⌥9"
346
361
  >
347
362
  Quote
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "registry": "https://registry.npmjs.org/"
5
5
  },
6
- "version": "0.1.0",
6
+ "version": "0.2.0",
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,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
 
14
15
  export { AIAdjustLengthIcon } from './ui/icons/AIAdjustLengthIcon';
15
16
  export { AIChatIcon } from './ui/icons/AIChatIcon';
@@ -53,3 +54,5 @@ export { SuperscriptIcon } from './ui/icons/SuperscriptIcon';
53
54
  export { ShowMoreHorizontalIcon } from './ui/icons/ShowMoreHorizontal';
54
55
 
55
56
  export type { IconComponent, ToolbarButtonGroupLocation } from './types';
57
+
58
+ 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}
@@ -3,7 +3,7 @@ import React, { type ReactNode, forwardRef, type Ref } from 'react';
3
3
  import { cssMap, cx } from '@atlaskit/css';
4
4
  import { DropdownItem } from '@atlaskit/dropdown-menu';
5
5
  import type { CustomItemComponentProps } from '@atlaskit/menu/types';
6
- import { Box, Pressable } from '@atlaskit/primitives/compiled';
6
+ import { Pressable } from '@atlaskit/primitives/compiled';
7
7
  import { token } from '@atlaskit/tokens';
8
8
 
9
9
  type TextStyle =
@@ -50,27 +50,6 @@ const styles = cssMap({
50
50
  backgroundColor: token('color.background.selected.pressed'),
51
51
  },
52
52
  },
53
- normal: {
54
- font: token('font.body'),
55
- },
56
- heading1: {
57
- font: token('font.heading.xlarge'),
58
- },
59
- heading2: {
60
- font: token('font.heading.large'),
61
- },
62
- heading3: {
63
- font: token('font.heading.medium'),
64
- },
65
- heading4: {
66
- font: token('font.heading.small'),
67
- },
68
- heading5: {
69
- font: token('font.heading.xsmall'),
70
- },
71
- heading6: {
72
- font: token('font.heading.xxsmall'),
73
- },
74
53
  });
75
54
 
76
55
  export type CustomDropdownMenuItemButtonProps = CustomItemComponentProps & {
@@ -137,7 +116,6 @@ export const ToolbarDropdownItem = ({
137
116
  elemAfter,
138
117
  isSelected,
139
118
  children,
140
- textStyle = 'normal',
141
119
  isDisabled,
142
120
  hasNestedDropdownMenu,
143
121
  triggerRef,
@@ -157,6 +135,6 @@ export const ToolbarDropdownItem = ({
157
135
  component={CustomDropdownMenuItemButton}
158
136
  testId={testId}
159
137
  >
160
- <Box xcss={styles[textStyle]}>{children}</Box>
138
+ {children}
161
139
  </DropdownItem>
162
140
  );