2022-02-23 13:52:06 +00:00
|
|
|
import {Component} from 'preact';
|
2020-10-10 23:32:27 +00:00
|
|
|
import {useContext} from 'preact/hooks';
|
2022-02-23 13:52:06 +00:00
|
|
|
import {html} from 'htm/preact';
|
|
|
|
|
|
|
|
import {AppContext} from '../context.js';
|
2020-10-10 23:32:27 +00:00
|
|
|
|
|
|
|
export type SettingProps = {
|
|
|
|
children: TRXComponent | undefined;
|
|
|
|
class: string;
|
|
|
|
enabled: boolean;
|
|
|
|
feature: string;
|
|
|
|
title: string;
|
|
|
|
};
|
|
|
|
|
2022-02-23 13:52:06 +00:00
|
|
|
class Header extends Component<SettingProps> {
|
|
|
|
render() {
|
|
|
|
const {props} = this;
|
|
|
|
const context = useContext(AppContext);
|
|
|
|
const enabled = props.enabled ? 'Enabled' : 'Disabled';
|
2020-10-10 23:32:27 +00:00
|
|
|
|
2022-02-23 13:52:06 +00:00
|
|
|
return html`
|
|
|
|
<header>
|
|
|
|
<h2>${props.title}</h2>
|
|
|
|
<button
|
|
|
|
onClick="${() => {
|
|
|
|
context.toggleFeature(props.feature);
|
|
|
|
}}"
|
|
|
|
>
|
|
|
|
${enabled}
|
|
|
|
</button>
|
|
|
|
</header>
|
|
|
|
`;
|
|
|
|
}
|
2020-10-10 23:32:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// A base component for all the settings, this adds the header and the
|
|
|
|
// enable/disable buttons. This can also be used as a placeholder for new
|
|
|
|
// settings when you're still developing them.
|
|
|
|
export function Setting(props: SettingProps): TRXComponent {
|
|
|
|
const children =
|
|
|
|
props.children === undefined
|
|
|
|
? html`<p class="info">This setting still needs a component!</p>`
|
|
|
|
: props.children;
|
|
|
|
|
|
|
|
const enabled = (props.enabled ? 'Enabled' : 'Disabled').toLowerCase();
|
|
|
|
|
|
|
|
return html`
|
|
|
|
<section class="setting ${props.class} ${enabled}">
|
|
|
|
<${Header} ...${props} />
|
|
|
|
<div class="content">${children}</div>
|
|
|
|
</section>
|
|
|
|
`;
|
|
|
|
}
|