-
-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathindex.tsx
More file actions
54 lines (42 loc) · 1.86 KB
/
index.tsx
File metadata and controls
54 lines (42 loc) · 1.86 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
import React, { useLayoutEffect, useRef } from 'react';
import { createRoot, Root } from 'react-dom/client';
import { Box, Toggle, TutorialPanel as TutorialPanelGeneric, TutorialPanelProps } from 'components';
import { useAppDispatch, useAppSelector } from 'hooks';
import { selectTutorialPanel, setHideAtStartup } from 'App/slice';
import { tutorialPanelI18nStrings } from './constants';
import { useTutorials } from './hooks';
export interface Props extends Partial<TutorialPanelProps> {
test?: string;
}
export const TutorialPanel: React.FC<Props> = () => {
const dispatch = useAppDispatch();
const { tutorials } = useTutorials();
const tutorialRootRef = useRef<Root>(null);
const { hideStartUp } = useAppSelector(selectTutorialPanel);
const onChangeShowStartUp = (value: boolean) => {
dispatch(setHideAtStartup(!value));
};
const renderShowAtStartup = () => {
return (
<Box padding={{ vertical: 'm' }}>
<Toggle onChange={({ detail }) => onChangeShowStartUp(detail.checked)} checked={!hideStartUp}>
Show at startup
</Toggle>
</Box>
);
};
useLayoutEffect(() => {
const tutorialPanelElement = document.querySelector('[class*="awsui_tutorial-panel"]');
if (tutorialPanelElement && !tutorialRootRef.current) {
const divElement = document.createElement('div');
tutorialPanelElement.appendChild(divElement);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
tutorialRootRef.current = createRoot(divElement);
}
if (tutorialRootRef.current) {
tutorialRootRef.current.render(renderShowAtStartup());
}
}, [hideStartUp]);
return <TutorialPanelGeneric i18nStrings={tutorialPanelI18nStrings} tutorials={tutorials} />;
};