-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathuseTeachingPopoverCarousel.ts
More file actions
58 lines (52 loc) · 1.74 KB
/
useTeachingPopoverCarousel.ts
File metadata and controls
58 lines (52 loc) · 1.74 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
50
51
52
53
54
55
56
57
58
'use client';
import * as React from 'react';
import { getIntrinsicElementProps, slot, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';
import type {
TeachingPopoverCarouselBaseProps,
TeachingPopoverCarouselBaseState,
TeachingPopoverCarouselProps,
TeachingPopoverCarouselState,
} from './TeachingPopoverCarousel.types';
import { usePopoverContext_unstable } from '@fluentui/react-popover';
import { useCarousel_unstable } from './Carousel/Carousel';
export const useTeachingPopoverCarouselBase_unstable = (
props: TeachingPopoverCarouselBaseProps,
ref: React.Ref<HTMLDivElement>,
): TeachingPopoverCarouselBaseState => {
const toggleOpen = usePopoverContext_unstable(c => c.toggleOpen);
const handleFinish: TeachingPopoverCarouselProps['onFinish'] = useEventCallback((event, data) => {
props.onFinish?.(event, data);
toggleOpen(event as React.MouseEvent<HTMLElement>);
});
const { carousel, carouselRef } = useCarousel_unstable({
announcement: props.announcement,
defaultValue: props.defaultValue,
value: props.value,
onValueChange: props.onValueChange,
onFinish: handleFinish,
});
return {
components: {
root: 'div',
},
root: slot.always(
getIntrinsicElementProps('div', {
ref: useMergedRefs(ref, carouselRef),
...props,
}),
{ elementType: 'div' },
),
...carousel,
};
};
export const useTeachingPopoverCarousel_unstable = (
props: TeachingPopoverCarouselProps,
ref: React.Ref<HTMLDivElement>,
): TeachingPopoverCarouselState => {
const appearance = usePopoverContext_unstable(context => context.appearance);
const baseState = useTeachingPopoverCarouselBase_unstable(props, ref);
return {
...baseState,
appearance,
};
};