@react-fabric/date 1.0.0-beta.61 → 1.0.0-beta.62

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.
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
4
5
  var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
5
6
  var core = require('@react-fabric/core');
6
7
  var utilities = require('@react-fabric/utilities');
@@ -39,11 +40,25 @@ var DateDuration = function DateDuration(_ref) {
39
40
  props = _objectWithoutProperties(_ref, _excluded);
40
41
  var _useTranslation = reactI18next.useTranslation("date"),
41
42
  t = _useTranslation.t;
42
- var interval = react.useMemo(function () {
43
- return dateFns.intervalToDuration({
43
+ var _useState = react.useState({}),
44
+ _useState2 = _slicedToArray(_useState, 2),
45
+ interval = _useState2[0],
46
+ setDateInterval = _useState2[1];
47
+ react.useEffect(function () {
48
+ setDateInterval(dateFns.intervalToDuration({
44
49
  start: new Date(date),
45
50
  end: new Date()
46
- });
51
+ }));
52
+ // update interval every minute
53
+ var tmr = setInterval(function () {
54
+ setDateInterval(dateFns.intervalToDuration({
55
+ start: new Date(date),
56
+ end: new Date()
57
+ }));
58
+ }, 60 * 1000);
59
+ return function () {
60
+ return clearInterval(tmr);
61
+ };
47
62
  }, [date]);
48
63
  var label = react.useMemo(function () {
49
64
  var before = dateFns.isBefore(dateUtil.DateUtil.parseDate(date), new Date());
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var core = require('@react-fabric/core');
4
- var ar = require('./ar.json.js');
5
- var en = require('./en.json.js');
4
+ var date$1 = require('./ar/date.json.js');
5
+ var date = require('./en/date.json.js');
6
6
 
7
7
  /*
8
8
  * React Fabric
@@ -28,6 +28,6 @@ var en = require('./en.json.js');
28
28
  */
29
29
 
30
30
  core.addTranslationBundle("date", {
31
- en: en.default,
32
- ar: ar.default
31
+ en: date.default,
32
+ ar: date$1.default
33
33
  });
@@ -1,12 +1,13 @@
1
1
  'use client';
2
2
 
3
3
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
5
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
5
6
  import { Tooltip, Dropdown } from '@react-fabric/core';
6
7
  import { Format } from '@react-fabric/utilities';
7
8
  import classNames from 'classnames';
8
9
  import { intervalToDuration, isBefore } from 'date-fns';
9
- import { useMemo } from 'react';
10
+ import { useState, useEffect, useMemo } from 'react';
10
11
  import { useTranslation } from 'react-i18next';
11
12
  import { DateUtil } from '../utils/dateUtil.js';
12
13
  import { jsx, jsxs } from 'react/jsx-runtime';
@@ -39,11 +40,25 @@ var DateDuration = function DateDuration(_ref) {
39
40
  props = _objectWithoutProperties(_ref, _excluded);
40
41
  var _useTranslation = useTranslation("date"),
41
42
  t = _useTranslation.t;
42
- var interval = useMemo(function () {
43
- return intervalToDuration({
43
+ var _useState = useState({}),
44
+ _useState2 = _slicedToArray(_useState, 2),
45
+ interval = _useState2[0],
46
+ setDateInterval = _useState2[1];
47
+ useEffect(function () {
48
+ setDateInterval(intervalToDuration({
44
49
  start: new Date(date),
45
50
  end: new Date()
46
- });
51
+ }));
52
+ // update interval every minute
53
+ var tmr = setInterval(function () {
54
+ setDateInterval(intervalToDuration({
55
+ start: new Date(date),
56
+ end: new Date()
57
+ }));
58
+ }, 60 * 1000);
59
+ return function () {
60
+ return clearInterval(tmr);
61
+ };
47
62
  }, [date]);
48
63
  var label = useMemo(function () {
49
64
  var before = isBefore(DateUtil.parseDate(date), new Date());
@@ -1,8 +1,8 @@
1
1
  'use client';
2
2
 
3
3
  import { addTranslationBundle } from '@react-fabric/core';
4
- import ar from './ar.json.js';
5
- import en from './en.json.js';
4
+ import ar from './ar/date.json.js';
5
+ import en from './en/date.json.js';
6
6
 
7
7
  /*
8
8
  * React Fabric
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-fabric/date",
3
- "version": "1.0.0-beta.61",
3
+ "version": "1.0.0-beta.62",
4
4
  "description": "RUF: Date package",
5
5
  "author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
6
6
  "license": "MIT",
@@ -35,8 +35,8 @@
35
35
  "watch": "npm-run-all -p watch:rollup watch:dts"
36
36
  },
37
37
  "dependencies": {
38
- "@react-fabric/core": "^1.0.0-beta.61",
39
- "@react-fabric/utilities": "^1.0.0-beta.61",
38
+ "@react-fabric/core": "^1.0.0-beta.62",
39
+ "@react-fabric/utilities": "^1.0.0-beta.62",
40
40
  "classnames": "~2.5.1",
41
41
  "date-fns": "~4.1.0",
42
42
  "resize-observer-polyfill": "~1.5.1"
@@ -51,5 +51,5 @@
51
51
  "node": ">=18.12.0",
52
52
  "npm": ">=8.19.0"
53
53
  },
54
- "gitHead": "a0b0c571bf9c189fa3355bbc3b896ecc4b9d6a04"
54
+ "gitHead": "9dce2fd9bb753d67e3f8adbf50be257b4bc64242"
55
55
  }
@@ -32,7 +32,7 @@ import {
32
32
  import { Format } from "@react-fabric/utilities";
33
33
  import classNames from "classnames";
34
34
  import { intervalToDuration, isBefore } from "date-fns";
35
- import { useMemo, type ElementType } from "react";
35
+ import { useEffect, useMemo, useState, type ElementType } from "react";
36
36
  import { useTranslation } from "react-i18next";
37
37
  import { type DateLike } from "../types";
38
38
  import { DateUtil } from "../utils/dateUtil";
@@ -76,9 +76,21 @@ export const DateDuration = ({
76
76
  ...props
77
77
  }: Props) => {
78
78
  const { t } = useTranslation("date");
79
+ const [interval, setDateInterval] = useState<
80
+ ReturnType<typeof intervalToDuration>
81
+ >({});
79
82
 
80
- const interval = useMemo(() => {
81
- return intervalToDuration({ start: new Date(date), end: new Date() });
83
+ useEffect(() => {
84
+ setDateInterval(
85
+ intervalToDuration({ start: new Date(date), end: new Date() }),
86
+ );
87
+ // update interval every minute
88
+ const tmr = setInterval(() => {
89
+ setDateInterval(
90
+ intervalToDuration({ start: new Date(date), end: new Date() }),
91
+ );
92
+ }, 60 * 1000);
93
+ return () => clearInterval(tmr);
82
94
  }, [date]);
83
95
 
84
96
  const label = useMemo(() => {
package/src/i18n/index.ts CHANGED
@@ -22,7 +22,7 @@
22
22
  */
23
23
 
24
24
  import { addTranslationBundle } from "@react-fabric/core";
25
- import ar from "./ar.json";
26
- import en from "./en.json";
25
+ import ar from "./ar/date.json";
26
+ import en from "./en/date.json";
27
27
 
28
28
  addTranslationBundle("date", { en, ar });
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes