@xh/hoist 75.0.0-SNAPSHOT.1753490062755 → 75.0.0-SNAPSHOT.1753720955374
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
CHANGED
|
@@ -21,6 +21,8 @@
|
|
|
21
21
|
* Deprecated the `RelativeTimestamp.options` prop - all the same options are now top-level props.
|
|
22
22
|
* Added new `GroupingChooserModel.sortDimensions` config. Set to `false` to respect the order in
|
|
23
23
|
which `dimensions` are provided to the model.
|
|
24
|
+
* Added new `ClipboardButton.errorMessage` prop to customize or suppress a toast alert if the copy
|
|
25
|
+
operation fails. Set to `false` to fail silently (the behavior prior to this change).
|
|
24
26
|
|
|
25
27
|
### 🐞 Bug Fixes
|
|
26
28
|
|
|
@@ -3,8 +3,16 @@ import '@xh/hoist/desktop/register';
|
|
|
3
3
|
export interface ClipboardButtonProps extends ButtonProps {
|
|
4
4
|
/** Function returning the text to copy. May be async. */
|
|
5
5
|
getCopyText: () => string | Promise<string>;
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Message to be displayed in a toast should the copy operation fail, or `true` (default) to
|
|
8
|
+
* show a toast-based alert from `XH.handleException`. Spec `false` to fail silently.
|
|
9
|
+
*/
|
|
10
|
+
errorMessage?: string | boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Message to be displayed in a toast when copy is complete, or `true` for a default success
|
|
13
|
+
* confirmation. Default `false`
|
|
14
|
+
*/
|
|
15
|
+
successMessage?: string | boolean;
|
|
8
16
|
}
|
|
9
17
|
/**
|
|
10
18
|
* Button to copy text to the clipboard.
|
|
@@ -10,12 +10,23 @@ import '@xh/hoist/desktop/register';
|
|
|
10
10
|
import {Icon} from '@xh/hoist/icon';
|
|
11
11
|
import {withDefault} from '@xh/hoist/utils/js';
|
|
12
12
|
import copy from 'clipboard-copy';
|
|
13
|
+
import {isString} from 'lodash';
|
|
13
14
|
|
|
14
15
|
export interface ClipboardButtonProps extends ButtonProps {
|
|
15
16
|
/** Function returning the text to copy. May be async. */
|
|
16
17
|
getCopyText: () => string | Promise<string>;
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Message to be displayed in a toast should the copy operation fail, or `true` (default) to
|
|
21
|
+
* show a toast-based alert from `XH.handleException`. Spec `false` to fail silently.
|
|
22
|
+
*/
|
|
23
|
+
errorMessage?: string | boolean;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Message to be displayed in a toast when copy is complete, or `true` for a default success
|
|
27
|
+
* confirmation. Default `false`
|
|
28
|
+
*/
|
|
29
|
+
successMessage?: string | boolean;
|
|
19
30
|
}
|
|
20
31
|
|
|
21
32
|
/**
|
|
@@ -24,24 +35,36 @@ export interface ClipboardButtonProps extends ButtonProps {
|
|
|
24
35
|
export const [ClipboardButton, clipboardButton] = hoistCmp.withFactory<ClipboardButtonProps>({
|
|
25
36
|
displayName: 'ClipboardButton',
|
|
26
37
|
model: false,
|
|
38
|
+
|
|
27
39
|
render(props) {
|
|
28
|
-
let {icon, onClick, text, getCopyText, successMessage, ...rest} = props;
|
|
40
|
+
let {icon, onClick, text, getCopyText, errorMessage, successMessage, ...rest} = props;
|
|
41
|
+
let errMsg = withDefault(errorMessage, true),
|
|
42
|
+
successMsg = withDefault(successMessage, false);
|
|
29
43
|
|
|
30
44
|
if (!onClick) {
|
|
31
45
|
onClick = async () => {
|
|
32
|
-
const {successMessage, getCopyText} = props;
|
|
33
|
-
|
|
34
46
|
try {
|
|
35
|
-
const
|
|
36
|
-
await copy(
|
|
37
|
-
if (
|
|
47
|
+
const copyText = await getCopyText();
|
|
48
|
+
await copy(copyText);
|
|
49
|
+
if (successMsg) {
|
|
50
|
+
successMsg = isString(successMsg) ? successMsg : 'Copied to clipboard';
|
|
38
51
|
XH.toast({
|
|
39
|
-
|
|
40
|
-
|
|
52
|
+
icon: Icon.clipboard(),
|
|
53
|
+
message: successMsg
|
|
41
54
|
});
|
|
42
55
|
}
|
|
43
56
|
} catch (e) {
|
|
44
|
-
|
|
57
|
+
if (errMsg) {
|
|
58
|
+
errMsg = isString(errMsg) ? errMsg : 'Error copying to clipboard';
|
|
59
|
+
XH.dangerToast({
|
|
60
|
+
icon: Icon.clipboard(),
|
|
61
|
+
message: errMsg
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
XH.handleException(e, {
|
|
65
|
+
message: 'Error copying to clipboard',
|
|
66
|
+
showAlert: false
|
|
67
|
+
});
|
|
45
68
|
}
|
|
46
69
|
};
|
|
47
70
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xh/hoist",
|
|
3
|
-
"version": "75.0.0-SNAPSHOT.
|
|
3
|
+
"version": "75.0.0-SNAPSHOT.1753720955374",
|
|
4
4
|
"description": "Hoist add-on for building and deploying React Applications.",
|
|
5
5
|
"repository": "github:xh/hoist-react",
|
|
6
6
|
"homepage": "https://xh.io",
|