Skip to content

Commit eda0f86

Browse files
committed
Introduce dedicated modal components for chat initialization and refactor the progress display into a modal
1 parent 495a380 commit eda0f86

17 files changed

Lines changed: 295 additions & 190 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.title {
2+
text-align: center;
3+
}
4+
5+
.progress {
6+
width: 100%;
7+
height: 2px;
8+
background-color: var(--vscode-input-background);
9+
overflow: hidden;
10+
11+
&__fill {
12+
height: 100%;
13+
background-color: var(--vscode-focusBorder);
14+
}
15+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { useState } from 'react'
2+
import { ChatInitializedModal } from './ChatInitializedModal'
3+
4+
export default {
5+
component: ChatInitializedModal
6+
}
7+
8+
export const Default = () => {
9+
const [visible, set_visible] = useState(true)
10+
11+
const handle_close = () => {
12+
set_visible(false)
13+
}
14+
15+
return visible ? (
16+
<ChatInitializedModal
17+
title="Chat has been initialized in the connected browser."
18+
duration={3000}
19+
on_close={handle_close}
20+
/>
21+
) : null
22+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { useEffect, useState } from 'react'
2+
import styles from './ChatInitializedModal.module.scss'
3+
import { Button } from '../Button'
4+
import { Modal } from '../Modal'
5+
6+
type Props = {
7+
title: string
8+
duration: number
9+
on_close: () => void
10+
}
11+
12+
export const ChatInitializedModal: React.FC<Props> = (props) => {
13+
const [is_filling, set_is_filling] = useState(false)
14+
15+
useEffect(() => {
16+
const request_id = requestAnimationFrame(() => {
17+
set_is_filling(true)
18+
})
19+
20+
const close_timeout = setTimeout(() => {
21+
props.on_close()
22+
}, props.duration)
23+
24+
return () => {
25+
cancelAnimationFrame(request_id)
26+
clearTimeout(close_timeout)
27+
}
28+
}, [props.duration, props.on_close])
29+
30+
return (
31+
<Modal>
32+
<div className={styles.title}>{props.title}</div>
33+
<div className={styles.progress}>
34+
<div
35+
className={styles.progress__fill}
36+
style={{
37+
width: is_filling ? '100%' : '0%',
38+
transition: `width ${props.duration}ms linear`
39+
}}
40+
/>
41+
</div>
42+
<Button on_click={props.on_close}>Close</Button>
43+
</Modal>
44+
)
45+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './ChatInitializedModal'
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.overlay {
2+
position: absolute;
3+
top: 0;
4+
left: 0;
5+
width: 100%;
6+
height: 100%;
7+
background-color: rgba(0, 0, 0, 0.5);
8+
display: flex;
9+
align-items: center;
10+
justify-content: center;
11+
opacity: 0;
12+
padding-bottom: 41px;
13+
14+
&--visible {
15+
opacity: 1;
16+
transition: opacity var(--transition-duration-250)
17+
var(--transition-timing-function);
18+
19+
.container {
20+
transform: scale(1);
21+
transition: transform var(--transition-duration-250)
22+
var(--transition-timing-function);
23+
}
24+
}
25+
}
26+
27+
.container {
28+
display: flex;
29+
flex-direction: column;
30+
background-color: var(--vscode-sideBar-background);
31+
padding: var(--padding-16px) var(--padding-12px) var(--padding-12px)
32+
var(--padding-12px);
33+
border-radius: var(--border-radius-8px);
34+
width: 100%;
35+
margin: var(--padding-24px);
36+
gap: var(--padding-12px);
37+
transform: scale(0.9);
38+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { useEffect, useState } from 'react'
2+
import styles from './Modal.module.scss'
3+
import cn from 'classnames'
4+
5+
type Props = {
6+
children: React.ReactNode
7+
}
8+
9+
export const Modal: React.FC<Props> = (props) => {
10+
const [is_hydrated, set_is_hydrated] = useState(false) // For entry animation
11+
12+
useEffect(() => {
13+
set_is_hydrated(true)
14+
}, [])
15+
16+
return (
17+
<div
18+
className={cn(styles.overlay, {
19+
[styles['overlay--visible']]: is_hydrated
20+
})}
21+
>
22+
<div className={styles.container}>{props.children}</div>
23+
</div>
24+
)
25+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './Modal'

‎packages/ui/src/components/editor/Progress/Progress.module.scss‎

Lines changed: 0 additions & 108 deletions
This file was deleted.

‎packages/ui/src/components/editor/Progress/Progress.tsx‎

Lines changed: 0 additions & 70 deletions
This file was deleted.

‎packages/ui/src/components/editor/Progress/index.ts‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)