Skip to content

Commit ffc8a06

Browse files
authored
Merge pull request #999 from dodona-edu/enhc/tab-bar-tweaks
Tweak layout and behaviour of tab bar
2 parents 47d815a + 479c8f2 commit ffc8a06

File tree

5 files changed

+45
-10
lines changed

5 files changed

+45
-10
lines changed

src/frontend/components/AddFileButton.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class AddFileButton extends PapyrosElement {
2424
.add-btn {
2525
padding: 0.375rem 0.5rem;
2626
border: none;
27+
border-bottom: 2px solid var(--md-sys-color-outline-variant);
2728
border-radius: 0.375rem 0.375rem 0 0;
2829
cursor: pointer;
2930
font-size: 1rem;
@@ -63,8 +64,19 @@ export class AddFileButton extends PapyrosElement {
6364
this.invalid = !isValidFileName(value) || this.papyros.io.files.some((f) => f.name === value);
6465
}
6566

67+
private onBlur(): void {
68+
if (!this.adding) return;
69+
const name = this.addInputRef.value?.value.trim() ?? "";
70+
if (name.length === 0) {
71+
this.cancelAdd();
72+
} else {
73+
this.confirmAdd();
74+
}
75+
}
76+
6677
private onAddKeydown(e: KeyboardEvent): void {
6778
if (e.key === "Enter") {
79+
e.preventDefault();
6880
this.confirmAdd();
6981
} else if (e.key === "Escape") {
7082
this.cancelAdd();
@@ -85,10 +97,15 @@ export class AddFileButton extends PapyrosElement {
8597
placeholder=${this.t("Papyros.add_file_placeholder")}
8698
@input=${this.onAddInput}
8799
@keydown=${this.onAddKeydown}
88-
@blur=${this.cancelAdd}
100+
@blur=${this.onBlur}
89101
/>`;
90102
}
91-
return html`<button class="add-btn" aria-label=${this.t("Papyros.add_file")} @click=${this.startAdding}>
103+
return html`<button
104+
class="add-btn"
105+
title=${this.t("Papyros.add_file")}
106+
aria-label=${this.t("Papyros.add_file")}
107+
@click=${this.startAdding}
108+
>
92109
+
93110
</button>`;
94111
}

src/frontend/components/EditorTab.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@ export class EditorTab extends PapyrosElement {
4545
opacity: 0.6;
4646
}
4747
48-
button:hover .rename-btn,
49-
button:hover .close-btn,
50-
button:focus-within .rename-btn,
51-
button:focus-within .close-btn,
48+
.rename-btn svg {
49+
width: 0.75rem;
50+
height: 0.75rem;
51+
}
52+
5253
button.active .rename-btn,
5354
button.active .close-btn {
5455
display: inline-flex;
@@ -76,6 +77,7 @@ export class EditorTab extends PapyrosElement {
7677

7778
private closeFile(e: Event): void {
7879
e.stopPropagation();
80+
if (!confirm(this.t("Papyros.close_file_confirm"))) return;
7981
this.papyros.io.removeFile(this.file.name);
8082
void this.papyros.runner.deleteFile(this.file.name);
8183
}
@@ -187,14 +189,18 @@ export class EditorTab extends PapyrosElement {
187189
class="rename-btn"
188190
role="button"
189191
tabindex="0"
192+
title=${this.t("Papyros.rename_file_tab")}
190193
aria-label=${this.t("Papyros.rename_file_tab")}
191194
@click=${this.onRenameClick}
192195
@keydown=${this.onRenameBtnKeydown}
193-
></span
194-
><span
196+
>
197+
${this.papyros.constants.icons.edit}
198+
</span>
199+
<span
195200
class="close-btn"
196201
role="button"
197202
tabindex="0"
203+
title=${this.t("Papyros.close_file_tab")}
198204
aria-label=${this.t("Papyros.close_file_tab")}
199205
@click=${this.closeFile}
200206
@keydown=${this.onCloseBtnKeydown}

src/frontend/components/shared-styles.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const tabButtonStyles: CSSResult = css`
44
button {
55
padding: 0.375rem 0.75rem;
66
border: none;
7+
border-bottom: 2px solid var(--md-sys-color-outline-variant);
78
border-radius: 0.375rem 0.375rem 0 0;
89
cursor: pointer;
910
font-size: 0.875rem;
@@ -18,6 +19,8 @@ export const tabButtonStyles: CSSResult = css`
1819
button.active {
1920
background-color: var(--md-sys-color-surface);
2021
color: var(--md-sys-color-on-surface);
22+
font-weight: 600;
23+
border-bottom: 2px solid var(--md-sys-color-primary);
2124
}
2225
2326
button:hover:not(.active) {

src/frontend/state/Constants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ export class Constants extends State {
6868
/>
6969
</svg>
7070
`,
71+
edit: html`
72+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
73+
<path
74+
d="M20.71,7.04C21.1,6.65 21.1,6 20.71,5.63L18.37,3.29C18,2.9 17.35,2.9 16.96,3.29L15.12,5.12L18.87,8.87M3,17.25V21H6.75L17.81,9.93L14.06,6.18L3,17.25Z"
75+
/>
76+
</svg>
77+
`,
7178
};
7279

7380
@stateProperty

src/frontend/state/Translations.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ export const ENGLISH_TRANSLATION = {
7171
stop: "Stop debugging",
7272
},
7373
editor_tab_code: "Code",
74-
close_file_tab: "Close file",
74+
close_file_tab: "Remove file",
75+
close_file_confirm: "Are you sure you want to remove this file?",
7576
rename_file_tab: "Rename file",
7677
add_file: "Add file",
7778
add_file_placeholder: "filename\u2026",
@@ -166,7 +167,8 @@ export const DUTCH_TRANSLATION = {
166167
stop: "Stop debugger",
167168
},
168169
editor_tab_code: "Code",
169-
close_file_tab: "Bestand sluiten",
170+
close_file_tab: "Bestand verwijderen",
171+
close_file_confirm: "Weet je zeker dat je dit bestand wilt verwijderen?",
170172
rename_file_tab: "Bestand hernoemen",
171173
add_file: "Bestand toevoegen",
172174
add_file_placeholder: "bestandsnaam\u2026",

0 commit comments

Comments
 (0)