@twentyfirstmedia/ui-core 0.7.0 → 0.8.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.
Files changed (54) hide show
  1. package/ICONS-LICENSE +24 -2
  2. package/dist/components/connected-data.d.ts +25 -0
  3. package/dist/components/connected-data.d.ts.map +1 -0
  4. package/dist/components/connected-data.js +264 -0
  5. package/dist/components/connected-data.js.map +1 -0
  6. package/dist/components/connectors.d.ts +22 -0
  7. package/dist/components/connectors.d.ts.map +1 -0
  8. package/dist/components/connectors.js +135 -0
  9. package/dist/components/connectors.js.map +1 -0
  10. package/dist/components/index.d.ts +2 -0
  11. package/dist/components/index.d.ts.map +1 -1
  12. package/dist/components/index.js +2 -0
  13. package/dist/components/index.js.map +1 -1
  14. package/dist/components/life.d.ts.map +1 -1
  15. package/dist/components/life.js +3 -2
  16. package/dist/components/life.js.map +1 -1
  17. package/dist/components/types.d.ts +290 -0
  18. package/dist/components/types.d.ts.map +1 -1
  19. package/dist/context.d.ts +1 -0
  20. package/dist/context.d.ts.map +1 -1
  21. package/dist/context.js +2 -1
  22. package/dist/context.js.map +1 -1
  23. package/dist/format.d.ts +5 -0
  24. package/dist/format.d.ts.map +1 -1
  25. package/dist/format.js +31 -0
  26. package/dist/format.js.map +1 -1
  27. package/dist/icon-library.d.ts +235 -4
  28. package/dist/icon-library.d.ts.map +1 -1
  29. package/dist/icon-library.js +467 -15
  30. package/dist/icon-library.js.map +1 -1
  31. package/dist/icons.d.ts +2 -0
  32. package/dist/icons.d.ts.map +1 -1
  33. package/dist/icons.js.map +1 -1
  34. package/dist/index.d.ts +2 -2
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +2 -2
  37. package/dist/index.js.map +1 -1
  38. package/dist/strings.d.ts +89 -1
  39. package/dist/strings.d.ts.map +1 -1
  40. package/dist/strings.js +110 -1
  41. package/dist/strings.js.map +1 -1
  42. package/dist/themes.css +14447 -12207
  43. package/package.json +1 -1
  44. package/src/components/connected-data.tsx +783 -0
  45. package/src/components/connectors.tsx +426 -0
  46. package/src/components/index.ts +17 -0
  47. package/src/components/life.tsx +8 -1
  48. package/src/components/types.ts +280 -0
  49. package/src/context.ts +10 -1
  50. package/src/format.ts +33 -0
  51. package/src/icon-library.ts +476 -19
  52. package/src/icons.ts +2 -0
  53. package/src/index.ts +3 -0
  54. package/src/strings.ts +277 -0
@@ -2990,6 +2990,10 @@ export interface ConsentScope {
2990
2990
  granted: boolean;
2991
2991
  /** Needed for the connection to work at all: shown, not switchable. */
2992
2992
  required?: boolean;
2993
+ /** What the permission allows: reading, acting (sending, booking, switching) or moving money. */
2994
+ level?: "read" | "act" | "money";
2995
+ /** The assistant asks you before it uses this permission. */
2996
+ asksFirst?: boolean;
2993
2997
  }
2994
2998
  export interface ConsentConnector {
2995
2999
  id: string;
@@ -3155,3 +3159,279 @@ export interface DocumentListProps extends BaseProps {
3155
3159
  /** Accessible name (default "Documents"). */
3156
3160
  label?: string;
3157
3161
  }
3162
+
3163
+ /* ── Connectors: services an assistant reads from and acts in ── */
3164
+ /** The state of a connected service. */
3165
+ export type ServiceState = "connected" | "syncing" | "error" | "paused" | "off";
3166
+ export interface ServiceMarkProps extends BaseProps {
3167
+ /** The service's name: the accessible name, and the monogram when there is no icon or logo. */
3168
+ name: string;
3169
+ /** A brand logo (`brandGmail` …) or a line icon. */
3170
+ icon?: IconName;
3171
+ /** Your own logo (an `<img>` or `<svg>`) instead of the icon. */
3172
+ logo?: ReactNode;
3173
+ /** Letters for the monogram (default: the initials of `name`). */
3174
+ monogram?: string;
3175
+ /** 24, 36 (default) or 48 px. */
3176
+ size?: "sm" | "md" | "lg";
3177
+ tint?: Tint | "plain";
3178
+ /** A dot in the corner with the state in words for screen readers. */
3179
+ status?: ServiceState;
3180
+ /** Hidden from screen readers when the name is written next to it. */
3181
+ decorative?: boolean;
3182
+ }
3183
+ export interface Connector {
3184
+ id: string;
3185
+ name: string;
3186
+ icon?: IconName;
3187
+ logo?: ReactNode;
3188
+ /** Letters shown when there is neither icon nor logo (default: the initials of `name`). */
3189
+ monogram?: string;
3190
+ tint?: Tint | "plain";
3191
+ /** The group it is listed under ("Health & fitness", "Money" …). */
3192
+ category: string;
3193
+ description?: ReactNode;
3194
+ /** `available` (default), `connected`, `error` (needs a reconnect) or `soon`. */
3195
+ state?: "available" | "connected" | "error" | "soon";
3196
+ /** A hint under the description: "Needs the iPhone app", "Import an export file". */
3197
+ note?: ReactNode;
3198
+ /** The connected account ("mara@gmail.com"). */
3199
+ account?: string;
3200
+ }
3201
+ export interface ConnectorGalleryProps extends BaseProps {
3202
+ connectors: Connector[];
3203
+ /** Order of the groups; categories not listed follow in the order they appear. */
3204
+ categories?: string[];
3205
+ onConnect?: (id: string) => void;
3206
+ /** Opens a connected (or failing) connector. */
3207
+ onOpen?: (id: string) => void;
3208
+ /** A search field and category chips above the grid (default true). */
3209
+ filters?: boolean;
3210
+ /** Accessible name (default "Connectors"). */
3211
+ label?: string;
3212
+ }
3213
+ export interface SyncStatusProps extends BaseProps {
3214
+ state: "synced" | "syncing" | "error" | "paused" | "never";
3215
+ /** The last successful sync. */
3216
+ last?: Date | string | number;
3217
+ /** The next planned sync. */
3218
+ next?: Date | string | number;
3219
+ /** "Now" for the relative times; pass it so server and client render the same. */
3220
+ now?: Date | string | number;
3221
+ /** What the last sync brought: `{ label: "emails", value: 1204 }`. */
3222
+ counts?: { label: string; value: number }[];
3223
+ /** Why the sync failed. */
3224
+ error?: ReactNode;
3225
+ onSync?: () => void;
3226
+ /** One line: state and time only. */
3227
+ compact?: boolean;
3228
+ }
3229
+ export interface AgentAction {
3230
+ id: string;
3231
+ /** The service the action used. */
3232
+ service?: { name: string; icon?: IconName; logo?: ReactNode };
3233
+ /** Which agent did it ("Assistant", "Money agent"). */
3234
+ agent?: string;
3235
+ /** What happened, in a sentence: "Moved the dentist to Friday, 10:00". */
3236
+ text: ReactNode;
3237
+ at: Date | string | number;
3238
+ /** `read` (looked something up), `act` (changed something) or `money`. */
3239
+ kind?: "read" | "act" | "money";
3240
+ /** `done` (default), `waiting` for your approval, `declined`, `undone` or `failed`. */
3241
+ state?: "done" | "waiting" | "declined" | "undone" | "failed";
3242
+ detail?: ReactNode;
3243
+ }
3244
+ export interface AgentActivityProps extends BaseProps {
3245
+ items: AgentAction[];
3246
+ /** "Now" for the day headings; pass it so server and client render the same. */
3247
+ now?: Date | string | number;
3248
+ /** Offers "Undo" on finished actions that changed something. */
3249
+ onUndo?: (id: string) => void;
3250
+ /** Opens an action that waits for your approval. */
3251
+ onReview?: (id: string) => void;
3252
+ /** Accessible name (default "Agent activity"). */
3253
+ label?: string;
3254
+ }
3255
+ export interface ConnectionItem {
3256
+ id: string;
3257
+ name: string;
3258
+ icon?: IconName;
3259
+ logo?: ReactNode;
3260
+ monogram?: string;
3261
+ tint?: Tint | "plain";
3262
+ /** The connected account ("mara@gmail.com", "Giro ••• 4410"). */
3263
+ account?: ReactNode;
3264
+ state: ServiceState;
3265
+ /** How fresh the data is, shown as a compact `SyncStatus`. */
3266
+ sync?: { state: SyncStatusProps["state"]; last?: Date | string | number };
3267
+ }
3268
+ export interface ConnectionListProps extends BaseProps {
3269
+ items: ConnectionItem[];
3270
+ /** "Now" for the relative times; pass it so server and client render the same. */
3271
+ now?: Date | string | number;
3272
+ onManage?: (id: string) => void;
3273
+ /** Shown instead of "Manage" on connections in the `error` state. */
3274
+ onReconnect?: (id: string) => void;
3275
+ /** Accessible name (default "Connections"). */
3276
+ label?: string;
3277
+ }
3278
+
3279
+ /* ── Connected data: home, car, media, workouts, calls, bookings, golf, investments ── */
3280
+ /** The service a value comes from, shown as a small mark. */
3281
+ export interface ServiceRef {
3282
+ name: string;
3283
+ icon?: IconName;
3284
+ logo?: ReactNode;
3285
+ }
3286
+ export interface DeviceTileProps extends BaseProps {
3287
+ name: string;
3288
+ room?: string;
3289
+ icon?: IconName;
3290
+ /** The kind sets the default icon and which controls appear. */
3291
+ kind?: "switch" | "light" | "thermostat" | "vacuum" | "purifier" | "camera" | "lock" | "sensor";
3292
+ /** On or off; with `onToggle` a switch. */
3293
+ on?: boolean;
3294
+ onToggle?: (on: boolean) => void;
3295
+ /** The main reading: "21.5 °C", "Cleaning", "AQI 12". */
3296
+ value?: ReactNode;
3297
+ /** A line under the value: "Heating to 22 °C", "Kitchen · 18 m² left". */
3298
+ status?: ReactNode;
3299
+ /** Thermostat target in °C; with `onTarget` a − / + stepper (steps of `step`, default 0.5). */
3300
+ target?: number;
3301
+ onTarget?: (value: number) => void;
3302
+ step?: number;
3303
+ /** Battery in percent (vacuums, sensors, locks). */
3304
+ battery?: number;
3305
+ /** Quick actions: "Start", "Dock", "Boost". */
3306
+ actions?: { label: string; icon?: IconName; onClick?: () => void }[];
3307
+ /** The device does not answer. */
3308
+ offline?: boolean;
3309
+ service?: ServiceRef;
3310
+ }
3311
+ export interface VehicleCardProps extends BaseProps {
3312
+ name: string;
3313
+ model?: string;
3314
+ /** Battery (or tank) in percent. */
3315
+ battery: number;
3316
+ /** Range in km. */
3317
+ range?: number;
3318
+ /** The charge limit in percent, marked on the bar. */
3319
+ limit?: number;
3320
+ charging?: "charging" | "complete" | "plugged" | "unplugged";
3321
+ /** Charging power in kW while charging. */
3322
+ power?: number;
3323
+ /** When charging reaches the limit. */
3324
+ until?: Date | string | number;
3325
+ locked?: boolean;
3326
+ /** Inside temperature in °C. */
3327
+ inside?: number;
3328
+ climateOn?: boolean;
3329
+ location?: ReactNode;
3330
+ onLock?: (locked: boolean) => void;
3331
+ onClimate?: (on: boolean) => void;
3332
+ service?: ServiceRef;
3333
+ }
3334
+ export interface NowPlayingProps extends BaseProps {
3335
+ title: string;
3336
+ artist?: string;
3337
+ album?: string;
3338
+ /** Cover art: an `<img>`. */
3339
+ art?: ReactNode;
3340
+ /** Position and length in seconds. */
3341
+ position?: number;
3342
+ duration?: number;
3343
+ playing?: boolean;
3344
+ /** Where it plays: "Living room speaker". */
3345
+ device?: string;
3346
+ onPlayPause?: () => void;
3347
+ onNext?: () => void;
3348
+ onPrevious?: () => void;
3349
+ service?: ServiceRef;
3350
+ }
3351
+ export interface WorkoutCardProps extends BaseProps {
3352
+ /** "Run", "Ride", "Strength", "Golf" … */
3353
+ type: string;
3354
+ icon?: IconName;
3355
+ date: Date | string | number;
3356
+ /** Minutes. */
3357
+ duration: number;
3358
+ /** Kilometres. */
3359
+ distance?: number;
3360
+ calories?: number;
3361
+ /** Average heart rate in bpm. */
3362
+ heartRate?: number;
3363
+ /** Minutes in heart-rate zones 1–5. */
3364
+ zones?: number[];
3365
+ service?: ServiceRef;
3366
+ }
3367
+ export interface CallItem {
3368
+ id: string;
3369
+ name: string;
3370
+ number?: string;
3371
+ direction: "incoming" | "outgoing" | "missed";
3372
+ at: Date | string | number;
3373
+ /** Seconds. */
3374
+ duration?: number;
3375
+ /** What the call was about (an assistant's summary). */
3376
+ summary?: ReactNode;
3377
+ }
3378
+ export interface CallLogProps extends BaseProps {
3379
+ calls: CallItem[];
3380
+ /** "Now" for the day headings. */
3381
+ now?: Date | string | number;
3382
+ onCall?: (id: string) => void;
3383
+ onOpen?: (id: string) => void;
3384
+ /** Accessible name (default "Calls"). */
3385
+ label?: string;
3386
+ }
3387
+ export interface ReservationCardProps extends BaseProps {
3388
+ kind: "stay" | "flight" | "train" | "ride" | "order" | "event";
3389
+ title: string;
3390
+ /** "Hotel Atlantic · 2 nights", "LH 2024 · Seat 14A". */
3391
+ subtitle?: ReactNode;
3392
+ start: Date | string | number;
3393
+ end?: Date | string | number;
3394
+ /** Where: an address, airport codes, a restaurant. */
3395
+ place?: ReactNode;
3396
+ /** Booking or order number. */
3397
+ code?: string;
3398
+ status?: "confirmed" | "pending" | "cancelled" | "delayed" | "onTheWay" | "delivered";
3399
+ /** Extra words for the status: "+25 min", "Arrives 19:40". */
3400
+ statusText?: string;
3401
+ service?: ServiceRef;
3402
+ actions?: ReactNode;
3403
+ }
3404
+ export interface GolfHole {
3405
+ par: number;
3406
+ strokes?: number;
3407
+ putts?: number;
3408
+ }
3409
+ export interface ScorecardProps extends BaseProps {
3410
+ course: string;
3411
+ date?: Date | string | number;
3412
+ /** 9 or 18 holes. */
3413
+ holes: GolfHole[];
3414
+ /** Tee and course rating: "Yellow · CR 71.2 / SR 128". */
3415
+ tee?: string;
3416
+ service?: ServiceRef;
3417
+ }
3418
+ export interface Holding {
3419
+ id: string;
3420
+ name: string;
3421
+ /** Ticker or ISIN. */
3422
+ symbol?: string;
3423
+ value: number;
3424
+ /** Change in percent over `period`. */
3425
+ change?: number;
3426
+ /** Share of the portfolio in percent. */
3427
+ weight?: number;
3428
+ }
3429
+ export interface HoldingsListProps extends BaseProps {
3430
+ holdings: Holding[];
3431
+ currency?: string;
3432
+ /** The period of `change` ("today", "1 year"). */
3433
+ period?: string;
3434
+ onSelect?: (id: string) => void;
3435
+ /** Accessible name (default "Holdings"). */
3436
+ label?: string;
3437
+ }
package/src/context.ts CHANGED
@@ -4,7 +4,14 @@
4
4
  * provider so a component that only needs its strings or formatters does not pull in theming.
5
5
  */
6
6
  import { createContext, useContext } from "react";
7
- import { LOCALE, formatDate, formatMoney, formatNumber, formatPercent } from "./format.js";
7
+ import {
8
+ LOCALE,
9
+ formatDate,
10
+ formatMoney,
11
+ formatNumber,
12
+ formatPercent,
13
+ formatRelative,
14
+ } from "./format.js";
8
15
  import {
9
16
  DEFAULT_STRINGS,
10
17
  SHARED_STRINGS,
@@ -87,6 +94,7 @@ export interface Formatters {
87
94
  formatMoney: (v: number, currency?: string | null, o?: Intl.NumberFormatOptions) => string;
88
95
  formatPercent: (v: number, o?: Intl.NumberFormatOptions) => string;
89
96
  formatDate: (input: Date | string | number, o?: Intl.DateTimeFormatOptions) => string;
97
+ formatRelative: (input: Date | string | number, now?: Date | string | number) => string;
90
98
  }
91
99
 
92
100
  const formatters = new Map<string, Formatters>();
@@ -100,6 +108,7 @@ export function formattersFor(locale: string): Formatters {
100
108
  formatMoney: (v, currency, o) => formatMoney(v, currency, o, locale),
101
109
  formatPercent: (v, o) => formatPercent(v, o, locale),
102
110
  formatDate: (input, o) => formatDate(input, o, locale),
111
+ formatRelative: (input, now) => formatRelative(input, now, locale),
103
112
  };
104
113
  formatters.set(locale, f);
105
114
  }
package/src/format.ts CHANGED
@@ -56,6 +56,39 @@ export function formatDate(
56
56
  }
57
57
  }
58
58
 
59
+ /**
60
+ * A moment relative to now, in words: "5 minutes ago", "in 2 hours", "yesterday". Picks the
61
+ * largest unit that fits; pass `now` so server and client render the same text.
62
+ */
63
+ export function formatRelative(
64
+ input: Date | string | number,
65
+ now: Date | string | number = Date.now(),
66
+ locale?: string,
67
+ ): string {
68
+ const t = (input instanceof Date ? input : new Date(input)).getTime();
69
+ const n = (now instanceof Date ? now : new Date(now)).getTime();
70
+ const sec = Math.round((t - n) / 1000);
71
+ const abs = Math.abs(sec);
72
+ const steps: [Intl.RelativeTimeFormatUnit, number][] = [
73
+ ["second", 1],
74
+ ["minute", 60],
75
+ ["hour", 3600],
76
+ ["day", 86400],
77
+ ["week", 604800],
78
+ ["month", 2629800],
79
+ ["year", 31557600],
80
+ ];
81
+ let unit: Intl.RelativeTimeFormatUnit = "second";
82
+ let size = 1;
83
+ for (const [u, s] of steps) if (abs >= s) [unit, size] = [u, s];
84
+ try {
85
+ const rtf = new Intl.RelativeTimeFormat(locale || LOCALE, { numeric: "auto" });
86
+ return abs < 45 ? rtf.format(0, "second") : rtf.format(Math.round(sec / size), unit);
87
+ } catch {
88
+ return new Date(t).toLocaleString();
89
+ }
90
+ }
91
+
59
92
  /** The group and decimal separators of a locale: `en-US` → `{ group: ",", decimal: "." }`. */
60
93
  export function numberSeparators(locale?: string): { group: string; decimal: string } {
61
94
  let group = ",",