@arcblock/ux 2.13.25 → 2.13.27

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,11 +1,11 @@
1
1
  <svg width="1024" height="1024" viewBox="0 0 1024 1024" fill="none" xmlns="http://www.w3.org/2000/svg">
2
- <rect width="1024" height="1024" fill="url(#paint0_linear_3911_1486)"/>
3
- <path fill-rule="evenodd" clip-rule="evenodd" d="M283.162 232.966C273.829 238.355 273.829 251.826 283.162 257.215C287.494 259.715 292.831 259.715 297.162 257.215L402 196.687C406.332 194.186 409 189.564 409 184.562C409 173.785 397.333 167.049 388 172.438L283.162 232.966ZM184.299 448.397C184.299 443.395 181.631 438.773 177.299 436.272C167.966 430.884 156.299 437.619 156.299 448.397V571.604C156.299 582.381 167.966 589.117 177.299 583.728C181.631 581.227 184.299 576.605 184.299 571.604V448.397ZM732.038 764.634C736.37 762.133 741.707 762.133 746.038 764.634C755.372 770.022 755.372 783.494 746.038 788.883L638 851.258C628.667 856.647 617 849.911 617 839.134C617 834.132 619.668 829.511 624 827.01L732.038 764.634ZM869.175 571.301C869.175 582.078 857.508 588.813 848.175 583.425C843.843 580.924 841.175 576.302 841.175 571.301V448.7C841.175 443.698 843.843 439.076 848.175 436.576C857.508 431.187 869.175 437.923 869.175 448.7V571.301ZM409 839.438C409 850.215 397.333 856.951 388 851.562L279.698 789.034C270.365 783.646 270.365 770.174 279.698 764.786C284.03 762.285 289.367 762.285 293.699 764.786L402 827.313C406.332 829.814 409 834.436 409 839.438ZM617 184.866C617 174.089 628.667 167.353 638 172.742L742.574 233.118C751.908 238.506 751.908 251.978 742.574 257.366C738.243 259.867 732.906 259.867 728.574 257.366L624 196.99C619.668 194.489 617 189.868 617 184.866Z" fill="white" fill-opacity="0.12"/>
2
+ <rect width="1024" height="1024" rx="250" fill="url(#paint0_linear_1780_6)"/>
3
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M283.163 232.966C273.829 238.355 273.829 251.826 283.163 257.215C287.494 259.715 292.831 259.715 297.163 257.215L402 196.687C406.332 194.186 409 189.564 409 184.562C409 173.785 397.334 167.049 388 172.438L283.163 232.966ZM184.299 448.397C184.299 443.395 181.631 438.773 177.299 436.272C167.966 430.884 156.299 437.619 156.299 448.397V571.604C156.299 582.381 167.966 589.117 177.299 583.728C181.631 581.227 184.299 576.605 184.299 571.604V448.397ZM732.038 764.634C736.37 762.133 741.707 762.133 746.038 764.634C755.372 770.022 755.372 783.494 746.038 788.883L638 851.258C628.667 856.647 617 849.911 617 839.134C617 834.132 619.669 829.511 624 827.01L732.038 764.634ZM869.175 571.301C869.175 582.078 857.508 588.813 848.175 583.425C843.844 580.924 841.175 576.302 841.175 571.301V448.7C841.175 443.698 843.844 439.076 848.175 436.576C857.508 431.187 869.175 437.923 869.175 448.7V571.301ZM409 839.438C409 850.215 397.334 856.951 388 851.562L279.699 789.034C270.365 783.646 270.365 770.174 279.699 764.786C284.03 762.285 289.367 762.285 293.699 764.786L402 827.313C406.332 829.814 409 834.436 409 839.438ZM617 184.866C617 174.089 628.667 167.353 638 172.742L742.575 233.118C751.908 238.506 751.908 251.978 742.575 257.366C738.243 259.867 732.906 259.867 728.575 257.366L624 196.99C619.669 194.489 617 189.868 617 184.866Z" fill="white" fill-opacity="0.12"/>
4
4
  <path fill-rule="evenodd" clip-rule="evenodd" d="M513.689 175.068C496.273 175.068 482.155 160.95 482.155 143.534C482.155 126.118 496.273 112 513.689 112C531.105 112 545.223 126.118 545.223 143.534C545.223 160.95 531.105 175.068 513.689 175.068ZM560.723 321.5C560.723 348.358 538.95 370.131 512.092 370.131C485.234 370.131 463.461 348.358 463.461 321.5C463.461 294.641 485.234 272.868 512.092 272.868C538.95 272.868 560.723 294.641 560.723 321.5ZM691.649 676.886C664.791 676.886 643.018 655.113 643.018 628.255C643.018 601.396 664.791 579.623 691.649 579.623C718.508 579.623 740.281 601.396 740.281 628.255C740.281 655.113 718.508 676.886 691.649 676.886ZM280.151 628.255C280.151 655.113 301.924 676.886 328.783 676.886C355.641 676.886 377.414 655.113 377.414 628.255C377.414 601.396 355.641 579.623 328.783 579.623C301.924 579.623 280.151 601.396 280.151 628.255ZM512.086 583.358C472.831 583.358 441.009 551.536 441.009 512.281C441.009 473.027 472.831 441.204 512.086 441.204C551.341 441.204 583.163 473.027 583.163 512.281C583.163 551.536 551.341 583.358 512.086 583.358ZM822.574 719.623C822.574 737.039 836.692 751.157 854.108 751.157C871.523 751.157 885.642 737.039 885.642 719.623C885.642 702.208 871.523 688.089 854.108 688.089C836.692 688.089 822.574 702.208 822.574 719.623ZM138.009 719.623C138.009 737.039 152.128 751.157 169.543 751.157C186.959 751.157 201.077 737.039 201.077 719.623C201.077 702.208 186.959 688.089 169.543 688.089C152.128 688.089 138.009 702.208 138.009 719.623Z" fill="white"/>
5
- <foreignObject x="118" y="252.842" width="787.643" height="679.157"><div xmlns="http://www.w3.org/1999/xhtml" style="backdrop-filter:blur(10px);clip-path:url(#bgblur_0_3911_1486_clip_path);height:100%;width:100%"></div></foreignObject><path data-figma-bg-blur-radius="20" fill-rule="evenodd" clip-rule="evenodd" d="M541.484 880.466C541.484 863.05 527.365 848.932 509.95 848.932C492.534 848.932 478.416 863.05 478.416 880.466C478.416 897.881 492.534 912 509.95 912C527.365 912 541.484 897.881 541.484 880.466ZM201.068 304.376C201.068 286.961 186.95 272.842 169.534 272.842C152.118 272.842 138 286.961 138 304.376C138 321.792 152.118 335.91 169.534 335.91C186.95 335.91 201.068 321.792 201.068 304.376ZM854.109 272.842C871.525 272.842 885.643 286.961 885.643 304.376C885.643 321.792 871.525 335.91 854.109 335.91C836.693 335.91 822.575 321.792 822.575 304.376C822.575 286.961 836.693 272.842 854.109 272.842ZM380.626 395.762C380.626 368.904 358.853 347.131 331.995 347.131C305.136 347.131 283.363 368.904 283.363 395.762C283.363 422.621 305.136 444.394 331.995 444.394C358.853 444.394 380.626 422.621 380.626 395.762ZM694.862 347.131C721.72 347.131 743.493 368.904 743.493 395.762C743.493 422.621 721.72 444.394 694.862 444.394C668.003 444.394 646.23 422.621 646.23 395.762C646.23 368.904 668.003 347.131 694.862 347.131ZM512.092 785.352C538.95 785.352 560.723 763.578 560.723 736.72C560.723 709.862 538.95 688.089 512.092 688.089C485.233 688.089 463.46 709.862 463.46 736.72C463.46 763.578 485.233 785.352 512.092 785.352Z" fill="white" fill-opacity="0.56"/>
5
+ <foreignObject x="118" y="252.842" width="787.643" height="679.157"><div xmlns="http://www.w3.org/1999/xhtml" style="backdrop-filter:blur(10px);clip-path:url(#bgblur_0_1780_6_clip_path);height:100%;width:100%"></div></foreignObject><path data-figma-bg-blur-radius="20" fill-rule="evenodd" clip-rule="evenodd" d="M541.484 880.466C541.484 863.05 527.365 848.932 509.95 848.932C492.534 848.932 478.416 863.05 478.416 880.466C478.416 897.881 492.534 912 509.95 912C527.365 912 541.484 897.881 541.484 880.466ZM201.068 304.376C201.068 286.961 186.95 272.842 169.534 272.842C152.118 272.842 138 286.961 138 304.376C138 321.792 152.118 335.91 169.534 335.91C186.95 335.91 201.068 321.792 201.068 304.376ZM854.109 272.842C871.525 272.842 885.643 286.961 885.643 304.376C885.643 321.792 871.525 335.91 854.109 335.91C836.693 335.91 822.575 321.792 822.575 304.376C822.575 286.961 836.693 272.842 854.109 272.842ZM380.626 395.762C380.626 368.904 358.853 347.131 331.995 347.131C305.136 347.131 283.363 368.904 283.363 395.762C283.363 422.621 305.136 444.394 331.995 444.394C358.853 444.394 380.626 422.621 380.626 395.762ZM694.862 347.131C721.72 347.131 743.493 368.904 743.493 395.762C743.493 422.621 721.72 444.394 694.862 444.394C668.003 444.394 646.23 422.621 646.23 395.762C646.23 368.904 668.003 347.131 694.862 347.131ZM512.092 785.352C538.95 785.352 560.723 763.578 560.723 736.72C560.723 709.862 538.95 688.089 512.092 688.089C485.233 688.089 463.46 709.862 463.46 736.72C463.46 763.578 485.233 785.352 512.092 785.352Z" fill="white" fill-opacity="0.56"/>
6
6
  <defs>
7
- <clipPath id="bgblur_0_3911_1486_clip_path" transform="translate(-118 -252.842)"><path fill-rule="evenodd" clip-rule="evenodd" d="M541.484 880.466C541.484 863.05 527.365 848.932 509.95 848.932C492.534 848.932 478.416 863.05 478.416 880.466C478.416 897.881 492.534 912 509.95 912C527.365 912 541.484 897.881 541.484 880.466ZM201.068 304.376C201.068 286.961 186.95 272.842 169.534 272.842C152.118 272.842 138 286.961 138 304.376C138 321.792 152.118 335.91 169.534 335.91C186.95 335.91 201.068 321.792 201.068 304.376ZM854.109 272.842C871.525 272.842 885.643 286.961 885.643 304.376C885.643 321.792 871.525 335.91 854.109 335.91C836.693 335.91 822.575 321.792 822.575 304.376C822.575 286.961 836.693 272.842 854.109 272.842ZM380.626 395.762C380.626 368.904 358.853 347.131 331.995 347.131C305.136 347.131 283.363 368.904 283.363 395.762C283.363 422.621 305.136 444.394 331.995 444.394C358.853 444.394 380.626 422.621 380.626 395.762ZM694.862 347.131C721.72 347.131 743.493 368.904 743.493 395.762C743.493 422.621 721.72 444.394 694.862 444.394C668.003 444.394 646.23 422.621 646.23 395.762C646.23 368.904 668.003 347.131 694.862 347.131ZM512.092 785.352C538.95 785.352 560.723 763.578 560.723 736.72C560.723 709.862 538.95 688.089 512.092 688.089C485.233 688.089 463.46 709.862 463.46 736.72C463.46 763.578 485.233 785.352 512.092 785.352Z"/>
8
- </clipPath><linearGradient id="paint0_linear_3911_1486" x1="956" y1="962" x2="70" y2="65.4999" gradientUnits="userSpaceOnUse">
7
+ <clipPath id="bgblur_0_1780_6_clip_path" transform="translate(-118 -252.842)"><path fill-rule="evenodd" clip-rule="evenodd" d="M541.484 880.466C541.484 863.05 527.365 848.932 509.95 848.932C492.534 848.932 478.416 863.05 478.416 880.466C478.416 897.881 492.534 912 509.95 912C527.365 912 541.484 897.881 541.484 880.466ZM201.068 304.376C201.068 286.961 186.95 272.842 169.534 272.842C152.118 272.842 138 286.961 138 304.376C138 321.792 152.118 335.91 169.534 335.91C186.95 335.91 201.068 321.792 201.068 304.376ZM854.109 272.842C871.525 272.842 885.643 286.961 885.643 304.376C885.643 321.792 871.525 335.91 854.109 335.91C836.693 335.91 822.575 321.792 822.575 304.376C822.575 286.961 836.693 272.842 854.109 272.842ZM380.626 395.762C380.626 368.904 358.853 347.131 331.995 347.131C305.136 347.131 283.363 368.904 283.363 395.762C283.363 422.621 305.136 444.394 331.995 444.394C358.853 444.394 380.626 422.621 380.626 395.762ZM694.862 347.131C721.72 347.131 743.493 368.904 743.493 395.762C743.493 422.621 721.72 444.394 694.862 444.394C668.003 444.394 646.23 422.621 646.23 395.762C646.23 368.904 668.003 347.131 694.862 347.131ZM512.092 785.352C538.95 785.352 560.723 763.578 560.723 736.72C560.723 709.862 538.95 688.089 512.092 688.089C485.233 688.089 463.46 709.862 463.46 736.72C463.46 763.578 485.233 785.352 512.092 785.352Z"/>
8
+ </clipPath><linearGradient id="paint0_linear_1780_6" x1="956" y1="962" x2="70" y2="65.4999" gradientUnits="userSpaceOnUse">
9
9
  <stop stop-color="#060E13"/>
10
10
  <stop offset="1" stop-color="#313434"/>
11
11
  </linearGradient>
@@ -414,11 +414,12 @@ var ArcSphereSvg = function ArcSphereSvg(props) {
414
414
  children: [/*#__PURE__*/_jsx("rect", {
415
415
  width: "1024",
416
416
  height: "1024",
417
- fill: "url(#paint0_linear_3911_1486)"
417
+ rx: "250",
418
+ fill: "url(#paint0_linear_1780_6)"
418
419
  }), /*#__PURE__*/_jsx("path", {
419
420
  fillRule: "evenodd",
420
421
  clipRule: "evenodd",
421
- d: "M283.162 232.966C273.829 238.355 273.829 251.826 283.162 257.215C287.494 259.715 292.831 259.715 297.162 257.215L402 196.687C406.332 194.186 409 189.564 409 184.562C409 173.785 397.333 167.049 388 172.438L283.162 232.966ZM184.299 448.397C184.299 443.395 181.631 438.773 177.299 436.272C167.966 430.884 156.299 437.619 156.299 448.397V571.604C156.299 582.381 167.966 589.117 177.299 583.728C181.631 581.227 184.299 576.605 184.299 571.604V448.397ZM732.038 764.634C736.37 762.133 741.707 762.133 746.038 764.634C755.372 770.022 755.372 783.494 746.038 788.883L638 851.258C628.667 856.647 617 849.911 617 839.134C617 834.132 619.668 829.511 624 827.01L732.038 764.634ZM869.175 571.301C869.175 582.078 857.508 588.813 848.175 583.425C843.843 580.924 841.175 576.302 841.175 571.301V448.7C841.175 443.698 843.843 439.076 848.175 436.576C857.508 431.187 869.175 437.923 869.175 448.7V571.301ZM409 839.438C409 850.215 397.333 856.951 388 851.562L279.698 789.034C270.365 783.646 270.365 770.174 279.698 764.786C284.03 762.285 289.367 762.285 293.699 764.786L402 827.313C406.332 829.814 409 834.436 409 839.438ZM617 184.866C617 174.089 628.667 167.353 638 172.742L742.574 233.118C751.908 238.506 751.908 251.978 742.574 257.366C738.243 259.867 732.906 259.867 728.574 257.366L624 196.99C619.668 194.489 617 189.868 617 184.866Z",
422
+ d: "M283.163 232.966C273.829 238.355 273.829 251.826 283.163 257.215C287.494 259.715 292.831 259.715 297.163 257.215L402 196.687C406.332 194.186 409 189.564 409 184.562C409 173.785 397.334 167.049 388 172.438L283.163 232.966ZM184.299 448.397C184.299 443.395 181.631 438.773 177.299 436.272C167.966 430.884 156.299 437.619 156.299 448.397V571.604C156.299 582.381 167.966 589.117 177.299 583.728C181.631 581.227 184.299 576.605 184.299 571.604V448.397ZM732.038 764.634C736.37 762.133 741.707 762.133 746.038 764.634C755.372 770.022 755.372 783.494 746.038 788.883L638 851.258C628.667 856.647 617 849.911 617 839.134C617 834.132 619.669 829.511 624 827.01L732.038 764.634ZM869.175 571.301C869.175 582.078 857.508 588.813 848.175 583.425C843.844 580.924 841.175 576.302 841.175 571.301V448.7C841.175 443.698 843.844 439.076 848.175 436.576C857.508 431.187 869.175 437.923 869.175 448.7V571.301ZM409 839.438C409 850.215 397.334 856.951 388 851.562L279.699 789.034C270.365 783.646 270.365 770.174 279.699 764.786C284.03 762.285 289.367 762.285 293.699 764.786L402 827.313C406.332 829.814 409 834.436 409 839.438ZM617 184.866C617 174.089 628.667 167.353 638 172.742L742.575 233.118C751.908 238.506 751.908 251.978 742.575 257.366C738.243 259.867 732.906 259.867 728.575 257.366L624 196.99C619.669 194.489 617 189.868 617 184.866Z",
422
423
  fill: "white",
423
424
  fillOpacity: "0.12"
424
425
  }), /*#__PURE__*/_jsx("path", {
@@ -435,7 +436,7 @@ var ArcSphereSvg = function ArcSphereSvg(props) {
435
436
  xmlns: "http://www.w3.org/1999/xhtml",
436
437
  style: {
437
438
  backdropFilter: "blur(10px)",
438
- clipPath: "url(#bgblur_0_3911_1486_clip_path)",
439
+ clipPath: "url(#bgblur_0_1780_6_clip_path)",
439
440
  height: "100%",
440
441
  width: "100%"
441
442
  }
@@ -449,7 +450,7 @@ var ArcSphereSvg = function ArcSphereSvg(props) {
449
450
  fillOpacity: "0.56"
450
451
  }), /*#__PURE__*/_jsxs("defs", {
451
452
  children: [/*#__PURE__*/_jsx("clipPath", {
452
- id: "bgblur_0_3911_1486_clip_path",
453
+ id: "bgblur_0_1780_6_clip_path",
453
454
  transform: "translate(-118 -252.842)",
454
455
  children: /*#__PURE__*/_jsx("path", {
455
456
  fillRule: "evenodd",
@@ -457,7 +458,7 @@ var ArcSphereSvg = function ArcSphereSvg(props) {
457
458
  d: "M541.484 880.466C541.484 863.05 527.365 848.932 509.95 848.932C492.534 848.932 478.416 863.05 478.416 880.466C478.416 897.881 492.534 912 509.95 912C527.365 912 541.484 897.881 541.484 880.466ZM201.068 304.376C201.068 286.961 186.95 272.842 169.534 272.842C152.118 272.842 138 286.961 138 304.376C138 321.792 152.118 335.91 169.534 335.91C186.95 335.91 201.068 321.792 201.068 304.376ZM854.109 272.842C871.525 272.842 885.643 286.961 885.643 304.376C885.643 321.792 871.525 335.91 854.109 335.91C836.693 335.91 822.575 321.792 822.575 304.376C822.575 286.961 836.693 272.842 854.109 272.842ZM380.626 395.762C380.626 368.904 358.853 347.131 331.995 347.131C305.136 347.131 283.363 368.904 283.363 395.762C283.363 422.621 305.136 444.394 331.995 444.394C358.853 444.394 380.626 422.621 380.626 395.762ZM694.862 347.131C721.72 347.131 743.493 368.904 743.493 395.762C743.493 422.621 721.72 444.394 694.862 444.394C668.003 444.394 646.23 422.621 646.23 395.762C646.23 368.904 668.003 347.131 694.862 347.131ZM512.092 785.352C538.95 785.352 560.723 763.578 560.723 736.72C560.723 709.862 538.95 688.089 512.092 688.089C485.233 688.089 463.46 709.862 463.46 736.72C463.46 763.578 485.233 785.352 512.092 785.352Z"
458
459
  })
459
460
  }), /*#__PURE__*/_jsxs("linearGradient", {
460
- id: "paint0_linear_3911_1486",
461
+ id: "paint0_linear_1780_6",
461
462
  x1: "956",
462
463
  y1: "962",
463
464
  x2: "70",
@@ -6,9 +6,9 @@ export interface RelativeTimeProps {
6
6
  withoutSuffix?: false | true;
7
7
  from?: string | number;
8
8
  to?: string | number;
9
- type?: 'relative' | 'absolute';
9
+ type?: 'relative' | 'absolute' | 'utc' | 'all';
10
10
  tz?: string;
11
11
  relativeRange?: number;
12
12
  enableTooltip?: boolean;
13
13
  }
14
- export default function RelativeTime({ value, locale, withoutSuffix, from, to, type, tz, relativeRange, enableTooltip, ...rest }: RelativeTimeProps): "-" | import("react/jsx-runtime").JSX.Element;
14
+ export default function RelativeTime({ value, locale, withoutSuffix, from, to, type, tz, relativeRange, enableTooltip, ...rest }: RelativeTimeProps): import("react/jsx-runtime").JSX.Element;
@@ -1,8 +1,9 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box, Tooltip } from '@mui/material';
3
+ import { useState } from 'react';
2
4
  import relativeTime from 'dayjs/plugin/relativeTime';
3
5
  import dayjs from 'dayjs';
4
6
  import 'dayjs/locale/zh-cn';
5
- import { Tooltip } from '@mui/material';
6
7
  import localizedFormat from 'dayjs/plugin/localizedFormat';
7
8
  import utc from 'dayjs/plugin/utc';
8
9
  import timezone from 'dayjs/plugin/timezone';
@@ -33,7 +34,15 @@ dayjs.updateLocale('zh-cn', {
33
34
  });
34
35
  // FIXME: @@ 此处不能真正的将 relativeTime 设置为支持中文
35
36
  setDateTool(dayjs);
36
- export default function RelativeTime({
37
+ const translations = {
38
+ en: {
39
+ utc: 'Your Timezone'
40
+ },
41
+ zh: {
42
+ utc: '你所在时区'
43
+ }
44
+ };
45
+ function useRelativeTime({
37
46
  value,
38
47
  locale = 'en',
39
48
  withoutSuffix = false,
@@ -41,17 +50,31 @@ export default function RelativeTime({
41
50
  to = '',
42
51
  type = 'relative',
43
52
  tz,
44
- relativeRange,
45
- enableTooltip = true,
46
- ...rest
53
+ relativeRange
47
54
  }) {
55
+ const date = new Date();
56
+ const timeZoneOffset = date.getTimezoneOffset();
57
+ const sign = timeZoneOffset > 0 ? '-' : '+';
58
+ const hoursOffset = Math.abs(timeZoneOffset) / 60;
59
+ const isLocalUtc = timeZoneOffset === 0;
60
+ const [isUtc, setIsUtc] = useState(isLocalUtc);
48
61
  if (!value) {
49
- return '-';
62
+ return {
63
+ innerContent: '-',
64
+ popContent: '-',
65
+ isUtc,
66
+ setIsUtc,
67
+ sign,
68
+ hoursOffset
69
+ };
50
70
  }
51
71
  const localeOption = locale === 'zh' ? 'zh-cn' : 'en-us';
52
- const datetime = dayjs(value).locale(localeOption);
72
+ let datetime = dayjs(value).locale(localeOption);
73
+ if (type === 'utc') {
74
+ datetime = dayjs(value).utc().locale(localeOption);
75
+ }
53
76
  if (tz) {
54
- datetime.tz(tz);
77
+ datetime = datetime.tz(tz);
55
78
  }
56
79
  const absoluteString = formatToDatetime(value, {
57
80
  locale: localeOption,
@@ -77,13 +100,150 @@ export default function RelativeTime({
77
100
  innerContent = absoluteString;
78
101
  popContent = relativeString;
79
102
  }
103
+ if (type === 'utc') {
104
+ if (isUtc) {
105
+ innerContent = formatToDatetime(value, {
106
+ locale: localeOption,
107
+ tz,
108
+ isUtc: true
109
+ });
110
+ popContent = formatToDatetime(value, {
111
+ locale: localeOption,
112
+ tz,
113
+ isUtc: true
114
+ });
115
+ } else {
116
+ innerContent = absoluteString;
117
+ popContent = relativeString;
118
+ }
119
+ }
120
+ return {
121
+ innerContent,
122
+ popContent,
123
+ isUtc,
124
+ setIsUtc,
125
+ sign,
126
+ hoursOffset,
127
+ relativeString,
128
+ absoluteString
129
+ };
130
+ }
131
+ function UTCChip({
132
+ locale,
133
+ isUtc,
134
+ sign,
135
+ hoursOffset,
136
+ setIsUtc
137
+ }) {
138
+ return /*#__PURE__*/_jsx(Box, {
139
+ component: "span",
140
+ sx: {
141
+ color: 'inherit',
142
+ cursor: 'pointer',
143
+ border: '1px solid',
144
+ fontSize: '0.8rem',
145
+ borderColor: 'divider',
146
+ borderRadius: '20px',
147
+ padding: '0px 8px'
148
+ },
149
+ onClick: () => setIsUtc(r => !r),
150
+ children: `${translations[locale].utc}: ${isUtc ? 'UTC' : `UTC${sign}${hoursOffset}`}`
151
+ });
152
+ }
153
+ export default function RelativeTime({
154
+ value,
155
+ locale = 'en',
156
+ withoutSuffix = false,
157
+ from = '',
158
+ to = '',
159
+ type = 'relative',
160
+ tz,
161
+ relativeRange,
162
+ enableTooltip = true,
163
+ ...rest
164
+ }) {
165
+ const {
166
+ innerContent,
167
+ popContent,
168
+ isUtc,
169
+ setIsUtc,
170
+ sign,
171
+ hoursOffset,
172
+ relativeString
173
+ } = useRelativeTime({
174
+ value,
175
+ locale,
176
+ withoutSuffix,
177
+ from,
178
+ to,
179
+ type: type === 'all' ? 'utc' : type,
180
+ tz,
181
+ relativeRange
182
+ });
183
+ if (type === 'all') {
184
+ return /*#__PURE__*/_jsx(Tooltip, {
185
+ title: undefined,
186
+ placement: "top-end",
187
+ enterTouchDelay: 0,
188
+ children: /*#__PURE__*/_jsxs(Box, {
189
+ display: "flex",
190
+ alignItems: "center",
191
+ gap: 0.5,
192
+ width: "max-content",
193
+ ...rest,
194
+ children: [/*#__PURE__*/_jsx(Box, {
195
+ component: "span",
196
+ ...rest,
197
+ sx: {},
198
+ children: innerContent
199
+ }), /*#__PURE__*/_jsx(Box, {
200
+ component: "span",
201
+ sx: {
202
+ color: 'inherit'
203
+ },
204
+ children: "\xB7"
205
+ }), /*#__PURE__*/_jsx(Box, {
206
+ component: "span",
207
+ sx: {
208
+ color: 'text.secondary'
209
+ },
210
+ children: relativeString
211
+ }), /*#__PURE__*/_jsx(Box, {
212
+ component: "span",
213
+ sx: {
214
+ color: 'inherit'
215
+ },
216
+ children: "\xB7"
217
+ }), /*#__PURE__*/_jsx(UTCChip, {
218
+ locale: locale,
219
+ isUtc: isUtc,
220
+ sign: sign,
221
+ hoursOffset: hoursOffset,
222
+ setIsUtc: setIsUtc
223
+ })]
224
+ })
225
+ });
226
+ }
80
227
  return /*#__PURE__*/_jsx(Tooltip, {
81
228
  title: enableTooltip ? popContent : undefined,
82
229
  placement: "top-end",
83
230
  enterTouchDelay: 0,
84
- children: /*#__PURE__*/_jsx("span", {
85
- ...rest,
86
- children: innerContent
231
+ children: /*#__PURE__*/_jsxs(Box, {
232
+ display: "flex",
233
+ alignItems: "center",
234
+ gap: 1,
235
+ width: "max-content",
236
+ children: [/*#__PURE__*/_jsx(Box, {
237
+ component: "span",
238
+ ...rest,
239
+ children: innerContent
240
+ }), type === 'utc' && /*#__PURE__*/_jsx(UTCChip, {
241
+ locale: locale,
242
+ isUtc: isUtc,
243
+ sign: sign,
244
+ hoursOffset: hoursOffset,
245
+ setIsUtc: setIsUtc
246
+ })]
87
247
  })
88
248
  });
89
249
  }
@@ -48,9 +48,10 @@ export declare function formatToDate(date: string | number | Date, { locale, tz
48
48
  * Ensure that the setDateTool() function is called first to set the time tool library.
49
49
  * @returns formatted date string
50
50
  */
51
- export declare function formatToDatetime(date: string | number | Date, { locale, tz }?: {
51
+ export declare function formatToDatetime(date: string | number | Date, { locale, tz, isUtc }?: {
52
52
  locale?: Locale;
53
53
  tz?: string;
54
+ isUtc?: boolean;
54
55
  }): any;
55
56
  export declare function detectWalletExtension(): any;
56
57
  export declare function openWebWallet({ webWalletUrl, action, locale, url, windowFeatures, appInfo, memberAppInfo, }: {
package/lib/Util/index.js CHANGED
@@ -189,7 +189,8 @@ export function getDateTool() {
189
189
  }
190
190
  const createDateFormatter = format => (date, {
191
191
  locale,
192
- tz
192
+ tz,
193
+ isUtc
193
194
  } = {}) => {
194
195
  if (dateTool === null) {
195
196
  throw new Error('call setDateTool to set the date tool library, such as: setDateTool(dayjs)');
@@ -201,6 +202,9 @@ const createDateFormatter = format => (date, {
201
202
  if (tz) {
202
203
  instance = instance.tz(tz);
203
204
  }
205
+ if (isUtc) {
206
+ instance = instance.utc();
207
+ }
204
208
  if (typeof locale !== 'undefined') {
205
209
  instance = instance.locale(locale);
206
210
  }
@@ -229,11 +233,13 @@ export function formatToDate(date, {
229
233
  */
230
234
  export function formatToDatetime(date, {
231
235
  locale = 'en',
232
- tz
236
+ tz,
237
+ isUtc = false
233
238
  } = {}) {
234
239
  return createDateFormatter('lll')(date, {
235
240
  locale,
236
- tz
241
+ tz,
242
+ isUtc
237
243
  });
238
244
  }
239
245
  export function detectWalletExtension() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "2.13.25",
3
+ "version": "2.13.27",
4
4
  "description": "Common used react components for arcblock products",
5
5
  "keywords": [
6
6
  "react",
@@ -71,14 +71,14 @@
71
71
  "react": ">=18.2.0",
72
72
  "react-router-dom": ">=6.22.3"
73
73
  },
74
- "gitHead": "8e7e9880fed6c726d2dbfd62b1352628f92fbc32",
74
+ "gitHead": "06abd7d8f9068ebca145a411b4a9b5b7f329535a",
75
75
  "dependencies": {
76
76
  "@arcblock/did-motif": "^1.1.13",
77
- "@arcblock/icons": "^2.13.25",
78
- "@arcblock/nft-display": "^2.13.25",
79
- "@arcblock/react-hooks": "^2.13.25",
77
+ "@arcblock/icons": "^2.13.27",
78
+ "@arcblock/nft-display": "^2.13.27",
79
+ "@arcblock/react-hooks": "^2.13.27",
80
80
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
81
- "@blocklet/theme": "^2.13.25",
81
+ "@blocklet/theme": "^2.13.27",
82
82
  "@fontsource/roboto": "~5.1.1",
83
83
  "@fontsource/ubuntu-mono": "^5.0.18",
84
84
  "@iconify-icons/logos": "^1.2.36",
@@ -1,11 +1,11 @@
1
1
  <svg width="1024" height="1024" viewBox="0 0 1024 1024" fill="none" xmlns="http://www.w3.org/2000/svg">
2
- <rect width="1024" height="1024" fill="url(#paint0_linear_3911_1486)"/>
3
- <path fill-rule="evenodd" clip-rule="evenodd" d="M283.162 232.966C273.829 238.355 273.829 251.826 283.162 257.215C287.494 259.715 292.831 259.715 297.162 257.215L402 196.687C406.332 194.186 409 189.564 409 184.562C409 173.785 397.333 167.049 388 172.438L283.162 232.966ZM184.299 448.397C184.299 443.395 181.631 438.773 177.299 436.272C167.966 430.884 156.299 437.619 156.299 448.397V571.604C156.299 582.381 167.966 589.117 177.299 583.728C181.631 581.227 184.299 576.605 184.299 571.604V448.397ZM732.038 764.634C736.37 762.133 741.707 762.133 746.038 764.634C755.372 770.022 755.372 783.494 746.038 788.883L638 851.258C628.667 856.647 617 849.911 617 839.134C617 834.132 619.668 829.511 624 827.01L732.038 764.634ZM869.175 571.301C869.175 582.078 857.508 588.813 848.175 583.425C843.843 580.924 841.175 576.302 841.175 571.301V448.7C841.175 443.698 843.843 439.076 848.175 436.576C857.508 431.187 869.175 437.923 869.175 448.7V571.301ZM409 839.438C409 850.215 397.333 856.951 388 851.562L279.698 789.034C270.365 783.646 270.365 770.174 279.698 764.786C284.03 762.285 289.367 762.285 293.699 764.786L402 827.313C406.332 829.814 409 834.436 409 839.438ZM617 184.866C617 174.089 628.667 167.353 638 172.742L742.574 233.118C751.908 238.506 751.908 251.978 742.574 257.366C738.243 259.867 732.906 259.867 728.574 257.366L624 196.99C619.668 194.489 617 189.868 617 184.866Z" fill="white" fill-opacity="0.12"/>
2
+ <rect width="1024" height="1024" rx="250" fill="url(#paint0_linear_1780_6)"/>
3
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M283.163 232.966C273.829 238.355 273.829 251.826 283.163 257.215C287.494 259.715 292.831 259.715 297.163 257.215L402 196.687C406.332 194.186 409 189.564 409 184.562C409 173.785 397.334 167.049 388 172.438L283.163 232.966ZM184.299 448.397C184.299 443.395 181.631 438.773 177.299 436.272C167.966 430.884 156.299 437.619 156.299 448.397V571.604C156.299 582.381 167.966 589.117 177.299 583.728C181.631 581.227 184.299 576.605 184.299 571.604V448.397ZM732.038 764.634C736.37 762.133 741.707 762.133 746.038 764.634C755.372 770.022 755.372 783.494 746.038 788.883L638 851.258C628.667 856.647 617 849.911 617 839.134C617 834.132 619.669 829.511 624 827.01L732.038 764.634ZM869.175 571.301C869.175 582.078 857.508 588.813 848.175 583.425C843.844 580.924 841.175 576.302 841.175 571.301V448.7C841.175 443.698 843.844 439.076 848.175 436.576C857.508 431.187 869.175 437.923 869.175 448.7V571.301ZM409 839.438C409 850.215 397.334 856.951 388 851.562L279.699 789.034C270.365 783.646 270.365 770.174 279.699 764.786C284.03 762.285 289.367 762.285 293.699 764.786L402 827.313C406.332 829.814 409 834.436 409 839.438ZM617 184.866C617 174.089 628.667 167.353 638 172.742L742.575 233.118C751.908 238.506 751.908 251.978 742.575 257.366C738.243 259.867 732.906 259.867 728.575 257.366L624 196.99C619.669 194.489 617 189.868 617 184.866Z" fill="white" fill-opacity="0.12"/>
4
4
  <path fill-rule="evenodd" clip-rule="evenodd" d="M513.689 175.068C496.273 175.068 482.155 160.95 482.155 143.534C482.155 126.118 496.273 112 513.689 112C531.105 112 545.223 126.118 545.223 143.534C545.223 160.95 531.105 175.068 513.689 175.068ZM560.723 321.5C560.723 348.358 538.95 370.131 512.092 370.131C485.234 370.131 463.461 348.358 463.461 321.5C463.461 294.641 485.234 272.868 512.092 272.868C538.95 272.868 560.723 294.641 560.723 321.5ZM691.649 676.886C664.791 676.886 643.018 655.113 643.018 628.255C643.018 601.396 664.791 579.623 691.649 579.623C718.508 579.623 740.281 601.396 740.281 628.255C740.281 655.113 718.508 676.886 691.649 676.886ZM280.151 628.255C280.151 655.113 301.924 676.886 328.783 676.886C355.641 676.886 377.414 655.113 377.414 628.255C377.414 601.396 355.641 579.623 328.783 579.623C301.924 579.623 280.151 601.396 280.151 628.255ZM512.086 583.358C472.831 583.358 441.009 551.536 441.009 512.281C441.009 473.027 472.831 441.204 512.086 441.204C551.341 441.204 583.163 473.027 583.163 512.281C583.163 551.536 551.341 583.358 512.086 583.358ZM822.574 719.623C822.574 737.039 836.692 751.157 854.108 751.157C871.523 751.157 885.642 737.039 885.642 719.623C885.642 702.208 871.523 688.089 854.108 688.089C836.692 688.089 822.574 702.208 822.574 719.623ZM138.009 719.623C138.009 737.039 152.128 751.157 169.543 751.157C186.959 751.157 201.077 737.039 201.077 719.623C201.077 702.208 186.959 688.089 169.543 688.089C152.128 688.089 138.009 702.208 138.009 719.623Z" fill="white"/>
5
- <foreignObject x="118" y="252.842" width="787.643" height="679.157"><div xmlns="http://www.w3.org/1999/xhtml" style="backdrop-filter:blur(10px);clip-path:url(#bgblur_0_3911_1486_clip_path);height:100%;width:100%"></div></foreignObject><path data-figma-bg-blur-radius="20" fill-rule="evenodd" clip-rule="evenodd" d="M541.484 880.466C541.484 863.05 527.365 848.932 509.95 848.932C492.534 848.932 478.416 863.05 478.416 880.466C478.416 897.881 492.534 912 509.95 912C527.365 912 541.484 897.881 541.484 880.466ZM201.068 304.376C201.068 286.961 186.95 272.842 169.534 272.842C152.118 272.842 138 286.961 138 304.376C138 321.792 152.118 335.91 169.534 335.91C186.95 335.91 201.068 321.792 201.068 304.376ZM854.109 272.842C871.525 272.842 885.643 286.961 885.643 304.376C885.643 321.792 871.525 335.91 854.109 335.91C836.693 335.91 822.575 321.792 822.575 304.376C822.575 286.961 836.693 272.842 854.109 272.842ZM380.626 395.762C380.626 368.904 358.853 347.131 331.995 347.131C305.136 347.131 283.363 368.904 283.363 395.762C283.363 422.621 305.136 444.394 331.995 444.394C358.853 444.394 380.626 422.621 380.626 395.762ZM694.862 347.131C721.72 347.131 743.493 368.904 743.493 395.762C743.493 422.621 721.72 444.394 694.862 444.394C668.003 444.394 646.23 422.621 646.23 395.762C646.23 368.904 668.003 347.131 694.862 347.131ZM512.092 785.352C538.95 785.352 560.723 763.578 560.723 736.72C560.723 709.862 538.95 688.089 512.092 688.089C485.233 688.089 463.46 709.862 463.46 736.72C463.46 763.578 485.233 785.352 512.092 785.352Z" fill="white" fill-opacity="0.56"/>
5
+ <foreignObject x="118" y="252.842" width="787.643" height="679.157"><div xmlns="http://www.w3.org/1999/xhtml" style="backdrop-filter:blur(10px);clip-path:url(#bgblur_0_1780_6_clip_path);height:100%;width:100%"></div></foreignObject><path data-figma-bg-blur-radius="20" fill-rule="evenodd" clip-rule="evenodd" d="M541.484 880.466C541.484 863.05 527.365 848.932 509.95 848.932C492.534 848.932 478.416 863.05 478.416 880.466C478.416 897.881 492.534 912 509.95 912C527.365 912 541.484 897.881 541.484 880.466ZM201.068 304.376C201.068 286.961 186.95 272.842 169.534 272.842C152.118 272.842 138 286.961 138 304.376C138 321.792 152.118 335.91 169.534 335.91C186.95 335.91 201.068 321.792 201.068 304.376ZM854.109 272.842C871.525 272.842 885.643 286.961 885.643 304.376C885.643 321.792 871.525 335.91 854.109 335.91C836.693 335.91 822.575 321.792 822.575 304.376C822.575 286.961 836.693 272.842 854.109 272.842ZM380.626 395.762C380.626 368.904 358.853 347.131 331.995 347.131C305.136 347.131 283.363 368.904 283.363 395.762C283.363 422.621 305.136 444.394 331.995 444.394C358.853 444.394 380.626 422.621 380.626 395.762ZM694.862 347.131C721.72 347.131 743.493 368.904 743.493 395.762C743.493 422.621 721.72 444.394 694.862 444.394C668.003 444.394 646.23 422.621 646.23 395.762C646.23 368.904 668.003 347.131 694.862 347.131ZM512.092 785.352C538.95 785.352 560.723 763.578 560.723 736.72C560.723 709.862 538.95 688.089 512.092 688.089C485.233 688.089 463.46 709.862 463.46 736.72C463.46 763.578 485.233 785.352 512.092 785.352Z" fill="white" fill-opacity="0.56"/>
6
6
  <defs>
7
- <clipPath id="bgblur_0_3911_1486_clip_path" transform="translate(-118 -252.842)"><path fill-rule="evenodd" clip-rule="evenodd" d="M541.484 880.466C541.484 863.05 527.365 848.932 509.95 848.932C492.534 848.932 478.416 863.05 478.416 880.466C478.416 897.881 492.534 912 509.95 912C527.365 912 541.484 897.881 541.484 880.466ZM201.068 304.376C201.068 286.961 186.95 272.842 169.534 272.842C152.118 272.842 138 286.961 138 304.376C138 321.792 152.118 335.91 169.534 335.91C186.95 335.91 201.068 321.792 201.068 304.376ZM854.109 272.842C871.525 272.842 885.643 286.961 885.643 304.376C885.643 321.792 871.525 335.91 854.109 335.91C836.693 335.91 822.575 321.792 822.575 304.376C822.575 286.961 836.693 272.842 854.109 272.842ZM380.626 395.762C380.626 368.904 358.853 347.131 331.995 347.131C305.136 347.131 283.363 368.904 283.363 395.762C283.363 422.621 305.136 444.394 331.995 444.394C358.853 444.394 380.626 422.621 380.626 395.762ZM694.862 347.131C721.72 347.131 743.493 368.904 743.493 395.762C743.493 422.621 721.72 444.394 694.862 444.394C668.003 444.394 646.23 422.621 646.23 395.762C646.23 368.904 668.003 347.131 694.862 347.131ZM512.092 785.352C538.95 785.352 560.723 763.578 560.723 736.72C560.723 709.862 538.95 688.089 512.092 688.089C485.233 688.089 463.46 709.862 463.46 736.72C463.46 763.578 485.233 785.352 512.092 785.352Z"/>
8
- </clipPath><linearGradient id="paint0_linear_3911_1486" x1="956" y1="962" x2="70" y2="65.4999" gradientUnits="userSpaceOnUse">
7
+ <clipPath id="bgblur_0_1780_6_clip_path" transform="translate(-118 -252.842)"><path fill-rule="evenodd" clip-rule="evenodd" d="M541.484 880.466C541.484 863.05 527.365 848.932 509.95 848.932C492.534 848.932 478.416 863.05 478.416 880.466C478.416 897.881 492.534 912 509.95 912C527.365 912 541.484 897.881 541.484 880.466ZM201.068 304.376C201.068 286.961 186.95 272.842 169.534 272.842C152.118 272.842 138 286.961 138 304.376C138 321.792 152.118 335.91 169.534 335.91C186.95 335.91 201.068 321.792 201.068 304.376ZM854.109 272.842C871.525 272.842 885.643 286.961 885.643 304.376C885.643 321.792 871.525 335.91 854.109 335.91C836.693 335.91 822.575 321.792 822.575 304.376C822.575 286.961 836.693 272.842 854.109 272.842ZM380.626 395.762C380.626 368.904 358.853 347.131 331.995 347.131C305.136 347.131 283.363 368.904 283.363 395.762C283.363 422.621 305.136 444.394 331.995 444.394C358.853 444.394 380.626 422.621 380.626 395.762ZM694.862 347.131C721.72 347.131 743.493 368.904 743.493 395.762C743.493 422.621 721.72 444.394 694.862 444.394C668.003 444.394 646.23 422.621 646.23 395.762C646.23 368.904 668.003 347.131 694.862 347.131ZM512.092 785.352C538.95 785.352 560.723 763.578 560.723 736.72C560.723 709.862 538.95 688.089 512.092 688.089C485.233 688.089 463.46 709.862 463.46 736.72C463.46 763.578 485.233 785.352 512.092 785.352Z"/>
8
+ </clipPath><linearGradient id="paint0_linear_1780_6" x1="956" y1="962" x2="70" y2="65.4999" gradientUnits="userSpaceOnUse">
9
9
  <stop stop-color="#060E13"/>
10
10
  <stop offset="1" stop-color="#313434"/>
11
11
  </linearGradient>
@@ -1,7 +1,8 @@
1
+ import { Box, Tooltip } from '@mui/material';
2
+ import { useState } from 'react';
1
3
  import relativeTime from 'dayjs/plugin/relativeTime';
2
4
  import dayjs from 'dayjs';
3
5
  import 'dayjs/locale/zh-cn';
4
- import { Tooltip } from '@mui/material';
5
6
  import localizedFormat from 'dayjs/plugin/localizedFormat';
6
7
  import utc from 'dayjs/plugin/utc';
7
8
  import timezone from 'dayjs/plugin/timezone';
@@ -35,19 +36,28 @@ dayjs.updateLocale('zh-cn', {
35
36
  // FIXME: @@ 此处不能真正的将 relativeTime 设置为支持中文
36
37
  setDateTool(dayjs);
37
38
 
39
+ const translations: Record<Locale, { utc: string }> = {
40
+ en: {
41
+ utc: 'Your Timezone',
42
+ },
43
+ zh: {
44
+ utc: '你所在时区',
45
+ },
46
+ };
47
+
38
48
  export interface RelativeTimeProps {
39
49
  value: string | number;
40
50
  locale?: Locale;
41
51
  withoutSuffix?: false | true;
42
52
  from?: string | number;
43
53
  to?: string | number;
44
- type?: 'relative' | 'absolute';
54
+ type?: 'relative' | 'absolute' | 'utc' | 'all';
45
55
  tz?: string;
46
56
  relativeRange?: number;
47
57
  enableTooltip?: boolean;
48
58
  }
49
59
 
50
- export default function RelativeTime({
60
+ function useRelativeTime({
51
61
  value,
52
62
  locale = 'en',
53
63
  withoutSuffix = false,
@@ -56,18 +66,36 @@ export default function RelativeTime({
56
66
  type = 'relative',
57
67
  tz,
58
68
  relativeRange,
59
- enableTooltip = true,
60
- ...rest
61
- }: RelativeTimeProps) {
69
+ }: {
70
+ value: string | number;
71
+ locale?: Locale;
72
+ withoutSuffix?: boolean;
73
+ from?: string | number;
74
+ to?: string | number;
75
+ type?: 'relative' | 'absolute' | 'utc';
76
+ tz?: string;
77
+ relativeRange?: number;
78
+ }) {
79
+ const date = new Date();
80
+ const timeZoneOffset = date.getTimezoneOffset();
81
+ const sign = timeZoneOffset > 0 ? '-' : '+';
82
+ const hoursOffset = Math.abs(timeZoneOffset) / 60;
83
+ const isLocalUtc = timeZoneOffset === 0;
84
+ const [isUtc, setIsUtc] = useState(isLocalUtc);
85
+
62
86
  if (!value) {
63
- return '-';
87
+ return { innerContent: '-', popContent: '-', isUtc, setIsUtc, sign, hoursOffset };
64
88
  }
65
89
 
66
90
  const localeOption = locale === 'zh' ? 'zh-cn' : 'en-us';
67
- const datetime = dayjs(value).locale(localeOption);
91
+ let datetime = dayjs(value).locale(localeOption);
92
+
93
+ if (type === 'utc') {
94
+ datetime = dayjs(value).utc().locale(localeOption);
95
+ }
68
96
 
69
97
  if (tz) {
70
- datetime.tz(tz);
98
+ datetime = datetime.tz(tz);
71
99
  }
72
100
 
73
101
  const absoluteString = formatToDatetime(value, { locale: localeOption, tz });
@@ -97,9 +125,110 @@ export default function RelativeTime({
97
125
  popContent = relativeString;
98
126
  }
99
127
 
128
+ if (type === 'utc') {
129
+ if (isUtc) {
130
+ innerContent = formatToDatetime(value, { locale: localeOption, tz, isUtc: true });
131
+ popContent = formatToDatetime(value, { locale: localeOption, tz, isUtc: true });
132
+ } else {
133
+ innerContent = absoluteString;
134
+ popContent = relativeString;
135
+ }
136
+ }
137
+
138
+ return { innerContent, popContent, isUtc, setIsUtc, sign, hoursOffset, relativeString, absoluteString };
139
+ }
140
+
141
+ function UTCChip({
142
+ locale,
143
+ isUtc,
144
+ sign,
145
+ hoursOffset,
146
+ setIsUtc,
147
+ }: {
148
+ locale: Locale;
149
+ isUtc?: boolean;
150
+ sign: string;
151
+ hoursOffset: number;
152
+ setIsUtc: (data: any) => void;
153
+ }) {
154
+ return (
155
+ <Box
156
+ component="span"
157
+ sx={{
158
+ color: 'inherit',
159
+ cursor: 'pointer',
160
+ border: '1px solid',
161
+ fontSize: '0.8rem',
162
+ borderColor: 'divider',
163
+ borderRadius: '20px',
164
+ padding: '0px 8px',
165
+ }}
166
+ onClick={() => setIsUtc((r: any) => !r)}>
167
+ {`${translations[locale].utc}: ${isUtc ? 'UTC' : `UTC${sign}${hoursOffset}`}`}
168
+ </Box>
169
+ );
170
+ }
171
+
172
+ export default function RelativeTime({
173
+ value,
174
+ locale = 'en',
175
+ withoutSuffix = false,
176
+ from = '',
177
+ to = '',
178
+ type = 'relative',
179
+ tz,
180
+ relativeRange,
181
+ enableTooltip = true,
182
+ ...rest
183
+ }: RelativeTimeProps) {
184
+ const { innerContent, popContent, isUtc, setIsUtc, sign, hoursOffset, relativeString } = useRelativeTime({
185
+ value,
186
+ locale,
187
+ withoutSuffix,
188
+ from,
189
+ to,
190
+ type: type === 'all' ? 'utc' : type,
191
+ tz,
192
+ relativeRange,
193
+ });
194
+
195
+ if (type === 'all') {
196
+ return (
197
+ <Tooltip title={undefined} placement="top-end" enterTouchDelay={0}>
198
+ <Box display="flex" alignItems="center" gap={0.5} width="max-content" {...rest}>
199
+ <Box component="span" {...rest} sx={{}}>
200
+ {innerContent}
201
+ </Box>
202
+
203
+ <Box component="span" sx={{ color: 'inherit' }}>
204
+ ·
205
+ </Box>
206
+
207
+ <Box component="span" sx={{ color: 'text.secondary' }}>
208
+ {relativeString}
209
+ </Box>
210
+
211
+ <Box component="span" sx={{ color: 'inherit' }}>
212
+ ·
213
+ </Box>
214
+
215
+ <UTCChip locale={locale} isUtc={isUtc} sign={sign} hoursOffset={hoursOffset} setIsUtc={setIsUtc} />
216
+ </Box>
217
+ </Tooltip>
218
+ );
219
+ }
220
+
100
221
  return (
101
222
  <Tooltip title={enableTooltip ? popContent : undefined} placement="top-end" enterTouchDelay={0}>
102
- <span {...rest}>{innerContent}</span>
223
+ <Box display="flex" alignItems="center" gap={1} width="max-content">
224
+ <Box component="span" {...rest}>
225
+ {innerContent}
226
+ </Box>
227
+
228
+ {type === 'utc' && (
229
+ <UTCChip locale={locale} isUtc={isUtc} sign={sign} hoursOffset={hoursOffset} setIsUtc={setIsUtc} />
230
+ )}
231
+ </Box>
103
232
  </Tooltip>
104
233
  );
105
234
  }
package/src/Util/index.ts CHANGED
@@ -246,7 +246,7 @@ export function getDateTool() {
246
246
 
247
247
  const createDateFormatter =
248
248
  (format: string) =>
249
- (date: string | number | Date, { locale, tz }: { locale?: Locale; tz?: string } = {}) => {
249
+ (date: string | number | Date, { locale, tz, isUtc }: { locale?: Locale; tz?: string; isUtc?: boolean } = {}) => {
250
250
  if (dateTool === null) {
251
251
  throw new Error('call setDateTool to set the date tool library, such as: setDateTool(dayjs)');
252
252
  }
@@ -261,6 +261,10 @@ const createDateFormatter =
261
261
  instance = instance.tz(tz);
262
262
  }
263
263
 
264
+ if (isUtc) {
265
+ instance = instance.utc();
266
+ }
267
+
264
268
  if (typeof locale !== 'undefined') {
265
269
  instance = instance.locale(locale);
266
270
  }
@@ -287,9 +291,9 @@ export function formatToDate(
287
291
  */
288
292
  export function formatToDatetime(
289
293
  date: string | number | Date,
290
- { locale = 'en', tz }: { locale?: Locale; tz?: string } = {}
294
+ { locale = 'en', tz, isUtc = false }: { locale?: Locale; tz?: string; isUtc?: boolean } = {}
291
295
  ) {
292
- return createDateFormatter('lll')(date, { locale, tz });
296
+ return createDateFormatter('lll')(date, { locale, tz, isUtc });
293
297
  }
294
298
 
295
299
  export function detectWalletExtension() {