({ title, description, ...props }: Toast)
| 138 | type Toast = Omit<ToasterToast, 'id'> |
| 139 | |
| 140 | function toast({ title, description, ...props }: Toast) { |
| 141 | const id = genId() |
| 142 | |
| 143 | const update = (props: ToasterToast) => |
| 144 | dispatch({ |
| 145 | type: 'UPDATE_TOAST', |
| 146 | toast: { ...props, id }, |
| 147 | }) |
| 148 | const dismiss = () => dispatch({ type: 'DISMISS_TOAST', toastId: id }) |
| 149 | |
| 150 | dispatch({ |
| 151 | type: 'ADD_TOAST', |
| 152 | toast: { |
| 153 | ...props, |
| 154 | id, |
| 155 | title, |
| 156 | description, |
| 157 | open: true, |
| 158 | onOpenChange: (open) => { |
| 159 | if (!open) dismiss() |
| 160 | }, |
| 161 | }, |
| 162 | }) |
| 163 | |
| 164 | // Track the toast in PostHog |
| 165 | const descriptionString = |
| 166 | typeof description === 'string' |
| 167 | ? description |
| 168 | : JSON.stringify(description ?? null) |
| 169 | posthog.capture(AnalyticsEvent.TOAST_SHOWN, { |
| 170 | title: typeof title === 'string' ? title : JSON.stringify(title ?? null), |
| 171 | description: descriptionString, |
| 172 | variant: props.variant ?? 'default', |
| 173 | }) |
| 174 | |
| 175 | return { |
| 176 | id: id, |
| 177 | dismiss, |
| 178 | update, |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | function useToast() { |
| 183 | const [state, setState] = React.useState<State>(memoryState) |
no test coverage detected