@atlaskit/editor-toolbar 0.1.1 → 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.
- package/CHANGELOG.md +21 -0
- package/dist/cjs/hooks/ui-context.js +35 -0
- package/dist/cjs/index.js +20 -1
- package/dist/cjs/ui/Toolbar.compiled.css +6 -2
- package/dist/cjs/ui/Toolbar.js +22 -3
- package/dist/cjs/ui/ToolbarButton.js +9 -1
- package/dist/cjs/ui/ToolbarDropdownMenu.js +5 -1
- package/dist/cjs/ui/ToolbarSection.js +4 -2
- package/dist/es2019/hooks/ui-context.js +28 -0
- package/dist/es2019/index.js +3 -2
- package/dist/es2019/ui/Toolbar.compiled.css +6 -2
- package/dist/es2019/ui/Toolbar.js +22 -2
- package/dist/es2019/ui/ToolbarButton.js +10 -1
- package/dist/es2019/ui/ToolbarDropdownMenu.js +6 -1
- package/dist/es2019/ui/ToolbarSection.js +4 -2
- package/dist/esm/hooks/ui-context.js +27 -0
- package/dist/esm/index.js +3 -2
- package/dist/esm/ui/Toolbar.compiled.css +6 -2
- package/dist/esm/ui/Toolbar.js +21 -2
- package/dist/esm/ui/ToolbarButton.js +9 -1
- package/dist/esm/ui/ToolbarDropdownMenu.js +5 -1
- package/dist/esm/ui/ToolbarSection.js +4 -2
- package/dist/types/hooks/ui-context.d.ts +23 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/types.d.ts +0 -1
- package/dist/types/ui/Toolbar.d.ts +7 -0
- package/dist/types/ui/ToolbarDropdownDivider.d.ts +0 -1
- package/dist/types/ui/ToolbarSection.d.ts +2 -1
- package/dist/types-ts4.5/hooks/ui-context.d.ts +23 -0
- package/dist/types-ts4.5/index.d.ts +2 -1
- package/dist/types-ts4.5/types.d.ts +0 -1
- package/dist/types-ts4.5/ui/Toolbar.d.ts +7 -0
- package/dist/types-ts4.5/ui/ToolbarDropdownDivider.d.ts +0 -1
- package/dist/types-ts4.5/ui/ToolbarSection.d.ts +2 -1
- package/examples/toolbar/examples/ExampleManuallyComposedToolbar.tsx +11 -11
- package/package.json +2 -2
- package/src/hooks/ui-context.tsx +51 -0
- package/src/index.ts +3 -1
- package/src/ui/Toolbar.tsx +31 -8
- package/src/ui/ToolbarButton.tsx +8 -0
- package/src/ui/ToolbarDropdownMenu.tsx +4 -0
- package/src/ui/ToolbarSection.tsx +7 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
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
|
+
|
|
3
24
|
## 0.1.1
|
|
4
25
|
|
|
5
26
|
### Patch 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() {
|
|
@@ -309,12 +315,24 @@ Object.defineProperty(exports, "ToolbarTooltip", {
|
|
|
309
315
|
return _ToolbarTooltip.ToolbarTooltip;
|
|
310
316
|
}
|
|
311
317
|
});
|
|
318
|
+
Object.defineProperty(exports, "ToolbarUIProvider", {
|
|
319
|
+
enumerable: true,
|
|
320
|
+
get: function get() {
|
|
321
|
+
return _uiContext.ToolbarUIProvider;
|
|
322
|
+
}
|
|
323
|
+
});
|
|
312
324
|
Object.defineProperty(exports, "UnderlineIcon", {
|
|
313
325
|
enumerable: true,
|
|
314
326
|
get: function get() {
|
|
315
327
|
return _UnderlineIcon.UnderlineIcon;
|
|
316
328
|
}
|
|
317
329
|
});
|
|
330
|
+
Object.defineProperty(exports, "useToolbarUI", {
|
|
331
|
+
enumerable: true,
|
|
332
|
+
get: function get() {
|
|
333
|
+
return _uiContext.useToolbarUI;
|
|
334
|
+
}
|
|
335
|
+
});
|
|
318
336
|
var _Toolbar = require("./ui/Toolbar");
|
|
319
337
|
var _ToolbarButton = require("./ui/ToolbarButton");
|
|
320
338
|
var _ToolbarButtonGroup = require("./ui/ToolbarButtonGroup");
|
|
@@ -366,4 +384,5 @@ var _StrikeThroughIcon = require("./ui/icons/StrikeThroughIcon");
|
|
|
366
384
|
var _CodeIcon = require("./ui/icons/CodeIcon");
|
|
367
385
|
var _SubscriptIcon = require("./ui/icons/SubscriptIcon");
|
|
368
386
|
var _SuperscriptIcon = require("./ui/icons/SuperscriptIcon");
|
|
369
|
-
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
|
-
.
|
|
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
|
-
.
|
|
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)}
|
package/dist/cjs/ui/Toolbar.js
CHANGED
|
@@ -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
|
-
|
|
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
|
});
|
|
@@ -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
|
+
};
|
package/dist/es2019/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';
|
|
@@ -50,4 +50,5 @@ export { StrikeThroughIcon } from './ui/icons/StrikeThroughIcon';
|
|
|
50
50
|
export { CodeIcon } from './ui/icons/CodeIcon';
|
|
51
51
|
export { SubscriptIcon } from './ui/icons/SubscriptIcon';
|
|
52
52
|
export { SuperscriptIcon } from './ui/icons/SuperscriptIcon';
|
|
53
|
-
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
|
-
.
|
|
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
|
-
.
|
|
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
|
-
|
|
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,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';
|
|
@@ -50,4 +50,5 @@ export { StrikeThroughIcon } from './ui/icons/StrikeThroughIcon';
|
|
|
50
50
|
export { CodeIcon } from './ui/icons/CodeIcon';
|
|
51
51
|
export { SubscriptIcon } from './ui/icons/SubscriptIcon';
|
|
52
52
|
export { SuperscriptIcon } from './ui/icons/SuperscriptIcon';
|
|
53
|
-
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
|
-
.
|
|
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
|
-
.
|
|
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)}
|
package/dist/esm/ui/Toolbar.js
CHANGED
|
@@ -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
|
-
|
|
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,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 {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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';
|
|
@@ -51,3 +51,4 @@ export { SubscriptIcon } from './ui/icons/SubscriptIcon';
|
|
|
51
51
|
export { SuperscriptIcon } from './ui/icons/SuperscriptIcon';
|
|
52
52
|
export { ShowMoreHorizontalIcon } from './ui/icons/ShowMoreHorizontal';
|
|
53
53
|
export type { IconComponent, ToolbarButtonGroupLocation } from './types';
|
|
54
|
+
export { useToolbarUI, ToolbarUIProvider } from './hooks/ui-context';
|
package/dist/types/types.d.ts
CHANGED
|
@@ -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,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';
|
|
@@ -51,3 +51,4 @@ export { SubscriptIcon } from './ui/icons/SubscriptIcon';
|
|
|
51
51
|
export { SuperscriptIcon } from './ui/icons/SuperscriptIcon';
|
|
52
52
|
export { ShowMoreHorizontalIcon } from './ui/icons/ShowMoreHorizontal';
|
|
53
53
|
export type { IconComponent, ToolbarButtonGroupLocation } from './types';
|
|
54
|
+
export { useToolbarUI, ToolbarUIProvider } from './hooks/ui-context';
|
|
@@ -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,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 {};
|
|
@@ -54,23 +54,23 @@ import { ToolbarTooltip } from '../../../src/ui/ToolbarTooltip';
|
|
|
54
54
|
import { useExampleToolbarState } from './useExampleToolbarState';
|
|
55
55
|
|
|
56
56
|
const headingSizeStylesMap = cssMap({
|
|
57
|
-
|
|
57
|
+
xlarge: {
|
|
58
58
|
font: token('font.heading.xlarge'),
|
|
59
59
|
},
|
|
60
|
-
|
|
61
|
-
font: token('font.heading.large')
|
|
60
|
+
large: {
|
|
61
|
+
font: token('font.heading.large'),
|
|
62
62
|
},
|
|
63
|
-
|
|
64
|
-
font: token('font.heading.medium')
|
|
63
|
+
medium: {
|
|
64
|
+
font: token('font.heading.medium'),
|
|
65
65
|
},
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
small: {
|
|
67
|
+
font: token('font.heading.small'),
|
|
68
68
|
},
|
|
69
|
-
|
|
70
|
-
font: token('font.heading.xsmall')
|
|
69
|
+
xsmall: {
|
|
70
|
+
font: token('font.heading.xsmall'),
|
|
71
71
|
},
|
|
72
|
-
|
|
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.
|
|
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.
|
|
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';
|
|
@@ -54,3 +54,5 @@ export { SuperscriptIcon } from './ui/icons/SuperscriptIcon';
|
|
|
54
54
|
export { ShowMoreHorizontalIcon } from './ui/icons/ShowMoreHorizontal';
|
|
55
55
|
|
|
56
56
|
export type { IconComponent, ToolbarButtonGroupLocation } from './types';
|
|
57
|
+
|
|
58
|
+
export { useToolbarUI, ToolbarUIProvider } from './hooks/ui-context';
|
package/src/ui/Toolbar.tsx
CHANGED
|
@@ -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
|
-
|
|
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
|
);
|
package/src/ui/ToolbarButton.tsx
CHANGED
|
@@ -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
|
|
18
|
+
export const ToolbarSection = ({ children, testId }: ToolbarSectionProps) => {
|
|
19
|
+
return (
|
|
20
|
+
<Box xcss={styles.container} testId={testId}>
|
|
21
|
+
{children}
|
|
22
|
+
</Box>
|
|
23
|
+
);
|
|
19
24
|
};
|