@trackunit/react-table-base-components 0.0.351 → 0.0.353
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/index.cjs.js +34 -4
- package/index.esm.js +35 -6
- package/package.json +4 -2
- package/src/components/PlainDateCell/PlainDateCell.d.ts +32 -0
- package/src/components/PlainDateCell/PlainDateCell.stories.d.ts +10 -0
- package/src/components/PlainDateCell/PlainDateCell.variants.d.ts +3 -0
- package/src/index.d.ts +1 -0
package/index.cjs.js
CHANGED
|
@@ -8,6 +8,8 @@ var cssClassVarianceUtilities = require('@trackunit/css-class-variance-utilities
|
|
|
8
8
|
var dateAndTimeUtils = require('@trackunit/date-and-time-utils');
|
|
9
9
|
var reactComponents = require('@trackunit/react-components');
|
|
10
10
|
var react = require('react');
|
|
11
|
+
var polyfill = require('@js-temporal/polyfill');
|
|
12
|
+
var sharedUtils = require('@trackunit/shared-utils');
|
|
11
13
|
|
|
12
14
|
const cvaCheckboxCell = cssClassVarianceUtilities.cvaMerge([""]);
|
|
13
15
|
|
|
@@ -23,8 +25,8 @@ const CheckboxCell = ({ checked, className, dataTestId }) => {
|
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
const cvaDateTimeCell = cssClassVarianceUtilities.cvaMerge([""]);
|
|
26
|
-
const cvaDateTime = cssClassVarianceUtilities.cvaMerge(["slashed-zero", "text-neutral-700", "text-sm", "text-ellipsis"]);
|
|
27
|
-
const cvaDateTimeSince = cssClassVarianceUtilities.cvaMerge(["slashed-zero", "text-neutral-500", "text-sm", "text-ellipsis"]);
|
|
28
|
+
const cvaDateTime$1 = cssClassVarianceUtilities.cvaMerge(["slashed-zero", "text-neutral-700", "text-sm", "text-ellipsis"]);
|
|
29
|
+
const cvaDateTimeSince$1 = cssClassVarianceUtilities.cvaMerge(["slashed-zero", "text-neutral-500", "text-sm", "text-ellipsis"]);
|
|
28
30
|
|
|
29
31
|
/**
|
|
30
32
|
* DateTimeCell is used for render a date and or time in a table cell.
|
|
@@ -37,12 +39,12 @@ const DateTimeCell = ({ format, timeZone, locale, date, withTimeSince = true, cl
|
|
|
37
39
|
return null;
|
|
38
40
|
}
|
|
39
41
|
const formattedDate = dateAndTimeUtils.formatDateUtil(date, format, timeZone, locale);
|
|
40
|
-
return (jsxRuntime.jsxs("div", { className: cvaDateTimeCell({ className }), "data-testid": dataTestId, children: [jsxRuntime.jsx("p", { className: cvaDateTime(), children: formattedDate }), withTimeSince ? jsxRuntime.jsx(TimeSince, { date: date, locale: locale, timeZone: timeZone }) : null] }));
|
|
42
|
+
return (jsxRuntime.jsxs("div", { className: cvaDateTimeCell({ className }), "data-testid": dataTestId, children: [jsxRuntime.jsx("p", { className: cvaDateTime$1(), children: formattedDate }), withTimeSince ? jsxRuntime.jsx(TimeSince, { date: date, locale: locale, timeZone: timeZone }) : null] }));
|
|
41
43
|
};
|
|
42
44
|
const TimeSince = ({ date, timeZone, locale }) => {
|
|
43
45
|
try {
|
|
44
46
|
const timeSince = dateAndTimeUtils.timeSinceAuto(date, new Date(Date.now()), timeZone, locale);
|
|
45
|
-
return jsxRuntime.jsx("p", { className: cvaDateTimeSince(), children: timeSince });
|
|
47
|
+
return jsxRuntime.jsx("p", { className: cvaDateTimeSince$1(), children: timeSince });
|
|
46
48
|
}
|
|
47
49
|
catch (_a) {
|
|
48
50
|
return null;
|
|
@@ -166,6 +168,33 @@ const NumberCell = ({ value = "", unit, className, dataTestId }) => {
|
|
|
166
168
|
return (jsxRuntime.jsxs("div", { className: cvaNumberCell({ className }), "data-testid": dataTestId, children: [jsxRuntime.jsx("span", { children: value }), value && unit ? jsxRuntime.jsx("span", { children: unit }) : null] }));
|
|
167
169
|
};
|
|
168
170
|
|
|
171
|
+
const cvaPlainDateCell = cssClassVarianceUtilities.cvaMerge([""]);
|
|
172
|
+
const cvaDateTime = cssClassVarianceUtilities.cvaMerge(["slashed-zero", "text-neutral-700", "text-sm", "text-ellipsis"]);
|
|
173
|
+
const cvaDateTimeSince = cssClassVarianceUtilities.cvaMerge(["slashed-zero", "text-neutral-500", "text-sm", "text-ellipsis"]);
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* PlainDateCell is used for render a date and or time in a table cell.
|
|
177
|
+
*
|
|
178
|
+
* @param {PlainDateCellProps} props - The props for the PlainDateCell component
|
|
179
|
+
* @returns {JSX.Element} PlainDateCell component
|
|
180
|
+
*/
|
|
181
|
+
const PlainDateCell = ({ locale, date, withDaysSince = true, className, dataTestId }) => {
|
|
182
|
+
if (!date) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
const formattedDate = dateAndTimeUtils.formatDateUtil(date.toZonedDateTime("UTC"), sharedUtils.DateTimeFormat.DATE_SHORT, "UTC", locale);
|
|
186
|
+
return (jsxRuntime.jsxs("div", { className: cvaPlainDateCell({ className }), "data-testid": dataTestId, children: [jsxRuntime.jsx("p", { className: cvaDateTime(), children: formattedDate }), withDaysSince ? jsxRuntime.jsx(DaysSince, { date: date, locale: locale }) : null] }));
|
|
187
|
+
};
|
|
188
|
+
const DaysSince = ({ date, locale }) => {
|
|
189
|
+
try {
|
|
190
|
+
const timeSince = dateAndTimeUtils.timeSinceInDays(date.toZonedDateTime("UTC"), polyfill.Temporal.Now.instant().toZonedDateTimeISO("UTC"), "UTC", locale);
|
|
191
|
+
return jsxRuntime.jsx("p", { className: cvaDateTimeSince(), children: timeSince });
|
|
192
|
+
}
|
|
193
|
+
catch (_a) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
|
|
169
198
|
/**
|
|
170
199
|
* Component for a resizable handle element.
|
|
171
200
|
*
|
|
@@ -430,6 +459,7 @@ exports.LinkCell = LinkCell;
|
|
|
430
459
|
exports.MultiValueTextCell = MultiValueTextCell;
|
|
431
460
|
exports.NoticeCell = NoticeCell;
|
|
432
461
|
exports.NumberCell = NumberCell;
|
|
462
|
+
exports.PlainDateCell = PlainDateCell;
|
|
433
463
|
exports.ResizeHandle = ResizeHandle;
|
|
434
464
|
exports.SortIndicator = SortIndicator;
|
|
435
465
|
exports.TableRoot = TableRoot;
|
package/index.esm.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { Checkbox } from '@trackunit/react-form-components';
|
|
3
3
|
import { cvaMerge } from '@trackunit/css-class-variance-utilities';
|
|
4
|
-
import { formatDateUtil, timeSinceAuto } from '@trackunit/date-and-time-utils';
|
|
4
|
+
import { formatDateUtil, timeSinceAuto, timeSinceInDays } from '@trackunit/date-and-time-utils';
|
|
5
5
|
import { Indicator, ExternalLink, Tooltip, Notice, Tag } from '@trackunit/react-components';
|
|
6
6
|
import { useState, useEffect } from 'react';
|
|
7
|
+
import { Temporal } from '@js-temporal/polyfill';
|
|
8
|
+
import { DateTimeFormat } from '@trackunit/shared-utils';
|
|
7
9
|
|
|
8
10
|
const cvaCheckboxCell = cvaMerge([""]);
|
|
9
11
|
|
|
@@ -19,8 +21,8 @@ const CheckboxCell = ({ checked, className, dataTestId }) => {
|
|
|
19
21
|
};
|
|
20
22
|
|
|
21
23
|
const cvaDateTimeCell = cvaMerge([""]);
|
|
22
|
-
const cvaDateTime = cvaMerge(["slashed-zero", "text-neutral-700", "text-sm", "text-ellipsis"]);
|
|
23
|
-
const cvaDateTimeSince = cvaMerge(["slashed-zero", "text-neutral-500", "text-sm", "text-ellipsis"]);
|
|
24
|
+
const cvaDateTime$1 = cvaMerge(["slashed-zero", "text-neutral-700", "text-sm", "text-ellipsis"]);
|
|
25
|
+
const cvaDateTimeSince$1 = cvaMerge(["slashed-zero", "text-neutral-500", "text-sm", "text-ellipsis"]);
|
|
24
26
|
|
|
25
27
|
/**
|
|
26
28
|
* DateTimeCell is used for render a date and or time in a table cell.
|
|
@@ -33,12 +35,12 @@ const DateTimeCell = ({ format, timeZone, locale, date, withTimeSince = true, cl
|
|
|
33
35
|
return null;
|
|
34
36
|
}
|
|
35
37
|
const formattedDate = formatDateUtil(date, format, timeZone, locale);
|
|
36
|
-
return (jsxs("div", { className: cvaDateTimeCell({ className }), "data-testid": dataTestId, children: [jsx("p", { className: cvaDateTime(), children: formattedDate }), withTimeSince ? jsx(TimeSince, { date: date, locale: locale, timeZone: timeZone }) : null] }));
|
|
38
|
+
return (jsxs("div", { className: cvaDateTimeCell({ className }), "data-testid": dataTestId, children: [jsx("p", { className: cvaDateTime$1(), children: formattedDate }), withTimeSince ? jsx(TimeSince, { date: date, locale: locale, timeZone: timeZone }) : null] }));
|
|
37
39
|
};
|
|
38
40
|
const TimeSince = ({ date, timeZone, locale }) => {
|
|
39
41
|
try {
|
|
40
42
|
const timeSince = timeSinceAuto(date, new Date(Date.now()), timeZone, locale);
|
|
41
|
-
return jsx("p", { className: cvaDateTimeSince(), children: timeSince });
|
|
43
|
+
return jsx("p", { className: cvaDateTimeSince$1(), children: timeSince });
|
|
42
44
|
}
|
|
43
45
|
catch (_a) {
|
|
44
46
|
return null;
|
|
@@ -162,6 +164,33 @@ const NumberCell = ({ value = "", unit, className, dataTestId }) => {
|
|
|
162
164
|
return (jsxs("div", { className: cvaNumberCell({ className }), "data-testid": dataTestId, children: [jsx("span", { children: value }), value && unit ? jsx("span", { children: unit }) : null] }));
|
|
163
165
|
};
|
|
164
166
|
|
|
167
|
+
const cvaPlainDateCell = cvaMerge([""]);
|
|
168
|
+
const cvaDateTime = cvaMerge(["slashed-zero", "text-neutral-700", "text-sm", "text-ellipsis"]);
|
|
169
|
+
const cvaDateTimeSince = cvaMerge(["slashed-zero", "text-neutral-500", "text-sm", "text-ellipsis"]);
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* PlainDateCell is used for render a date and or time in a table cell.
|
|
173
|
+
*
|
|
174
|
+
* @param {PlainDateCellProps} props - The props for the PlainDateCell component
|
|
175
|
+
* @returns {JSX.Element} PlainDateCell component
|
|
176
|
+
*/
|
|
177
|
+
const PlainDateCell = ({ locale, date, withDaysSince = true, className, dataTestId }) => {
|
|
178
|
+
if (!date) {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
const formattedDate = formatDateUtil(date.toZonedDateTime("UTC"), DateTimeFormat.DATE_SHORT, "UTC", locale);
|
|
182
|
+
return (jsxs("div", { className: cvaPlainDateCell({ className }), "data-testid": dataTestId, children: [jsx("p", { className: cvaDateTime(), children: formattedDate }), withDaysSince ? jsx(DaysSince, { date: date, locale: locale }) : null] }));
|
|
183
|
+
};
|
|
184
|
+
const DaysSince = ({ date, locale }) => {
|
|
185
|
+
try {
|
|
186
|
+
const timeSince = timeSinceInDays(date.toZonedDateTime("UTC"), Temporal.Now.instant().toZonedDateTimeISO("UTC"), "UTC", locale);
|
|
187
|
+
return jsx("p", { className: cvaDateTimeSince(), children: timeSince });
|
|
188
|
+
}
|
|
189
|
+
catch (_a) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
165
194
|
/**
|
|
166
195
|
* Component for a resizable handle element.
|
|
167
196
|
*
|
|
@@ -418,4 +447,4 @@ const cvaTr = cvaMerge(["border-b", "border-neutral-300", "w-full", "h-max"], {
|
|
|
418
447
|
},
|
|
419
448
|
});
|
|
420
449
|
|
|
421
|
-
export { CheckboxCell, DateTimeCell, ImageCell, IndicatorCell, LinkCell, MultiValueTextCell, NoticeCell, NumberCell, ResizeHandle, SortIndicator, TableRoot, TagsCell, Tbody, Td, TextCell, Tfoot, Th, Thead, Tr };
|
|
450
|
+
export { CheckboxCell, DateTimeCell, ImageCell, IndicatorCell, LinkCell, MultiValueTextCell, NoticeCell, NumberCell, PlainDateCell, ResizeHandle, SortIndicator, TableRoot, TagsCell, Tbody, Td, TextCell, Tfoot, Th, Thead, Tr };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-table-base-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.353",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
"@trackunit/react-form-components": "*",
|
|
12
12
|
"@trackunit/css-class-variance-utilities": "*",
|
|
13
13
|
"@trackunit/date-and-time-utils": "*",
|
|
14
|
-
"
|
|
14
|
+
"@trackunit/shared-utils": "*",
|
|
15
|
+
"react": "^18.2.0",
|
|
16
|
+
"@js-temporal/polyfill": "^0.4.4"
|
|
15
17
|
},
|
|
16
18
|
"module": "./index.esm.js",
|
|
17
19
|
"main": "./index.cjs.js"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
import { CommonProps } from "@trackunit/react-components";
|
|
4
|
+
export interface PlainDateCellProps extends CommonProps {
|
|
5
|
+
/**
|
|
6
|
+
* The PlainDate to render.
|
|
7
|
+
* If not provided, the component will not render.
|
|
8
|
+
*/
|
|
9
|
+
date?: Temporal.PlainDate;
|
|
10
|
+
/**
|
|
11
|
+
* If true, the component will render the time since the date.
|
|
12
|
+
* This is rendered on a separate line.
|
|
13
|
+
*
|
|
14
|
+
* @default true
|
|
15
|
+
*/
|
|
16
|
+
withDaysSince?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* The locale to use for the date.
|
|
19
|
+
* See the formatDateUtil function for more information.
|
|
20
|
+
*/
|
|
21
|
+
locale?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* PlainDateCell is used for render a date and or time in a table cell.
|
|
25
|
+
*
|
|
26
|
+
* @param {PlainDateCellProps} props - The props for the PlainDateCell component
|
|
27
|
+
* @returns {JSX.Element} PlainDateCell component
|
|
28
|
+
*/
|
|
29
|
+
export declare const PlainDateCell: ({ locale, date, withDaysSince, className, dataTestId }: PlainDateCellProps) => JSX.Element | null;
|
|
30
|
+
export interface DaysSinceProps extends Pick<PlainDateCellProps, "date" | "locale"> {
|
|
31
|
+
date: Temporal.PlainDate;
|
|
32
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Meta, StoryObj } from "@storybook/react";
|
|
3
|
+
import { PlainDateCell } from "./PlainDateCell";
|
|
4
|
+
import "./PlainDateCell.variants";
|
|
5
|
+
type Story = StoryObj<typeof PlainDateCell>;
|
|
6
|
+
declare const meta: Meta<typeof PlainDateCell>;
|
|
7
|
+
export default meta;
|
|
8
|
+
export declare const packageName: () => JSX.Element;
|
|
9
|
+
export declare const Default: Story;
|
|
10
|
+
export declare const Variants: () => JSX.Element;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const cvaPlainDateCell: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
|
|
2
|
+
export declare const cvaDateTime: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
|
|
3
|
+
export declare const cvaDateTimeSince: (props?: import("class-variance-authority/dist/types").ClassProp | undefined) => string;
|
package/src/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./components/LinkCell/LinkCell";
|
|
|
6
6
|
export * from "./components/MultiValueTextCell/MultiValueTextCell";
|
|
7
7
|
export * from "./components/NoticeCell/NoticeCell";
|
|
8
8
|
export * from "./components/NumberCell/NumberCell";
|
|
9
|
+
export * from "./components/PlainDateCell/PlainDateCell";
|
|
9
10
|
export * from "./components/ResizeHandle";
|
|
10
11
|
export * from "./components/SortIndicator";
|
|
11
12
|
export * from "./components/TableRoot";
|