@collective-intelligence/ui-react 0.1.25 → 0.1.27

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/README.md CHANGED
@@ -98,6 +98,46 @@ or `open` with `onOpenChange` to control it. Labels, translations, diagnostic
98
98
  formatting and error recovery remain with the caller. Use `className` and
99
99
  `classes` to customize the root and individual presentation parts.
100
100
 
101
+ ## Failed write toast
102
+
103
+ Import `ciWriteFailedToast` and `Toaster` from
104
+ `@collective-intelligence/ui-react/ui`. `ciWriteFailedToast(messages?)` returns
105
+ a handler for the `onWriteFailed` prop of `CollectiveIntelligenceProvider`
106
+ (`@collective-intelligence/external-apps-client-sdk-react`). The handler calls
107
+ `toast.error` with one text:
108
+
109
+ - For a `CiError`, the English text of its `code`.
110
+ - For a `CiTransportError`, an English connection text. It does not say that the change was
111
+ not saved: when the answer of a write is lost, CI can have saved it.
112
+
113
+ To use other texts, for example in another language, pass `messages`
114
+ (`CiWriteFailedMessages`). Its keys are the `CiError` codes and `transport`. A
115
+ key that you do not give keeps its English text.
116
+
117
+ ```tsx
118
+ import {
119
+ Toaster,
120
+ ciWriteFailedToast
121
+ } from "@collective-intelligence/ui-react/ui"
122
+
123
+ const onWriteFailed = ciWriteFailedToast({
124
+ conflict: "Quelqu'un a modifié cet élément.",
125
+ transport:
126
+ "Pas de connexion. La modification n'est peut-être pas enregistrée."
127
+ })
128
+
129
+ ;<CollectiveIntelligenceProvider client={client} onWriteFailed={onWriteFailed}>
130
+ <App />
131
+ <Toaster />
132
+ </CollectiveIntelligenceProvider>
133
+ ```
134
+
135
+ The handler reads only the `_tag` and `code` of the error
136
+ (`CiWriteFailedEvent`), so this package does not depend on the client SDK. The
137
+ toast shows in the `Toaster` only when the app has one copy of this package:
138
+ two copies have two toast stores. For this reason the client SDK for React has
139
+ this package as a peer dependency.
140
+
101
141
  ## Card options
102
142
 
103
143
  Import `CardOptionsBlock`, `CheckboxCardOption` and `RadioCardOption` from
@@ -126,6 +126,21 @@ export declare const CarouselItem: ({ className, ...props }: React$1.ComponentPr
126
126
  export declare const CarouselPrevious: ({ className, variant, size, ...props }: React$1.ComponentProps<typeof Button>) => React$1.JSX.Element;
127
127
  export declare const CarouselNext: ({ className, variant, size, ...props }: React$1.ComponentProps<typeof Button>) => React$1.JSX.Element;
128
128
  export declare const Checkbox: ({ className, ...props }: React$1.ComponentProps<typeof CheckboxPrimitive.Root>) => React$1.JSX.Element;
129
+ export type CiErrorCode = "conflict" | "forbidden" | "internal" | "invalid_request" | "not_found" | "rate_limited" | "unauthenticated" | "unavailable";
130
+ /** The part of a client SDK `WriteFailed` event that the toast reads. */
131
+ export type CiWriteFailedEvent = Readonly<{
132
+ error: Readonly<{
133
+ _tag: "CiError";
134
+ code: CiErrorCode;
135
+ }> | Readonly<{
136
+ _tag: "CiTransportError";
137
+ }>;
138
+ }>;
139
+ export type TextKey = CiErrorCode | "transport";
140
+ /** App texts by `CiError` code, and `transport` for a `CiTransportError`. */
141
+ export type CiWriteFailedMessages = Partial<Readonly<Record<TextKey, string>>>;
142
+ /** Returns an `onWriteFailed` handler that shows a failed write as an error toast. */
143
+ export declare const ciWriteFailedToast: (messages?: CiWriteFailedMessages) => ({ error }: CiWriteFailedEvent) => void;
129
144
  export declare const Collapsible: ({ ...props }: React$1.ComponentProps<typeof CollapsiblePrimitive.Root>) => React$1.JSX.Element;
130
145
  export declare const CollapsibleTrigger: ({ ...props }: React$1.ComponentProps<typeof CollapsiblePrimitive.CollapsibleTrigger>) => React$1.JSX.Element;
131
146
  export declare const CollapsibleContent: ({ ...props }: React$1.ComponentProps<typeof CollapsiblePrimitive.CollapsibleContent>) => React$1.JSX.Element;