@yuntijs/ui 1.0.0-beta.17 → 1.0.0-beta.18

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.
@@ -0,0 +1,32 @@
1
+ import { Typography as AntdTypography } from 'antd';
2
+ import { TextProps } from 'antd/es/typography/Text';
3
+ import { TooltipPropsWithTitle } from 'antd/lib/tooltip';
4
+ import React from 'react';
5
+ export declare const Typography: TypographyProps;
6
+ interface TimeProps extends TextProps {
7
+ /**
8
+ * @description Set display time
9
+ * @default '-'
10
+ */
11
+ time: string;
12
+ /**
13
+ * @description Formatted display time
14
+ * @default 'YYYY-MM-DD HH:mm:ss'
15
+ */
16
+ format?: string;
17
+ /**
18
+ * @description Display relative time
19
+ * @default 'true'
20
+ */
21
+ relativeTime?: boolean;
22
+ /**
23
+ * @description Mouse above to show time
24
+ * @default '{title: "YYYY-MM-DD HH:mm:ss"}'
25
+ */
26
+ tooltip?: TooltipPropsWithTitle;
27
+ }
28
+ declare const Time: React.FC<TimeProps>;
29
+ export type TypographyProps = typeof AntdTypography & {
30
+ Time: typeof Time;
31
+ };
32
+ export default Typography;
@@ -0,0 +1,85 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4
+ var _excluded = ["time", "format", "relativeTime", "tooltip"];
5
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
+ import { Typography as AntdTypography, Tooltip } from 'antd';
8
+ import dayjs from 'dayjs';
9
+ import dayjsRelativeTime from 'dayjs/plugin/relativeTime';
10
+ import { set } from 'lodash-es';
11
+ import React, { useEffect, useState } from 'react';
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ dayjs.extend(dayjsRelativeTime);
14
+ export var Typography = AntdTypography;
15
+ var getFromNow = function getFromNow(t) {
16
+ return dayjs(t ? new Date(t) : new Date()).fromNow();
17
+ };
18
+ var Time = function Time(props) {
19
+ var _tooltip$title;
20
+ var time = props.time,
21
+ format = props.format,
22
+ _props$relativeTime = props.relativeTime,
23
+ relativeTime = _props$relativeTime === void 0 ? true : _props$relativeTime,
24
+ tooltip = props.tooltip,
25
+ textProps = _objectWithoutProperties(props, _excluded);
26
+ var _useState = useState(getFromNow(time)),
27
+ _useState2 = _slicedToArray(_useState, 2),
28
+ showTime = _useState2[0],
29
+ setShowTime = _useState2[1];
30
+ var _useState3 = useState(),
31
+ _useState4 = _slicedToArray(_useState3, 2),
32
+ timer = _useState4[0],
33
+ setTimer = _useState4[1];
34
+ var clearTimer = function clearTimer() {
35
+ if (timer) {
36
+ clearInterval(timer);
37
+ }
38
+ };
39
+
40
+ // The relative time within the last hour is updated automatically
41
+ var setTimeInterval = function setTimeInterval(currentTime) {
42
+ clearTimer();
43
+ var now = dayjs();
44
+ var timeMoment = dayjs(currentTime);
45
+ var diff = now.diff(timeMoment);
46
+ if (diff > 0 && diff < 60 * 60 * 1000) {
47
+ var t = setInterval(function () {
48
+ setShowTime(getFromNow(currentTime));
49
+ }, 60 * 1000);
50
+ setTimer(t);
51
+ }
52
+ };
53
+ useEffect(function () {
54
+ if (relativeTime) {
55
+ setTimeInterval(new Date(time));
56
+ }
57
+ return function () {
58
+ clearTimer();
59
+ };
60
+ }, []);
61
+ useEffect(function () {
62
+ if (!relativeTime) return;
63
+ var nextFromNow = getFromNow(time);
64
+ if (nextFromNow !== showTime) {
65
+ setShowTime(nextFromNow);
66
+ setTimeInterval(new Date(time));
67
+ }
68
+ }, [time, relativeTime]);
69
+ var fmtTime = dayjs(time).format(format || 'YYYY-MM-DD HH:mm:ss');
70
+ var currentTime = relativeTime ? showTime : fmtTime;
71
+ var tooltipTitle = (_tooltip$title = tooltip === null || tooltip === void 0 ? void 0 : tooltip.title) !== null && _tooltip$title !== void 0 ? _tooltip$title : relativeTime ? fmtTime : undefined;
72
+
73
+ // Avoid duplicate tooltips
74
+ if (tooltipTitle) {
75
+ set(textProps, 'ellipsis.tooltip.title', undefined);
76
+ }
77
+ return /*#__PURE__*/_jsx(Tooltip, _objectSpread(_objectSpread({}, tooltip || {}), {}, {
78
+ title: tooltipTitle,
79
+ children: /*#__PURE__*/_jsx(Typography.Text, _objectSpread(_objectSpread({}, textProps), {}, {
80
+ children: currentTime
81
+ }))
82
+ }));
83
+ };
84
+ Typography.Time = Time;
85
+ export default Typography;
package/es/index.d.ts CHANGED
@@ -15,9 +15,10 @@ export * from './Modal';
15
15
  export * from './notification';
16
16
  export * from './Radio';
17
17
  export * from './Table';
18
+ export * from './Typography';
18
19
  export { Affix, type AffixProps, Anchor, type AnchorProps, AutoComplete, type AutoCompleteProps, Avatar, type AvatarProps, BackTop, type BackTopProps, Badge, // @todo composed type
19
20
  type BadgeProps, Button, // @todo dependence unifiedLink. link type, hover primary color, back button
20
21
  type ButtonProps, Calendar, type CalendarProps, Carousel, type CarouselProps, Cascader, type CascaderProps, Checkbox, type CheckboxProps, Col, Collapse, type CollapseProps, ColorPicker, type ColorPickerProps, type ColProps, // @todo center style
21
- type CountdownProps, DatePicker, type DatePickerProps, Dropdown, type DropDownProps, Empty, type EmptyProps, Flex, type FlexProps, FloatButton, type FloatButtonProps, Form, type FormInstance, type FormItemProps, type FormListFieldData, type FormListOperation, type FormProps, type FormRule, type GlobalToken, Grid, Image, type ImageProps, Input, InputNumber, type InputNumberProps, type InputProps, type InputRef, Layout, type LayoutProps, List, type ListProps, type MappingAlgorithm, type MentionProps, Mentions, Menu, type MenuItemProps, type MenuProps, type MenuRef, type MenuTheme, message, type MessageArgsProps, Pagination, type PaginationProps, Popconfirm, type PopconfirmProps, Popover, type PopoverProps, Progress, type ProgressProps, QRCode, type QRCodeProps, type QRPropsCanvas, type QRPropsSvg, Rate, type RateProps, type RefSelectProps, Result, type ResultProps, Row, type RowProps, Segmented, type SegmentedProps, Select, type SelectProps, Skeleton, type SkeletonProps, Slider, type SliderSingleProps, Space, type SpaceProps, Spin, type SpinProps, Statistic, type StatisticProps, type StepProps, Steps, type StepsProps, type SubMenuProps, Switch, type SwitchProps, type TabPaneProps, Tabs, type TabsProps, Tag, type TagProps, type TagType, theme, Timeline, type TimelineItemProps, type TimelineProps, TimePicker, type TimePickerProps, type TimeRangePickerProps, Tooltip, type TooltipProps, Tour, type TourProps, type TourStepProps, Transfer, type TransferProps, Tree, type TreeDataNode, type TreeNodeProps, type TreeProps, TreeSelect, type TreeSelectProps, Typography, type TypographyProps, Upload, type UploadFile, type UploadProps, version, Watermark, type WatermarkProps, } from 'antd';
22
+ type CountdownProps, DatePicker, type DatePickerProps, Dropdown, type DropDownProps, Empty, type EmptyProps, Flex, type FlexProps, FloatButton, type FloatButtonProps, Form, type FormInstance, type FormItemProps, type FormListFieldData, type FormListOperation, type FormProps, type FormRule, type GlobalToken, Grid, Image, type ImageProps, Input, InputNumber, type InputNumberProps, type InputProps, type InputRef, Layout, type LayoutProps, List, type ListProps, type MappingAlgorithm, type MentionProps, Mentions, Menu, type MenuItemProps, type MenuProps, type MenuRef, type MenuTheme, message, type MessageArgsProps, Pagination, type PaginationProps, Popconfirm, type PopconfirmProps, Popover, type PopoverProps, Progress, type ProgressProps, QRCode, type QRCodeProps, type QRPropsCanvas, type QRPropsSvg, Rate, type RateProps, type RefSelectProps, Result, type ResultProps, Row, type RowProps, Segmented, type SegmentedProps, Select, type SelectProps, Skeleton, type SkeletonProps, Slider, type SliderSingleProps, Space, type SpaceProps, Spin, type SpinProps, Statistic, type StatisticProps, type StepProps, Steps, type StepsProps, type SubMenuProps, Switch, type SwitchProps, type TabPaneProps, Tabs, type TabsProps, Tag, type TagProps, type TagType, theme, Timeline, type TimelineItemProps, type TimelineProps, TimePicker, type TimePickerProps, type TimeRangePickerProps, Tooltip, type TooltipProps, Tour, type TourProps, type TourStepProps, Transfer, type TransferProps, Tree, type TreeDataNode, type TreeNodeProps, type TreeProps, TreeSelect, type TreeSelectProps, Upload, type UploadFile, type UploadProps, version, Watermark, type WatermarkProps, } from 'antd';
22
23
  export { Highlighter, type HighlighterProps, Markdown, type MarkdownProps, SyntaxHighlighter, type SyntaxHighlighterProps, } from '@lobehub/ui';
23
24
  export { useResponsive, useTheme, useThemeMode } from 'antd-style';
package/es/index.js CHANGED
@@ -17,6 +17,7 @@ export * from "./Modal";
17
17
  export * from "./notification";
18
18
  export * from "./Radio";
19
19
  export * from "./Table";
20
+ export * from "./Typography";
20
21
 
21
22
  // ~ antd
22
23
  export { Affix, Anchor, AutoComplete, Avatar, BackTop, Badge // @todo composed type
@@ -24,7 +25,7 @@ export { Affix, Anchor, AutoComplete, Avatar, BackTop, Badge // @todo composed t
24
25
  , Calendar, Carousel, Cascader, Checkbox, Col, Collapse, ColorPicker
25
26
 
26
27
  // @todo center style
27
- , DatePicker, Dropdown, Empty, Flex, FloatButton, Form, Grid, Image, Input, InputNumber, Layout, List, Mentions, Menu, message, Pagination, Popconfirm, Popover, Progress, QRCode, Rate, Result, Row, Segmented, Select, Skeleton, Slider, Space, Spin, Statistic, Steps, Switch, Tabs, Tag, theme, Timeline, TimePicker, Tooltip, Tour, Transfer, Tree, TreeSelect, Typography, Upload, version, Watermark } from 'antd';
28
+ , DatePicker, Dropdown, Empty, Flex, FloatButton, Form, Grid, Image, Input, InputNumber, Layout, List, Mentions, Menu, message, Pagination, Popconfirm, Popover, Progress, QRCode, Rate, Result, Row, Segmented, Select, Skeleton, Slider, Space, Spin, Statistic, Steps, Switch, Tabs, Tag, theme, Timeline, TimePicker, Tooltip, Tour, Transfer, Tree, TreeSelect, Upload, version, Watermark } from 'antd';
28
29
 
29
30
  // ~ @lobehub/ui
30
31
  export { Highlighter, Markdown, SyntaxHighlighter } from '@lobehub/ui';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuntijs/ui",
3
- "version": "1.0.0-beta.17",
3
+ "version": "1.0.0-beta.18",
4
4
  "description": "☁️ Yunti UI - an open-source UI component library for building Cloud Native web apps",
5
5
  "keywords": [
6
6
  "yuntijs",
@@ -82,6 +82,7 @@
82
82
  "@ant-design/icons": "^5",
83
83
  "@babel/runtime": "^7",
84
84
  "@lobehub/ui": "^1",
85
+ "dayjs": "^1.11.10",
85
86
  "leva": "^0",
86
87
  "lodash-es": "^4",
87
88
  "lucide-react": "latest",