@streamscloud/kit 0.93.4 → 0.93.6

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.
@@ -53,7 +53,7 @@ whose action exists but is currently unavailable.
53
53
  | `--sc-kit--popover-item--color--disabled` | Disabled text color | `var(--sc-kit--color--text--muted)` |
54
54
  | `--sc-kit--popover-item--background--hover` | Hover background | `var(--sc-kit--color--bg--hover)` |
55
55
  | `--sc-kit--popover-item--divider-color` | Divider line color | `var(--sc-kit--color--border)` |
56
- | `--sc-kit--popover-item--divider-spacing` | Vertical gap added by divider | `var(--sc-kit--space--1)` |
56
+ | `--sc-kit--popover-item--divider-spacing` | Gap on each side of the divider line | `var(--sc-kit--space--1)` |
57
57
  | `--sc-kit--popover-item--text-align` | Text alignment | `left` |
58
58
  | `--sc-kit--popover-item--margin-inline` | Inline margin when `inset` (default on) | `var(--sc-kit--space--2)` |
59
59
  | `--sc-kit--popover-item--border-radius` | Corner radius when `inset` (default on) | `var(--sc-kit--radius--sm)` |
@@ -97,11 +97,20 @@ whose action exists but is currently unavailable.
97
97
  cursor: default;
98
98
  }
99
99
  .popover-item--divider {
100
- box-shadow: 0 1px 0 0 var(--_di--divider-color);
101
- margin-bottom: var(--_di--divider-spacing);
102
- padding-bottom: calc(var(--_di--padding-block) + 1px);
100
+ position: relative;
101
+ margin-bottom: calc(2 * var(--_di--divider-spacing) + 1px);
102
+ }
103
+ .popover-item--divider::after {
104
+ content: "";
105
+ position: absolute;
106
+ inset-inline: var(--_di--divider-inset-inline, 0);
107
+ bottom: calc(-1 * var(--_di--divider-spacing) - 1px);
108
+ height: 1px;
109
+ background: var(--_di--divider-color);
110
+ pointer-events: none;
103
111
  }
104
112
  .popover-item--inset {
113
+ --_di--divider-inset-inline: calc(-1 * var(--_di--margin-inline));
105
114
  margin-inline: var(--_di--margin-inline);
106
115
  border-radius: var(--_di--border-radius);
107
116
  }
@@ -35,7 +35,7 @@ type Props = {
35
35
  * | `--sc-kit--popover-item--color--disabled` | Disabled text color | `var(--sc-kit--color--text--muted)` |
36
36
  * | `--sc-kit--popover-item--background--hover` | Hover background | `var(--sc-kit--color--bg--hover)` |
37
37
  * | `--sc-kit--popover-item--divider-color` | Divider line color | `var(--sc-kit--color--border)` |
38
- * | `--sc-kit--popover-item--divider-spacing` | Vertical gap added by divider | `var(--sc-kit--space--1)` |
38
+ * | `--sc-kit--popover-item--divider-spacing` | Gap on each side of the divider line | `var(--sc-kit--space--1)` |
39
39
  * | `--sc-kit--popover-item--text-align` | Text alignment | `left` |
40
40
  * | `--sc-kit--popover-item--margin-inline` | Inline margin when `inset` (default on) | `var(--sc-kit--space--2)` |
41
41
  * | `--sc-kit--popover-item--border-radius` | Corner radius when `inset` (default on) | `var(--sc-kit--radius--sm)` |
@@ -5,7 +5,7 @@
5
5
  const { value, segments, variant = 'tray', size = 'md', fullWidth = false, compare, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, on } = $props();
6
6
  const formFieldLabel = getFormFieldLabel();
7
7
  const segmentIdPrefix = $props.id();
8
- const segmentEls = [];
8
+ const segmentEls = $state([]);
9
9
  const isActive = (segment) => (compare ? compare(value, segment.value) : value === segment.value);
10
10
  const tabStopIndex = $derived.by(() => {
11
11
  const activeIndex = segments.findIndex((segment) => !segment.disabled && isActive(segment));
@@ -1,8 +1,10 @@
1
- <script lang="ts" generics="T extends {id: string}">import { DateHelper } from '../../../core/utils';
1
+ <script lang="ts" generics="T extends {id: string}">import { AppLocale } from '../../../core/locale';
2
+ import { DateHelper } from '../../../core/utils';
2
3
  import { ImageRound } from '../../image';
4
+ import { TimeAgo } from '../../time-ago';
3
5
  import { Tooltip } from '../../tooltip';
4
6
  let { item, column } = $props();
5
- const fmt = (d, options) => new Intl.DateTimeFormat(undefined, options).format(d);
7
+ const fmt = (d, options) => new Intl.DateTimeFormat(column.locale ?? AppLocale.current, options).format(d);
6
8
  const timeFormat = { hour: '2-digit', minute: '2-digit', hour12: false };
7
9
  const dateFormat = { day: '2-digit' };
8
10
  const monthFormat = { month: 'short' };
@@ -15,6 +17,7 @@ const getDateValueForColumn = (column, item) => {
15
17
  const dateTime = $derived(getDateValueForColumn(column, item));
16
18
  const by = $derived(column.byValueFactory ? column.byValueFactory(item) : null);
17
19
  const underline = $derived(column.underline ?? 'hover');
20
+ const showTime = $derived(column.showTime ?? true);
18
21
  const getHref = (by) => {
19
22
  return column.hrefFactory ? column.hrefFactory(by) : null;
20
23
  };
@@ -46,13 +49,19 @@ const navigateToUser = (event, by) => {
46
49
  </span>
47
50
  {/if}
48
51
  <span class="table-by-cell__date">
49
- {fmt(dateTime, dateFormat)}.
50
- <span class="table-by-cell__month">{fmt(dateTime, monthFormat)}</span>
51
- {#if dateTime.getFullYear() !== new Date().getFullYear()}
52
- .{fmt(dateTime, yearFormat)}
52
+ {#if column.dateDisplay === 'absolute'}
53
+ {fmt(dateTime, dateFormat)}.
54
+ <span class="table-by-cell__month">{fmt(dateTime, monthFormat)}</span>
55
+ {#if dateTime.getFullYear() !== new Date().getFullYear()}
56
+ .{fmt(dateTime, yearFormat)}
57
+ {/if}
58
+ {#if showTime}
59
+ <span>&nbsp;&middot;&nbsp;</span>
60
+ {fmt(dateTime, timeFormat)}
61
+ {/if}
62
+ {:else}
63
+ <TimeAgo date={dateTime} autoUpdate={column.autoUpdate ?? false} showTime={showTime} locale={column.locale} />
53
64
  {/if}
54
- <span>&nbsp;&middot;&nbsp;</span>
55
- {fmt(dateTime, timeFormat)}
56
65
  </span>
57
66
  {:else if by}
58
67
  {@const href = getHref(by)}
@@ -1,3 +1,4 @@
1
+ import type { AppLocaleValue } from '../../core/locale';
1
2
  import type { Repository } from '../../core/repository';
2
3
  import type { BadgeShape, BadgeVariant } from '../badge';
3
4
  import type { ButtonSize, ButtonVariant } from '../button';
@@ -77,6 +78,14 @@ export interface ITableByColumn<T> extends ITableColumn<T> {
77
78
  }) => void) | null;
78
79
  /** When the person-name link shows its underline: only on hover, permanently, or not at all. @default 'hover' */
79
80
  underline?: 'hover' | 'always' | 'never';
81
+ /** Relative "5 minutes ago" text, or the absolute "04. Nov · 14:32" form. @default 'relative' */
82
+ dateDisplay?: 'relative' | 'absolute';
83
+ /** Re-render the relative text on a timer as time passes. Relative display only. */
84
+ autoUpdate?: boolean;
85
+ /** Include the time of day in the date. @default true */
86
+ showTime?: boolean;
87
+ /** Falls back to the global `AppLocale` when not set. */
88
+ locale?: AppLocaleValue | null;
80
89
  }
81
90
  export interface ITableButtonColumn<T> extends ITableColumn<T> {
82
91
  type: 'button';
@@ -1,14 +1,16 @@
1
1
  <script lang="ts">import { DateFormatOptions, DateHelper } from '../../core/utils/date-helper';
2
2
  import { TimeAgoLocalization } from './time-ago-localization';
3
- let { date = null, thresholdMinutes = 60 * 24 * 2 /* 2 days */ } = $props();
4
- const localization = new TimeAgoLocalization();
3
+ let { date = null, thresholdMinutes = 60 * 24 * 2 /* 2 days */, autoUpdate = true, showTime = true, locale = null } = $props();
4
+ const localization = new TimeAgoLocalization(() => locale);
5
5
  let timeSpan = $state.raw(null);
6
6
  let timeoutId;
7
7
  const setRelativeTime = (d) => {
8
8
  disableTimeout();
9
9
  const dateVal = d ? DateHelper.toDate(d) : new Date();
10
+ const formatTime = () => dateVal.toLocaleString(localization.locale, DateFormatOptions.timeFormat);
10
11
  const setupAbsDate = () => {
11
- timeSpan = localization.at(dateVal.toLocaleString(localization.locale, dateVal.getFullYear() === new Date().getFullYear() ? DateFormatOptions.dateFormatWithoutYear : DateFormatOptions.dateFormat), dateVal.toLocaleString(localization.locale, DateFormatOptions.timeFormat));
12
+ const formattedDate = dateVal.toLocaleString(localization.locale, dateVal.getFullYear() === new Date().getFullYear() ? DateFormatOptions.dateFormatWithoutYear : DateFormatOptions.dateFormat);
13
+ timeSpan = showTime ? localization.at(formattedDate, formatTime()) : formattedDate;
12
14
  };
13
15
  const diffSeconds = (+new Date() - +dateVal) / 1000;
14
16
  if (diffSeconds > thresholdMinutes * 60) {
@@ -40,13 +42,15 @@ const setRelativeTime = (d) => {
40
42
  refreshIntervalSec = 3600;
41
43
  }
42
44
  else if (diffSeconds < secsIn2Days) {
43
- timeSpan = localization.yesterday(dateVal.toLocaleString(localization.locale, DateFormatOptions.timeFormat));
45
+ timeSpan = showTime ? localization.yesterdayAt(formatTime()) : localization.yesterday;
44
46
  refreshIntervalSec = 3600;
45
47
  }
46
48
  else {
47
49
  return setupAbsDate();
48
50
  }
49
- timeoutId = setTimeout(() => setRelativeTime(d), refreshIntervalSec * 1000);
51
+ if (autoUpdate) {
52
+ timeoutId = setTimeout(() => setRelativeTime(d), refreshIntervalSec * 1000);
53
+ }
50
54
  };
51
55
  $effect(() => {
52
56
  setRelativeTime(date);
@@ -69,7 +73,7 @@ const disableTimeout = () => {
69
73
 
70
74
  <!--
71
75
  @component
72
- Displays a human-readable relative time string (e.g. "5 minutes ago") that auto-updates on a self-scheduled
76
+ Displays a human-readable relative time string (e.g. "5 minutes ago") that can auto-update on a self-scheduled
73
77
  timer. Falls back to an absolute date/time after `thresholdMinutes`.
74
78
 
75
79
  Inherits typography from the parent — pass `font-size` / `color` through CSS on a surrounding element to
@@ -1,11 +1,18 @@
1
+ import type { AppLocaleValue } from '../../core/locale';
1
2
  type Props = {
2
3
  /** Date to display relative to now */
3
4
  date: Date | string | null;
4
5
  /** Minutes after which absolute date format is used @default 2880 */
5
6
  thresholdMinutes?: number;
7
+ /** Re-render the relative text on a timer as time passes. @default true */
8
+ autoUpdate?: boolean;
9
+ /** Include the time of day in the absolute and "yesterday" forms. @default true */
10
+ showTime?: boolean;
11
+ /** Falls back to the global `AppLocale` when not set. */
12
+ locale?: AppLocaleValue | null;
6
13
  };
7
14
  /**
8
- * Displays a human-readable relative time string (e.g. "5 minutes ago") that auto-updates on a self-scheduled
15
+ * Displays a human-readable relative time string (e.g. "5 minutes ago") that can auto-update on a self-scheduled
9
16
  * timer. Falls back to an absolute date/time after `thresholdMinutes`.
10
17
  *
11
18
  * Inherits typography from the parent — pass `font-size` / `color` through CSS on a surrounding element to
@@ -1,10 +1,14 @@
1
+ import { type AppLocaleValue } from '../../core/locale';
1
2
  export declare class TimeAgoLocalization {
3
+ #private;
4
+ constructor(locale?: () => AppLocaleValue | null | undefined);
2
5
  get locale(): string;
3
6
  get aMinuteAgo(): string;
4
7
  get anHourAgo(): string;
5
8
  get justNow(): string;
6
- get at(): (date: string, time: string) => string;
7
- get hoursAgo(): (hours: number) => string;
8
- get minutesAgo(): (minutes: number) => string;
9
- get yesterday(): (time: string) => string;
9
+ get yesterday(): string;
10
+ at: (date: string, time: string) => string;
11
+ hoursAgo: (hours: number) => string;
12
+ minutesAgo: (minutes: number) => string;
13
+ yesterdayAt: (time: string) => string;
10
14
  }
@@ -1,29 +1,39 @@
1
1
  import { AppLocale } from '../../core/locale';
2
2
  export class TimeAgoLocalization {
3
+ #locale;
4
+ constructor(locale = () => undefined) {
5
+ this.#locale = locale;
6
+ }
3
7
  get locale() {
4
- return loc.locale[AppLocale.current];
8
+ return loc.locale[this.#current];
5
9
  }
6
10
  get aMinuteAgo() {
7
- return loc.aMinuteAgo[AppLocale.current];
11
+ return loc.aMinuteAgo[this.#current];
8
12
  }
9
13
  get anHourAgo() {
10
- return loc.anHourAgo[AppLocale.current];
14
+ return loc.anHourAgo[this.#current];
11
15
  }
12
16
  get justNow() {
13
- return loc.justNow[AppLocale.current];
14
- }
15
- get at() {
16
- return loc.at[AppLocale.current];
17
- }
18
- get hoursAgo() {
19
- return loc.hoursAgo[AppLocale.current];
20
- }
21
- get minutesAgo() {
22
- return loc.minutesAgo[AppLocale.current];
17
+ return loc.justNow[this.#current];
23
18
  }
24
19
  get yesterday() {
25
- return loc.yesterday[AppLocale.current];
20
+ return loc.yesterday[this.#current];
26
21
  }
22
+ get #current() {
23
+ return this.#locale() ?? AppLocale.current;
24
+ }
25
+ at = (date, time) => {
26
+ return loc.at[this.#current](date, time);
27
+ };
28
+ hoursAgo = (hours) => {
29
+ return loc.hoursAgo[this.#current](hours);
30
+ };
31
+ minutesAgo = (minutes) => {
32
+ return loc.minutesAgo[this.#current](minutes);
33
+ };
34
+ yesterdayAt = (time) => {
35
+ return loc.yesterdayAt[this.#current](time);
36
+ };
27
37
  }
28
38
  const loc = {
29
39
  locale: {
@@ -42,6 +52,10 @@ const loc = {
42
52
  en: 'just now',
43
53
  no: 'nettopp nå'
44
54
  },
55
+ yesterday: {
56
+ en: 'Yesterday',
57
+ no: 'I går'
58
+ },
45
59
  at: {
46
60
  en: (date, time) => `${date} at ${time}`,
47
61
  no: (date, time) => `${date} kl. ${time}`
@@ -54,7 +68,7 @@ const loc = {
54
68
  en: (minutes) => `${minutes} minutes ago`,
55
69
  no: (minutes) => `${minutes} minutter siden`
56
70
  },
57
- yesterday: {
71
+ yesterdayAt: {
58
72
  en: (time) => `Yesterday at ${time}`,
59
73
  no: (time) => `I går kl. ${time}`
60
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamscloud/kit",
3
- "version": "0.93.4",
3
+ "version": "0.93.6",
4
4
  "author": "StreamsCloud",
5
5
  "repository": {
6
6
  "type": "git",