Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 48 additions & 20 deletions src/components/CustomThemeEditor.jsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,55 @@
import { HexColorPicker, RgbaColorPicker } from 'react-colorful';
import { THEME_COLOR_CONFIG } from '../theme/themeConfig';
import { useTranslation } from 'react-i18next';

export default function CustomThemeEditor({ id, customTheme, updateCustomVar }) {
const { t } = useTranslation();
import { rgbaStringToObject, rgbaObjectToString } from '../theme/colorUtils';

export default function CustomThemeEditor({
id = 'custom-theme-editor-component',
customTheme,
updateCustomVar,
resetCustomToDefault,
t,
}) {
return (
<div id={id}>
{Object.entries(THEME_COLOR_CONFIG).map(([key, cfg]) => {
const Picker = cfg.alpha ? RgbaColorPicker : HexColorPicker;
<>
<button
className="reset-theme-button"
onClick={() => {
if (window.confirm(t('station.settings.theme.reset.confirm'))) {
resetCustomToDefault();
}
}}
>
⚠️ {t('station.settings.theme.reset')}
</button>

<div id={id}>
{Object.entries(THEME_COLOR_CONFIG).map(([key, cfg]) => {
const value = customTheme[key];

return (
<div key={key} className={'custom-theme-colorpicker'}>
<label>{t('station.settings.theme.custom.' + key)}</label>

return (
<div key={key} className={`custom-theme-colorpicker ${cfg.hueRestrict !== null ? 'hue-locked' : ''}`}>
<label>{t('station.settings.theme.custom.' + key)}</label>
<Picker
color={customTheme[key]}
onChange={(color) => {
updateCustomVar(key, color);
}}
/>
</div>
);
})}
</div>
{cfg.alpha ? (
<RgbaColorPicker
color={rgbaStringToObject(value)}
onChange={(colorObj) => {
const rgbaString = rgbaObjectToString(colorObj);
updateCustomVar(key, rgbaString);
}}
/>
) : (
<HexColorPicker
color={value}
onChange={(hex) => {
updateCustomVar(key, hex);
}}
/>
)}
</div>
);
})}
</div>
</>
);
}
9 changes: 4 additions & 5 deletions src/components/SettingsPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const SettingsPanel = ({
onToggleDXNews,
wakeLockStatus,
}) => {
const { theme, setTheme, customTheme, updateCustomVar } = useTheme();
const { theme, setTheme, customTheme, updateCustomVar, resetCustomToDefault } = useTheme();

const [callsign, setCallsign] = useState(config?.callsign || '');
const [headerSize, setheaderSize] = useState(config?.headerSize || 1.0);
Expand Down Expand Up @@ -2290,15 +2290,14 @@ export const SettingsPanel = ({
>
{t('station.settings.theme')}
</label>
<ThemeSelector theme={theme} setTheme={setTheme} id="theme-selector-component" />
<div style={{ fontSize: '11px', color: 'var(--text-muted)', marginTop: '6px' }}>
{t('station.settings.theme.' + theme + '.describe')}
</div>
<ThemeSelector theme={theme} setTheme={setTheme} t={t} />
{theme === 'custom' && customTheme && (
<CustomThemeEditor
customTheme={customTheme}
updateCustomVar={updateCustomVar}
resetCustomToDefault={resetCustomToDefault}
id="custom-theme-editor-component"
t={t}
/>
)}
</div>
Expand Down
117 changes: 102 additions & 15 deletions src/components/ThemeSelector.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,108 @@
import { useEffect } from 'react';
import { setActiveThemeButton } from '../theme/themeUtils';
import { AVAILABLE_THEMES } from '../theme/themeConfig';

export default function ThemeSelector({ id, theme, setTheme }) {
useEffect(() => {
setActiveThemeButton(theme);
}, []);

export default function ThemeSelector({
id = 'theme-selector-component',
className = 'theme-selector-component',
theme,
setTheme,
selectedTheme,
t,
}) {
return (
<>
<div id={id} style={{ display: 'grid', gridTemplateColumns: 'repeat(5, 1fr)', gap: '8px' }}>
{Object.entries(AVAILABLE_THEMES).map(([key, t]) => (
<button className={`${key}-theme-select-button theme-select-button`} key={key} onClick={() => setTheme(key)}>
<span className="icon">{t.icon}</span> {t.label}
</button>
))}
<div id={id} className={className}>
<div className="theme-selector-control">
<select value={theme} onChange={(e) => setTheme(e.target.value)}>
{Object.entries(AVAILABLE_THEMES).map(([key, t]) => (
<option value={key} key={key}>
{t.label}
</option>
))}
</select>
<div className="theme-description">{t('station.settings.theme.' + theme + '.describe')}</div>
</div>
<div className="theme-selector-preview" data-theme={theme}>
<h2>
{t('station.settings.theme')}: {AVAILABLE_THEMES[theme].label}
</h2>
<div className="preview-element">
<h3>
{t('station.settings.theme.custom.--text-secondary')} / {t('station.settings.theme.custom.--bg-secondary')}
</h3>
<div className="preview-panel">
<h4>
{t('station.settings.theme.custom.--text-primary')} / {t('station.settings.theme.custom.--bg-panel')}
</h4>
<p className="muted-text">
{t('station.settings.theme.custom.--text-muted')} / {t('station.settings.theme.custom.--bg-panel')}
</p>
<button className="btn-primary">{t('station.settings.theme.sampleButtonText')}</button>
<button className="btn-secondary">{t('station.settings.theme.sampleButtonText')}</button>
</div>
<p className="muted-text">
{t('station.settings.theme.custom.--text-muted')} / {t('station.settings.theme.custom.--bg-secondary')}
</p>
<div className="preview-panel">
<ul>
<li
style={{
color: 'var(--accent-amber)',
}}
>
{t('station.settings.theme.custom.--accent-amber')}
</li>
<li
style={{
color: 'var(--accent-amber-dim)',
}}
>
{t('station.settings.theme.custom.--accent-amber-dim')}
</li>
<li
style={{
color: 'var(--accent-green)',
}}
>
{t('station.settings.theme.custom.--accent-green')}
</li>
<li
style={{
color: 'var(--accent-green-dim)',
}}
>
{t('station.settings.theme.custom.--accent-green-dim')}
</li>
<li
style={{
color: 'var(--accent-red)',
}}
>
{t('station.settings.theme.custom.--accent-red')}
</li>
<li
style={{
color: 'var(--accent-blue)',
}}
>
{t('station.settings.theme.custom.--accent-blue')}
</li>
<li
style={{
color: 'var(--accent-cyan)',
}}
>
{t('station.settings.theme.custom.--accent-cyan')}
</li>
<li
style={{
color: 'var(--accent-purple)',
}}
>
{t('station.settings.theme.custom.--accent-purple')}
</li>
</ul>
</div>
</div>
</div>
</>
</div>
);
}
Loading