@@ -2,7 +2,7 @@ import { Tooltip as MuiTooltip } from '@mui/material';
2
2
import LinkTo from '@storybook/addon-links/react' ;
3
3
import type { Meta , StoryObj } from '@storybook/react' ;
4
4
import { Highlight , themes as prismThemes } from 'prism-react-renderer' ;
5
- import { cloneElement , useMemo } from 'react' ;
5
+ import { type ForwardedRef , cloneElement , useMemo , useRef } from 'react' ;
6
6
import { Tooltip as ReactTooltip } from 'react-tooltip' ;
7
7
import 'react-tooltip/dist/react-tooltip.css' ;
8
8
import { useDarkMode } from 'storybook-dark-mode' ;
@@ -13,6 +13,7 @@ import exampleEventHandlersInterface from '../../examples/event-handlers-type?ra
13
13
import exampleEventHandlers from '../../examples/event-handlers?raw' ;
14
14
import exampleLabelsShape from '../../examples/labels-shape?raw' ;
15
15
import exampleLabels from '../../examples/labels?raw' ;
16
+ import exampleRef from '../../examples/ref?raw' ;
16
17
import exampleThemeExplicit from '../../examples/themes-explicit?raw' ;
17
18
import exampleTheme from '../../examples/themes?raw' ;
18
19
import exampleTooltipsMui from '../../examples/tooltips-mui?raw' ;
@@ -25,22 +26,9 @@ type Story = StoryObj<Props>;
25
26
26
27
/* eslint-disable react-hooks/rules-of-hooks */
27
28
28
- const meta : Meta < Props > = {
29
+ const meta : Meta < ForwardedRef < Props > > = {
29
30
title : 'React Activity Calendar' ,
30
31
component : ActivityCalendar ,
31
- decorators : [
32
- ( Story , { args } ) => {
33
- args . colorScheme = useDarkMode ( ) ? 'dark' : 'light' ;
34
-
35
- return < Story /> ;
36
- } ,
37
- ] ,
38
- parameters : {
39
- controls : {
40
- sort : 'requiredFirst' ,
41
- } ,
42
- layout : 'centered' ,
43
- } ,
44
32
argTypes : {
45
33
data : {
46
34
control : false ,
@@ -63,6 +51,9 @@ const meta: Meta<Props> = {
63
51
maxLevel : {
64
52
control : { type : 'range' , min : 1 , max : 9 } ,
65
53
} ,
54
+ ref : {
55
+ control : false ,
56
+ } ,
66
57
style : {
67
58
control : false ,
68
59
} ,
@@ -82,6 +73,21 @@ const meta: Meta<Props> = {
82
73
} ,
83
74
} ,
84
75
} ,
76
+ decorators : [
77
+ ( Story , { args } ) => {
78
+ // @ts -expect-error unsure if typing forward refs correctly is possible
79
+ args . colorScheme = useDarkMode ( ) ? 'dark' : 'light' ;
80
+
81
+ return < Story /> ;
82
+ } ,
83
+ ] ,
84
+ parameters : {
85
+ controls : {
86
+ sort : 'requiredFirst' ,
87
+ } ,
88
+ layout : 'centered' ,
89
+ } ,
90
+ tags : [ 'autodocs' ] ,
85
91
} ;
86
92
87
93
// Storybook does not initialize the controls for some reason
@@ -559,6 +565,30 @@ export const NarrowScreens: Story = {
559
565
} ,
560
566
} ;
561
567
568
+ export const ContainerRef : Story = {
569
+ args : defaultProps ,
570
+ parameters : {
571
+ docs : {
572
+ source : {
573
+ code : exampleRef ,
574
+ } ,
575
+ } ,
576
+ } ,
577
+ render : args => {
578
+ const data = useMemo ( ( ) => generateTestData ( { maxLevel : args . maxLevel } ) , [ args . maxLevel ] ) ;
579
+ const calendarRef = useRef < HTMLElement > ( null ) ;
580
+ console . log ( 'calendar ref' , calendarRef ) ;
581
+
582
+ return (
583
+ < >
584
+ < ActivityCalendar { ...args } data = { data } ref = { calendarRef } />
585
+ < br />
586
+ < p > Check the JavaScript console to see the ref logged.</ p >
587
+ </ >
588
+ ) ;
589
+ } ,
590
+ } ;
591
+
562
592
const Source = ( {
563
593
code,
564
594
isDarkMode,
0 commit comments