lemmy-ui/src/shared/components/theme.tsx

44 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-12-24 01:58:27 +00:00
import { User_ } from 'lemmy-js-client';
2020-10-26 14:28:17 +00:00
import { Helmet } from 'inferno-helmet';
2020-10-26 18:42:07 +00:00
import { Component } from 'inferno';
2020-10-26 14:28:17 +00:00
2020-10-26 18:42:07 +00:00
interface Props {
2020-12-24 01:58:27 +00:00
user: User_ | undefined;
2020-10-26 18:42:07 +00:00
}
2020-10-26 14:28:17 +00:00
2020-10-26 18:42:07 +00:00
export class Theme extends Component<Props> {
render() {
const { user } = this.props;
2020-10-27 00:52:50 +00:00
const hasUserTheme = user && user.theme !== 'browser';
2020-10-26 18:42:07 +00:00
return (
<Helmet>
2020-10-27 00:52:50 +00:00
{hasUserTheme ? (
<link
rel="stylesheet"
type="text/css"
href={`/static/assets/css/themes/${user.theme}.min.css`}
/>
) : (
[
2020-10-26 18:42:07 +00:00
<link
rel="stylesheet"
type="text/css"
href="/static/assets/css/themes/litely.min.css"
id="default-light"
media="(prefers-color-scheme: light)"
2020-10-27 00:52:50 +00:00
/>,
2020-10-26 18:42:07 +00:00
<link
rel="stylesheet"
type="text/css"
href="/static/assets/css/themes/darkly.min.css"
id="default-dark"
media="(prefers-color-scheme: no-preference), (prefers-color-scheme: dark)"
2020-10-27 00:52:50 +00:00
/>,
]
2020-10-26 18:42:07 +00:00
)}
</Helmet>
);
}
}