@soul-refiner/design-system 0.2.102 → 0.2.103

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.
@@ -2,3 +2,5 @@ export { Box } from './box';
2
2
  export type { BoxProps } from './box';
3
3
  export { Display, H, P, Typography } from './typography';
4
4
  export type { DisplayProps, HeadingProps, ParagraphProps, TypographyProps, } from './typography';
5
+ export { TimeAgo } from './time_ago';
6
+ export type { TimeAgoProps } from './time_ago';
@@ -1,2 +1,3 @@
1
1
  export { Box } from './box';
2
2
  export { Display, H, P, Typography } from './typography';
3
+ export { TimeAgo } from './time_ago';
@@ -0,0 +1,2 @@
1
+ export { TimeAgo } from './time_ago';
2
+ export type { TimeAgoProps } from './time_ago';
@@ -0,0 +1 @@
1
+ export { TimeAgo } from './time_ago';
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ export interface TimeAgoProps extends React.PropsWithChildren {
3
+ date: Date;
4
+ }
5
+ export declare const TimeAgo: ({ date }: TimeAgoProps) => React.JSX.Element;
@@ -1,4 +1,9 @@
1
- export const abbrTimeBeforeDate = (date) => {
1
+ 'use client';
2
+ import React from 'react';
3
+ export const TimeAgo = ({ date }) => {
4
+ return React.createElement(React.Fragment, null, abbrTimeBeforeDate(date));
5
+ };
6
+ const abbrTimeBeforeDate = (date) => {
2
7
  const now = new Date();
3
8
  const diff = now.getTime() - date.getTime();
4
9
  if (diff < 60000) {
@@ -8,17 +13,17 @@ export const abbrTimeBeforeDate = (date) => {
8
13
  else if (diff < 3600000) {
9
14
  // under one hour
10
15
  const minutes = Math.floor(diff / 60000);
11
- return `${minutes} ${minutes === 1 ? 'min' : 'mins'}`;
16
+ return `${minutes} ${minutes === 1 ? 'min' : 'mins'} ago`;
12
17
  }
13
18
  else if (diff < 86400000) {
14
19
  // under one day
15
20
  const hours = Math.floor(diff / 3600000);
16
- return `${hours} ${hours === 1 ? 'hour' : 'hours'}`;
21
+ return `${hours} ${hours === 1 ? 'hour' : 'hours'} ago`;
17
22
  }
18
23
  else if (diff < 604800000) {
19
24
  // under one week
20
25
  const days = Math.floor(diff / 86400000);
21
- return `${days} ${days === 1 ? 'day' : 'days'}`;
26
+ return `${days} ${days === 1 ? 'day' : 'days'} ago`;
22
27
  }
23
28
  else {
24
29
  return date.toDateString().slice(4);
@@ -2,18 +2,18 @@
2
2
  import React from 'react';
3
3
  import styled from 'styled-components';
4
4
  import { H, P } from '../../atoms/typography';
5
+ import { TimeAgo } from '../../atoms/time_ago/time_ago';
5
6
  import { Button } from '../../actions/button';
6
7
  import { Avatar } from '../../iconography/avatar';
7
8
  import { Lock } from '../../../icons';
8
- import { abbrTimeBeforeDate } from './helpers';
9
9
  export const Post = ({ actions, author, authorActive, authorHref, authorImage, avatarTooltipContent, children, content, createdDate, dropdown, hasComments, id, images, isPaywalled = false, onJoin, }) => {
10
10
  const componentId = React.useId();
11
11
  const _actions = React.Children.toArray(actions);
12
12
  const _comments = React.Children.toArray(children);
13
- const subtitle = abbrTimeBeforeDate(new Date(createdDate));
14
13
  return (React.createElement(Wrapper, { id: id },
15
14
  React.createElement(Header, null,
16
- React.createElement(Avatar, { href: authorHref, image: authorImage, size: 64, status: authorActive ? 'online' : undefined, subtitle: React.createElement(P, { as: "span", sx: "vertical-align: top;", "$fontSize": 14, "$lineHeight": 20 }, subtitle), title: React.createElement(H, { as: "span", "$bold": true, "$fontSize": 18, "$lineHeight": 26 }, author), textPosition: "right", tooltipContent: avatarTooltipContent }),
15
+ React.createElement(Avatar, { href: authorHref, image: authorImage, size: 64, status: authorActive ? 'online' : undefined, subtitle: React.createElement(P, { as: "span", sx: "vertical-align: top;", "$fontSize": 14, "$lineHeight": 20 },
16
+ React.createElement(TimeAgo, { date: new Date(createdDate) })), title: React.createElement(H, { as: "span", "$bold": true, "$fontSize": 18, "$lineHeight": 26 }, author), textPosition: "right", tooltipContent: avatarTooltipContent }),
17
17
  dropdown),
18
18
  !!content?.length && (React.createElement("div", { style: { padding: 24 } },
19
19
  React.createElement(P, { "$textClampLines": isPaywalled ? 2 : undefined }, content))),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soul-refiner/design-system",
3
- "version": "0.2.102",
3
+ "version": "0.2.103",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -1 +0,0 @@
1
- export declare const abbrTimeBeforeDate: (date: Date) => string;