Skip to content

Commit 57a5280

Browse files
committed
implement theme switcher
refactor theme choosing
1 parent 5c25c0f commit 57a5280

File tree

2 files changed

+103
-36
lines changed

2 files changed

+103
-36
lines changed

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

Lines changed: 79 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
1-
import React from "react";
2-
import { Menu, MenuItemModel, MenuSelectEvent } from "@progress/kendo-react-layout";
3-
import { Button } from "@progress/kendo-react-buttons";
1+
import React, { useState } from "react";
2+
import {
3+
Menu,
4+
MenuSelectEvent,
5+
MenuItemModel,
6+
} from "@progress/kendo-react-layout";
7+
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";
6-
import { searchIcon, userIcon, cartIcon } from "@progress/kendo-svg-icons";
10+
import { searchIcon, userIcon, cartIcon, paletteIcon } from "@progress/kendo-svg-icons";
711
import items from "../data/items";
12+
import themeItems from "../data/themeItems";
813
import { AppBar, AppBarSection } from "@progress/kendo-react-layout";
914
import { isAdmin } from "../helpers/adminStore";
1015
import { useStore } from "@nanostores/react";
1116

1217
interface CustomMenuItemModel extends MenuItemModel {
13-
page?: string;
14-
}
18+
page?: string;
19+
}
1520

1621
const Header: React.FC = () => {
1722
const isAdminValue = useStore(isAdmin);
23+
const [theme, setTheme] = useState(
24+
"https://kendo.cdn.telerik.com/themes/5.0.1/default/default-main.css"
25+
);
26+
27+
const handleThemeChange = (event: any) => {
28+
const selectedTheme = themeItems.find(
29+
(item) => item.themeName === event.item.themeName
30+
);
31+
if (selectedTheme) {
32+
setTheme(selectedTheme.link);
33+
}
34+
};
1835

1936
const handleCartClick = () => {
2037
window.location.href = "/kendo-react/kendo-react-e-commerce-astro-app/shoppingcart";
@@ -28,46 +45,72 @@ const Header: React.FC = () => {
2845
const selectedItem: CustomMenuItemModel = event.item;
2946

3047
if (selectedItem.page) {
31-
window.location.href = '/kendo-react/kendo-react-e-commerce-astro-app/' + selectedItem.page;
32-
return;
48+
window.location.href = "/kendo-react/kendo-react-e-commerce-astro-app/" + selectedItem.page;
49+
return;
3350
}
3451

3552
const selectedCategory = selectedItem.text;
3653
if (selectedCategory === "All") {
37-
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`;
3855
} else {
3956
window.location.href = `/kendo-react/kendo-react-e-commerce-astro-app/products?category=${encodeURIComponent(selectedCategory)}`;
4057
}
4158
};
4259

4360
return (
44-
<AppBar themeColor="inherit">
45-
<AppBarSection className="k-flex-basis-0 k-flex-grow k-gap-2 k-align-items-center" style={{ paddingLeft: "50px" }}>
46-
<a href="/" className="k-d-sm-flex" style={{ marginRight: "50px" }}>
47-
<img src="/kendo-react/kendo-react-e-commerce-astro-app/vilora-logo.png" alt="Logo" />
48-
</a>
49-
<Menu items={items} onSelect={handleMenuSelect} />
50-
</AppBarSection>
51-
<AppBarSection className="k-flex-basis-0 k-flex-grow k-justify-content-end k-gap-1.5">
52-
<TextBox
53-
placeholder="Search"
54-
prefix={() => (
55-
<>
56-
<InputPrefix orientation="horizontal">
57-
<span className="k-input-prefix-text">
58-
<SvgIcon icon={searchIcon} size="medium" />
59-
</span>
60-
</InputPrefix>
61-
<InputSeparator />
62-
</>
63-
)}
64-
style={{ width: 300 }}
65-
/>
66-
<Button svgIcon={userIcon} fillMode="flat" className="k-ml-2" />
67-
<Button svgIcon={cartIcon} fillMode="flat" className="k-ml-2" onClick={handleCartClick} />
68-
<Switch onLabel="Admin" offLabel="Client" checked={isAdminValue} onChange={handleSwitchChange} />
69-
</AppBarSection>
70-
</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+
</>
71114
);
72115
};
73116

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const themeItems = [
2+
{
3+
themeName: 'Main',
4+
link: 'https://unpkg.com/@progress/[email protected]/dist/default-main.css'
5+
},
6+
{
7+
themeName: 'Main Dark',
8+
link: 'https://unpkg.com/@progress/[email protected]/dist/default-main-dark.css'
9+
},
10+
{
11+
themeName: 'Ocean Blue',
12+
link: 'https://unpkg.com/@progress/[email protected]/dist/default-ocean-blue-a11y.css'
13+
},
14+
{
15+
themeName: 'Nordic',
16+
link: 'https://unpkg.com/@progress/[email protected]/dist/default-nordic.css'
17+
},
18+
{
19+
themeName: 'Purple',
20+
link: 'https://unpkg.com/@progress/[email protected]/dist/default-purple.css'
21+
}
22+
];
23+
24+
export default themeItems;

0 commit comments

Comments
 (0)