Skip to content

Commit 02cc21d

Browse files
perryd01Miklos Daniel
authored andcommitted
refactor: extract header related components and event handlers
1 parent 1e20a73 commit 02cc21d

File tree

2 files changed

+253
-147
lines changed

2 files changed

+253
-147
lines changed

src/App.svelte

Lines changed: 3 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<script lang="ts">
22
// UI5 Components
3-
import { setTheme } from "@ui5/webcomponents-base/dist/config/Theme";
3+
import { setTheme } from "@ui5/webcomponents-base/dist/config/Theme.js";
44
import "@ui5/webcomponents-base/dist/features/F6Navigation";
5-
import applyDirection from "@ui5/webcomponents-base/dist/locale/applyDirection.js";
65
76
import "@ui5/webcomponents/dist/Button";
87
import "@ui5/webcomponents/dist/Input";
@@ -13,8 +12,6 @@
1312
import "@ui5/webcomponents/dist/Popover";
1413
import "@ui5/webcomponents/dist/Tab";
1514
import "@ui5/webcomponents/dist/TabContainer";
16-
import "@ui5/webcomponents-fiori/dist/ShellBar";
17-
import "@ui5/webcomponents-fiori/dist/ShellBarItem";
1815
import "@ui5/webcomponents-fiori/dist/Assets.js";
1916
import "@ui5/webcomponents/dist/Switch";
2017
import "@ui5/webcomponents-icons/dist/palette.js";
@@ -27,23 +24,18 @@
2724
import "@ui5/webcomponents-icons/dist/globe.js";
2825
import TodoList from "./lib/TodoList.svelte";
2926
import { todos, doneTodos } from "./stores/stores";
30-
import logo from "./assets/imgs/UI5-orange-pheonix-logo.png";
3127
import type { TodoItemT } from "./types/TodoItem.type";
32-
import { references } from "./stores/stores.svelte";
3328
import Dialog from "@ui5/webcomponents/dist/Dialog.js";
34-
import Popover from "@ui5/webcomponents/dist/Popover.js";
29+
import Header from "./lib/Header.svelte";
3530
3631
setTheme("sap_horizon");
3732
38-
const shellBarTitle: string = "UI5 Web Components Svelte Sample Application";
3933
const dialogHeaderText: string = "Edit Todo";
4034
4135
// Elements
4236
let dialog = $state<Dialog | null>();
4337
let dialogTextArea = $state();
4438
let dialogDatePicker = $state();
45-
let themeSettingsPopover = $state<Popover | null>(null);
46-
let profileSettingsPopover = $state<Popover | null>(null);
4739
4840
// Create ToDo Fields
4941
let itemInputValue;
@@ -56,65 +48,6 @@
5648
5749
// Event Handlers
5850
59-
const handleThemeSettingsToggle = (event) => {
60-
if (themeSettingsPopover) {
61-
themeSettingsPopover.opener = event.detail.targetRef;
62-
themeSettingsPopover.open = !themeSettingsPopover.open;
63-
}
64-
};
65-
66-
const handleThemeChange = (event) => {
67-
setTheme(event.detail.selectedItems[0].getAttribute("data-theme"));
68-
if (themeSettingsPopover) {
69-
themeSettingsPopover.open = false;
70-
}
71-
};
72-
73-
const handleProfileClick = (event) => {
74-
if (profileSettingsPopover) {
75-
profileSettingsPopover.opener = event.detail.targetRef;
76-
profileSettingsPopover.open = !profileSettingsPopover.open;
77-
}
78-
};
79-
80-
const handleProfileSettingsSelect = (event) => {
81-
const selectedKey = event.detail.item.getAttribute("data-key");
82-
if (selectedKey === "settings") {
83-
if (references.dialog.settings) {
84-
references.dialog.settings.open = true;
85-
}
86-
} else if (selectedKey === "help") {
87-
if (references.dialog.help) {
88-
references.dialog.help.open = true;
89-
}
90-
}
91-
};
92-
93-
const handleRtlSwitchChange = (event) => {
94-
document.body.dir = event.target.checked ? "rtl" : "ltr";
95-
applyDirection();
96-
};
97-
98-
const handleContentDensitySwitchChange = (event) => {
99-
if (event.target.checked) {
100-
document.body.classList.add("ui5-content-density-compact");
101-
} else {
102-
document.body.classList.remove("ui5-content-density-compact");
103-
}
104-
};
105-
106-
const handleSettingsDialogCloseButtonClick = () => {
107-
if (references.dialog.settings) {
108-
references.dialog.settings.open = false;
109-
}
110-
};
111-
112-
const handleHelpDialogCloseButtonClick = () => {
113-
if (references.dialog.help) {
114-
references.dialog.help.open = false;
115-
}
116-
};
117-
11851
const handleItemInput = (event) => {
11952
itemInputValue = event.target.value;
12053
};
@@ -237,13 +170,7 @@
237170
</script>
238171

239172
<main class="app">
240-
<header class="app-header">
241-
<ui5-shellbar primary-title={shellBarTitle} show-notifications notifications-count="2" onprofile-click={handleProfileClick}>
242-
<img class="app-header-logo" slot="logo" src={logo} alt="ui5 orange pheonix logo" />
243-
<ui5-shellbar-item icon="palette" text="Theme" onclick={handleThemeSettingsToggle}></ui5-shellbar-item>
244-
<ui5-avatar slot="profile" size="XS" initials="JD"></ui5-avatar>
245-
</ui5-shellbar>
246-
</header>
173+
<Header />
247174

248175
<ui5-tabcontainer collapsed>
249176
<ui5-tab text="My Todos"></ui5-tab>
@@ -400,15 +327,6 @@
400327
width: calc(100% - 2rem);
401328
}
402329
403-
.app-header-logo {
404-
height: 2rem;
405-
max-height: 2rem;
406-
}
407-
408-
.app-bar-theming-popover {
409-
width: 250px;
410-
}
411-
412330
.create-todo-wrapper {
413331
display: flex;
414332
align-items: center;
@@ -490,66 +408,4 @@
490408
width: 100%;
491409
}
492410
}
493-
.app-bar-profile-popover {
494-
width: 250px;
495-
}
496-
497-
#settings-dialog {
498-
max-width: 300px;
499-
}
500-
501-
.dialog-button {
502-
display: flex;
503-
justify-content: flex-end;
504-
margin-top: 0.625rem;
505-
margin-bottom: -0.425rem;
506-
}
507-
508-
.profile-settings,
509-
.help-header {
510-
display: flex;
511-
flex-direction: row;
512-
justify-content: flex-start;
513-
}
514-
515-
.profile-text {
516-
display: flex;
517-
flex-direction: column;
518-
justify-content: center;
519-
margin-inline-start: 1rem;
520-
}
521-
522-
.app-header-logo {
523-
height: 2rem;
524-
}
525-
526-
.profile-settings-list {
527-
margin-top: 1.25rem;
528-
}
529-
530-
.help-dialog-text {
531-
font-size: 0.875rem;
532-
}
533-
534-
.profile-rtl-switch {
535-
width: 100%;
536-
display: flex;
537-
align-items: center;
538-
justify-content: space-between;
539-
}
540-
541-
#header-title-align {
542-
margin: 1rem 0;
543-
gap: 0.225rem;
544-
}
545-
546-
#header-logo-align {
547-
margin: 0.225rem 3.225rem 0.225rem 0;
548-
align-items: center;
549-
gap: 0.435rem;
550-
}
551-
552-
#help-dialog::part(header) {
553-
justify-content: flex-start;
554-
}
555411
</style>

0 commit comments

Comments
 (0)