Skip to content

Commit 4e41435

Browse files
committed
#103 Tutorial bubble UI
1 parent 3314020 commit 4e41435

1 file changed

Lines changed: 46 additions & 118 deletions

File tree

webapp/components/general/TutorialBubble.js

Lines changed: 46 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState, useRef, useEffect } from 'react';
2-
import { Button, Grid } from '@material-ui/core';
2+
import { Box, Button, Grid, Typography } from '@material-ui/core';
33
import {
44
primaryColor, secondaryColor, bgLight, bgDark, primaryTextColor, secondaryTextColor, fontColor,
55
} from '../../theme';
@@ -37,7 +37,7 @@ const TutorialBubble = ({
3737
return DOMtargets[config?.collectionIndex || 0];
3838
};
3939

40-
function calculateVisiblePosition (rect1, width2, height2) {
40+
function calculateVisiblePosition(rect1, width2, height2) {
4141
const windowHeight = window.innerHeight;
4242
const windowWidth = window.innerWidth;
4343

@@ -68,7 +68,7 @@ const TutorialBubble = ({
6868
}
6969

7070
const nextTourStep = steps[requestedTourStep];
71-
const { target: nextTarget } = nextTourStep? nextTourStep: {target: undefined};
71+
const { target: nextTarget } = nextTourStep ? nextTourStep : { target: undefined };
7272

7373
const { target, title, content } = tourStep;
7474

@@ -83,11 +83,11 @@ const TutorialBubble = ({
8383

8484
// validateTutorialStep({ tourStep: requestedTourStep });
8585
const isEditable = (el) => {
86-
if (el && ~['input','textarea'].indexOf(el.tagName.toLowerCase())) {
86+
if (el && ~['input', 'textarea'].indexOf(el.tagName.toLowerCase())) {
8787
return !el.readOnly && !el.disabled;
8888
}
8989
el = getSelection().anchorNode;
90-
if (!el){
90+
if (!el) {
9191
return false;
9292
}
9393
return el.parentNode.isContentEditable;
@@ -129,9 +129,9 @@ const TutorialBubble = ({
129129
switch (waitFor) {
130130
case 'click':
131131
if (requestedTourStep === steps.length) {
132-
DOMtarget.addEventListener('click', stop, {once: true, capture: true});
132+
DOMtarget.addEventListener('click', stop, { once: true, capture: true });
133133
} else {
134-
DOMtarget.addEventListener('click', listen, {once: true, capture: true});
134+
DOMtarget.addEventListener('click', listen, { once: true, capture: true });
135135
}
136136
break;
137137
case 'fieldEdition': // Do nothing, we wait for a click on "next"
@@ -148,133 +148,61 @@ const TutorialBubble = ({
148148
const nextIsVisible = nextDOMtarget?.checkVisibility();
149149

150150
return (
151-
<div>
152-
<div
151+
<Box className='tutorials'>
152+
<Box
153+
className='tutorials_highlight'
153154
id="tutorialTargetRectangle"
154155
style={{
155-
position: 'absolute',
156156
top: targetRect.top - rectMargin,
157157
left: targetRect.left - rectMargin,
158158
width: targetRect.width + (2 * rectMargin),
159159
height: targetRect.height + (2 * rectMargin),
160-
borderRadius: '4px',
161-
pointerEvents: 'none',
162-
border: `solid 3px ${primaryColor}`,
163-
zIndex: 1501, // Just over the menus items (1500)
160+
borderColor: primaryColor,
161+
164162
}}
165163
/>
166-
<div style={{ position: 'relative' }} id="tutorialBubble">
164+
165+
<Box className='tutorials_wrapper' id="tutorialBubble">
167166
{lastCheckRender}
168-
<div
169-
style={{
170-
position: 'absolute',
171-
top: y,
172-
left: x,
173-
backgroundColor: '#434343',
174-
borderRadius: '4px',
175-
boxShadow: '0 2px 8px rgba(0, 0, 0, 0.2)',
176-
padding: '16px',
177-
minWidth: '150px',
178-
maxWidth: '300px',
179-
maxHeight: '300px',
180-
fontSize: '16px',
181-
lineHeight: '1.5',
182-
zIndex: 1501, // Just over the menus items (1500)
183-
}}
184-
>
185-
<h3
186-
style={{
187-
marginTop: 0,
188-
color: fontColor,
189-
}}
190-
>
167+
168+
<Box className='tutorials_content' style={{
169+
top: y,
170+
left: x,
171+
}}>
172+
<Typography component='h3'>
191173
{title}
192-
</h3>
193-
194-
<div
195-
style={{
196-
color: fontColor,
197-
paddingBottom: '20px',
198-
}}
199-
>
200-
{content}
201-
</div>
202-
203-
<Grid alignItems="flex-start" container spacing={1}>
204-
<Grid
205-
container
206-
direction="column"
207-
item
208-
xs={3}
209-
spacing={1}
210-
alignItems="flex-start"
211-
justifyContent="flex-start"
212-
>
213-
<Grid item xs={12}>
214-
<p style={{ color: '#fff' }}>
215-
{requestedTourStep}
216-
/
217-
{steps.length}
218-
</p>
219-
</Grid>
220-
</Grid>
221-
<Grid
222-
container
223-
direction="column"
224-
item
225-
xs={9}
226-
spacing={1}
227-
alignItems="flex-end"
228-
justifyContent="flex-end"
229-
>
230-
<Grid item xs={12}>
174+
</Typography>
175+
176+
{content}
177+
178+
<Box pt={2.5} display='flex' alignItems='center' justifyContent='space-between'>
179+
<Typography>
180+
{requestedTourStep}/{steps.length}
181+
</Typography>
182+
183+
<Box display='flex' alignItems='center'>
184+
<Button
185+
onClick={stop}
186+
color="primary"
187+
>
188+
{hasOtherSteps ? 'Skip' : 'Close'}
189+
</Button>
190+
191+
{hasOtherSteps && (
231192
<Button
232-
onClick={stop}
193+
variant='contained'
233194
color="primary"
234-
style={{
235-
display: 'block',
236-
margin: '0 auto',
237-
color: primaryColor,
238-
border: 'none',
239-
padding: '8px 16px',
240-
borderRadius: '4px',
241-
fontSize: '16px',
242-
cursor: 'pointer',
243-
position: 'absolute',
244-
right: '85px',
245-
bottom: '25px',
246-
}}
247-
>
248-
{hasOtherSteps ? 'Skip' : 'Close'}
249-
</Button>
250-
{(hasOtherSteps && nextIsVisible)
251-
&& (
252-
<Button
253195
onClick={listen}
254-
style={{
255-
display: 'block',
256-
margin: '0 auto',
257-
backgroundColor: primaryColor,
258-
color: '#fff',
259-
border: 'none',
260-
padding: '8px 16px',
261-
borderRadius: '4px',
262-
fontSize: '16px',
263-
cursor: 'pointer',
264-
position: 'absolute',
265-
right: '15px',
266-
bottom: '25px',
267-
}}
196+
disabled={!nextIsVisible}
268197
>
269198
Next
270199
</Button>
271-
)}
272-
</Grid>
273-
</Grid>
274-
</Grid>
275-
</div>
276-
</div>
277-
</div>
200+
)}
201+
</Box>
202+
</Box>
203+
</Box>
204+
</Box>
205+
</Box>
278206
);
279207
};
280208

0 commit comments

Comments
 (0)