Skip to content

Commit f6d3a68

Browse files
committed
refactor theme choosing
1 parent 44f2d64 commit f6d3a68

File tree

1 file changed

+64
-54
lines changed
  • examples/kendo-react-e-commerce-astro-app/src/components

1 file changed

+64
-54
lines changed

examples/kendo-react-e-commerce-astro-app/src/components/Header.tsx

Lines changed: 64 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import React from "react";
2-
import { Menu, MenuSelectEvent, MenuItemModel } from "@progress/kendo-react-layout";
1+
import React, { useState } from "react";
2+
import {
3+
Menu,
4+
MenuSelectEvent,
5+
MenuItemModel,
6+
} from "@progress/kendo-react-layout";
37
import { Button, DropDownButton } from "@progress/kendo-react-buttons";
48
import { SvgIcon } from "@progress/kendo-react-common";
59
import { InputPrefix, InputSeparator, TextBox, Switch } from "@progress/kendo-react-inputs";
@@ -16,19 +20,9 @@ interface CustomMenuItemModel extends MenuItemModel {
1620

1721
const Header: React.FC = () => {
1822
const isAdminValue = useStore(isAdmin);
19-
20-
const setTheme = (themeLink: string) => {
21-
let themeLinkElement = document.getElementById("theme-link") as HTMLLinkElement;
22-
23-
if (!themeLinkElement) {
24-
themeLinkElement = document.createElement("link");
25-
themeLinkElement.rel = "stylesheet";
26-
themeLinkElement.id = "theme-link";
27-
document.head.appendChild(themeLinkElement);
28-
}
29-
30-
themeLinkElement.href = themeLink;
31-
};
23+
const [theme, setTheme] = useState(
24+
"https://kendo.cdn.telerik.com/themes/5.0.1/default/default-main.css"
25+
);
3226

3327
const handleThemeChange = (event: any) => {
3428
const selectedTheme = themeItems.find(
@@ -51,56 +45,72 @@ const Header: React.FC = () => {
5145
const selectedItem: CustomMenuItemModel = event.item;
5246

5347
if (selectedItem.page) {
54-
window.location.href = '/kendo-react/kendo-react-e-commerce-astro-app/' + selectedItem.page;
48+
window.location.href = "/kendo-react/kendo-react-e-commerce-astro-app/" + selectedItem.page;
5549
return;
5650
}
5751

5852
const selectedCategory = selectedItem.text;
5953
if (selectedCategory === "All") {
60-
window.location.href = `/kendo-react/kendo-react-e-commerce-astro-app/products`; // No category filter applied
54+
window.location.href = `/kendo-react/kendo-react-e-commerce-astro-app/products`;
6155
} else {
6256
window.location.href = `/kendo-react/kendo-react-e-commerce-astro-app/products?category=${encodeURIComponent(selectedCategory)}`;
6357
}
6458
};
6559

6660
return (
67-
<AppBar themeColor="inherit">
68-
<AppBarSection
69-
className="k-flex-basis-0 k-flex-grow k-gap-2 k-align-items-center"
70-
style={{ paddingLeft: "50px" }}
71-
>
72-
<a href="/" className="k-d-sm-flex" style={{ marginRight: "50px" }}>
73-
<img src="/kendo-react/kendo-react-e-commerce-astro-app/vilora-logo.png" alt="Logo" />
74-
</a>
75-
<Menu items={items} onSelect={handleMenuSelect} />
76-
</AppBarSection>
77-
<AppBarSection className="k-flex-basis-0 k-flex-grow k-justify-content-end k-gap-1.5">
78-
<TextBox
79-
placeholder="Search"
80-
prefix={() => (
81-
<>
82-
<InputPrefix orientation="horizontal">
83-
<span className="k-input-prefix-text">
84-
<SvgIcon icon={searchIcon} size="medium" />
85-
</span>
86-
</InputPrefix>
87-
<InputSeparator />
88-
</>
89-
)}
90-
style={{ width: 300 }}
91-
/>
92-
<Button svgIcon={userIcon} fillMode="flat" className="k-ml-2" />
93-
<Button svgIcon={cartIcon} fillMode="flat" className="k-ml-2" onClick={handleCartClick} />
94-
<DropDownButton
95-
svgIcon={paletteIcon}
96-
items={themeItems}
97-
textField="themeName"
98-
fillMode="flat"
99-
onItemClick={handleThemeChange}
100-
/>
101-
<Switch onLabel="Admin" offLabel="Client" checked={isAdminValue} onChange={handleSwitchChange} />
102-
</AppBarSection>
103-
</AppBar>
61+
<>
62+
<link id="theme-link" rel="stylesheet" href={theme} />
63+
<AppBar themeColor="inherit">
64+
<AppBarSection
65+
className="k-flex-basis-0 k-flex-grow k-gap-2 k-align-items-center"
66+
style={{ paddingLeft: "50px" }}
67+
>
68+
<a href="/" className="k-d-sm-flex" style={{ marginRight: "50px" }}>
69+
<img
70+
src="/kendo-react/kendo-react-e-commerce-astro-app/vilora-logo.png"
71+
alt="Logo"
72+
/>
73+
</a>
74+
<Menu items={items} onSelect={handleMenuSelect} />
75+
</AppBarSection>
76+
<AppBarSection className="k-flex-basis-0 k-flex-grow k-justify-content-end k-gap-1.5">
77+
<TextBox
78+
placeholder="Search"
79+
prefix={() => (
80+
<>
81+
<InputPrefix orientation="horizontal">
82+
<span className="k-input-prefix-text">
83+
<SvgIcon icon={searchIcon} size="medium" />
84+
</span>
85+
</InputPrefix>
86+
<InputSeparator />
87+
</>
88+
)}
89+
style={{ width: 300 }}
90+
/>
91+
<Button svgIcon={userIcon} fillMode="flat" className="k-ml-2" />
92+
<Button
93+
svgIcon={cartIcon}
94+
fillMode="flat"
95+
className="k-ml-2"
96+
onClick={handleCartClick}
97+
/>
98+
<DropDownButton
99+
svgIcon={paletteIcon}
100+
items={themeItems}
101+
textField="themeName"
102+
fillMode="flat"
103+
onItemClick={handleThemeChange}
104+
/>
105+
<Switch
106+
onLabel="Admin"
107+
offLabel="Client"
108+
checked={isAdminValue}
109+
onChange={handleSwitchChange}
110+
/>
111+
</AppBarSection>
112+
</AppBar>
113+
</>
104114
);
105115
};
106116

0 commit comments

Comments
 (0)