@twentyfirstmedia/ui-core 0.6.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.
- package/ICONS-LICENSE +24 -2
- package/dist/components/connected-data.d.ts +25 -0
- package/dist/components/connected-data.d.ts.map +1 -0
- package/dist/components/connected-data.js +264 -0
- package/dist/components/connected-data.js.map +1 -0
- package/dist/components/connectors.d.ts +22 -0
- package/dist/components/connectors.d.ts.map +1 -0
- package/dist/components/connectors.js +135 -0
- package/dist/components/connectors.js.map +1 -0
- package/dist/components/household.d.ts +19 -0
- package/dist/components/household.d.ts.map +1 -0
- package/dist/components/household.js +137 -0
- package/dist/components/household.js.map +1 -0
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +4 -0
- package/dist/components/index.js.map +1 -1
- package/dist/components/life.d.ts +26 -0
- package/dist/components/life.d.ts.map +1 -0
- package/dist/components/life.js +187 -0
- package/dist/components/life.js.map +1 -0
- package/dist/components/types.d.ts +622 -0
- package/dist/components/types.d.ts.map +1 -1
- package/dist/context.d.ts +1 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +2 -1
- package/dist/context.js.map +1 -1
- package/dist/format.d.ts +5 -0
- package/dist/format.d.ts.map +1 -1
- package/dist/format.js +31 -0
- package/dist/format.js.map +1 -1
- package/dist/icon-library.d.ts +235 -4
- package/dist/icon-library.d.ts.map +1 -1
- package/dist/icon-library.js +467 -15
- package/dist/icon-library.js.map +1 -1
- package/dist/icons.d.ts +2 -0
- package/dist/icons.d.ts.map +1 -1
- package/dist/icons.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/strings.d.ts +184 -0
- package/dist/strings.d.ts.map +1 -1
- package/dist/strings.js +182 -1
- package/dist/strings.js.map +1 -1
- package/dist/themes.css +16438 -11238
- package/package.json +1 -1
- package/src/components/connected-data.tsx +783 -0
- package/src/components/connectors.tsx +426 -0
- package/src/components/household.tsx +489 -0
- package/src/components/index.ts +39 -0
- package/src/components/life.tsx +679 -0
- package/src/components/types.ts +602 -0
- package/src/context.ts +10 -1
- package/src/format.ts +33 -0
- package/src/icon-library.ts +476 -19
- package/src/icons.ts +2 -0
- package/src/index.ts +5 -0
- package/src/strings.ts +518 -0
package/src/components/types.ts
CHANGED
|
@@ -2833,3 +2833,605 @@ export interface QrCodeProps extends BaseProps {
|
|
|
2833
2833
|
/** Accessible name (default "QR code"). */
|
|
2834
2834
|
label?: string;
|
|
2835
2835
|
}
|
|
2836
|
+
|
|
2837
|
+
/* ── Life: wellbeing, health, goals, AI insights, consent ── */
|
|
2838
|
+
export interface Habit {
|
|
2839
|
+
id: string;
|
|
2840
|
+
label: string;
|
|
2841
|
+
icon?: IconName;
|
|
2842
|
+
tint?: Tint;
|
|
2843
|
+
/** One entry per day, oldest first, today last: true done, false missed, null no data. */
|
|
2844
|
+
days: (boolean | null)[];
|
|
2845
|
+
/** Days in a row (shown as "12-day streak"). */
|
|
2846
|
+
streak?: number;
|
|
2847
|
+
/** A short target, e.g. "8 glasses" or "3× a week". */
|
|
2848
|
+
goal?: string;
|
|
2849
|
+
}
|
|
2850
|
+
export interface HabitTrackerProps extends BaseProps {
|
|
2851
|
+
habits: Habit[];
|
|
2852
|
+
/** Labels of the day columns, oldest first (default: weekday initials ending today). */
|
|
2853
|
+
dayLabels?: string[];
|
|
2854
|
+
/** Today's box of a habit was toggled. */
|
|
2855
|
+
onToggle?: (id: string, done: boolean) => void;
|
|
2856
|
+
/** Accessible name of the list (default "Habits"). */
|
|
2857
|
+
label?: string;
|
|
2858
|
+
}
|
|
2859
|
+
export type MoodLevel = 1 | 2 | 3 | 4 | 5;
|
|
2860
|
+
export interface MoodPickerProps extends BaseProps {
|
|
2861
|
+
value?: MoodLevel | null;
|
|
2862
|
+
defaultValue?: MoodLevel | null;
|
|
2863
|
+
onChange?: (mood: MoodLevel) => void;
|
|
2864
|
+
/** The question (default "How are you feeling?"). */
|
|
2865
|
+
label?: ReactNode;
|
|
2866
|
+
/** Words for the five levels, lowest first (default Awful, Low, Okay, Good, Great). */
|
|
2867
|
+
levels?: [string, string, string, string, string];
|
|
2868
|
+
/** Only the faces; the words stay as accessible names. */
|
|
2869
|
+
compact?: boolean;
|
|
2870
|
+
}
|
|
2871
|
+
export interface VitalTileProps extends BaseProps {
|
|
2872
|
+
/** `"glass"`: translucent glass over a backdrop (`Ambient`, a photo, a map); `"solid"` opts out inside a glass `UIProvider`. */
|
|
2873
|
+
surface?: Surface;
|
|
2874
|
+
label: string;
|
|
2875
|
+
value: number;
|
|
2876
|
+
unit?: string;
|
|
2877
|
+
icon?: IconName;
|
|
2878
|
+
/** The healthy range [low, high]; the tile says whether the value is below, in or above it. */
|
|
2879
|
+
normal?: [number, number];
|
|
2880
|
+
/** The whole scale of the band [min, max] (default: the normal range with room on both sides). */
|
|
2881
|
+
scale?: [number, number];
|
|
2882
|
+
/** Recent values, oldest first, drawn as a sparkline. */
|
|
2883
|
+
trend?: number[];
|
|
2884
|
+
/** Under the value: when it was measured, the source … */
|
|
2885
|
+
caption?: ReactNode;
|
|
2886
|
+
/** Digits after the decimal point (default 0). */
|
|
2887
|
+
digits?: number;
|
|
2888
|
+
}
|
|
2889
|
+
export interface ActivityRing {
|
|
2890
|
+
label: string;
|
|
2891
|
+
value: number;
|
|
2892
|
+
goal: number;
|
|
2893
|
+
unit?: string;
|
|
2894
|
+
tint?: Tint;
|
|
2895
|
+
}
|
|
2896
|
+
export interface ActivityRingsProps extends BaseProps {
|
|
2897
|
+
/** Outer ring first. */
|
|
2898
|
+
rings: ActivityRing[];
|
|
2899
|
+
/** Diameter of the rings (default 132). */
|
|
2900
|
+
size?: number;
|
|
2901
|
+
/** Hide the legend beside the rings. */
|
|
2902
|
+
legend?: boolean;
|
|
2903
|
+
/** Accessible name (default "Activity"). */
|
|
2904
|
+
label?: string;
|
|
2905
|
+
}
|
|
2906
|
+
export type SleepStage = "awake" | "rem" | "light" | "deep";
|
|
2907
|
+
export interface SleepSegment {
|
|
2908
|
+
stage: SleepStage;
|
|
2909
|
+
start: Date | string | number;
|
|
2910
|
+
end: Date | string | number;
|
|
2911
|
+
}
|
|
2912
|
+
export interface SleepChartProps extends BaseProps {
|
|
2913
|
+
/** The night in order, from falling asleep to getting up. */
|
|
2914
|
+
segments: SleepSegment[];
|
|
2915
|
+
/** Accessible name (default "Sleep stages"). */
|
|
2916
|
+
label?: string;
|
|
2917
|
+
/** Hide the totals per stage under the chart. */
|
|
2918
|
+
summary?: boolean;
|
|
2919
|
+
}
|
|
2920
|
+
export interface MedicationItem {
|
|
2921
|
+
id: string;
|
|
2922
|
+
name: string;
|
|
2923
|
+
dose?: string;
|
|
2924
|
+
/** When, as shown ("08:00", "With breakfast"). */
|
|
2925
|
+
time: string;
|
|
2926
|
+
/** Set by the app, which knows the clock: default "taken" when `taken`, else "due". */
|
|
2927
|
+
status?: "taken" | "due" | "missed" | "upcoming";
|
|
2928
|
+
taken?: boolean;
|
|
2929
|
+
note?: string;
|
|
2930
|
+
icon?: IconName;
|
|
2931
|
+
}
|
|
2932
|
+
export interface MedicationListProps extends BaseProps {
|
|
2933
|
+
items: MedicationItem[];
|
|
2934
|
+
/** "Mark as taken" was pressed. */
|
|
2935
|
+
onTake?: (id: string) => void;
|
|
2936
|
+
/** Accessible name (default "Medication"). */
|
|
2937
|
+
label?: string;
|
|
2938
|
+
}
|
|
2939
|
+
export interface JournalEntryProps extends BaseProps {
|
|
2940
|
+
/** `"glass"`: translucent glass over a backdrop (`Ambient`, a photo, a map); `"solid"` opts out inside a glass `UIProvider`. */
|
|
2941
|
+
surface?: Surface;
|
|
2942
|
+
date: Date | string | number;
|
|
2943
|
+
title?: string;
|
|
2944
|
+
mood?: MoodLevel;
|
|
2945
|
+
tags?: string[];
|
|
2946
|
+
children?: ReactNode;
|
|
2947
|
+
/** Buttons at the end (edit, share …). */
|
|
2948
|
+
actions?: ReactNode;
|
|
2949
|
+
}
|
|
2950
|
+
export interface GoalCardProps extends BaseProps {
|
|
2951
|
+
/** `"glass"`: translucent glass over a backdrop (`Ambient`, a photo, a map); `"solid"` opts out inside a glass `UIProvider`. */
|
|
2952
|
+
surface?: Surface;
|
|
2953
|
+
title: string;
|
|
2954
|
+
value: number;
|
|
2955
|
+
target: number;
|
|
2956
|
+
/** How to show value and target (default number). */
|
|
2957
|
+
format?: "number" | "money" | "percent";
|
|
2958
|
+
/** Unit after numbers ("km", "books"). */
|
|
2959
|
+
unit?: string;
|
|
2960
|
+
currency?: string;
|
|
2961
|
+
due?: Date | string | number;
|
|
2962
|
+
icon?: IconName;
|
|
2963
|
+
tint?: Tint;
|
|
2964
|
+
milestones?: { label: string; done?: boolean }[];
|
|
2965
|
+
/** A note under the progress ("€250 a month keeps you on track"). */
|
|
2966
|
+
note?: ReactNode;
|
|
2967
|
+
}
|
|
2968
|
+
export interface InsightCardProps extends BaseProps {
|
|
2969
|
+
/** `"glass"`: translucent glass over a backdrop (`Ambient`, a photo, a map); `"solid"` opts out inside a glass `UIProvider`. */
|
|
2970
|
+
surface?: Surface;
|
|
2971
|
+
title: string;
|
|
2972
|
+
children?: ReactNode;
|
|
2973
|
+
icon?: IconName;
|
|
2974
|
+
tone?: "info" | "success" | "warning" | "highlight";
|
|
2975
|
+
/** Above the title: area and time ("Money · 2 h ago"). */
|
|
2976
|
+
meta?: ReactNode;
|
|
2977
|
+
/** Where the insight comes from, as chips (like chat sources). */
|
|
2978
|
+
sources?: Source[];
|
|
2979
|
+
/** Why the assistant shows it; folded away behind "Why am I seeing this?". */
|
|
2980
|
+
why?: ReactNode;
|
|
2981
|
+
onAccept?: () => void;
|
|
2982
|
+
acceptLabel?: string;
|
|
2983
|
+
onSnooze?: () => void;
|
|
2984
|
+
onDismiss?: () => void;
|
|
2985
|
+
}
|
|
2986
|
+
export interface ConsentScope {
|
|
2987
|
+
id: string;
|
|
2988
|
+
label: string;
|
|
2989
|
+
description?: string;
|
|
2990
|
+
granted: boolean;
|
|
2991
|
+
/** Needed for the connection to work at all: shown, not switchable. */
|
|
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;
|
|
2997
|
+
}
|
|
2998
|
+
export interface ConsentConnector {
|
|
2999
|
+
id: string;
|
|
3000
|
+
name: string;
|
|
3001
|
+
icon?: IconName;
|
|
3002
|
+
/** A logo instead of the icon. */
|
|
3003
|
+
logo?: ReactNode;
|
|
3004
|
+
/** What the assistant uses it for. */
|
|
3005
|
+
purpose?: ReactNode;
|
|
3006
|
+
scopes: ConsentScope[];
|
|
3007
|
+
lastUsed?: Date | string | number;
|
|
3008
|
+
}
|
|
3009
|
+
export interface ConsentListProps extends BaseProps {
|
|
3010
|
+
/** `"glass"`: translucent glass over a backdrop (`Ambient`, a photo, a map); `"solid"` opts out inside a glass `UIProvider`. */
|
|
3011
|
+
surface?: Surface;
|
|
3012
|
+
connectors: ConsentConnector[];
|
|
3013
|
+
onScopeChange?: (connectorId: string, scopeId: string, granted: boolean) => void;
|
|
3014
|
+
onRevoke?: (connectorId: string) => void;
|
|
3015
|
+
/** Accessible name (default "Data access"). */
|
|
3016
|
+
label?: string;
|
|
3017
|
+
}
|
|
3018
|
+
|
|
3019
|
+
/* ── Life: money, insurance, deadlines, documents ── */
|
|
3020
|
+
export interface BudgetCategory {
|
|
3021
|
+
id: string;
|
|
3022
|
+
label: string;
|
|
3023
|
+
icon?: IconName;
|
|
3024
|
+
tint?: Tint;
|
|
3025
|
+
spent: number;
|
|
3026
|
+
limit: number;
|
|
3027
|
+
}
|
|
3028
|
+
export interface BudgetListProps extends BaseProps {
|
|
3029
|
+
categories: BudgetCategory[];
|
|
3030
|
+
currency?: string;
|
|
3031
|
+
/** A category was picked (to show its transactions). */
|
|
3032
|
+
onSelect?: (id: string) => void;
|
|
3033
|
+
/** Accessible name (default "Budgets"). */
|
|
3034
|
+
label?: string;
|
|
3035
|
+
}
|
|
3036
|
+
export interface Subscription {
|
|
3037
|
+
id: string;
|
|
3038
|
+
name: string;
|
|
3039
|
+
icon?: IconName;
|
|
3040
|
+
/** A logo instead of the icon. */
|
|
3041
|
+
logo?: ReactNode;
|
|
3042
|
+
amount: number;
|
|
3043
|
+
period: "week" | "month" | "year";
|
|
3044
|
+
/** Next charge. */
|
|
3045
|
+
next?: Date | string | number;
|
|
3046
|
+
status?: "active" | "trial" | "cancelled";
|
|
3047
|
+
category?: string;
|
|
3048
|
+
}
|
|
3049
|
+
export interface SubscriptionListProps extends BaseProps {
|
|
3050
|
+
items: Subscription[];
|
|
3051
|
+
currency?: string;
|
|
3052
|
+
/** "Manage" on a subscription (cancel, change plan …). */
|
|
3053
|
+
onManage?: (id: string) => void;
|
|
3054
|
+
/** Hide the monthly and yearly totals. */
|
|
3055
|
+
totals?: boolean;
|
|
3056
|
+
/** Accessible name (default "Subscriptions"). */
|
|
3057
|
+
label?: string;
|
|
3058
|
+
}
|
|
3059
|
+
export interface NetWorthCardProps extends BaseProps {
|
|
3060
|
+
/** `"glass"`: translucent glass over a backdrop (`Ambient`, a photo, a map); `"solid"` opts out inside a glass `UIProvider`. */
|
|
3061
|
+
surface?: Surface;
|
|
3062
|
+
assets: { label: string; value: number; icon?: IconName }[];
|
|
3063
|
+
liabilities?: { label: string; value: number; icon?: IconName }[];
|
|
3064
|
+
/** Net worth over time, oldest first. */
|
|
3065
|
+
history?: number[];
|
|
3066
|
+
/** Change over `changeLabel` (e.g. +1,240 "since October"). */
|
|
3067
|
+
change?: number;
|
|
3068
|
+
changeLabel?: string;
|
|
3069
|
+
currency?: string;
|
|
3070
|
+
title?: string;
|
|
3071
|
+
}
|
|
3072
|
+
export interface DeadlineItem {
|
|
3073
|
+
id: string;
|
|
3074
|
+
title: string;
|
|
3075
|
+
/** What kind: "Contract", "ID card", "Tax" … */
|
|
3076
|
+
kind?: string;
|
|
3077
|
+
icon?: IconName;
|
|
3078
|
+
date: Date | string | number;
|
|
3079
|
+
amount?: number;
|
|
3080
|
+
done?: boolean;
|
|
3081
|
+
note?: string;
|
|
3082
|
+
}
|
|
3083
|
+
export interface DeadlineListProps extends BaseProps {
|
|
3084
|
+
items: DeadlineItem[];
|
|
3085
|
+
/** The day to count from (default: now). Set it for server rendering and stable output. */
|
|
3086
|
+
today?: Date | string | number;
|
|
3087
|
+
/** Days ahead that count as soon (default 14). */
|
|
3088
|
+
soon?: number;
|
|
3089
|
+
currency?: string;
|
|
3090
|
+
onDone?: (id: string) => void;
|
|
3091
|
+
/** Accessible name (default "Deadlines"). */
|
|
3092
|
+
label?: string;
|
|
3093
|
+
}
|
|
3094
|
+
export interface PolicyCardProps extends BaseProps {
|
|
3095
|
+
/** `"glass"`: translucent glass over a backdrop (`Ambient`, a photo, a map); `"solid"` opts out inside a glass `UIProvider`. */
|
|
3096
|
+
surface?: Surface;
|
|
3097
|
+
/** The kind of insurance: "Household contents", "Liability" … */
|
|
3098
|
+
type: string;
|
|
3099
|
+
insurer: string;
|
|
3100
|
+
icon?: IconName;
|
|
3101
|
+
tint?: Tint;
|
|
3102
|
+
policyNumber?: string;
|
|
3103
|
+
/** Show only the last four characters of the policy number. */
|
|
3104
|
+
maskNumber?: boolean;
|
|
3105
|
+
/** Sum insured: a number (money) or text ("unlimited"). */
|
|
3106
|
+
coverage?: number | ReactNode;
|
|
3107
|
+
premium?: { amount: number; period: "month" | "quarter" | "year" };
|
|
3108
|
+
deductible?: number;
|
|
3109
|
+
renews?: Date | string | number;
|
|
3110
|
+
status?: "active" | "pending" | "expiring" | "lapsed";
|
|
3111
|
+
currency?: string;
|
|
3112
|
+
/** Buttons at the foot (documents, report a claim …). */
|
|
3113
|
+
actions?: ReactNode;
|
|
3114
|
+
}
|
|
3115
|
+
export interface CoverageRow {
|
|
3116
|
+
id: string;
|
|
3117
|
+
risk: string;
|
|
3118
|
+
status: "covered" | "partial" | "none";
|
|
3119
|
+
note?: ReactNode;
|
|
3120
|
+
/** Which policy covers it. */
|
|
3121
|
+
policy?: string;
|
|
3122
|
+
}
|
|
3123
|
+
export interface CoverageMatrixProps extends BaseProps {
|
|
3124
|
+
rows: CoverageRow[];
|
|
3125
|
+
/** Accessible name and caption (default "Coverage"). */
|
|
3126
|
+
label?: string;
|
|
3127
|
+
}
|
|
3128
|
+
export interface ClaimStep {
|
|
3129
|
+
label: string;
|
|
3130
|
+
date?: Date | string | number;
|
|
3131
|
+
state: "done" | "current" | "todo" | "failed";
|
|
3132
|
+
note?: ReactNode;
|
|
3133
|
+
}
|
|
3134
|
+
export interface ClaimTimelineProps extends BaseProps {
|
|
3135
|
+
title: string;
|
|
3136
|
+
/** Reference and insurer under the title. */
|
|
3137
|
+
meta?: ReactNode;
|
|
3138
|
+
amount?: number;
|
|
3139
|
+
currency?: string;
|
|
3140
|
+
steps: ClaimStep[];
|
|
3141
|
+
}
|
|
3142
|
+
export interface LifeDocument {
|
|
3143
|
+
id: string;
|
|
3144
|
+
title: string;
|
|
3145
|
+
category?: string;
|
|
3146
|
+
icon?: IconName;
|
|
3147
|
+
holder?: string;
|
|
3148
|
+
expires?: Date | string | number;
|
|
3149
|
+
/** "PDF · 240 KB" */
|
|
3150
|
+
meta?: string;
|
|
3151
|
+
}
|
|
3152
|
+
export interface DocumentListProps extends BaseProps {
|
|
3153
|
+
documents: LifeDocument[];
|
|
3154
|
+
/** The day to count expiry from (default: now). */
|
|
3155
|
+
today?: Date | string | number;
|
|
3156
|
+
/** Days ahead that count as expiring soon (default 60). */
|
|
3157
|
+
soon?: number;
|
|
3158
|
+
onOpen?: (id: string) => void;
|
|
3159
|
+
/** Accessible name (default "Documents"). */
|
|
3160
|
+
label?: string;
|
|
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 {
|
|
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 = ",",
|