Skip to content

Commit 558eede

Browse files
committed
refactor ribbon component
1 parent 360d4a5 commit 558eede

2 files changed

Lines changed: 4 additions & 173 deletions

File tree

Lines changed: 2 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,21 @@
11
"use client";
22

3-
import React, { useCallback, useEffect, useMemo, useState } from "react";
3+
import React from "react";
44
import { LayoutDictionaryModel } from "@/features/localization/models/layout-dictionary.model";
55
import styles from "./ribbon.module.scss";
66
import { BoxComponent } from "@/features/common/components/box/box.component";
7-
import { savePreferredLanguage } from "@/features/localization/services/ui-language.utils";
87
import Link from "next/link";
9-
import {
10-
getSanitizedThemePickerCodeValue,
11-
isLightThemePreference,
12-
isSystemThemePreference,
13-
} from "@/features/themes/services/theme.utils";
14-
import { RibbonPickerComponent } from "@/features/common/components/bars/ribbon/ribbon-picker/ribbon-picker.component";
15-
import { LightIconComponent } from "@/features/common/components/bars/ribbon/assets/light-icon.component";
16-
import { DarkIconComponent } from "@/features/common/components/bars/ribbon/assets/dark-icon.component";
17-
import { ThemeModel } from "@/features/common/models/theme.model";
18-
import { useAppStore } from "@/features/common/services/app.store";
19-
import { SystemIconComponent } from "@/features/common/components/bars/ribbon/assets/system-icon.component";
20-
import {
21-
ThemeCookieValues,
22-
ThemePickerCodeValues,
23-
} from "@/features/common/values/theme.values";
24-
import { savePreferredThemeInCookie } from "@/features/themes/services/theme.client.utils";
258

269
interface RibbonComponentProps {
27-
themeCode: ThemeCookieValues;
28-
languageCode: string;
2910
dictionary: LayoutDictionaryModel["ribbon"];
3011
}
3112

3213
export const RibbonComponent: React.FC<RibbonComponentProps> = ({
33-
themeCode,
34-
languageCode,
3514
dictionary,
3615
}) => {
37-
const theme$ = useAppStore((state) => state.theme$);
38-
39-
const sanitizedThemePickerCodeValue = useMemo(() => {
40-
return getSanitizedThemePickerCodeValue(themeCode);
41-
}, [themeCode]);
42-
43-
const [currentTheme, setCurrentTheme] = useState<ThemeModel>(
44-
dictionary.themePicker.options.filter((element) =>
45-
isSystemThemePreference(themeCode)
46-
? isSystemThemePreference(element.code)
47-
: element.code === sanitizedThemePickerCodeValue,
48-
)[0],
49-
);
50-
51-
const themeOptions = useMemo(
52-
() =>
53-
dictionary.themePicker.options.map((option) => {
54-
return {
55-
code: option.code,
56-
full: {
57-
...option,
58-
label: option.label,
59-
icon: isSystemThemePreference(option.code) ? (
60-
<SystemIconComponent />
61-
) : isLightThemePreference(option.code) ? (
62-
<LightIconComponent />
63-
) : (
64-
<DarkIconComponent />
65-
),
66-
},
67-
compact: {
68-
...option,
69-
label: null,
70-
icon: isSystemThemePreference(option.code) ? (
71-
<SystemIconComponent />
72-
) : isLightThemePreference(option.code) ? (
73-
<LightIconComponent />
74-
) : (
75-
<DarkIconComponent />
76-
),
77-
},
78-
};
79-
}),
80-
[dictionary.themePicker.options],
81-
);
82-
83-
const handleThemeSelection = useCallback(
84-
async (value: ThemePickerCodeValues) => {
85-
const themePreference = await savePreferredThemeInCookie(
86-
value,
87-
languageCode,
88-
);
89-
90-
if (themePreference) {
91-
setCurrentTheme(themePreference);
92-
}
93-
},
94-
[languageCode],
95-
);
96-
97-
const handleLanguageSelection = useCallback(async (value: string) => {
98-
await savePreferredLanguage(value);
99-
}, []);
100-
101-
useEffect(() => {
102-
if (theme$) {
103-
setCurrentTheme(
104-
dictionary.themePicker.options.filter((element) =>
105-
isSystemThemePreference(themeCode)
106-
? isSystemThemePreference(element.code)
107-
: element.code === sanitizedThemePickerCodeValue,
108-
)[0],
109-
);
110-
}
111-
}, [
112-
dictionary.themePicker.options,
113-
sanitizedThemePickerCodeValue,
114-
theme$,
115-
themeCode,
116-
]);
11716

11817
return (
119-
<>
120-
<BoxComponent
121-
contentAs="section"
122-
containerClassName={styles.container}
123-
wrapperClassName={styles.wrapper}
124-
contentClassName={styles.content}
125-
aria-label="Page options"
126-
>
18+
12719
<div className={styles.cta}>
12820
<span className={styles.cta__title}>{dictionary.cta.title}</span>
12921
<Link
@@ -156,30 +48,5 @@ export const RibbonComponent: React.FC<RibbonComponentProps> = ({
15648
</div>
15749
</Link>
15850
</div>
159-
<div className={styles.actions}>
160-
<RibbonPickerComponent<ThemePickerCodeValues>
161-
label={null}
162-
compactLabel={null}
163-
icon={
164-
isSystemThemePreference(currentTheme.code) ? (
165-
<SystemIconComponent />
166-
) : isLightThemePreference(currentTheme.code) ? (
167-
<LightIconComponent />
168-
) : (
169-
<DarkIconComponent />
170-
)
171-
}
172-
languageCode={languageCode}
173-
selectedOptionCode={currentTheme.code}
174-
handleSelection={handleThemeSelection}
175-
options={themeOptions}
176-
aria={{
177-
buttonLabel: dictionary.themePicker.button.ariaLabel,
178-
listLabel: dictionary.themePicker.list.ariaLabel,
179-
}}
180-
/>
181-
</div>
182-
</BoxComponent>
183-
</>
18451
);
18552
};

src/features/common/components/bars/ribbon/ribbon.module.scss

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,10 @@
11
@use "@/libs/theme/styles/variables" as *;
22
@use "@/libs/theme/styles/mixins" as *;
33

4-
.container {
5-
@include Container;
6-
7-
background: var(--color_bg_app_bar);
8-
border-bottom: 1px solid;
9-
border-image-slice: 1;
10-
border-image-source: linear-gradient(
11-
135deg,
12-
rgb(76, 183, 163) 0%,
13-
rgb(63, 89, 228) 50%,
14-
rgb(64, 22, 160) 100%
15-
);
16-
}
17-
18-
.wrapper {
19-
@include ExtendedGrid;
20-
height: $ribbon-height;
21-
}
22-
23-
.content {
24-
position: relative;
25-
@include InnerContentFlex;
26-
height: 100%;
27-
grid-column: 1 / -1;
28-
align-items: center;
29-
justify-content: space-between;
30-
31-
color: $neutrals-light-100-snow;
32-
}
33-
344
.cta {
355
display: flex;
6+
align-items: center;
7+
justify-content: center;
368
font-size: 0.75rem;
379
line-height: 1.25rem;
3810
color: $Neutral0;
@@ -88,11 +60,3 @@
8860
}
8961
}
9062

91-
.actions {
92-
display: flex;
93-
gap: 0.5rem;
94-
95-
@media #{$breakpoint-dimension-md} {
96-
gap: 1rem;
97-
}
98-
}

0 commit comments

Comments
 (0)