@cloudtower/eagle 0.35.7 → 0.35.8
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/hooks/useFormatDuration.js +35 -0
- package/dist/cjs/index.js +247 -245
- package/dist/cjs/stats1.html +1 -1
- package/dist/cjs/utils/formatDuration.js +67 -0
- package/dist/components.css +3401 -3401
- package/dist/esm/core/Duration/index.js +72 -0
- package/dist/esm/core/index.js +4 -2
- package/dist/esm/hooks/useFormatDuration.js +33 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/stats1.html +1 -1
- package/dist/esm/utils/formatDuration.js +65 -0
- package/dist/linaria.merged.scss +4359 -4359
- 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/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 +3401 -3401
- package/package.json +4 -4
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { IEmptyProps } from "../../core/Empty";
|
|
3
|
+
import { DurationUnitType, FormatDurationItem } from "../../utils/formatDuration";
|
|
4
|
+
import { RawValue } from "../Units/units.type";
|
|
5
|
+
/**
|
|
6
|
+
* Duration 组件的属性类型
|
|
7
|
+
*/
|
|
8
|
+
export interface DurationProps extends Omit<RawValue, "decimals"> {
|
|
9
|
+
/**
|
|
10
|
+
* 最大展示单位数量,默认为 2
|
|
11
|
+
* @default 2
|
|
12
|
+
* @example
|
|
13
|
+
* maxDisplayUnits={3} // 最多展示 3 个单位,如:1 day 1 hour 1 minute
|
|
14
|
+
*/
|
|
15
|
+
maxDisplayUnits?: number;
|
|
16
|
+
/**
|
|
17
|
+
* 最小展示单位,默认为 "second"(秒)
|
|
18
|
+
* @default "second"
|
|
19
|
+
* @example
|
|
20
|
+
* minUnit="minute" // 最小单位为分钟,秒数会被忽略
|
|
21
|
+
*/
|
|
22
|
+
minUnit?: DurationUnitType;
|
|
23
|
+
/**
|
|
24
|
+
* Empty组件的配置属性
|
|
25
|
+
*/
|
|
26
|
+
emptyProps?: IEmptyProps;
|
|
27
|
+
/**
|
|
28
|
+
* 自定义返回结果的渲染
|
|
29
|
+
* 当提供此函数时,将使用自定义渲染函数来渲染持续时间,而不是使用默认的渲染方式
|
|
30
|
+
* @param parts 格式化后的持续时间数组,每个元素包含 value 和 unit
|
|
31
|
+
* @returns 自定义的 React 节点
|
|
32
|
+
* @example
|
|
33
|
+
* contentRender={(parts) => (
|
|
34
|
+
* <div>
|
|
35
|
+
* {parts.map((part, i) => (
|
|
36
|
+
* <span key={i}>{part.value} {part.unit}</span>
|
|
37
|
+
* ))}
|
|
38
|
+
* </div>
|
|
39
|
+
* )}
|
|
40
|
+
*/
|
|
41
|
+
contentRender?: (parts: FormatDurationItem[]) => React.ReactNode;
|
|
42
|
+
}
|
package/dist/src/core/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
export * from "./AccordionCard";
|
|
2
3
|
export * from "./Alert";
|
|
3
4
|
export * from "./Antd5Anchor";
|
|
@@ -28,6 +29,7 @@ export * from "./DeprecatedProgress";
|
|
|
28
29
|
export * from "./DetailCard";
|
|
29
30
|
export * from "./DonutChart";
|
|
30
31
|
export * from "./DropdownMenu";
|
|
32
|
+
export * from "./Duration";
|
|
31
33
|
export * from "./Empty";
|
|
32
34
|
export * from "./ErrorBoundary";
|
|
33
35
|
export * from "./ExpandableList";
|
|
@@ -103,6 +105,7 @@ export declare const units: {
|
|
|
103
105
|
BitPerSecond: import("./Units").UnitFn;
|
|
104
106
|
Bit: import("./Units").UnitFn;
|
|
105
107
|
Second: import("./Units").UnitFn;
|
|
108
|
+
Duration: import("react").FC<import("./Duration/duration.type").DurationProps>;
|
|
106
109
|
};
|
|
107
110
|
export { units as Units };
|
|
108
111
|
export { default as AccordionCard } from "./AccordionCard";
|
|
@@ -128,6 +131,7 @@ export { default as DeprecatedProgress } from "./DeprecatedProgress";
|
|
|
128
131
|
export { default as DetailCard } from "./DetailCard";
|
|
129
132
|
export { default as DonutChart } from "./DonutChart";
|
|
130
133
|
export { default as DropdownMenu } from "./DropdownMenu";
|
|
134
|
+
export { default as Duration } from "./Duration";
|
|
131
135
|
export { default as Empty } from "./Empty";
|
|
132
136
|
export { default as Error } from "./Error";
|
|
133
137
|
export { default as ErrorBoundary } from "./ErrorBoundary";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { DurationUnitType } from "../utils/formatDuration";
|
|
2
|
+
/**
|
|
3
|
+
* 格式化持续时间的结果项,可用于 ParrotTrans 组件
|
|
4
|
+
*/
|
|
5
|
+
export interface FormatDurationPart {
|
|
6
|
+
value: number;
|
|
7
|
+
unit: DurationUnitType;
|
|
8
|
+
i18nKey: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 格式化持续时间的 Hook
|
|
12
|
+
* @param milliseconds 毫秒数
|
|
13
|
+
* @param options 配置选项
|
|
14
|
+
* @param options.maxDisplayUnits 最大展示单位数量,默认为 2
|
|
15
|
+
* @param options.useAbbreviation 是否使用简写表述,默认为 false。注意:当仅展示一个单位时,会自动使用全称(忽略此参数)
|
|
16
|
+
* @param options.minUnit 最小展示单位,默认为 "second"(秒),不满足进位逻辑的剩余时间会被忽略
|
|
17
|
+
* @returns 格式化后的持续时间数组,每个元素包含可用于 ParrotTrans 的信息
|
|
18
|
+
* @example
|
|
19
|
+
* const { parts } = useFormatDuration(3661000);
|
|
20
|
+
* // parts: [
|
|
21
|
+
* // { value: 1, unit: "hour", i18nKey: "unit.hour" },
|
|
22
|
+
* // { value: 1, unit: "minute", i18nKey: "unit.minute" }
|
|
23
|
+
* // ]
|
|
24
|
+
*/
|
|
25
|
+
export declare function useFormatDuration(milliseconds: number, options?: {
|
|
26
|
+
maxDisplayUnits?: number;
|
|
27
|
+
useAbbreviation?: boolean;
|
|
28
|
+
minUnit?: DurationUnitType;
|
|
29
|
+
}): {
|
|
30
|
+
parts: FormatDurationPart[];
|
|
31
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 持续时间单位联合类型
|
|
3
|
+
*/
|
|
4
|
+
export type DurationUnitType = "year" | "month" | "week" | "day" | "hour" | "minute" | "second" | "millisecond";
|
|
5
|
+
/**
|
|
6
|
+
* 格式化持续时间的结果项
|
|
7
|
+
*/
|
|
8
|
+
export interface FormatDurationItem {
|
|
9
|
+
value: number;
|
|
10
|
+
unit: DurationUnitType;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 格式化持续时间
|
|
14
|
+
* @param milliseconds 毫秒数
|
|
15
|
+
* @param options 配置选项
|
|
16
|
+
* @param options.maxDisplayUnits 最大展示单位数量,默认为 2
|
|
17
|
+
* @param options.minUnit 最小展示单位,默认为 "second"(秒),不满足进位逻辑的剩余时间会被忽略
|
|
18
|
+
* @returns 格式化后的持续时间数组,每个元素包含数值和单位
|
|
19
|
+
* @example
|
|
20
|
+
* formatDuration(3661000) // [{ value: 1, unit: "hour" }, { value: 1, unit: "minute" }]
|
|
21
|
+
* formatDuration(90061000, { maxDisplayUnits: 3 }) // [{ value: 1, unit: "day" }, { value: 1, unit: "hour" }, { value: 1, unit: "minute" }]
|
|
22
|
+
* formatDuration(5000) // [{ value: 5, unit: "second" }]
|
|
23
|
+
* formatDuration(1500, { minUnit: "second" }) // [{ value: 1, unit: "second" }] (500ms 被忽略)
|
|
24
|
+
*/
|
|
25
|
+
export declare function formatDuration(milliseconds: number, options?: {
|
|
26
|
+
maxDisplayUnits?: number;
|
|
27
|
+
minUnit?: DurationUnitType;
|
|
28
|
+
}): FormatDurationItem[];
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import Duration from "../../../src/core/Duration";
|
|
2
|
+
import { StoryObj } from "@storybook/react";
|
|
3
|
+
import React from "react";
|
|
4
|
+
/**
|
|
5
|
+
* * Duration 组件
|
|
6
|
+
* * 用于展示持续时间(毫秒),支持多个时间单位的组合展示
|
|
7
|
+
* * 提供标准、缩写和自定义空值展示等功能
|
|
8
|
+
* * 继承自基础的 Units 系列组件
|
|
9
|
+
*/
|
|
10
|
+
declare const meta: {
|
|
11
|
+
title: string;
|
|
12
|
+
component: React.FC<import("../../../src/core/Duration/duration.type").DurationProps>;
|
|
13
|
+
parameters: {
|
|
14
|
+
docs: {
|
|
15
|
+
description: {
|
|
16
|
+
component: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
tags: string[];
|
|
21
|
+
};
|
|
22
|
+
export default meta;
|
|
23
|
+
type Story = StoryObj<typeof Duration>;
|
|
24
|
+
/**
|
|
25
|
+
* 基础持续时间展示
|
|
26
|
+
* 展示最基本的持续时间,默认展示最多 2 个单位
|
|
27
|
+
*/
|
|
28
|
+
export declare const Basic: Story;
|
|
29
|
+
/**
|
|
30
|
+
* 多单位展示
|
|
31
|
+
* 展示多个时间单位,如:1天 1小时 1分钟
|
|
32
|
+
*/
|
|
33
|
+
export declare const MultipleUnits: Story;
|
|
34
|
+
/**
|
|
35
|
+
* 缩写形式展示
|
|
36
|
+
* 当需要节省空间时,可以使用缩写形式展示持续时间
|
|
37
|
+
*/
|
|
38
|
+
export declare const Abbreviated: Story;
|
|
39
|
+
/**
|
|
40
|
+
* 指定最小单位
|
|
41
|
+
* 可以指定最小展示单位,小于该单位的时间会被忽略
|
|
42
|
+
*/
|
|
43
|
+
export declare const WithMinUnit: Story;
|
|
44
|
+
/**
|
|
45
|
+
* 单单位展示
|
|
46
|
+
* 只展示一个时间单位
|
|
47
|
+
*/
|
|
48
|
+
export declare const SingleUnit: Story;
|
|
49
|
+
/**
|
|
50
|
+
* 大数值展示
|
|
51
|
+
* 展示较大的持续时间,如:1年 1个月
|
|
52
|
+
*/
|
|
53
|
+
export declare const LargeValue: Story;
|
|
54
|
+
/**
|
|
55
|
+
* 自定义空值展示
|
|
56
|
+
* 当没有有效值时的自定义展示
|
|
57
|
+
*/
|
|
58
|
+
export declare const CustomEmpty: Story;
|
|
59
|
+
/**
|
|
60
|
+
* 零值展示
|
|
61
|
+
* 展示零值的情况
|
|
62
|
+
*/
|
|
63
|
+
export declare const ZeroValue: Story;
|
|
64
|
+
/**
|
|
65
|
+
* 零值不带单位
|
|
66
|
+
* 当值为0时,可以选择不显示单位
|
|
67
|
+
*/
|
|
68
|
+
export declare const ZeroWithoutUnit: Story;
|
|
69
|
+
/**
|
|
70
|
+
* 自定义样式
|
|
71
|
+
* 可以通过自定义类名来调整展示样式
|
|
72
|
+
*/
|
|
73
|
+
export declare const CustomStyle: Story;
|
|
74
|
+
/**
|
|
75
|
+
* 自定义渲染
|
|
76
|
+
* 使用 contentRender 自定义渲染方式
|
|
77
|
+
*/
|
|
78
|
+
export declare const CustomRender: Story;
|
|
79
|
+
/**
|
|
80
|
+
* 自定义渲染 - 简洁格式
|
|
81
|
+
* 使用自定义渲染函数展示更简洁的格式
|
|
82
|
+
*/
|
|
83
|
+
export declare const CustomRenderCompact: Story;
|
|
84
|
+
/**
|
|
85
|
+
* 复杂场景组合
|
|
86
|
+
* 展示多个配置项的组合使用
|
|
87
|
+
*/
|
|
88
|
+
export declare const Complex: Story;
|