@cloudtower/eagle 0.35.7 → 0.35.9
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/dist/cjs/core/Duration/index.js +78 -0
- package/dist/cjs/core/index.js +15 -12
- package/dist/cjs/coreX/Copy/CopyButton.js +40 -0
- package/dist/cjs/coreX/Copy/CopyTooltip.js +66 -0
- package/dist/cjs/hooks/useFormatDuration.js +35 -0
- package/dist/cjs/index.js +251 -245
- package/dist/cjs/stats1.html +1 -1
- package/dist/cjs/utils/formatDuration.js +67 -0
- package/dist/components.css +3043 -3043
- package/dist/esm/core/Duration/index.js +72 -0
- package/dist/esm/core/index.js +4 -2
- package/dist/esm/coreX/Copy/CopyButton.js +34 -0
- package/dist/esm/coreX/Copy/CopyTooltip.js +59 -0
- package/dist/esm/hooks/useFormatDuration.js +33 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/stats1.html +1 -1
- package/dist/esm/utils/formatDuration.js +65 -0
- package/dist/linaria.merged.scss +3619 -3619
- package/dist/src/core/Duration/duration.type.d.ts +42 -0
- package/dist/src/core/Duration/index.d.ts +4 -0
- package/dist/src/core/index.d.ts +4 -0
- package/dist/src/coreX/index.d.ts +2 -0
- package/dist/src/hooks/__tests__/useFormatDuration.test.d.ts +1 -0
- package/dist/src/hooks/index.d.ts +1 -0
- package/dist/src/hooks/useFormatDuration.d.ts +31 -0
- package/dist/src/utils/__test__/formatDuration.spec.d.ts +1 -0
- package/dist/src/utils/formatDuration.d.ts +28 -0
- package/dist/src/utils/index.d.ts +1 -0
- package/dist/stories/docs/core/Duration.stories.d.ts +88 -0
- package/dist/style.css +3043 -3043
- package/package.json +4 -4
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React__default from 'react';
|
|
2
|
+
import { cx } from '@linaria/core';
|
|
3
|
+
import Empty from '../Empty/index.js';
|
|
4
|
+
import { ParrotTrans } from '../ParrotTrans/index.js';
|
|
5
|
+
import { useFormatDuration } from '../../hooks/useFormatDuration.js';
|
|
6
|
+
import isEmpty from '../../utils/isEmpty.js';
|
|
7
|
+
import { formatDuration } from '../../utils/formatDuration.js';
|
|
8
|
+
import { UnitStyle } from '../Styled/index.js';
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
12
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
14
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
15
|
+
var __spreadValues = (a, b) => {
|
|
16
|
+
for (var prop in b || (b = {}))
|
|
17
|
+
if (__hasOwnProp.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
if (__getOwnPropSymbols)
|
|
20
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
21
|
+
if (__propIsEnum.call(b, prop))
|
|
22
|
+
__defNormalProp(a, prop, b[prop]);
|
|
23
|
+
}
|
|
24
|
+
return a;
|
|
25
|
+
};
|
|
26
|
+
const Duration = ({
|
|
27
|
+
rawValue,
|
|
28
|
+
valueClassName,
|
|
29
|
+
unitClassName,
|
|
30
|
+
abbreviate,
|
|
31
|
+
emptyProps,
|
|
32
|
+
maxDisplayUnits = 2,
|
|
33
|
+
minUnit = "second",
|
|
34
|
+
noUnitOnZero = false,
|
|
35
|
+
contentRender
|
|
36
|
+
}) => {
|
|
37
|
+
const { parts } = useFormatDuration(rawValue != null ? rawValue : 0, {
|
|
38
|
+
maxDisplayUnits,
|
|
39
|
+
useAbbreviation: abbreviate,
|
|
40
|
+
minUnit
|
|
41
|
+
});
|
|
42
|
+
if (isEmpty(rawValue)) {
|
|
43
|
+
return /* @__PURE__ */ React__default.createElement(Empty, __spreadValues({}, emptyProps));
|
|
44
|
+
}
|
|
45
|
+
if (parts.length === 0) {
|
|
46
|
+
return /* @__PURE__ */ React__default.createElement(Empty, __spreadValues({}, emptyProps));
|
|
47
|
+
}
|
|
48
|
+
if (contentRender) {
|
|
49
|
+
const formatItems = formatDuration(rawValue, {
|
|
50
|
+
maxDisplayUnits,
|
|
51
|
+
minUnit
|
|
52
|
+
});
|
|
53
|
+
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, contentRender(formatItems));
|
|
54
|
+
}
|
|
55
|
+
const allZero = parts.every((part) => part.value === 0);
|
|
56
|
+
if (noUnitOnZero && allZero) {
|
|
57
|
+
return /* @__PURE__ */ React__default.createElement("span", { className: cx("value", valueClassName) }, "0");
|
|
58
|
+
}
|
|
59
|
+
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, parts.map((part, index) => /* @__PURE__ */ React__default.createElement(React__default.Fragment, { key: `${part.unit}-${index}` }, index > 0 && /* @__PURE__ */ React__default.createElement("span", null, " "), /* @__PURE__ */ React__default.createElement(
|
|
60
|
+
ParrotTrans,
|
|
61
|
+
{
|
|
62
|
+
parent: "span",
|
|
63
|
+
i18nKey: part.i18nKey,
|
|
64
|
+
count: part.value
|
|
65
|
+
},
|
|
66
|
+
/* @__PURE__ */ React__default.createElement("span", { className: cx("value", valueClassName) }),
|
|
67
|
+
/* @__PURE__ */ React__default.createElement("span", { className: cx("unit", UnitStyle, unitClassName) })
|
|
68
|
+
))));
|
|
69
|
+
};
|
|
70
|
+
var Duration$1 = Duration;
|
|
71
|
+
|
|
72
|
+
export { Duration$1 as default };
|
package/dist/esm/core/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import BitPerSecond from './BitPerSecond/index.js';
|
|
|
3
3
|
import Bps from './Bps/index.js';
|
|
4
4
|
import Byte from './Byte/index.js';
|
|
5
5
|
import BytePerSecond from './BytePerSecond/index.js';
|
|
6
|
+
import Duration from './Duration/index.js';
|
|
6
7
|
import Frequency from './Frequency/index.js';
|
|
7
8
|
import Percent from './Percent/index.js';
|
|
8
9
|
import Second from './Second/index.js';
|
|
@@ -17,7 +18,8 @@ const units = {
|
|
|
17
18
|
Bps,
|
|
18
19
|
BitPerSecond,
|
|
19
20
|
Bit,
|
|
20
|
-
Second
|
|
21
|
+
Second,
|
|
22
|
+
Duration
|
|
21
23
|
};
|
|
22
24
|
|
|
23
|
-
export { Bit, BitPerSecond, Bps, Byte, BytePerSecond, Frequency, Percent, Second, Speed, units as Units, units };
|
|
25
|
+
export { Bit, BitPerSecond, Bps, Byte, BytePerSecond, Duration, Frequency, Percent, Second, Speed, units as Units, units };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import Button from '../../core/Button/index.js';
|
|
2
|
+
import useParrotTranslation from '../../hooks/useParrotTranslation.js';
|
|
3
|
+
import React__default, { useState } from 'react';
|
|
4
|
+
import CopyTooltip from './CopyTooltip.js';
|
|
5
|
+
|
|
6
|
+
const CopyButton = ({
|
|
7
|
+
text,
|
|
8
|
+
buttonText,
|
|
9
|
+
tooltipText
|
|
10
|
+
}) => {
|
|
11
|
+
const { t } = useParrotTranslation();
|
|
12
|
+
const [tooltipVisible, setTooltipVisible] = useState(false);
|
|
13
|
+
const handleCopy = async () => {
|
|
14
|
+
try {
|
|
15
|
+
setTooltipVisible(true);
|
|
16
|
+
setTimeout(() => {
|
|
17
|
+
setTooltipVisible(false);
|
|
18
|
+
}, 1e3);
|
|
19
|
+
} catch (err) {
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
23
|
+
CopyTooltip,
|
|
24
|
+
{
|
|
25
|
+
tooltipProps: { visible: tooltipVisible },
|
|
26
|
+
text,
|
|
27
|
+
afterTooltip: tooltipText ? tooltipText : t("common.has_copied_to_clipboard")
|
|
28
|
+
},
|
|
29
|
+
/* @__PURE__ */ React__default.createElement(Button, { onClick: handleCopy }, buttonText ? buttonText : t("common.copy"))
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
var CopyButton$1 = CopyButton;
|
|
33
|
+
|
|
34
|
+
export { CopyButton$1 as default };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ClipboardCopy16GradientGrayIcon } from '@cloudtower/icons-react';
|
|
2
|
+
import Icon from '../../core/Icon/index.js';
|
|
3
|
+
import Tooltip from '../../core/Tooltip/index.js';
|
|
4
|
+
import useParrotTranslation from '../../hooks/useParrotTranslation.js';
|
|
5
|
+
import React__default, { useState } from 'react';
|
|
6
|
+
import CopyToClipboard from 'react-copy-to-clipboard';
|
|
7
|
+
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __defProps = Object.defineProperties;
|
|
10
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
11
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
12
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
14
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
15
|
+
var __spreadValues = (a, b) => {
|
|
16
|
+
for (var prop in b || (b = {}))
|
|
17
|
+
if (__hasOwnProp.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
if (__getOwnPropSymbols)
|
|
20
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
21
|
+
if (__propIsEnum.call(b, prop))
|
|
22
|
+
__defNormalProp(a, prop, b[prop]);
|
|
23
|
+
}
|
|
24
|
+
return a;
|
|
25
|
+
};
|
|
26
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
27
|
+
const CopyTooltip = React__default.forwardRef(
|
|
28
|
+
(props, ref) => {
|
|
29
|
+
const { t } = useParrotTranslation();
|
|
30
|
+
const {
|
|
31
|
+
text,
|
|
32
|
+
beforeTooltip = t("common.click_to_copy"),
|
|
33
|
+
afterTooltip = t("common.copy_done"),
|
|
34
|
+
children = /* @__PURE__ */ React__default.createElement(Icon, { src: ClipboardCopy16GradientGrayIcon }),
|
|
35
|
+
tooltipProps,
|
|
36
|
+
className
|
|
37
|
+
} = props;
|
|
38
|
+
const [tooltipText, setTooltipText] = useState(beforeTooltip);
|
|
39
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
40
|
+
"span",
|
|
41
|
+
{
|
|
42
|
+
ref,
|
|
43
|
+
onMouseEnter: () => setTooltipText(beforeTooltip),
|
|
44
|
+
className
|
|
45
|
+
},
|
|
46
|
+
/* @__PURE__ */ React__default.createElement(Tooltip, __spreadProps(__spreadValues({}, tooltipProps), { title: tooltipText }), /* @__PURE__ */ React__default.createElement(
|
|
47
|
+
CopyToClipboard,
|
|
48
|
+
{
|
|
49
|
+
text,
|
|
50
|
+
onCopy: () => setTooltipText(afterTooltip)
|
|
51
|
+
},
|
|
52
|
+
children
|
|
53
|
+
))
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
var CopyTooltip$1 = CopyTooltip;
|
|
58
|
+
|
|
59
|
+
export { CopyTooltip$1 as default };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { formatDuration } from '../utils/formatDuration.js';
|
|
3
|
+
|
|
4
|
+
function useFormatDuration(milliseconds, options = {
|
|
5
|
+
maxDisplayUnits: 2,
|
|
6
|
+
useAbbreviation: false,
|
|
7
|
+
minUnit: "second"
|
|
8
|
+
}) {
|
|
9
|
+
const {
|
|
10
|
+
maxDisplayUnits = 2,
|
|
11
|
+
useAbbreviation = false,
|
|
12
|
+
minUnit = "second"
|
|
13
|
+
} = options;
|
|
14
|
+
const result = useMemo(() => {
|
|
15
|
+
const items = formatDuration(milliseconds, { maxDisplayUnits, minUnit });
|
|
16
|
+
const shouldUseAbbreviation = items.length > 1 && useAbbreviation;
|
|
17
|
+
const parts = items.map((item) => {
|
|
18
|
+
const suffix = shouldUseAbbreviation ? "_abbreviation" : "";
|
|
19
|
+
const i18nKey = `unit.${item.unit}${suffix}`;
|
|
20
|
+
return {
|
|
21
|
+
value: item.value,
|
|
22
|
+
unit: item.unit,
|
|
23
|
+
i18nKey
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
parts
|
|
28
|
+
};
|
|
29
|
+
}, [milliseconds, maxDisplayUnits, useAbbreviation, minUnit]);
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { useFormatDuration };
|
package/dist/esm/index.js
CHANGED
|
@@ -31,6 +31,7 @@ export { default as DeprecatedProgress } from './core/DeprecatedProgress/index.j
|
|
|
31
31
|
export { default as DetailCard } from './core/DetailCard/index.js';
|
|
32
32
|
export { default as DonutChart, DonutChartColor, formatChartData, formatCollapse } from './core/DonutChart/index.js';
|
|
33
33
|
export { default as DropdownMenu, RenderMenuItem } from './core/DropdownMenu/index.js';
|
|
34
|
+
export { default as Duration } from './core/Duration/index.js';
|
|
34
35
|
export { default as Empty } from './core/Empty/index.js';
|
|
35
36
|
export { default as Error } from './core/Error/index.js';
|
|
36
37
|
export { default as ErrorBoundary } from './core/ErrorBoundary/index.js';
|
|
@@ -131,6 +132,8 @@ export { default as BarChart, getWidth } from './coreX/BarChart/index.js';
|
|
|
131
132
|
export { default as BatchOperation, renderBatchOperationMenuItem } from './coreX/BatchOperation/index.js';
|
|
132
133
|
export { default as ChartWithTooltip, ChartWithUnit } from './coreX/ChartWithTooltip/index.js';
|
|
133
134
|
export { default as CircleLoading } from './coreX/CircleLoading/index.js';
|
|
135
|
+
export { default as CopyButton } from './coreX/Copy/CopyButton.js';
|
|
136
|
+
export { default as CopyTooltip } from './coreX/Copy/CopyTooltip.js';
|
|
134
137
|
export { default as Counting } from './coreX/Counting/index.js';
|
|
135
138
|
export { default as CronCalendar } from './coreX/CronCalendar/index.js';
|
|
136
139
|
export { default as CronPlan, stringifyPlan } from './coreX/CronPlan/index.js';
|