Skip to content

Commit f73c1f5

Browse files
committed
feat: add maximize/minimize button to the header
1 parent e5804df commit f73c1f5

File tree

6 files changed

+101
-37
lines changed

6 files changed

+101
-37
lines changed

_build/js/src/ui/dom/button.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export type Button = HTMLButtonElement & {
77

88
export const button = (
99
content: string | HTMLElement | Element | (HTMLElement | Element | string)[],
10-
onClick: () => Promise<void> | void,
10+
onClick: (e: MouseEvent) => Promise<void> | void,
1111
styleObj?: string,
1212
btnProps?: Partial<HTMLButtonElement>,
1313
) => {

_build/js/src/ui/icons/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@ export const bot = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="2
3535
export const sparkles = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-sparkles"><path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"></path><path d="M20 3v4"></path><path d="M22 5h-4"></path><path d="M4 17v2"></path><path d="M5 18H3"></path></svg>`;
3636

3737
export const textSelect = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-text-select"><path d="M14 21h1"></path><path d="M14 3h1"></path><path d="M19 3a2 2 0 0 1 2 2"></path><path d="M21 14v1"></path><path d="M21 19a2 2 0 0 1-2 2"></path><path d="M21 9v1"></path><path d="M3 14v1"></path><path d="M3 9v1"></path><path d="M5 21a2 2 0 0 1-2-2"></path><path d="M5 3a2 2 0 0 0-2 2"></path><path d="M7 12h10"></path><path d="M7 16h6"></path><path d="M7 8h8"></path><path d="M9 21h1"></path><path d="M9 3h1"></path></svg>`;
38+
39+
export const expand = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg>`;
40+
41+
export const minimize = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-minimize-2"><polyline points="4 14 10 14 10 20"></polyline><polyline points="20 10 14 10 14 4"></polyline><line x1="14" x2="21" y1="10" y2="3"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg>`;

_build/js/src/ui/localChat/modalHeader.ts

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,73 @@ import { drag, endDrag, initDrag } from './dragHandlers';
55
import { globalState } from '../../globalState';
66
import { lng } from '../../lng';
77
import { icon } from '../dom/icon';
8-
import { x } from '../icons';
8+
import { expand, minimize, x } from '../icons';
9+
10+
const centerModal = (element: HTMLElement) => {
11+
const modalWidth = element.offsetWidth;
12+
const modalHeight = element.offsetHeight;
13+
14+
const viewportWidth = window.innerWidth;
15+
const viewportHeight = window.innerHeight;
16+
17+
const newLeft = viewportWidth / 2 - modalWidth / 2;
18+
const newTop = viewportHeight / 2 - modalHeight / 2;
19+
20+
element.style.left = `${newLeft}px`;
21+
element.style.top = `${newTop}px`;
22+
};
923

1024
export const buildModalHeader = () => {
1125
const closeModalBtn = button(
1226
icon(24, x),
1327
() => {
1428
closeModal();
1529
},
16-
'closeBtn',
30+
'',
1731
{ ariaLabel: lng('modai.ui.close_dialog') },
1832
);
1933

34+
const buttonsWrapper = createElement('div', 'buttonsWrapper', [
35+
button(
36+
icon(24, expand),
37+
(e) => {
38+
const self = e.currentTarget as HTMLButtonElement;
39+
40+
if (globalState.modal.modal.style.width === '90%') {
41+
globalState.modal.modal.style.width = '';
42+
globalState.modal.modal.style.height = '';
43+
44+
self.ariaLabel = lng('modai.ui.maximize_dialog');
45+
self.innerHTML = '';
46+
self.appendChild(icon(24, expand));
47+
48+
centerModal(globalState.modal.modal);
49+
return;
50+
}
51+
52+
globalState.modal.modal.style.width = '90%';
53+
globalState.modal.modal.style.height = '90%';
54+
55+
self.ariaLabel = lng('modai.ui.minimize_dialog');
56+
self.innerHTML = '';
57+
self.appendChild(icon(24, minimize));
58+
59+
centerModal(globalState.modal.modal);
60+
},
61+
'',
62+
{
63+
ariaLabel:
64+
globalState.modal.modal.style.width === '90%'
65+
? lng('modai.ui.minimize_dialog')
66+
: lng('modai.ui.maximize_dialog'),
67+
},
68+
),
69+
closeModalBtn,
70+
]);
71+
2072
const header = createElement('header', 'header', [
2173
createElement('h1', '', lng('modai.ui.modai_assistant')),
22-
closeModalBtn,
74+
buttonsWrapper,
2375
]);
2476

2577
header.addEventListener('mousedown', (e) => {

assets/components/modai/css/modai.css

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,25 +119,31 @@
119119
padding-left: var(--spacing-sm);
120120
}
121121

122-
.closeBtn {
123-
background: none;
124-
border: none;
125-
cursor: pointer;
126-
padding: var(--spacing-sm);
122+
.buttonsWrapper {
127123
display: flex;
128-
align-items: center;
129-
justify-content: center;
130-
border-radius: 50%;
131-
transition: background-color var(--transition-speed);
124+
justify-items: center;
132125

133-
&:hover, &:focus {
134-
background-color: var(--border-light);
135-
}
126+
button {
127+
background: none;
128+
border: none;
129+
cursor: pointer;
130+
padding: var(--spacing-sm);
131+
display: flex;
132+
align-items: center;
133+
justify-content: center;
134+
border-radius: 50%;
135+
transition: background-color var(--transition-speed);
136136

137-
&:focus {
138-
outline: 2px solid var(--primary);
139-
outline-offset: 2px;
137+
&:hover, &:focus {
138+
background-color: var(--border-light);
139+
}
140+
141+
&:focus {
142+
outline: 2px solid var(--primary);
143+
outline-offset: 2px;
144+
}
140145
}
146+
141147
}
142148
}
143149

0 commit comments

Comments
 (0)