@canonical/svelte-ds-app-launchpad 0.27.1-experimental.0 → 0.28.0

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.
@@ -0,0 +1,80 @@
1
+ <!-- @canonical/generator-ds 0.10.0-experimental.5 -->
2
+
3
+ <script lang="ts">
4
+ import { setLogContext } from "./context.js";
5
+ import type { LogProps } from "./types.js";
6
+ import "./styles.css";
7
+ import { useDefaultTimestampFormatter } from "./utils/useDefaultTimestampFormatter.svelte.js";
8
+
9
+ const componentCssClassName = "ds log";
10
+
11
+ let {
12
+ class: className,
13
+ children,
14
+ hideTimestamps = false,
15
+ wrapLines = false,
16
+ timeZone = "UTC",
17
+ timestampFormatter,
18
+ caption,
19
+ ...rest
20
+ }: LogProps = $props();
21
+
22
+ const defaultFormatter = useDefaultTimestampFormatter(() => timeZone);
23
+
24
+ setLogContext({
25
+ get hideTimestamps() {
26
+ return hideTimestamps;
27
+ },
28
+ get wrapLines() {
29
+ return wrapLines;
30
+ },
31
+ get timestampFormatter() {
32
+ return timestampFormatter ?? defaultFormatter;
33
+ },
34
+ });
35
+ </script>
36
+
37
+ <table class={[componentCssClassName, className]} {...rest}>
38
+ {#if caption}
39
+ <caption class="visually-hidden">{caption}</caption>
40
+ {/if}
41
+
42
+ <thead class="visually-hidden">
43
+ <tr>
44
+ <th scope="col" class="line-number">Line</th>
45
+ {#if !hideTimestamps}
46
+ <th scope="col" class="timestamp">Timestamp</th>
47
+ {/if}
48
+ <th scope="col" class="content">Content</th>
49
+ </tr>
50
+ </thead>
51
+
52
+ <tbody>
53
+ {@render children?.()}
54
+ </tbody>
55
+ </table>
56
+
57
+ <!-- @component
58
+ `Log` is used to display log entries in a structured table format.
59
+
60
+ ## Example Usage
61
+ ```svelte
62
+ <Log>
63
+ <Log.Line
64
+ line={1}
65
+ timestamp="2024-10-27T10:00:59.400Z"
66
+ >
67
+ Starting database connection...
68
+ </Log.Line>
69
+ <Log.Line
70
+ id="line-2"
71
+ timestamp="2024-10-27T10:05:12.300Z"
72
+ >
73
+ {#snippet line()}
74
+ <Link href="#line-2" soft>2</Link>
75
+ {/snippet}
76
+ Database connection failed: Connection timed out
77
+ </Log.Line>
78
+ </Log>
79
+ ```
80
+ -->
@@ -0,0 +1,29 @@
1
+ import type { LogProps } from "./types.js";
2
+ import "./styles.css";
3
+ /**
4
+ * `Log` is used to display log entries in a structured table format.
5
+ *
6
+ * ## Example Usage
7
+ * ```svelte
8
+ * <Log>
9
+ * <Log.Line
10
+ * line={1}
11
+ * timestamp="2024-10-27T10:00:59.400Z"
12
+ * >
13
+ * Starting database connection...
14
+ * </Log.Line>
15
+ * <Log.Line
16
+ * id="line-2"
17
+ * timestamp="2024-10-27T10:05:12.300Z"
18
+ * >
19
+ * {#snippet line()}
20
+ * <Link href="#line-2" soft>2</Link>
21
+ * {/snippet}
22
+ * Database connection failed: Connection timed out
23
+ * </Log.Line>
24
+ * </Log>
25
+ * ```
26
+ */
27
+ declare const Log: import("svelte").Component<LogProps, {}, "">;
28
+ type Log = ReturnType<typeof Log>;
29
+ export default Log;
@@ -0,0 +1,44 @@
1
+ <!-- @canonical/generator-ds 0.10.0-experimental.5 -->
2
+
3
+ <script lang="ts">
4
+ import { getLogContext } from "../../context.js";
5
+ import type { LineProps } from "./types.js";
6
+ import "./styles.css";
7
+
8
+ const componentCssClassName = "ds log-line";
9
+
10
+ let {
11
+ class: className,
12
+ line,
13
+ timestamp,
14
+ children,
15
+ ...rest
16
+ }: LineProps = $props();
17
+
18
+ const logContext = getLogContext();
19
+ </script>
20
+
21
+ <tr class={[componentCssClassName, className]} {...rest}>
22
+ <th class="line-number" scope="row">
23
+ {#if typeof line === "number"}
24
+ {line}
25
+ {:else}
26
+ {@render line()}
27
+ {/if}
28
+ </th>
29
+ {#if !logContext.hideTimestamps}
30
+ <!-- If timestamps are hidden globally, don't render the timestamp column at all -->
31
+ <td class="timestamp">
32
+ <!-- If only this particular line doesn't have a timestamp, render the cell, but leave it empty -->
33
+ {#if timestamp !== undefined}
34
+ {@const timestampDate = new Date(timestamp)}
35
+ <time datetime={timestampDate.toISOString()}>
36
+ {logContext.timestampFormatter.format(timestampDate)}
37
+ </time>
38
+ {/if}
39
+ </td>
40
+ {/if}
41
+ <td class={["content", { wrap: logContext.wrapLines }]}
42
+ >{@render children()}</td
43
+ >
44
+ </tr>
@@ -0,0 +1,5 @@
1
+ import type { LineProps } from "./types.js";
2
+ import "./styles.css";
3
+ declare const Line: import("svelte").Component<LineProps, {}, "">;
4
+ type Line = ReturnType<typeof Line>;
5
+ export default Line;
@@ -0,0 +1,2 @@
1
+ export { default as Line } from "./Line.svelte";
2
+ export * from "./types.js";
@@ -0,0 +1,3 @@
1
+ /* @canonical/generator-ds 0.10.0-experimental.5 */
2
+ export { default as Line } from "./Line.svelte";
3
+ export * from "./types.js";
@@ -0,0 +1,76 @@
1
+ .ds.log-line {
2
+ vertical-align: top;
3
+ display: grid;
4
+ grid-column: 1 / -1;
5
+ grid-template-columns: subgrid;
6
+ font: var(--lp-typography-code-s);
7
+ color: var(--lp-color-text-default);
8
+
9
+ --log-line-background-color: var(--lp-color-background-alt);
10
+ --log-line-target-highlight-color: var(--lp-color-background-active);
11
+ --log-line-target-highlight-time: 5s;
12
+
13
+ > td,
14
+ > th {
15
+ padding-block: var(--lp-dimension-spacing-block-xxxs);
16
+ font-weight: var(--lp-typography-weight-regular);
17
+ background-color: var(--log-line-background-color);
18
+ }
19
+
20
+ &:target {
21
+ > td,
22
+ > th {
23
+ animation:
24
+ target-highlight-hold var(--log-line-target-highlight-time) step-end
25
+ forwards,
26
+ target-highlight-fade var(--lp-transition-duration-sleepy) ease-out
27
+ var(--log-line-target-highlight-time) forwards;
28
+ }
29
+ }
30
+
31
+ > .line-number {
32
+ grid-column: line-number;
33
+ text-align: right;
34
+ color: var(--lp-color-text-muted);
35
+ position: sticky;
36
+ left: 0;
37
+ padding-inline-start: var(--log-padding-inline);
38
+ padding-inline-end: var(--lp-dimension-spacing-inline-s);
39
+ }
40
+
41
+ > .timestamp {
42
+ grid-column: timestamp;
43
+ white-space: nowrap;
44
+
45
+ padding-inline-end: var(--lp-dimension-spacing-inline-m);
46
+ }
47
+
48
+ > .content {
49
+ grid-column: content;
50
+ white-space: pre;
51
+
52
+ &.wrap {
53
+ white-space: pre-wrap;
54
+ word-break: break-word;
55
+ }
56
+ }
57
+
58
+ /* TODO: Implement level-based styling when designs ready */
59
+ }
60
+
61
+ @keyframes target-highlight-hold {
62
+ from,
63
+ to {
64
+ background-color: var(--log-line-target-highlight-color);
65
+ }
66
+ }
67
+
68
+ @keyframes target-highlight-fade {
69
+ from {
70
+ background-color: var(--log-line-target-highlight-color);
71
+ }
72
+
73
+ to {
74
+ background-color: var(--log-line-background-color);
75
+ }
76
+ }
@@ -0,0 +1,18 @@
1
+ import type { Snippet } from "svelte";
2
+ import type { SvelteHTMLElements } from "svelte/elements";
3
+ type BaseProps = SvelteHTMLElements["tr"];
4
+ export interface LineProps extends BaseProps {
5
+ /**
6
+ * The line number of the log entry.
7
+ */
8
+ line: number | Snippet<[]>;
9
+ /**
10
+ * The timestamp of the log entry.
11
+ */
12
+ timestamp?: Date | string | number;
13
+ /**
14
+ * The message content of the log entry.
15
+ */
16
+ children: Snippet<[]>;
17
+ }
18
+ export {};
@@ -0,0 +1,2 @@
1
+ /* @canonical/generator-ds 0.10.0-experimental.5 */
2
+ export {};
@@ -0,0 +1 @@
1
+ export * from "./Line/index.js";
@@ -0,0 +1 @@
1
+ export * from "./Line/index.js";
@@ -0,0 +1,2 @@
1
+ import type { LogContext } from "./types.js";
2
+ export declare const getLogContext: () => LogContext, setLogContext: (context: LogContext) => LogContext;
@@ -0,0 +1,2 @@
1
+ import { createContext } from "svelte";
2
+ export const [getLogContext, setLogContext] = createContext();
@@ -0,0 +1,23 @@
1
+ import { Line } from "./common/index.js";
2
+ import { default as LogRoot } from "./Log.svelte";
3
+ declare const Log: typeof LogRoot & {
4
+ /**
5
+ * The Log Line component for individual log entries.
6
+ *
7
+ * @example
8
+ * ```svelte
9
+ * <Log>
10
+ * <Log.Line
11
+ * line={1}
12
+ * timestamp={new Date()}
13
+ * >
14
+ * Application started successfully.
15
+ * </Log.Line>
16
+ * </Log>
17
+ * ```
18
+ */
19
+ Line: typeof Line;
20
+ };
21
+ export type { LineProps as LogLineProps } from "./common/index.js";
22
+ export type { LogProps, TimeZone as LogTimeZone } from "./types.js";
23
+ export { Log };
@@ -0,0 +1,6 @@
1
+ /* @canonical/generator-ds 0.10.0-experimental.5 */
2
+ import { Line } from "./common/index.js";
3
+ import { default as LogRoot } from "./Log.svelte";
4
+ const Log = LogRoot;
5
+ Log.Line = Line;
6
+ export { Log };
@@ -0,0 +1,18 @@
1
+ .ds.log {
2
+ display: block;
3
+ contain: inline-size layout paint;
4
+ overflow: auto;
5
+
6
+ --log-padding-inline: var(--lp-dimension-spacing-inline-m);
7
+
8
+ background-color: var(--lp-color-background-alt);
9
+ padding-inline-end: var(--log-padding-inline);
10
+ padding-block-end: var(--lp-dimension-spacing-block-xxxl);
11
+
12
+ tbody {
13
+ display: grid;
14
+ min-width: fit-content;
15
+ grid-template-columns: [line-number-start] auto [line-number-end
16
+ timestamp-start] max-content [timestamp-end content-start] 1fr [content-end];
17
+ }
18
+ }
@@ -0,0 +1,57 @@
1
+ import type { SvelteHTMLElements } from "svelte/elements";
2
+ type CommonLogProps = SvelteHTMLElements["table"] & {
3
+ /**
4
+ * If true, timestamps won't be shown in log lines.
5
+ *
6
+ * @default false
7
+ */
8
+ hideTimestamps?: boolean;
9
+ /**
10
+ * If true, long lines will wrap onto multiple lines.
11
+ *
12
+ * @default false
13
+ */
14
+ wrapLines?: boolean;
15
+ /**
16
+ * An optional caption for the log table to provide additional context for assistive technologies. Not visually displayed.
17
+ */
18
+ caption?: string;
19
+ };
20
+ interface DefaultFormatterLogProps extends CommonLogProps {
21
+ /**
22
+ * Allows displaying timestamps in UTC, runtime local time, or an explicit timezone.
23
+ *
24
+ * Uses `YYYY-MM-DD HH:mm:ss.SSS` format for all timezones.
25
+ *
26
+ * In SSR, `local` resolves to the server runtime timezone and may differ from the browser timezone during hydration.
27
+ * For deterministic SSR output in a user timezone, pass an explicit timezone (for example `Europe/Warsaw`).
28
+ * Invalid timezones will fall back to UTC.
29
+ *
30
+ * @default "UTC"
31
+ *
32
+ * Has no effect if `timestampFormatter` is provided.
33
+ */
34
+ timeZone?: TimeZone;
35
+ timestampFormatter?: never;
36
+ }
37
+ interface CustomFormatterLogProps extends CommonLogProps {
38
+ /**
39
+ * A custom timestamp formatter. If provided, this will be used instead of the default timestamp formatting.
40
+ *
41
+ * `timeZone` prop is ignored when using a custom formatter, as it's assumed that the custom formatter will handle timezones internally if needed.
42
+ */
43
+ timestampFormatter: Formatter;
44
+ timeZone?: never;
45
+ }
46
+ export type LogProps = DefaultFormatterLogProps | CustomFormatterLogProps;
47
+ export type LogContext = {
48
+ hideTimestamps: boolean;
49
+ wrapLines: boolean;
50
+ timestampFormatter: Formatter;
51
+ };
52
+ type ExplicitTimeZone = Exclude<Intl.DateTimeFormatOptions["timeZone"], undefined>;
53
+ export type TimeZone = "UTC" | "local" | ({} & ExplicitTimeZone);
54
+ type Formatter = {
55
+ format: (date: Date) => string;
56
+ };
57
+ export {};
@@ -0,0 +1,2 @@
1
+ /* @canonical/generator-ds 0.10.0-experimental.5 */
2
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { TimeZone } from "../types.js";
2
+ /**
3
+ * Creates a default timestamp formatter that updates when the timezone changes. The formatter formats dates as `YYYY-MM-DD HH:mm:ss.SSS` in UTC, runtime local time, or an explicit timezone.
4
+ *
5
+ * @param getTimeZone A function that returns the current timezone.
6
+ * @returns An object with a reactive `format` function that formats dates according to the current timezone.
7
+ */
8
+ export declare function useDefaultTimestampFormatter(getTimeZone: () => TimeZone): {
9
+ format: (date: Date) => string;
10
+ };
@@ -0,0 +1,45 @@
1
+ const dateTimeFormatOptions = {
2
+ year: "numeric",
3
+ month: "2-digit",
4
+ day: "2-digit",
5
+ hour: "2-digit",
6
+ minute: "2-digit",
7
+ second: "2-digit",
8
+ fractionalSecondDigits: 3,
9
+ hour12: false,
10
+ };
11
+ /**
12
+ * Creates a default timestamp formatter that updates when the timezone changes. The formatter formats dates as `YYYY-MM-DD HH:mm:ss.SSS` in UTC, runtime local time, or an explicit timezone.
13
+ *
14
+ * @param getTimeZone A function that returns the current timezone.
15
+ * @returns An object with a reactive `format` function that formats dates according to the current timezone.
16
+ */
17
+ export function useDefaultTimestampFormatter(getTimeZone) {
18
+ const dateTimeFormat = $derived.by(() => {
19
+ const timeZone = getTimeZone();
20
+ try {
21
+ return new Intl.DateTimeFormat("en-US", {
22
+ ...dateTimeFormatOptions,
23
+ timeZone: timeZone === "local" ? undefined : timeZone,
24
+ });
25
+ }
26
+ catch (error) {
27
+ if (error instanceof RangeError) {
28
+ console.warn(`Invalid timezone "${timeZone}" provided to Log component. Falling back to UTC.`);
29
+ }
30
+ else {
31
+ throw error;
32
+ }
33
+ }
34
+ return new Intl.DateTimeFormat("en-US", {
35
+ ...dateTimeFormatOptions,
36
+ timeZone: "UTC",
37
+ });
38
+ });
39
+ const format = (date) => {
40
+ const parts = dateTimeFormat.formatToParts(date);
41
+ const partsObject = Object.fromEntries(parts.map((part) => [part.type, part.value]));
42
+ return `${partsObject.year}-${partsObject.month}-${partsObject.day} ${partsObject.hour}:${partsObject.minute}:${partsObject.second}.${partsObject.fractionalSecond}`;
43
+ };
44
+ return { format };
45
+ }
@@ -12,7 +12,7 @@
12
12
  userName: userNameProp,
13
13
  userAvatarUrl,
14
14
  size = "medium",
15
- alt,
15
+ imageAttributes,
16
16
  ...rest
17
17
  }: UserAvatarProps = $props();
18
18
 
@@ -33,11 +33,11 @@
33
33
  <img
34
34
  class={className}
35
35
  src={userAvatarUrl}
36
- {alt}
37
36
  title={userName || undefined}
38
37
  data-initials={userInitials}
39
38
  onerror={() => (imageError = true)}
40
39
  {...rest}
40
+ {...imageAttributes}
41
41
  />
42
42
  {:else if userName}
43
43
  <abbr class={className} title={userName} {...rest}>
@@ -60,4 +60,15 @@ In case JavaScript is disabled, and the image at `userAvatarUrl` fails to load,
60
60
  ```svelte
61
61
  <UserAvatar userName="John Doe" userAvatarUrl="https://example.com/avatar.png" />
62
62
  ```
63
+
64
+ `<img>`-specific attributes (such as `alt` or `loading`) can be passed via `imageAttributes`.
65
+ They only take effect when the avatar renders as an image.
66
+
67
+ ```svelte
68
+ <UserAvatar
69
+ userName="John Doe"
70
+ userAvatarUrl="https://example.com/avatar.png"
71
+ imageAttributes={{ alt: "John Doe's avatar", loading: "lazy" }}
72
+ />
73
+ ```
63
74
  -->
@@ -11,6 +11,17 @@ import "./styles.css";
11
11
  * ```svelte
12
12
  * <UserAvatar userName="John Doe" userAvatarUrl="https://example.com/avatar.png" />
13
13
  * ```
14
+ *
15
+ * `<img>`-specific attributes (such as `alt` or `loading`) can be passed via `imageAttributes`.
16
+ * They only take effect when the avatar renders as an image.
17
+ *
18
+ * ```svelte
19
+ * <UserAvatar
20
+ * userName="John Doe"
21
+ * userAvatarUrl="https://example.com/avatar.png"
22
+ * imageAttributes={{ alt: "John Doe's avatar", loading: "lazy" }}
23
+ * />
24
+ * ```
14
25
  */
15
26
  declare const UserAvatar: import("svelte").Component<UserAvatarProps, {}, "">;
16
27
  type UserAvatar = ReturnType<typeof UserAvatar>;
@@ -1,4 +1,5 @@
1
- import type { HTMLAttributes } from "svelte/elements";
1
+ import type { HTMLAttributes, HTMLImgAttributes } from "svelte/elements";
2
+ type ImageOnlyAttributes = Omit<HTMLImgAttributes, keyof HTMLAttributes<HTMLElement> | "bind:naturalWidth" | "bind:naturalHeight" | "children" | "src">;
2
3
  export type UserOptions = {
3
4
  /** The user's name */
4
5
  userName?: string;
@@ -7,6 +8,10 @@ export type UserOptions = {
7
8
  };
8
9
  export interface UserAvatarProps extends Omit<HTMLAttributes<HTMLElement>, "children">, UserOptions {
9
10
  size?: "small" | "medium" | "large";
10
- /** The alt text for the avatar image, if available */
11
- alt?: string;
11
+ /**
12
+ * `<img>`-specific attributes (e.g. `alt`, `loading`, `fetchpriority`) for the avatar image.
13
+ * Only applied when the avatar renders as an image — i.e. `userAvatarUrl` is set and the image has not failed to load.
14
+ */
15
+ imageAttributes?: ImageOnlyAttributes;
12
16
  }
17
+ export {};
@@ -6,6 +6,7 @@ export * from "./Chip/index.js";
6
6
  export * from "./DateTime/index.js";
7
7
  export * from "./DescriptionList/index.js";
8
8
  export * from "./Link/index.js";
9
+ export * from "./Log/index.js";
9
10
  export * from "./Modal/index.js";
10
11
  export * from "./NumberInput/index.js";
11
12
  export * from "./Popover/index.js";
@@ -6,6 +6,7 @@ export * from "./Chip/index.js";
6
6
  export * from "./DateTime/index.js";
7
7
  export * from "./DescriptionList/index.js";
8
8
  export * from "./Link/index.js";
9
+ export * from "./Log/index.js";
9
10
  export * from "./Modal/index.js";
10
11
  export * from "./NumberInput/index.js";
11
12
  export * from "./Popover/index.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@canonical/svelte-ds-app-launchpad",
3
3
  "description": "Launchpad-specific components for the Pragma design system.",
4
- "version": "0.27.1-experimental.0",
4
+ "version": "0.28.0",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -63,13 +63,13 @@
63
63
  },
64
64
  "devDependencies": {
65
65
  "@biomejs/biome": "2.4.9",
66
- "@canonical/biome-config": "^0.27.1-experimental.0",
66
+ "@canonical/biome-config": "^0.28.0",
67
67
  "@canonical/design-tokens": "^0.6.0",
68
- "@canonical/storybook-config": "^0.27.1-experimental.0",
69
- "@canonical/storybook-helpers": "^0.27.1-experimental.0",
70
- "@canonical/svelte-ssr-test": "^0.27.1-experimental.0",
71
- "@canonical/typescript-config-svelte": "^0.27.1-experimental.0",
72
- "@canonical/webarchitect": "^0.27.1-experimental.0",
68
+ "@canonical/storybook-config": "^0.28.0",
69
+ "@canonical/storybook-helpers": "^0.28.0",
70
+ "@canonical/svelte-ssr-test": "^0.28.0",
71
+ "@canonical/typescript-config-svelte": "^0.28.0",
72
+ "@canonical/webarchitect": "^0.28.0",
73
73
  "@storybook/addon-docs": "^10.3.1",
74
74
  "@storybook/addon-svelte-csf": "^5.0.11",
75
75
  "@sveltejs/package": "^2.5.7",
@@ -93,5 +93,5 @@
93
93
  "peerDependencies": {
94
94
  "svelte": "^5.47.1"
95
95
  },
96
- "gitHead": "d3f5b9aab7bec07fce40a12b45097d28d3cf0201"
96
+ "gitHead": "8297d72122bcba903f7e8833cb23ccbaa164ed56"
97
97
  }