-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathuseToast.ts
More file actions
49 lines (45 loc) · 1.59 KB
/
useToast.ts
File metadata and controls
49 lines (45 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use client';
import * as React from 'react';
import { getIntrinsicElementProps, slot } from '@fluentui/react-utilities';
import type { ToastBaseProps, ToastBaseState, ToastProps, ToastState } from './Toast.types';
import { useToastContainerContext } from '../../contexts/toastContainerContext';
/**
* Create the base state required to render Toast, without design-only props.
*
* @param props - props from this instance of Toast (without appearance)
* @param ref - reference to root HTMLElement of Toast
*/
export const useToastBase_unstable = (props: ToastBaseProps, ref: React.Ref<HTMLElement>): ToastBaseState => {
const { intent } = useToastContainerContext();
return {
components: {
root: 'div',
},
root: slot.always(
getIntrinsicElementProps('div', {
// FIXME:
// `ref` is wrongly assigned to be `HTMLElement` instead of `HTMLDivElement`
// but since it would be a breaking change to fix it, we are casting ref to it's proper type
ref: ref as React.Ref<HTMLDivElement>,
...props,
}),
{ elementType: 'div' },
),
intent,
};
};
/**
* Create the state required to render Toast.
*
* The returned state can be modified with hooks such as useToastStyles_unstable,
* before being passed to renderToast_unstable.
*
* @param props - props from this instance of Toast
* @param ref - reference to root HTMLElement of Toast
*/
export const useToast_unstable = (props: ToastProps, ref: React.Ref<HTMLElement>): ToastState => {
return {
...useToastBase_unstable(props, ref),
backgroundAppearance: props.appearance,
};
};