@neo4j-ndl/react 4.9.43 → 4.9.45
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/lib/cjs/clean-icon-button/CleanIconButton.js +2 -2
- package/lib/cjs/clean-icon-button/CleanIconButton.js.map +1 -1
- package/lib/cjs/clean-icon-button/stories/clean-icon-button-keyboard-display.story.js +31 -0
- package/lib/cjs/clean-icon-button/stories/clean-icon-button-keyboard-display.story.js.map +1 -0
- package/lib/cjs/clean-icon-button/stories/index.js +5 -1
- package/lib/cjs/clean-icon-button/stories/index.js.map +1 -1
- package/lib/cjs/clipboard-button/ClipboardButton.js +6 -5
- package/lib/cjs/clipboard-button/ClipboardButton.js.map +1 -1
- package/lib/cjs/icon-button/IconButton.js +2 -2
- package/lib/cjs/icon-button/IconButton.js.map +1 -1
- package/lib/cjs/icon-button-base/IconButtonBase.js +43 -4
- package/lib/cjs/icon-button-base/IconButtonBase.js.map +1 -1
- package/lib/cjs/kbd/Kbd.js +7 -6
- package/lib/cjs/kbd/Kbd.js.map +1 -1
- package/lib/cjs/kbd/kbd-utils.js +29 -0
- package/lib/cjs/kbd/kbd-utils.js.map +1 -1
- package/lib/cjs/menu/stories/index.js +3 -3
- package/lib/cjs/menu/stories/index.js.map +1 -1
- package/lib/cjs/tooltip/stories/index.js +5 -5
- package/lib/cjs/tooltip/stories/index.js.map +1 -1
- package/lib/cjs/tooltip/stories/{tooltip-with-keyboard-shortcut.story.js → tooltip-with-keyboard-display.story.js} +1 -1
- package/lib/cjs/tooltip/stories/tooltip-with-keyboard-display.story.js.map +1 -0
- package/lib/esm/clean-icon-button/CleanIconButton.js +2 -2
- package/lib/esm/clean-icon-button/CleanIconButton.js.map +1 -1
- package/lib/esm/clean-icon-button/stories/clean-icon-button-keyboard-display.story.js +29 -0
- package/lib/esm/clean-icon-button/stories/clean-icon-button-keyboard-display.story.js.map +1 -0
- package/lib/esm/clean-icon-button/stories/index.js +3 -0
- package/lib/esm/clean-icon-button/stories/index.js.map +1 -1
- package/lib/esm/clipboard-button/ClipboardButton.js +6 -5
- package/lib/esm/clipboard-button/ClipboardButton.js.map +1 -1
- package/lib/esm/icon-button/IconButton.js +2 -2
- package/lib/esm/icon-button/IconButton.js.map +1 -1
- package/lib/esm/icon-button-base/IconButtonBase.js +11 -5
- package/lib/esm/icon-button-base/IconButtonBase.js.map +1 -1
- package/lib/esm/kbd/Kbd.js +8 -7
- package/lib/esm/kbd/Kbd.js.map +1 -1
- package/lib/esm/kbd/kbd-utils.js +28 -0
- package/lib/esm/kbd/kbd-utils.js.map +1 -1
- package/lib/esm/menu/stories/index.js +3 -3
- package/lib/esm/menu/stories/index.js.map +1 -1
- package/lib/esm/tooltip/stories/index.js +3 -3
- package/lib/esm/tooltip/stories/index.js.map +1 -1
- package/lib/esm/tooltip/stories/{tooltip-with-keyboard-shortcut.story.js → tooltip-with-keyboard-display.story.js} +1 -1
- package/lib/esm/tooltip/stories/tooltip-with-keyboard-display.story.js.map +1 -0
- package/lib/types/clean-icon-button/CleanIconButton.d.ts +1 -1
- package/lib/types/clean-icon-button/CleanIconButton.d.ts.map +1 -1
- package/lib/types/clean-icon-button/stories/clean-icon-button-keyboard-display.story.d.ts +24 -0
- package/lib/types/clean-icon-button/stories/clean-icon-button-keyboard-display.story.d.ts.map +1 -0
- package/lib/types/clean-icon-button/stories/index.d.ts +2 -0
- package/lib/types/clean-icon-button/stories/index.d.ts.map +1 -1
- package/lib/types/clipboard-button/ClipboardButton.d.ts +3 -1
- package/lib/types/clipboard-button/ClipboardButton.d.ts.map +1 -1
- package/lib/types/icon-button/IconButton.d.ts +1 -1
- package/lib/types/icon-button/IconButton.d.ts.map +1 -1
- package/lib/types/icon-button-base/IconButtonBase.d.ts +7 -4
- package/lib/types/icon-button-base/IconButtonBase.d.ts.map +1 -1
- package/lib/types/kbd/Kbd.d.ts.map +1 -1
- package/lib/types/kbd/kbd-utils.d.ts +2 -0
- package/lib/types/kbd/kbd-utils.d.ts.map +1 -1
- package/lib/types/menu/stories/index.d.ts +2 -2
- package/lib/types/menu/stories/index.d.ts.map +1 -1
- package/lib/types/tooltip/stories/index.d.ts +2 -2
- package/lib/types/tooltip/stories/index.d.ts.map +1 -1
- package/lib/types/tooltip/stories/{tooltip-with-keyboard-shortcut.story.d.ts → tooltip-with-keyboard-display.story.d.ts} +1 -1
- package/lib/types/tooltip/stories/tooltip-with-keyboard-display.story.d.ts.map +1 -0
- package/package.json +25 -25
- package/lib/cjs/tooltip/stories/tooltip-with-keyboard-shortcut.story.js.map +0 -1
- package/lib/esm/tooltip/stories/tooltip-with-keyboard-shortcut.story.js.map +0 -1
- package/lib/types/tooltip/stories/tooltip-with-keyboard-shortcut.story.d.ts.map +0 -1
|
@@ -38,8 +38,8 @@ const icon_button_base_1 = require("../icon-button-base");
|
|
|
38
38
|
const CleanIconButton = (_a) => {
|
|
39
39
|
var { children, as, isLoading = false, isDisabled = false, size = 'medium',
|
|
40
40
|
// Does not have a default value to avoid setting aria-pressed to true if not explicitly set
|
|
41
|
-
isActive, variant = 'neutral', description, tooltipProps, className, style, htmlAttributes, onClick, ref } = _a, restProps = __rest(_a, ["children", "as", "isLoading", "isDisabled", "size", "isActive", "variant", "description", "tooltipProps", "className", "style", "htmlAttributes", "onClick", "ref"]);
|
|
42
|
-
return ((0, jsx_runtime_1.jsx)(icon_button_base_1.IconButtonBase, Object.assign({ as: as, iconButtonVariant: "clean", isDisabled: isDisabled, size: size, isLoading: isLoading, isActive: isActive, variant: variant, description: description, tooltipProps: tooltipProps, className: className, style: style, htmlAttributes: htmlAttributes, onClick: onClick, ref: ref }, restProps, { children: children })));
|
|
41
|
+
isActive, variant = 'neutral', description, descriptionKdbProps, tooltipProps, className, style, htmlAttributes, onClick, ref } = _a, restProps = __rest(_a, ["children", "as", "isLoading", "isDisabled", "size", "isActive", "variant", "description", "descriptionKdbProps", "tooltipProps", "className", "style", "htmlAttributes", "onClick", "ref"]);
|
|
42
|
+
return ((0, jsx_runtime_1.jsx)(icon_button_base_1.IconButtonBase, Object.assign({ as: as, iconButtonVariant: "clean", isDisabled: isDisabled, size: size, isLoading: isLoading, isActive: isActive, variant: variant, descriptionKdbProps: descriptionKdbProps, description: description, tooltipProps: tooltipProps, className: className, style: style, htmlAttributes: htmlAttributes, onClick: onClick, ref: ref }, restProps, { children: children })));
|
|
43
43
|
};
|
|
44
44
|
exports.CleanIconButton = CleanIconButton;
|
|
45
45
|
//# sourceMappingURL=CleanIconButton.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CleanIconButton.js","sourceRoot":"","sources":["../../../src/clean-icon-button/CleanIconButton.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AAuBA,0DAA+E;AAOxE,MAAM,eAAe,GAAG,CAAyC,
|
|
1
|
+
{"version":3,"file":"CleanIconButton.js","sourceRoot":"","sources":["../../../src/clean-icon-button/CleanIconButton.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AAuBA,0DAA+E;AAOxE,MAAM,eAAe,GAAG,CAAyC,EAkBhB,EAAE,EAAE;QAlBY,EACtE,QAAQ,EACR,EAAE,EACF,SAAS,GAAG,KAAK,EACjB,UAAU,GAAG,KAAK,EAClB,IAAI,GAAG,QAAQ;IACf,4FAA4F;IAC5F,QAAQ,EACR,OAAO,GAAG,SAAS,EACnB,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,SAAS,EACT,KAAK,EACL,cAAc,EACd,OAAO,EACP,GAAG,OAEmD,EADnD,SAAS,cAjB0D,4LAkBvE,CADa;IAEZ,OAAO,CACL,uBAAC,iCAAc,kBACb,EAAE,EAAE,EAAE,EACN,iBAAiB,EAAC,OAAO,EACzB,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,mBAAmB,EAAE,mBAAmB,EACxC,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,KAAK,EACZ,cAAc,EAAE,cAAc,EAC9B,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,GAAG,IACJ,SAAS,cAEZ,QAAQ,IACM,CAClB,CAAC;AACJ,CAAC,CAAC;AAzCW,QAAA,eAAe,mBAyC1B","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport type React from 'react';\n\nimport { type PolymorphicCommonProps } from '../_common/types';\nimport { IconButtonBase, type IconButtonBaseProps } from '../icon-button-base';\n\ntype CleanIconButtonButtonProps = Omit<\n IconButtonBaseProps,\n 'iconButtonVariant' | 'isFloating'\n>;\n\nexport const CleanIconButton = <T extends React.ElementType = 'button'>({\n children,\n as,\n isLoading = false,\n isDisabled = false,\n size = 'medium',\n // Does not have a default value to avoid setting aria-pressed to true if not explicitly set\n isActive,\n variant = 'neutral',\n description,\n descriptionKdbProps,\n tooltipProps,\n className,\n style,\n htmlAttributes,\n onClick,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, CleanIconButtonButtonProps>) => {\n return (\n <IconButtonBase\n as={as}\n iconButtonVariant=\"clean\"\n isDisabled={isDisabled}\n size={size}\n isLoading={isLoading}\n isActive={isActive}\n variant={variant}\n descriptionKdbProps={descriptionKdbProps}\n description={description}\n tooltipProps={tooltipProps}\n className={className}\n style={style}\n htmlAttributes={htmlAttributes}\n onClick={onClick}\n ref={ref}\n {...restProps}\n >\n {children}\n </IconButtonBase>\n );\n};\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) "Neo4j"
|
|
7
|
+
* Neo4j Sweden AB [http://neo4j.com]
|
|
8
|
+
*
|
|
9
|
+
* This file is part of Neo4j.
|
|
10
|
+
*
|
|
11
|
+
* Neo4j is free software: you can redistribute it and/or modify
|
|
12
|
+
* it under the terms of the GNU General Public License as published by
|
|
13
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
14
|
+
* (at your option) any later version.
|
|
15
|
+
*
|
|
16
|
+
* This program is distributed in the hope that it will be useful,
|
|
17
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
+
* GNU General Public License for more details.
|
|
20
|
+
*
|
|
21
|
+
* You should have received a copy of the GNU General Public License
|
|
22
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
+
*/
|
|
24
|
+
require("@neo4j-ndl/base/lib/neo4j-ds-styles.css");
|
|
25
|
+
const react_1 = require("@neo4j-ndl/react");
|
|
26
|
+
const icons_1 = require("@neo4j-ndl/react/icons");
|
|
27
|
+
const Component = () => {
|
|
28
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: "n-flex n-flex-col n-gap-token-16", children: (0, jsx_runtime_1.jsx)("div", { className: "n-flex n-flex-row n-gap-token-16 n-items-center", children: (0, jsx_runtime_1.jsx)(react_1.CleanIconButton, { description: "Search", descriptionKdbProps: { keys: ['B'], modifierKeys: ['meta'] }, variant: "neutral", children: (0, jsx_runtime_1.jsx)(icons_1.MagnifyingGlassIconOutline, {}) }) }) }));
|
|
29
|
+
};
|
|
30
|
+
exports.default = Component;
|
|
31
|
+
//# sourceMappingURL=clean-icon-button-keyboard-display.story.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clean-icon-button-keyboard-display.story.js","sourceRoot":"","sources":["../../../../src/clean-icon-button/stories/clean-icon-button-keyboard-display.story.tsx"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,mDAAiD;AAEjD,4CAAmD;AACnD,kDAAoE;AAEpE,MAAM,SAAS,GAAG,GAAG,EAAE;IACrB,OAAO,CACL,gCAAK,SAAS,EAAC,kCAAkC,YAC/C,gCAAK,SAAS,EAAC,iDAAiD,YAC9D,uBAAC,uBAAe,IACd,WAAW,EAAC,QAAQ,EACpB,mBAAmB,EAAE,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,YAAY,EAAE,CAAC,MAAM,CAAC,EAAE,EAC5D,OAAO,EAAC,SAAS,YAEjB,uBAAC,kCAA0B,KAAG,GACd,GACd,GACF,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,SAAS,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport '@neo4j-ndl/base/lib/neo4j-ds-styles.css';\n\nimport { CleanIconButton } from '@neo4j-ndl/react';\nimport { MagnifyingGlassIconOutline } from '@neo4j-ndl/react/icons';\n\nconst Component = () => {\n return (\n <div className=\"n-flex n-flex-col n-gap-token-16\">\n <div className=\"n-flex n-flex-row n-gap-token-16 n-items-center\">\n <CleanIconButton\n description=\"Search\"\n descriptionKdbProps={{ keys: ['B'], modifierKeys: ['meta'] }}\n variant=\"neutral\"\n >\n <MagnifyingGlassIconOutline />\n </CleanIconButton>\n </div>\n </div>\n );\n};\n\nexport default Component;\n"]}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.CleanIconButtonToneSrc = exports.CleanIconButtonSizesSrc = exports.CleanIconButtonLoadingSrc = exports.CleanIconButtonDisabledSrc = exports.CleanIconButtonDefaultSrc = exports.CleanIconButtonActiveSrc = exports.CleanIconButtonTone = exports.CleanIconButtonSizes = exports.CleanIconButtonLoading = exports.CleanIconButtonDisabled = exports.CleanIconButtonDefault = exports.CleanIconButtonActive = void 0;
|
|
6
|
+
exports.CleanIconButtonKeyboardDisplaySrc = exports.CleanIconButtonToneSrc = exports.CleanIconButtonSizesSrc = exports.CleanIconButtonLoadingSrc = exports.CleanIconButtonDisabledSrc = exports.CleanIconButtonDefaultSrc = exports.CleanIconButtonActiveSrc = exports.CleanIconButtonKeyboardDisplay = exports.CleanIconButtonTone = exports.CleanIconButtonSizes = exports.CleanIconButtonLoading = exports.CleanIconButtonDisabled = exports.CleanIconButtonDefault = exports.CleanIconButtonActive = void 0;
|
|
7
7
|
/**
|
|
8
8
|
*
|
|
9
9
|
* Copyright (c) "Neo4j"
|
|
@@ -36,10 +36,13 @@ var clean_icon_button_sizes_story_1 = require("./clean-icon-button-sizes.story")
|
|
|
36
36
|
Object.defineProperty(exports, "CleanIconButtonSizes", { enumerable: true, get: function () { return __importDefault(clean_icon_button_sizes_story_1).default; } });
|
|
37
37
|
var clean_icon_button_tone_story_1 = require("./clean-icon-button-tone.story");
|
|
38
38
|
Object.defineProperty(exports, "CleanIconButtonTone", { enumerable: true, get: function () { return __importDefault(clean_icon_button_tone_story_1).default; } });
|
|
39
|
+
var clean_icon_button_keyboard_display_story_1 = require("./clean-icon-button-keyboard-display.story");
|
|
40
|
+
Object.defineProperty(exports, "CleanIconButtonKeyboardDisplay", { enumerable: true, get: function () { return __importDefault(clean_icon_button_keyboard_display_story_1).default; } });
|
|
39
41
|
const export_stories_utils_1 = require("../../_common/export-stories-utils");
|
|
40
42
|
const clean_icon_button_active_story_raw_1 = __importDefault(require("./clean-icon-button-active.story?raw"));
|
|
41
43
|
const clean_icon_button_default_story_raw_1 = __importDefault(require("./clean-icon-button-default.story?raw"));
|
|
42
44
|
const clean_icon_button_disabled_story_raw_1 = __importDefault(require("./clean-icon-button-disabled.story?raw"));
|
|
45
|
+
const clean_icon_button_keyboard_display_story_raw_1 = __importDefault(require("./clean-icon-button-keyboard-display.story?raw"));
|
|
43
46
|
const clean_icon_button_loading_story_raw_1 = __importDefault(require("./clean-icon-button-loading.story?raw"));
|
|
44
47
|
const clean_icon_button_sizes_story_raw_1 = __importDefault(require("./clean-icon-button-sizes.story?raw"));
|
|
45
48
|
const clean_icon_button_tone_story_raw_1 = __importDefault(require("./clean-icon-button-tone.story?raw"));
|
|
@@ -49,4 +52,5 @@ exports.CleanIconButtonDisabledSrc = (0, export_stories_utils_1.removeLicenseHea
|
|
|
49
52
|
exports.CleanIconButtonLoadingSrc = (0, export_stories_utils_1.removeLicenseHeader)(clean_icon_button_loading_story_raw_1.default);
|
|
50
53
|
exports.CleanIconButtonSizesSrc = (0, export_stories_utils_1.removeLicenseHeader)(clean_icon_button_sizes_story_raw_1.default);
|
|
51
54
|
exports.CleanIconButtonToneSrc = (0, export_stories_utils_1.removeLicenseHeader)(clean_icon_button_tone_story_raw_1.default);
|
|
55
|
+
exports.CleanIconButtonKeyboardDisplaySrc = (0, export_stories_utils_1.removeLicenseHeader)(clean_icon_button_keyboard_display_story_raw_1.default);
|
|
52
56
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/clean-icon-button/stories/index.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,mFAAoF;AAA3E,wJAAA,OAAO,OAAyB;AACzC,qFAAsF;AAA7E,0JAAA,OAAO,OAA0B;AAC1C,uFAAwF;AAA/E,4JAAA,OAAO,OAA2B;AAC3C,qFAAsF;AAA7E,0JAAA,OAAO,OAA0B;AAC1C,iFAAkF;AAAzE,sJAAA,OAAO,OAAwB;AACxC,+EAAgF;AAAvE,oJAAA,OAAO,OAAuB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/clean-icon-button/stories/index.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,mFAAoF;AAA3E,wJAAA,OAAO,OAAyB;AACzC,qFAAsF;AAA7E,0JAAA,OAAO,OAA0B;AAC1C,uFAAwF;AAA/E,4JAAA,OAAO,OAA2B;AAC3C,qFAAsF;AAA7E,0JAAA,OAAO,OAA0B;AAC1C,iFAAkF;AAAzE,sJAAA,OAAO,OAAwB;AACxC,+EAAgF;AAAvE,oJAAA,OAAO,OAAuB;AACvC,uGAAuG;AAA9F,2KAAA,OAAO,OAAkC;AAElD,6EAAyE;AACzE,8GAA+E;AAC/E,gHAAiF;AACjF,kHAAmF;AACnF,kIAAkG;AAClG,gHAAiF;AACjF,4GAA6E;AAC7E,0GAA2E;AAE9D,QAAA,wBAAwB,GAAG,IAAA,0CAAmB,EACzD,4CAA2B,CAC5B,CAAC;AACW,QAAA,yBAAyB,GAAG,IAAA,0CAAmB,EAC1D,6CAA4B,CAC7B,CAAC;AACW,QAAA,0BAA0B,GAAG,IAAA,0CAAmB,EAC3D,8CAA6B,CAC9B,CAAC;AACW,QAAA,yBAAyB,GAAG,IAAA,0CAAmB,EAC1D,6CAA4B,CAC7B,CAAC;AACW,QAAA,uBAAuB,GAAG,IAAA,0CAAmB,EACxD,2CAA0B,CAC3B,CAAC;AACW,QAAA,sBAAsB,GAAG,IAAA,0CAAmB,EACvD,0CAAyB,CAC1B,CAAC;AACW,QAAA,iCAAiC,GAAG,IAAA,0CAAmB,EAClE,sDAAoC,CACrC,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nexport { default as CleanIconButtonActive } from './clean-icon-button-active.story';\nexport { default as CleanIconButtonDefault } from './clean-icon-button-default.story';\nexport { default as CleanIconButtonDisabled } from './clean-icon-button-disabled.story';\nexport { default as CleanIconButtonLoading } from './clean-icon-button-loading.story';\nexport { default as CleanIconButtonSizes } from './clean-icon-button-sizes.story';\nexport { default as CleanIconButtonTone } from './clean-icon-button-tone.story';\nexport { default as CleanIconButtonKeyboardDisplay } from './clean-icon-button-keyboard-display.story';\n\nimport { removeLicenseHeader } from '../../_common/export-stories-utils';\nimport CleanIconButtonActiveSrcRaw from './clean-icon-button-active.story?raw';\nimport CleanIconButtonDefaultSrcRaw from './clean-icon-button-default.story?raw';\nimport CleanIconButtonDisabledSrcRaw from './clean-icon-button-disabled.story?raw';\nimport CleanIconButtonKeyboardDisplaySrcRaw from './clean-icon-button-keyboard-display.story?raw';\nimport CleanIconButtonLoadingSrcRaw from './clean-icon-button-loading.story?raw';\nimport CleanIconButtonSizesSrcRaw from './clean-icon-button-sizes.story?raw';\nimport CleanIconButtonToneSrcRaw from './clean-icon-button-tone.story?raw';\n\nexport const CleanIconButtonActiveSrc = removeLicenseHeader(\n CleanIconButtonActiveSrcRaw,\n);\nexport const CleanIconButtonDefaultSrc = removeLicenseHeader(\n CleanIconButtonDefaultSrcRaw,\n);\nexport const CleanIconButtonDisabledSrc = removeLicenseHeader(\n CleanIconButtonDisabledSrcRaw,\n);\nexport const CleanIconButtonLoadingSrc = removeLicenseHeader(\n CleanIconButtonLoadingSrcRaw,\n);\nexport const CleanIconButtonSizesSrc = removeLicenseHeader(\n CleanIconButtonSizesSrcRaw,\n);\nexport const CleanIconButtonToneSrc = removeLicenseHeader(\n CleanIconButtonToneSrcRaw,\n);\nexport const CleanIconButtonKeyboardDisplaySrc = removeLicenseHeader(\n CleanIconButtonKeyboardDisplaySrcRaw,\n);\n"]}
|
|
@@ -41,10 +41,11 @@ const clean_icon_button_1 = require("../clean-icon-button");
|
|
|
41
41
|
const hooks_1 = require("../hooks");
|
|
42
42
|
const icon_button_1 = require("../icon-button");
|
|
43
43
|
const icons_1 = require("../icons");
|
|
44
|
+
const kbd_1 = require("../kbd");
|
|
44
45
|
const outlined_button_1 = require("../outlined-button");
|
|
45
46
|
const tooltip_1 = require("../tooltip");
|
|
46
47
|
const ConfirmationButton = (_a) => {
|
|
47
|
-
var { description, actionFeedbackText, icon, children, onClick, htmlAttributes, tooltipProps, type = 'clean-icon-button' } = _a, restProps = __rest(_a, ["description", "actionFeedbackText", "icon", "children", "onClick", "htmlAttributes", "tooltipProps", "type"]);
|
|
48
|
+
var { descriptionKdbProps, description, actionFeedbackText, icon, children, onClick, htmlAttributes, tooltipProps, type = 'clean-icon-button' } = _a, restProps = __rest(_a, ["descriptionKdbProps", "description", "actionFeedbackText", "icon", "children", "onClick", "htmlAttributes", "tooltipProps", "type"]);
|
|
48
49
|
const [timeoutId, setTimeoutId] = react_1.default.useState(null);
|
|
49
50
|
const [isOpen, setIsOpen] = react_1.default.useState(false);
|
|
50
51
|
const handleClick = () => {
|
|
@@ -65,7 +66,7 @@ const ConfirmationButton = (_a) => {
|
|
|
65
66
|
const content = timeoutId === null ? description : actionFeedbackText;
|
|
66
67
|
/* Controlling the tip to make it disappear in a timely manner*/
|
|
67
68
|
if (type === 'clean-icon-button') {
|
|
68
|
-
return ((0, jsx_runtime_1.jsx)(clean_icon_button_1.CleanIconButton, Object.assign({}, restProps.cleanIconButtonProps, { description: content, tooltipProps: {
|
|
69
|
+
return ((0, jsx_runtime_1.jsx)(clean_icon_button_1.CleanIconButton, Object.assign({}, restProps.cleanIconButtonProps, { description: content, descriptionKdbProps: descriptionKdbProps, tooltipProps: {
|
|
69
70
|
root: Object.assign(Object.assign({}, tooltipProps), { isOpen: isOpen || timeoutId !== null }),
|
|
70
71
|
trigger: {
|
|
71
72
|
htmlAttributes: {
|
|
@@ -121,10 +122,10 @@ const ConfirmationButton = (_a) => {
|
|
|
121
122
|
onClick(event);
|
|
122
123
|
}
|
|
123
124
|
handleClick();
|
|
124
|
-
}, leadingVisual: icon, className: restProps.className, htmlAttributes: htmlAttributes, children: children })) }), (0, jsx_runtime_1.
|
|
125
|
+
}, leadingVisual: icon, className: restProps.className, htmlAttributes: htmlAttributes, children: children })) }), (0, jsx_runtime_1.jsxs)(tooltip_1.Tooltip.Content, { children: [content, descriptionKdbProps && (0, jsx_runtime_1.jsx)(kbd_1.Kbd, Object.assign({}, descriptionKdbProps))] })] })));
|
|
125
126
|
}
|
|
126
127
|
};
|
|
127
|
-
const ClipboardButton = ({ textToCopy, isDisabled, size, tooltipProps, htmlAttributes, type, }) => {
|
|
128
|
+
const ClipboardButton = ({ textToCopy, descriptionKdbProps, isDisabled, size, tooltipProps, htmlAttributes, type, }) => {
|
|
128
129
|
const [, copyFunction] = (0, hooks_1.useCopyToClipboard)();
|
|
129
130
|
const isOutlinedButton = type === 'outlined-button';
|
|
130
131
|
const isIconButton = type === 'icon-button';
|
|
@@ -153,7 +154,7 @@ const ClipboardButton = ({ textToCopy, isDisabled, size, tooltipProps, htmlAttri
|
|
|
153
154
|
},
|
|
154
155
|
type: 'clean-icon-button',
|
|
155
156
|
};
|
|
156
|
-
return ((0, jsx_runtime_1.jsx)(ConfirmationButton, Object.assign({ onClick: () => copyFunction(textToCopy), description: "Copy to clipboard", actionFeedbackText: "Copied" }, props, { tooltipProps: tooltipProps, className: "n-gap-token-8", icon: (0, jsx_runtime_1.jsx)(icons_1.Square2StackIconOutline, { className: "ndl-icon-svg" }), htmlAttributes: Object.assign({ 'aria-live': 'polite' }, htmlAttributes), children: type === 'outlined-button' && 'Copy' })));
|
|
157
|
+
return ((0, jsx_runtime_1.jsx)(ConfirmationButton, Object.assign({ onClick: () => copyFunction(textToCopy), description: "Copy to clipboard", actionFeedbackText: "Copied", descriptionKdbProps: descriptionKdbProps }, props, { tooltipProps: tooltipProps, className: "n-gap-token-8", icon: (0, jsx_runtime_1.jsx)(icons_1.Square2StackIconOutline, { className: "ndl-icon-svg" }), htmlAttributes: Object.assign({ 'aria-live': 'polite' }, htmlAttributes), children: type === 'outlined-button' && 'Copy' })));
|
|
157
158
|
};
|
|
158
159
|
exports.ClipboardButton = ClipboardButton;
|
|
159
160
|
//# sourceMappingURL=ClipboardButton.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClipboardButton.js","sourceRoot":"","sources":["../../../src/clipboard-button/ClipboardButton.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,kDAA0B;AAG1B,4DAAuD;AACvD,oCAA8C;AAC9C,gDAA4C;AAC5C,oCAAmD;AACnD,wDAAoD;AACpD,wCAAqC;AAmCrC,MAAM,kBAAkB,GAAG,CAAC,EAUF,EAAE,EAAE;QAVF,EAC1B,WAAW,EACX,kBAAkB,EAClB,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,cAAc,EACd,YAAY,EACZ,IAAI,GAAG,mBAAmB,OAEF,EADrB,SAAS,cATc,8GAU3B,CADa;IAEZ,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,G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CAAC,CAAC;gBACE,oBAAoB,EAAE;oBACpB,WAAW,EAAE,mBAAmB;oBAChC,UAAU;oBACV,IAAI;iBACL;gBACD,IAAI,EAAE,mBAA4B;aACnC,CAAC;IAER,OAAO,CACL,uBAAC,kBAAkB,kBACjB,OAAO,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC,EACvC,WAAW,EAAC,mBAAmB,EAC/B,kBAAkB,EAAC,QAAQ,IACvB,KAAK,IACT,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAC,eAAe,EACzB,IAAI,EAAE,uBAAC,+BAAuB,IAAC,SAAS,EAAC,cAAc,GAAG,EAC1D,cAAc,kBACZ,WAAW,EAAE,QAAQ,IAClB,cAAc,aAGlB,IAAI,KAAK,iBAAiB,IAAI,MAAM,IAClB,CACtB,CAAC;AACJ,CAAC,CAAC;AAxDW,QAAA,eAAe,mBAwD1B","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport React from 'react';\n\nimport { type ButtonSizes } from '../button';\nimport { CleanIconButton } from '../clean-icon-button';\nimport { useCopyToClipboard } from '../hooks';\nimport { IconButton } from '../icon-button';\nimport { Square2StackIconOutline } from '../icons';\nimport { OutlinedButton } from '../outlined-button';\nimport { Tooltip } from '../tooltip';\n\ntype ConfirmationButtonProps = {\n description: string;\n actionFeedbackText: string;\n tooltipProps?: Omit<React.ComponentProps<typeof Tooltip>, 'children'>;\n onClick?: React.ComponentPropsWithoutRef<'button'>['onClick'];\n children: React.ReactNode;\n className?: string;\n icon: React.ReactNode;\n htmlAttributes?: React.ComponentPropsWithoutRef<'button'>;\n} & (\n | {\n type: 'clean-icon-button';\n cleanIconButtonProps?: Omit<\n React.ComponentProps<typeof CleanIconButton>,\n 'children' | 'onClick' | 'tooltip'\n >;\n }\n | {\n type: 'icon-button';\n iconButtonProps?: Omit<\n React.ComponentProps<typeof IconButton>,\n 'children' | 'onClick' | 'tooltip'\n >;\n }\n | {\n type: 'outlined-button';\n outlinedButtonProps?: Omit<\n React.ComponentProps<typeof OutlinedButton>,\n 'children' | 'onClick' | 'tooltip'\n >;\n }\n);\n\nconst ConfirmationButton = ({\n description,\n actionFeedbackText,\n icon,\n children,\n onClick,\n htmlAttributes,\n tooltipProps,\n type = 'clean-icon-button',\n ...restProps\n}: ConfirmationButtonProps) => {\n const [timeoutId, setTimeoutId] = React.useState<number | null>(null);\n const [isOpen, setIsOpen] = React.useState(false);\n\n const handleClick = () => {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n }\n\n const newTimeoutId = window.setTimeout(() => {\n setTimeoutId(null);\n }, 2000);\n\n setTimeoutId(newTimeoutId);\n };\n\n const handleCloseTooltip = () => {\n setIsOpen(false);\n };\n\n const handleOpenTooltip = () => {\n setIsOpen(true);\n };\n\n const content = timeoutId === null ? description : actionFeedbackText;\n /* Controlling the tip to make it disappear in a timely manner*/\n\n if (type === 'clean-icon-button') {\n return (\n <CleanIconButton\n {...(\n restProps as {\n cleanIconButtonProps: React.ComponentProps<typeof CleanIconButton>;\n }\n ).cleanIconButtonProps}\n description={content}\n tooltipProps={{\n root: {\n ...tooltipProps,\n isOpen: isOpen || timeoutId !== null,\n },\n trigger: {\n htmlAttributes: {\n onBlur: handleCloseTooltip,\n onFocus: handleOpenTooltip,\n onMouseEnter: handleOpenTooltip,\n onMouseLeave: handleCloseTooltip,\n },\n },\n }}\n onClick={(event) => {\n if (onClick) {\n onClick(event);\n }\n handleClick();\n }}\n className={restProps.className}\n htmlAttributes={htmlAttributes}\n >\n {icon}\n </CleanIconButton>\n );\n } else if (type === 'icon-button') {\n return (\n <IconButton\n {...(\n restProps as {\n iconButtonProps: React.ComponentProps<typeof IconButton>;\n }\n ).iconButtonProps}\n description={content}\n tooltipProps={{\n root: {\n ...tooltipProps,\n isOpen: isOpen || timeoutId !== null,\n },\n trigger: {\n htmlAttributes: {\n onBlur: handleCloseTooltip,\n onFocus: handleOpenTooltip,\n onMouseEnter: handleOpenTooltip,\n onMouseLeave: handleCloseTooltip,\n },\n },\n }}\n onClick={(event) => {\n if (onClick) {\n onClick(event);\n }\n handleClick();\n }}\n className={restProps.className}\n htmlAttributes={htmlAttributes}\n >\n {icon}\n </IconButton>\n );\n } else if (type === 'outlined-button') {\n return (\n <Tooltip\n type=\"simple\"\n isOpen={isOpen || timeoutId !== null}\n {...tooltipProps}\n onOpenChange={(open) => {\n if (open) {\n handleOpenTooltip();\n } else {\n handleCloseTooltip();\n }\n tooltipProps?.onOpenChange?.(open);\n }}\n >\n <Tooltip.Trigger\n hasButtonWrapper\n htmlAttributes={{\n 'aria-label': content,\n onBlur: handleCloseTooltip,\n onFocus: handleOpenTooltip,\n onMouseEnter: handleOpenTooltip,\n onMouseLeave: handleCloseTooltip,\n }}\n >\n <OutlinedButton\n variant=\"neutral\"\n {...(\n restProps as {\n buttonProps: React.ComponentProps<typeof OutlinedButton>;\n }\n ).buttonProps}\n onClick={(event) => {\n if (onClick) {\n onClick(event);\n }\n handleClick();\n }}\n leadingVisual={icon}\n className={restProps.className}\n htmlAttributes={htmlAttributes}\n >\n {children}\n </OutlinedButton>\n </Tooltip.Trigger>\n <Tooltip.Content>{content}</Tooltip.Content>\n </Tooltip>\n );\n }\n};\n\ninterface ClipboardButtonProps {\n /** The text that should be set to users clipboard */\n textToCopy: string;\n tooltipProps?: Omit<React.ComponentProps<typeof Tooltip>, 'children'>;\n isDisabled?: boolean;\n size?: ButtonSizes;\n htmlAttributes?: React.ComponentPropsWithoutRef<'button'>;\n type?: 'outlined-button' | 'clean-icon-button' | 'icon-button';\n}\n\nexport const ClipboardButton = ({\n textToCopy,\n isDisabled,\n size,\n tooltipProps,\n htmlAttributes,\n type,\n}: ClipboardButtonProps) => {\n const [, copyFunction] = useCopyToClipboard();\n\n const isOutlinedButton = type === 'outlined-button';\n const isIconButton = type === 'icon-button';\n\n const props = isOutlinedButton\n ? {\n outlinedButtonProps: {\n isDisabled,\n size,\n },\n type: 'outlined-button' as const,\n }\n : isIconButton\n ? {\n iconButtonProps: {\n description: 'Copy to clipboard',\n isDisabled,\n size,\n },\n type: 'icon-button' as const,\n }\n : {\n cleanIconButtonProps: {\n description: 'Copy to clipboard',\n isDisabled,\n size,\n },\n type: 'clean-icon-button' as const,\n };\n\n return (\n <ConfirmationButton\n onClick={() => copyFunction(textToCopy)}\n description=\"Copy to clipboard\"\n actionFeedbackText=\"Copied\"\n {...props}\n tooltipProps={tooltipProps}\n className=\"n-gap-token-8\"\n icon={<Square2StackIconOutline className=\"ndl-icon-svg\" />}\n htmlAttributes={{\n 'aria-live': 'polite',\n ...htmlAttributes,\n }}\n >\n {type === 'outlined-button' && 'Copy'}\n </ConfirmationButton>\n );\n};\n"]}
|
|
1
|
+
{"version":3,"file":"ClipboardButton.js","sourceRoot":"","sources":["../../../src/clipboard-button/ClipboardButton.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,kDAA0B;AAG1B,4DAAuD;AACvD,oCAA8C;AAC9C,gDAA4C;AAC5C,oCAAmD;AACnD,gCAA6B;AAC7B,wDAAoD;AACpD,wCAAqC;AAoCrC,MAAM,kBAAkB,GAAG,CAAC,EAWF,EAAE,EAAE;QAXF,EAC1B,mBAAmB,EACnB,WAAW,EACX,kBAAkB,EAClB,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,cAAc,EACd,YAAY,EACZ,IAAI,GAAG,mBAAmB,OAEF,EADrB,SAAS,cAV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QACH,CAAC,CAAC,YAAY;YACZ,CAAC,CAAC;gBACE,eAAe,EAAE;oBACf,WAAW,EAAE,mBAAmB;oBAChC,UAAU;oBACV,IAAI;iBACL;gBACD,IAAI,EAAE,aAAsB;aAC7B;YACH,CAAC,CAAC;gBACE,oBAAoB,EAAE;oBACpB,WAAW,EAAE,mBAAmB;oBAChC,UAAU;oBACV,IAAI;iBACL;gBACD,IAAI,EAAE,mBAA4B;aACnC,CAAC;IAER,OAAO,CACL,uBAAC,kBAAkB,kBACjB,OAAO,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC,EACvC,WAAW,EAAC,mBAAmB,EAC/B,kBAAkB,EAAC,QAAQ,EAC3B,mBAAmB,EAAE,mBAAmB,IACpC,KAAK,IACT,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAC,eAAe,EACzB,IAAI,EAAE,uBAAC,+BAAuB,IAAC,SAAS,EAAC,cAAc,GAAG,EAC1D,cAAc,kBACZ,WAAW,EAAE,QAAQ,IAClB,cAAc,aAGlB,IAAI,KAAK,iBAAiB,IAAI,MAAM,IAClB,CACtB,CAAC;AACJ,CAAC,CAAC;AA1DW,QAAA,eAAe,mBA0D1B","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport React from 'react';\n\nimport { type ButtonSizes } from '../button';\nimport { CleanIconButton } from '../clean-icon-button';\nimport { useCopyToClipboard } from '../hooks';\nimport { IconButton } from '../icon-button';\nimport { Square2StackIconOutline } from '../icons';\nimport { Kbd } from '../kbd';\nimport { OutlinedButton } from '../outlined-button';\nimport { Tooltip } from '../tooltip';\n\ntype ConfirmationButtonProps = {\n description: string;\n descriptionKdbProps?: React.ComponentProps<typeof Kbd>;\n actionFeedbackText: string;\n tooltipProps?: Omit<React.ComponentProps<typeof Tooltip>, 'children'>;\n onClick?: React.ComponentPropsWithoutRef<'button'>['onClick'];\n children: React.ReactNode;\n className?: string;\n icon: React.ReactNode;\n htmlAttributes?: React.ComponentPropsWithoutRef<'button'>;\n} & (\n | {\n type: 'clean-icon-button';\n cleanIconButtonProps?: Omit<\n React.ComponentProps<typeof CleanIconButton>,\n 'children' | 'onClick' | 'tooltip'\n >;\n }\n | {\n type: 'icon-button';\n iconButtonProps?: Omit<\n React.ComponentProps<typeof IconButton>,\n 'children' | 'onClick' | 'tooltip'\n >;\n }\n | {\n type: 'outlined-button';\n outlinedButtonProps?: Omit<\n React.ComponentProps<typeof OutlinedButton>,\n 'children' | 'onClick' | 'tooltip'\n >;\n }\n);\n\nconst ConfirmationButton = ({\n descriptionKdbProps,\n description,\n actionFeedbackText,\n icon,\n children,\n onClick,\n htmlAttributes,\n tooltipProps,\n type = 'clean-icon-button',\n ...restProps\n}: ConfirmationButtonProps) => {\n const [timeoutId, setTimeoutId] = React.useState<number | null>(null);\n const [isOpen, setIsOpen] = React.useState(false);\n\n const handleClick = () => {\n if (timeoutId !== null) {\n clearTimeout(timeoutId);\n }\n\n const newTimeoutId = window.setTimeout(() => {\n setTimeoutId(null);\n }, 2000);\n\n setTimeoutId(newTimeoutId);\n };\n\n const handleCloseTooltip = () => {\n setIsOpen(false);\n };\n\n const handleOpenTooltip = () => {\n setIsOpen(true);\n };\n\n const content = timeoutId === null ? description : actionFeedbackText;\n /* Controlling the tip to make it disappear in a timely manner*/\n\n if (type === 'clean-icon-button') {\n return (\n <CleanIconButton\n {...(\n restProps as {\n cleanIconButtonProps: React.ComponentProps<typeof CleanIconButton>;\n }\n ).cleanIconButtonProps}\n description={content}\n descriptionKdbProps={descriptionKdbProps}\n tooltipProps={{\n root: {\n ...tooltipProps,\n isOpen: isOpen || timeoutId !== null,\n },\n trigger: {\n htmlAttributes: {\n onBlur: handleCloseTooltip,\n onFocus: handleOpenTooltip,\n onMouseEnter: handleOpenTooltip,\n onMouseLeave: handleCloseTooltip,\n },\n },\n }}\n onClick={(event) => {\n if (onClick) {\n onClick(event);\n }\n handleClick();\n }}\n className={restProps.className}\n htmlAttributes={htmlAttributes}\n >\n {icon}\n </CleanIconButton>\n );\n } else if (type === 'icon-button') {\n return (\n <IconButton\n {...(\n restProps as {\n iconButtonProps: React.ComponentProps<typeof IconButton>;\n }\n ).iconButtonProps}\n description={content}\n tooltipProps={{\n root: {\n ...tooltipProps,\n isOpen: isOpen || timeoutId !== null,\n },\n trigger: {\n htmlAttributes: {\n onBlur: handleCloseTooltip,\n onFocus: handleOpenTooltip,\n onMouseEnter: handleOpenTooltip,\n onMouseLeave: handleCloseTooltip,\n },\n },\n }}\n onClick={(event) => {\n if (onClick) {\n onClick(event);\n }\n handleClick();\n }}\n className={restProps.className}\n htmlAttributes={htmlAttributes}\n >\n {icon}\n </IconButton>\n );\n } else if (type === 'outlined-button') {\n return (\n <Tooltip\n type=\"simple\"\n isOpen={isOpen || timeoutId !== null}\n {...tooltipProps}\n onOpenChange={(open) => {\n if (open) {\n handleOpenTooltip();\n } else {\n handleCloseTooltip();\n }\n tooltipProps?.onOpenChange?.(open);\n }}\n >\n <Tooltip.Trigger\n hasButtonWrapper\n htmlAttributes={{\n 'aria-label': content,\n onBlur: handleCloseTooltip,\n onFocus: handleOpenTooltip,\n onMouseEnter: handleOpenTooltip,\n onMouseLeave: handleCloseTooltip,\n }}\n >\n <OutlinedButton\n variant=\"neutral\"\n {...(\n restProps as {\n buttonProps: React.ComponentProps<typeof OutlinedButton>;\n }\n ).buttonProps}\n onClick={(event) => {\n if (onClick) {\n onClick(event);\n }\n handleClick();\n }}\n leadingVisual={icon}\n className={restProps.className}\n htmlAttributes={htmlAttributes}\n >\n {children}\n </OutlinedButton>\n </Tooltip.Trigger>\n <Tooltip.Content>\n {content}\n {descriptionKdbProps && <Kbd {...descriptionKdbProps} />}\n </Tooltip.Content>\n </Tooltip>\n );\n }\n};\n\ninterface ClipboardButtonProps {\n /** The text that should be set to users clipboard */\n textToCopy: string;\n descriptionKdbProps?: React.ComponentProps<typeof Kbd>;\n tooltipProps?: Omit<React.ComponentProps<typeof Tooltip>, 'children'>;\n isDisabled?: boolean;\n size?: ButtonSizes;\n htmlAttributes?: React.ComponentPropsWithoutRef<'button'>;\n type?: 'outlined-button' | 'clean-icon-button' | 'icon-button';\n}\n\nexport const ClipboardButton = ({\n textToCopy,\n descriptionKdbProps,\n isDisabled,\n size,\n tooltipProps,\n htmlAttributes,\n type,\n}: ClipboardButtonProps) => {\n const [, copyFunction] = useCopyToClipboard();\n\n const isOutlinedButton = type === 'outlined-button';\n const isIconButton = type === 'icon-button';\n\n const props = isOutlinedButton\n ? {\n outlinedButtonProps: {\n isDisabled,\n size,\n },\n type: 'outlined-button' as const,\n }\n : isIconButton\n ? {\n iconButtonProps: {\n description: 'Copy to clipboard',\n isDisabled,\n size,\n },\n type: 'icon-button' as const,\n }\n : {\n cleanIconButtonProps: {\n description: 'Copy to clipboard',\n isDisabled,\n size,\n },\n type: 'clean-icon-button' as const,\n };\n\n return (\n <ConfirmationButton\n onClick={() => copyFunction(textToCopy)}\n description=\"Copy to clipboard\"\n actionFeedbackText=\"Copied\"\n descriptionKdbProps={descriptionKdbProps}\n {...props}\n tooltipProps={tooltipProps}\n className=\"n-gap-token-8\"\n icon={<Square2StackIconOutline className=\"ndl-icon-svg\" />}\n htmlAttributes={{\n 'aria-live': 'polite',\n ...htmlAttributes,\n }}\n >\n {type === 'outlined-button' && 'Copy'}\n </ConfirmationButton>\n );\n};\n"]}
|
|
@@ -38,8 +38,8 @@ const icon_button_base_1 = require("../icon-button-base");
|
|
|
38
38
|
const IconButton = (_a) => {
|
|
39
39
|
var { children, as, isLoading = false, isDisabled = false, size = 'medium', isFloating = false,
|
|
40
40
|
// Does not have a default value to avoid setting aria-pressed to true if not explicitly set
|
|
41
|
-
isActive, variant = 'neutral', description, tooltipProps, className, style, htmlAttributes, onClick, ref } = _a, restProps = __rest(_a, ["children", "as", "isLoading", "isDisabled", "size", "isFloating", "isActive", "variant", "description", "tooltipProps", "className", "style", "htmlAttributes", "onClick", "ref"]);
|
|
42
|
-
return ((0, jsx_runtime_1.jsx)(icon_button_base_1.IconButtonBase, Object.assign({ as: as, iconButtonVariant: "default", isDisabled: isDisabled, size: size, isLoading: isLoading, isActive: isActive, isFloating: isFloating, description: description, tooltipProps: tooltipProps, className: className, style: style, variant: variant, htmlAttributes: htmlAttributes, onClick: onClick, ref: ref }, restProps, { children: children })));
|
|
41
|
+
isActive, variant = 'neutral', description, descriptionKdbProps, tooltipProps, className, style, htmlAttributes, onClick, ref } = _a, restProps = __rest(_a, ["children", "as", "isLoading", "isDisabled", "size", "isFloating", "isActive", "variant", "description", "descriptionKdbProps", "tooltipProps", "className", "style", "htmlAttributes", "onClick", "ref"]);
|
|
42
|
+
return ((0, jsx_runtime_1.jsx)(icon_button_base_1.IconButtonBase, Object.assign({ as: as, iconButtonVariant: "default", isDisabled: isDisabled, size: size, isLoading: isLoading, isActive: isActive, isFloating: isFloating, descriptionKdbProps: descriptionKdbProps, description: description, tooltipProps: tooltipProps, className: className, style: style, variant: variant, htmlAttributes: htmlAttributes, onClick: onClick, ref: ref }, restProps, { children: children })));
|
|
43
43
|
};
|
|
44
44
|
exports.IconButton = IconButton;
|
|
45
45
|
//# sourceMappingURL=IconButton.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IconButton.js","sourceRoot":"","sources":["../../../src/icon-button/IconButton.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AAuBA,0DAA+E;AAIxE,MAAM,UAAU,GAAG,CAAyC,
|
|
1
|
+
{"version":3,"file":"IconButton.js","sourceRoot":"","sources":["../../../src/icon-button/IconButton.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AAuBA,0DAA+E;AAIxE,MAAM,UAAU,GAAG,CAAyC,EAmBhB,EAAE,EAAE;QAnBY,EACjE,QAAQ,EACR,EAAE,EACF,SAAS,GAAG,KAAK,EACjB,UAAU,GAAG,KAAK,EAClB,IAAI,GAAG,QAAQ,EACf,UAAU,GAAG,KAAK;IAClB,4FAA4F;IAC5F,QAAQ,EACR,OAAO,GAAG,SAAS,EACnB,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,SAAS,EACT,KAAK,EACL,cAAc,EACd,OAAO,EACP,GAAG,OAE8C,EAD9C,SAAS,cAlBqD,0MAmBlE,CADa;IAEZ,OAAO,CACL,uBAAC,iCAAc,kBACb,EAAE,EAAE,EAAE,EACN,iBAAiB,EAAC,SAAS,EAC3B,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,UAAU,EACtB,mBAAmB,EAAE,mBAAmB,EACxC,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,cAAc,EAC9B,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,GAAG,IACJ,SAAS,cAEZ,QAAQ,IACM,CAClB,CAAC;AACJ,CAAC,CAAC;AA3CW,QAAA,UAAU,cA2CrB","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport type React from 'react';\n\nimport { type PolymorphicCommonProps } from '../_common/types';\nimport { IconButtonBase, type IconButtonBaseProps } from '../icon-button-base';\n\ntype IconButtonButtonProps = Omit<IconButtonBaseProps, 'iconButtonVariant'>;\n\nexport const IconButton = <T extends React.ElementType = 'button'>({\n children,\n as,\n isLoading = false,\n isDisabled = false,\n size = 'medium',\n isFloating = false,\n // Does not have a default value to avoid setting aria-pressed to true if not explicitly set\n isActive,\n variant = 'neutral',\n description,\n descriptionKdbProps,\n tooltipProps,\n className,\n style,\n htmlAttributes,\n onClick,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, IconButtonButtonProps>) => {\n return (\n <IconButtonBase\n as={as}\n iconButtonVariant=\"default\"\n isDisabled={isDisabled}\n size={size}\n isLoading={isLoading}\n isActive={isActive}\n isFloating={isFloating}\n descriptionKdbProps={descriptionKdbProps}\n description={description}\n tooltipProps={tooltipProps}\n className={className}\n style={style}\n variant={variant}\n htmlAttributes={htmlAttributes}\n onClick={onClick}\n ref={ref}\n {...restProps}\n >\n {children}\n </IconButtonBase>\n );\n};\n"]}
|
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
36
|
var t = {};
|
|
4
37
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -37,17 +70,18 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
37
70
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
38
71
|
*/
|
|
39
72
|
const classnames_1 = __importDefault(require("classnames"));
|
|
40
|
-
const react_1 = require("react");
|
|
73
|
+
const react_1 = __importStar(require("react"));
|
|
41
74
|
const ButtonSpinner_1 = require("../_common/ButtonSpinner");
|
|
42
75
|
const utils_1 = require("../_common/utils");
|
|
76
|
+
const kbd_1 = require("../kbd");
|
|
43
77
|
const tooltip_1 = require("../tooltip");
|
|
44
78
|
const IconButtonBase = (_a) => {
|
|
45
79
|
var _b;
|
|
46
80
|
var { children, as, iconButtonVariant = 'default', isLoading = false, isDisabled = false, size = 'medium', isFloating = false,
|
|
47
81
|
// Does not have a default value to avoid setting aria-pressed to true if not explicitly set
|
|
48
|
-
isActive = undefined, description, tooltipProps, className, style, variant = 'neutral', htmlAttributes, onClick, ref,
|
|
82
|
+
isActive = undefined, description, descriptionKdbProps, tooltipProps, className, style, variant = 'neutral', htmlAttributes, onClick, ref,
|
|
49
83
|
// TODO v5: maybe update default message to 'Loading'. This value is for backward compatibility with loading spinners old aria-label
|
|
50
|
-
loadingMessage = 'Loading content' } = _a, restProps = __rest(_a, ["children", "as", "iconButtonVariant", "isLoading", "isDisabled", "size", "isFloating", "isActive", "description", "tooltipProps", "className", "style", "variant", "htmlAttributes", "onClick", "ref", "loadingMessage"]);
|
|
84
|
+
loadingMessage = 'Loading content' } = _a, restProps = __rest(_a, ["children", "as", "iconButtonVariant", "isLoading", "isDisabled", "size", "isFloating", "isActive", "description", "descriptionKdbProps", "tooltipProps", "className", "style", "variant", "htmlAttributes", "onClick", "ref", "loadingMessage"]);
|
|
51
85
|
const Component = as !== null && as !== void 0 ? as : 'button';
|
|
52
86
|
const loadingId = (0, react_1.useId)();
|
|
53
87
|
const isInteractable = !isDisabled && !isLoading;
|
|
@@ -84,10 +118,15 @@ const IconButtonBase = (_a) => {
|
|
|
84
118
|
onClick(e);
|
|
85
119
|
}
|
|
86
120
|
};
|
|
121
|
+
const tooltipContent = react_1.default.useMemo(() => {
|
|
122
|
+
var _a;
|
|
123
|
+
const descriptionContent = description !== null && description !== void 0 ? description : (_a = tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.content) === null || _a === void 0 ? void 0 : _a.children;
|
|
124
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [descriptionContent, descriptionKdbProps && (0, jsx_runtime_1.jsx)(kbd_1.Kbd, Object.assign({}, descriptionKdbProps))] }));
|
|
125
|
+
}, [description, descriptionKdbProps, (_b = tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.content) === null || _b === void 0 ? void 0 : _b.children]);
|
|
87
126
|
return ((0, jsx_runtime_1.jsxs)(tooltip_1.Tooltip, Object.assign({ hoverDelay: {
|
|
88
127
|
close: 0,
|
|
89
128
|
open: 500,
|
|
90
|
-
}, isDisabled: description === null || isDisabled, type: "simple" }, tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.root, { children: [(0, jsx_runtime_1.jsx)(tooltip_1.Tooltip.Trigger, Object.assign({}, tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.trigger, { hasButtonWrapper: true, children: (0, jsx_runtime_1.jsx)(Component, Object.assign({ type: "button", onClick: handleClick, disabled: isDisabled, "aria-disabled": !isInteractable, "aria-label": description, "aria-pressed": isActive, className: classes, style: style, ref: ref, "aria-describedby": isLoading ? loadingId : undefined }, restProps, htmlAttributes, { children: (0, jsx_runtime_1.jsx)("div", { className: "ndl-icon-btn-inner", children: isLoading ? ((0, jsx_runtime_1.jsx)(ButtonSpinner_1.ButtonSpinner, { loadingMessage: loadingMessage, size: "small", htmlAttributes: { id: loadingId } })) : ((0, jsx_runtime_1.jsx)("div", { className: "ndl-icon", children: children })) }) })) })), (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip.Content, Object.assign({}, tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.content, { children:
|
|
129
|
+
}, isDisabled: description === null || isDisabled, type: "simple" }, tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.root, { children: [(0, jsx_runtime_1.jsx)(tooltip_1.Tooltip.Trigger, Object.assign({}, tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.trigger, { hasButtonWrapper: true, children: (0, jsx_runtime_1.jsx)(Component, Object.assign({ type: "button", onClick: handleClick, disabled: isDisabled, "aria-disabled": !isInteractable, "aria-label": description, "aria-pressed": isActive, className: classes, style: style, ref: ref, "aria-describedby": isLoading ? loadingId : undefined }, restProps, htmlAttributes, { children: (0, jsx_runtime_1.jsx)("div", { className: "ndl-icon-btn-inner", children: isLoading ? ((0, jsx_runtime_1.jsx)(ButtonSpinner_1.ButtonSpinner, { loadingMessage: loadingMessage, size: "small", htmlAttributes: { id: loadingId } })) : ((0, jsx_runtime_1.jsx)("div", { className: "ndl-icon", children: children })) }) })) })), (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip.Content, Object.assign({}, tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.content, { children: tooltipContent }))] })));
|
|
91
130
|
};
|
|
92
131
|
exports.IconButtonBase = IconButtonBase;
|
|
93
132
|
//# sourceMappingURL=IconButtonBase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IconButtonBase.js","sourceRoot":"","sources":["../../../src/icon-button-base/IconButtonBase.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"IconButtonBase.js","sourceRoot":"","sources":["../../../src/icon-button-base/IconButtonBase.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,4DAAoC;AACpC,+CAAqC;AAErC,4DAAyD;AAKzD,4CAAwD;AAExD,gCAA6B;AAC7B,wCAAqC;AAoD9B,MAAM,cAAc,GAAG,CAAyC,EAsBtB,EAAE,EAAE;;QAtBkB,EACrE,QAAQ,EACR,EAAE,EACF,iBAAiB,GAAG,SAAS,EAC7B,SAAS,GAAG,KAAK,EACjB,UAAU,GAAG,KAAK,EAClB,IAAI,GAAG,QAAQ,EACf,UAAU,GAAG,KAAK;IAClB,4FAA4F;IAC5F,QAAQ,GAAG,SAAS,EACpB,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,SAAS,EACT,KAAK,EACL,OAAO,GAAG,SAAS,EACnB,cAAc,EACd,OAAO,EACP,GAAG;IACH,oIAAoI;IACpI,cAAc,GAAG,iBAAiB,OAEa,EAD5C,SAAS,cArByD,iPAsBtE,CADa;IAEZ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AAE,EAAE,EAAE,SAAS,EAAE,GACjC,CACH,CAAC,CAAC,CAAC,CACF,gCAAK,SAAS,EAAC,UAAU,YAAE,QAAQ,GAAO,CAC3C,GACG,IACI,IACI,EAClB,uBAAC,iBAAO,CAAC,OAAO,oBAAK,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,OAAO,cACvC,cAAc,IACC,KACV,CACX,CAAC;AACJ,CAAC,CAAC;AA5HW,QAAA,cAAc,kBA4HzB","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport classNames from 'classnames';\nimport React, { useId } from 'react';\n\nimport { ButtonSpinner } from '../_common/ButtonSpinner';\nimport {\n type PolymorphicCommonProps,\n type TooltipObjectProps,\n} from '../_common/types';\nimport { needleWarningMessage } from '../_common/utils';\nimport { type ButtonSizes } from '../button';\nimport { Kbd } from '../kbd';\nimport { Tooltip } from '../tooltip';\n\n/**\n *\n *\n * Types\n *\n *\n */\n\nexport type IconButtonBaseProps = {\n children?: React.ReactNode;\n\n /** If the icon button is in disabled state */\n isDisabled?: boolean;\n\n /** If the button is doing something Async, it will display a loading spinner */\n isLoading?: boolean;\n\n /** Size of button */\n size?: ButtonSizes;\n\n /** If the button is in floating state */\n isFloating?: boolean;\n\n /** Active - used for open context menus for example */\n isActive?: boolean;\n\n /** A string that will be shown as a tooltip when hovering over the button it also acts as an aria-label- {@link https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-label} */\n description: React.ReactNode;\n\n /** The Kbd components that will be displayed in the tooltip after the description text, this does not include the keyboard shortcut functionality this only displays the Kbd components. */\n descriptionKdbProps?: React.ComponentProps<typeof Kbd>;\n\n /** Variant of the button */\n variant?: 'neutral' | 'danger';\n\n /** Variant of the button */\n iconButtonVariant?: 'default' | 'clean';\n\n /**\n * Props for the tooltip component.\n */\n tooltipProps?: TooltipObjectProps;\n\n /** Click handler */\n onClick?: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;\n\n /** Accessible message for screen readers when the button is in a loading state */\n loadingMessage?: string;\n};\n\nexport const IconButtonBase = <T extends React.ElementType = 'button'>({\n children,\n as,\n iconButtonVariant = 'default',\n isLoading = false,\n isDisabled = false,\n size = 'medium',\n isFloating = false,\n // Does not have a default value to avoid setting aria-pressed to true if not explicitly set\n isActive = undefined,\n description,\n descriptionKdbProps,\n tooltipProps,\n className,\n style,\n variant = 'neutral',\n htmlAttributes,\n onClick,\n ref,\n // TODO v5: maybe update default message to 'Loading'. This value is for backward compatibility with loading spinners old aria-label\n loadingMessage = 'Loading content',\n ...restProps\n}: PolymorphicCommonProps<T, IconButtonBaseProps>) => {\n const Component: React.ElementType = as ?? 'button';\n const loadingId = useId();\n\n const isInteractable = !isDisabled && !isLoading;\n\n const isClean = iconButtonVariant === 'clean';\n const isDanger = variant === 'danger';\n\n const classes = classNames('ndl-icon-btn', className, {\n 'ndl-active': Boolean(isActive),\n 'ndl-clean': isClean,\n 'ndl-danger': isDanger,\n 'ndl-disabled': isDisabled,\n 'ndl-floating': isFloating,\n 'ndl-large': size === 'large',\n 'ndl-loading': isLoading,\n 'ndl-medium': size === 'medium',\n 'ndl-small': size === 'small',\n });\n\n if (isClean && isFloating) {\n throw new Error(\n 'BaseIconButton: Cannot use isFloating and iconButtonVariant=\"clean\" at the same time.',\n );\n }\n\n if (!description && !htmlAttributes?.['aria-label']) {\n needleWarningMessage(\n 'Icon buttons do not have text, be sure to include a description or an aria-label for screen readers link: https://dequeuniversity.com/rules/axe/4.4/button-name?application=axeAPI',\n );\n }\n\n const handleClick = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {\n if (!isInteractable) {\n // By default, a <button /> element with disabled set to true will not get its\n // on click handler called. To support the same behavior on <a /> tags we\n // swallow the event here when disabled, since the <a /> tag with disabled set to\n // true will have its onClick handler called\n e.preventDefault();\n e.stopPropagation();\n return;\n }\n\n if (onClick) {\n onClick(e);\n }\n };\n\n const tooltipContent = React.useMemo(() => {\n const descriptionContent = description ?? tooltipProps?.content?.children;\n return (\n <>\n {descriptionContent}\n {descriptionKdbProps && <Kbd {...descriptionKdbProps} />}\n </>\n );\n }, [description, descriptionKdbProps, tooltipProps?.content?.children]);\n\n return (\n <Tooltip\n hoverDelay={{\n close: 0,\n open: 500,\n }}\n isDisabled={description === null || isDisabled}\n type=\"simple\"\n {...tooltipProps?.root}\n >\n <Tooltip.Trigger {...tooltipProps?.trigger} hasButtonWrapper>\n <Component\n type=\"button\"\n onClick={handleClick}\n disabled={isDisabled}\n aria-disabled={!isInteractable}\n aria-label={description}\n aria-pressed={isActive}\n className={classes}\n style={style}\n ref={ref}\n aria-describedby={isLoading ? loadingId : undefined}\n {...restProps}\n {...htmlAttributes}\n >\n <div className=\"ndl-icon-btn-inner\">\n {isLoading ? (\n <ButtonSpinner\n loadingMessage={loadingMessage}\n size=\"small\"\n htmlAttributes={{ id: loadingId }}\n />\n ) : (\n <div className=\"ndl-icon\">{children}</div>\n )}\n </div>\n </Component>\n </Tooltip.Trigger>\n <Tooltip.Content {...tooltipProps?.content}>\n {tooltipContent}\n </Tooltip.Content>\n </Tooltip>\n );\n};\n"]}
|
package/lib/cjs/kbd/Kbd.js
CHANGED
|
@@ -39,16 +39,16 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
39
39
|
const classnames_1 = __importDefault(require("classnames"));
|
|
40
40
|
const react_1 = require("react");
|
|
41
41
|
const kbd_utils_1 = require("./kbd-utils");
|
|
42
|
+
// TODO v5: Change element type to 'kbd'
|
|
42
43
|
const Kbd = (_a) => {
|
|
43
44
|
var { modifierKeys, keys, os, as, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["modifierKeys", "keys", "os", "as", "className", "style", "htmlAttributes", "ref"]);
|
|
44
|
-
const Component = as !== null && as !== void 0 ? as : '
|
|
45
|
+
const Component = as !== null && as !== void 0 ? as : 'kbd';
|
|
45
46
|
const modifierKeysContent = (0, react_1.useMemo)(() => {
|
|
46
47
|
if (modifierKeys === undefined) {
|
|
47
48
|
return null;
|
|
48
49
|
}
|
|
49
50
|
const keyMap = (0, kbd_utils_1.getKbdKeysMap)(os);
|
|
50
|
-
|
|
51
|
-
return modifierKeys === null || modifierKeys === void 0 ? void 0 : modifierKeys.map((key) => ((0, jsx_runtime_1.jsx)("abbr", { className: "ndl-kbd-key", title: labelMap[key], children: keyMap[key] }, key)));
|
|
51
|
+
return modifierKeys === null || modifierKeys === void 0 ? void 0 : modifierKeys.map((key) => ((0, jsx_runtime_1.jsx)("span", { className: "ndl-kbd-key", "aria-hidden": "true", children: keyMap[key] }, key)));
|
|
52
52
|
}, [modifierKeys, os]);
|
|
53
53
|
const keysContent = (0, react_1.useMemo)(() => {
|
|
54
54
|
if (keys === undefined) {
|
|
@@ -56,13 +56,14 @@ const Kbd = (_a) => {
|
|
|
56
56
|
}
|
|
57
57
|
return keys === null || keys === void 0 ? void 0 : keys.map((key, index) => {
|
|
58
58
|
if (index === 0) {
|
|
59
|
-
return ((0, jsx_runtime_1.jsx)("span", { className: "ndl-kbd-key", children: key }, key === null || key === void 0 ? void 0 : key.toString()));
|
|
59
|
+
return ((0, jsx_runtime_1.jsx)("span", { className: "ndl-kbd-key", "aria-hidden": "true", children: key }, key === null || key === void 0 ? void 0 : key.toString()));
|
|
60
60
|
}
|
|
61
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("span", { className: "ndl-kbd-then", children: "Then" }), (0, jsx_runtime_1.jsx)("span", { className: "ndl-kbd-key", children: key }, key === null || key === void 0 ? void 0 : key.toString())] }));
|
|
61
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("span", { className: "ndl-kbd-then", "aria-hidden": "true", children: "Then" }), (0, jsx_runtime_1.jsx)("span", { className: "ndl-kbd-key", "aria-hidden": "true", children: key }, key === null || key === void 0 ? void 0 : key.toString())] }));
|
|
62
62
|
});
|
|
63
63
|
}, [keys]);
|
|
64
|
+
const screenReaderFriendlyText = (0, react_1.useMemo)(() => (0, kbd_utils_1.getKbdScreenReaderFriendlyText)(keys, modifierKeys, os), [keys, modifierKeys, os]);
|
|
64
65
|
const classes = (0, classnames_1.default)('ndl-kbd', className);
|
|
65
|
-
return ((0, jsx_runtime_1.jsxs)(Component, Object.assign({ className: classes, style: style, ref: ref }, restProps, htmlAttributes, { children: [modifierKeysContent, keysContent] })));
|
|
66
|
+
return ((0, jsx_runtime_1.jsxs)(Component, Object.assign({ className: classes, style: style, ref: ref }, restProps, htmlAttributes, { children: [(0, jsx_runtime_1.jsx)("span", { className: "ndl-kbd-sr-friendly-text", children: screenReaderFriendlyText }), modifierKeysContent, keysContent] })));
|
|
66
67
|
};
|
|
67
68
|
exports.Kbd = Kbd;
|
|
68
69
|
//# sourceMappingURL=Kbd.js.map
|
package/lib/cjs/kbd/Kbd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Kbd.js","sourceRoot":"","sources":["../../../src/kbd/Kbd.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,4DAAoC;AACpC,iCAAgC;AAGhC,2CAKqB;
|
|
1
|
+
{"version":3,"file":"Kbd.js","sourceRoot":"","sources":["../../../src/kbd/Kbd.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,4DA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M,SAAS,EAAC,cAAc,iBAAa,MAAM,qBAE1C,EACP,iCACE,SAAS,EAAC,aAAa,iBAEX,MAAM,YAEjB,GAAG,IAHC,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,QAAQ,EAAE,CAIf,IACN,CACJ,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAEX,MAAM,wBAAwB,GAAG,IAAA,eAAO,EACtC,GAAG,EAAE,CAAC,IAAA,0CAA8B,EAAC,IAAI,EAAE,YAAY,EAAE,EAAE,CAAC,EAC5D,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,CAAC,CACzB,CAAC;IACF,MAAM,OAAO,GAAG,IAAA,oBAAU,EAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAEjD,OAAO,CACL,wBAAC,SAAS,kBACR,SAAS,EAAE,OAAO,EAClB,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,GAAG,IACJ,SAAS,EACT,cAAc,eAElB,iCAAM,SAAS,EAAC,0BAA0B,YACvC,wBAAwB,GACpB,EACN,mBAAmB,EACnB,WAAW,KACF,CACb,CAAC;AACJ,CAAC,CAAC;AAlFW,QAAA,GAAG,OAkFd","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport classNames from 'classnames';\nimport { useMemo } from 'react';\n\nimport { type PolymorphicCommonProps } from '../_common/types';\nimport {\n getKbdKeysMap,\n getKbdScreenReaderFriendlyText,\n type KbdKey,\n type OperatingSystem,\n} from './kbd-utils';\n\ntype KbdProps = {\n /**\n * The modifier keys to display in the keyboard shortcut.\n */\n modifierKeys?: KbdKey[];\n /**\n * The main keys to display in the keyboard shortcut.\n */\n keys?: React.ReactNode[];\n /**\n * Override the operating system detection for key symbols\n */\n os?: OperatingSystem;\n};\n\n// TODO v5: Change element type to 'kbd'\nexport const Kbd = <T extends React.ElementType = 'span'>({\n modifierKeys,\n keys,\n os,\n as,\n className,\n style,\n htmlAttributes,\n ref,\n ...restProps\n}: PolymorphicCommonProps<T, KbdProps>) => {\n const Component: React.ElementType = as ?? 'kbd';\n\n const modifierKeysContent = useMemo(() => {\n if (modifierKeys === undefined) {\n return null;\n }\n\n const keyMap = getKbdKeysMap(os);\n\n return modifierKeys?.map((key) => (\n <span className=\"ndl-kbd-key\" key={key} aria-hidden=\"true\">\n {keyMap[key]}\n </span>\n ));\n }, [modifierKeys, os]);\n\n const keysContent = useMemo(() => {\n if (keys === undefined) {\n return null;\n }\n\n return keys?.map((key, index) => {\n if (index === 0) {\n return (\n <span\n className=\"ndl-kbd-key\"\n key={key?.toString()}\n aria-hidden=\"true\"\n >\n {key}\n </span>\n );\n }\n return (\n <>\n <span className=\"ndl-kbd-then\" aria-hidden=\"true\">\n Then\n </span>\n <span\n className=\"ndl-kbd-key\"\n key={key?.toString()}\n aria-hidden=\"true\"\n >\n {key}\n </span>\n </>\n );\n });\n }, [keys]);\n\n const screenReaderFriendlyText = useMemo(\n () => getKbdScreenReaderFriendlyText(keys, modifierKeys, os),\n [keys, modifierKeys, os],\n );\n const classes = classNames('ndl-kbd', className);\n\n return (\n <Component\n className={classes}\n style={style}\n ref={ref}\n {...restProps}\n {...htmlAttributes}\n >\n <span className=\"ndl-kbd-sr-friendly-text\">\n {screenReaderFriendlyText}\n </span>\n {modifierKeysContent}\n {keysContent}\n </Component>\n );\n};\n"]}
|
package/lib/cjs/kbd/kbd-utils.js
CHANGED
|
@@ -24,6 +24,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
24
24
|
exports.detectOS = detectOS;
|
|
25
25
|
exports.getKbdKeysMap = getKbdKeysMap;
|
|
26
26
|
exports.getKbdKeysLabelMap = getKbdKeysLabelMap;
|
|
27
|
+
exports.getKbdScreenReaderFriendlyText = getKbdScreenReaderFriendlyText;
|
|
27
28
|
/**
|
|
28
29
|
* Detects the operating system based on the user agent
|
|
29
30
|
*/
|
|
@@ -95,4 +96,32 @@ function getKbdKeysLabelMap(os = detectOS()) {
|
|
|
95
96
|
up: 'Up',
|
|
96
97
|
};
|
|
97
98
|
}
|
|
99
|
+
function resolveKeyLabel(key, labels) {
|
|
100
|
+
if (key === null || key === undefined || typeof key === 'boolean') {
|
|
101
|
+
return '';
|
|
102
|
+
}
|
|
103
|
+
if (typeof key === 'string') {
|
|
104
|
+
return key in labels ? labels[key] : key;
|
|
105
|
+
}
|
|
106
|
+
if (typeof key === 'number') {
|
|
107
|
+
return String(key);
|
|
108
|
+
}
|
|
109
|
+
return '';
|
|
110
|
+
}
|
|
111
|
+
function getKbdScreenReaderFriendlyText(keys, modifierKeys, os = detectOS()) {
|
|
112
|
+
const labels = getKbdKeysLabelMap(os);
|
|
113
|
+
const modStr = (modifierKeys !== null && modifierKeys !== void 0 ? modifierKeys : []).map((k) => labels[k]).join(' + ');
|
|
114
|
+
const keyLabels = (keys !== null && keys !== void 0 ? keys : [])
|
|
115
|
+
.map((k) => resolveKeyLabel(k, labels))
|
|
116
|
+
.filter(Boolean);
|
|
117
|
+
let keyStr = '';
|
|
118
|
+
if (keyLabels.length === 1) {
|
|
119
|
+
keyStr = keyLabels[0];
|
|
120
|
+
}
|
|
121
|
+
else if (keyLabels.length > 1) {
|
|
122
|
+
keyStr = keyLabels.join(' then ');
|
|
123
|
+
}
|
|
124
|
+
const body = [modStr, keyStr].filter(Boolean).join(' + ');
|
|
125
|
+
return body ? `Shortcut: ${body}` : '';
|
|
126
|
+
}
|
|
98
127
|
//# sourceMappingURL=kbd-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kbd-utils.js","sourceRoot":"","sources":["../../../src/kbd/kbd-utils.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"kbd-utils.js","sourceRoot":"","sources":["../../../src/kbd/kbd-utils.ts"],"names":[],"mappings":";;AAgDA,4BAcC;AAKD,sCA0BC;AAKD,gDAwBC;AAkBD,wEAkBC;AAjHD;;GAEG;AACH,SAAgB,QAAQ;IACtB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC;IAE3D,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;SAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACrC,OAAO,SAAS,CAAC;IACnB,CAAC;SAAM,CAAC;QACN,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAC3B,KAAsB,QAAQ,EAAE;IAEhC,MAAM,OAAO,GAA2B;QACtC,GAAG,EAAE,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK;QAC/B,QAAQ,EAAE,GAAG;QACb,IAAI,EAAE,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM;QACjC,MAAM,EAAE,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ;QACrC,IAAI,EAAE,GAAG;QACT,GAAG,EAAE,KAAK;QACV,KAAK,EAAE,GAAG;QACV,MAAM,EAAE,GAAG;QACX,EAAE,EAAE,IAAI;QACR,IAAI,EAA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;IAC1D,OAAO,IAAI,CAAC,CAAC,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AACzC,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport type { ReactNode } from 'react';\n\nexport type OperatingSystem = 'mac' | 'windows' | 'linux';\n\nexport type KbdKey =\n | 'meta'\n | 'shift'\n | 'ctrl'\n | 'enter'\n | 'delete'\n | 'escape'\n | 'tab'\n | 'capslock'\n | 'up'\n | 'right'\n | 'down'\n | 'left'\n | 'pageup'\n | 'pagedown'\n | 'home'\n | 'end'\n | 'space'\n | 'fn'\n | 'alt';\n\n/**\n * Detects the operating system based on the user agent\n */\nexport function detectOS(): OperatingSystem {\n if (typeof window === 'undefined') {\n return 'linux';\n }\n\n const userAgent = window.navigator.userAgent.toLowerCase();\n\n if (userAgent.includes('mac')) {\n return 'mac';\n } else if (userAgent.includes('win')) {\n return 'windows';\n } else {\n return 'linux';\n }\n}\n\n/**\n * Returns OS-aware keyboard key symbols\n */\nexport function getKbdKeysMap(\n os: OperatingSystem = detectOS(),\n): Record<KbdKey, string> {\n const baseMap: Record<KbdKey, string> = {\n alt: os === 'mac' ? '⌥' : 'alt',\n capslock: '⇪',\n ctrl: os === 'mac' ? '⌃' : 'ctrl',\n delete: os === 'mac' ? '⌫' : 'delete',\n down: '↓',\n end: 'end',\n enter: '↵',\n escape: '⎋',\n fn: 'Fn',\n home: 'home',\n left: '←',\n meta: os === 'mac' ? '⌘' : os === 'windows' ? '⊞' : 'meta',\n pagedown: '⇟',\n pageup: '⇞',\n right: '→',\n shift: '⇧',\n space: '␣',\n tab: '⇥',\n up: '↑',\n };\n\n return baseMap;\n}\n\n/**\n * Returns OS-aware keyboard key labels\n */\nexport function getKbdKeysLabelMap(\n os: OperatingSystem = detectOS(),\n): Record<KbdKey, string> {\n return {\n alt: 'Alt',\n capslock: 'Caps Lock',\n ctrl: 'Control',\n delete: 'Delete',\n down: 'Down',\n end: 'End',\n enter: 'Enter',\n escape: 'Escape',\n fn: 'Fn',\n home: 'Home',\n left: 'Left',\n meta: os === 'mac' ? 'Command' : os === 'windows' ? 'Windows' : 'Meta',\n pagedown: 'Page Down',\n pageup: 'Page Up',\n right: 'Right',\n shift: 'Shift',\n space: 'Space',\n tab: 'Tab',\n up: 'Up',\n };\n}\n\nfunction resolveKeyLabel(\n key: KbdKey | ReactNode,\n labels: Record<KbdKey, string>,\n): string {\n if (key === null || key === undefined || typeof key === 'boolean') {\n return '';\n }\n if (typeof key === 'string') {\n return key in labels ? labels[key as KbdKey] : key;\n }\n if (typeof key === 'number') {\n return String(key);\n }\n return '';\n}\n\nexport function getKbdScreenReaderFriendlyText(\n keys: readonly (KbdKey | ReactNode)[] | undefined,\n modifierKeys: readonly KbdKey[] | undefined,\n os: OperatingSystem = detectOS(),\n): string {\n const labels = getKbdKeysLabelMap(os);\n const modStr = (modifierKeys ?? []).map((k) => labels[k]).join(' + ');\n const keyLabels = (keys ?? [])\n .map((k) => resolveKeyLabel(k, labels))\n .filter(Boolean);\n let keyStr = '';\n if (keyLabels.length === 1) {\n keyStr = keyLabels[0];\n } else if (keyLabels.length > 1) {\n keyStr = keyLabels.join(' then ');\n }\n const body = [modStr, keyStr].filter(Boolean).join(' + ');\n return body ? `Shortcut: ${body}` : '';\n}\n"]}
|
|
@@ -23,7 +23,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
23
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.MenuRadioAndNormalSrc = exports.MenuRadioItemsSrc = exports.
|
|
26
|
+
exports.MenuRadioAndNormalSrc = exports.MenuRadioItemsSrc = exports.MenuWithKeyboardDisplaySrc = exports.MenuPlacementsSrc = exports.MenuWithDisabledItemSrc = exports.MenuDividerSrc = exports.MenuInDialogSrc = exports.MenuInPopoverSrc = exports.MenuCustomItemsSrc = exports.MenuWithIconSrc = exports.MenuWithCategorySrc = exports.MenuNestedSrc = exports.MenuDefaultSrc = exports.MenuRadioAndNormal = exports.MenuRadioItems = exports.MenuWithKeyboardDisplay = exports.MenuPlacements = exports.MenuWithDisabledItem = exports.MenuDivider = exports.MenuInDialog = exports.MenuInPopover = exports.MenuCustomItems = exports.MenuWithIcon = exports.MenuWithCategory = exports.MenuNested = exports.MenuDefault = void 0;
|
|
27
27
|
var menu_default_story_1 = require("./menu-default.story");
|
|
28
28
|
Object.defineProperty(exports, "MenuDefault", { enumerable: true, get: function () { return __importDefault(menu_default_story_1).default; } });
|
|
29
29
|
var menu_nested_story_1 = require("./menu-nested.story");
|
|
@@ -45,7 +45,7 @@ Object.defineProperty(exports, "MenuWithDisabledItem", { enumerable: true, get:
|
|
|
45
45
|
var menu_placements_story_1 = require("./menu-placements.story");
|
|
46
46
|
Object.defineProperty(exports, "MenuPlacements", { enumerable: true, get: function () { return __importDefault(menu_placements_story_1).default; } });
|
|
47
47
|
var menu_with_keyboard_shortcuts_story_1 = require("./menu-with-keyboard-shortcuts.story");
|
|
48
|
-
Object.defineProperty(exports, "
|
|
48
|
+
Object.defineProperty(exports, "MenuWithKeyboardDisplay", { enumerable: true, get: function () { return __importDefault(menu_with_keyboard_shortcuts_story_1).default; } });
|
|
49
49
|
var menu_radio_items_story_1 = require("./menu-radio-items.story");
|
|
50
50
|
Object.defineProperty(exports, "MenuRadioItems", { enumerable: true, get: function () { return __importDefault(menu_radio_items_story_1).default; } });
|
|
51
51
|
var menu_radio_and_normal_story_1 = require("./menu-radio-and-normal.story");
|
|
@@ -74,7 +74,7 @@ exports.MenuInDialogSrc = (0, export_stories_utils_1.removeLicenseHeader)(menu_i
|
|
|
74
74
|
exports.MenuDividerSrc = (0, export_stories_utils_1.removeLicenseHeader)(menu_with_divider_story_raw_1.default);
|
|
75
75
|
exports.MenuWithDisabledItemSrc = (0, export_stories_utils_1.removeLicenseHeader)(menu_with_disabled_item_story_raw_1.default);
|
|
76
76
|
exports.MenuPlacementsSrc = (0, export_stories_utils_1.removeLicenseHeader)(menu_placements_story_raw_1.default);
|
|
77
|
-
exports.
|
|
77
|
+
exports.MenuWithKeyboardDisplaySrc = (0, export_stories_utils_1.removeLicenseHeader)(menu_with_keyboard_shortcuts_story_raw_1.default);
|
|
78
78
|
exports.MenuRadioItemsSrc = (0, export_stories_utils_1.removeLicenseHeader)(menu_radio_items_story_raw_1.default);
|
|
79
79
|
exports.MenuRadioAndNormalSrc = (0, export_stories_utils_1.removeLicenseHeader)(menu_radio_and_normal_story_raw_1.default);
|
|
80
80
|
//# sourceMappingURL=index.js.map
|