mirror of
https://github.com/pawelmalak/flame.git
synced 2026-03-12 07:04:45 +08:00
WeatherIcon. Small changes to theme state
This commit is contained in:
6
client/src/components/UI/Icons/Icon/Icon.module.css
Normal file
6
client/src/components/UI/Icons/Icon/Icon.module.css
Normal file
@@ -0,0 +1,6 @@
|
||||
.Icon {
|
||||
color: var(--color-primary);
|
||||
/* for settings */
|
||||
/* color: var(--color-background); */
|
||||
width: 90%;
|
||||
}
|
||||
28
client/src/components/UI/Icons/Icon/Icon.tsx
Normal file
28
client/src/components/UI/Icons/Icon/Icon.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import classes from './Icon.module.css';
|
||||
|
||||
import { Icon as MDIcon } from '@mdi/react';
|
||||
|
||||
interface ComponentProps {
|
||||
icon: string;
|
||||
color?: string;
|
||||
}
|
||||
|
||||
const Icon = (props: ComponentProps): JSX.Element => {
|
||||
const MDIcons = require('@mdi/js');
|
||||
let iconPath = MDIcons[props.icon];
|
||||
|
||||
if (!iconPath) {
|
||||
console.log(`Icon ${props.icon} not found`);
|
||||
iconPath = MDIcons.mdiCancel;
|
||||
}
|
||||
|
||||
return (
|
||||
<MDIcon
|
||||
className={classes.Icon}
|
||||
path={iconPath}
|
||||
color={props.color ? props.color : 'var(--color-primary)'}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export default Icon;
|
||||
34
client/src/components/UI/Icons/WeatherIcon/WeatherIcon.tsx
Normal file
34
client/src/components/UI/Icons/WeatherIcon/WeatherIcon.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import { useEffect } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { IconKey, Skycons } from 'skycons-ts';
|
||||
import { GlobalState, Theme } from '../../../../interfaces';
|
||||
|
||||
interface ComponentProps {
|
||||
theme: Theme;
|
||||
icon: IconKey
|
||||
}
|
||||
|
||||
const WeatherIcon = (props: ComponentProps): JSX.Element => {
|
||||
const randomId = `icon-${Math.floor(Math.random() * 1000)}`;
|
||||
useEffect(() => {
|
||||
const delay = setTimeout(() => {
|
||||
const skycons = new Skycons({'color': props.theme.colors.accent});
|
||||
skycons.add(`weather-icon-${randomId}`, props.icon);
|
||||
skycons.play();
|
||||
}, 1);
|
||||
|
||||
return () => {
|
||||
clearTimeout(delay);
|
||||
}
|
||||
}, []);
|
||||
|
||||
return <canvas id={`weather-icon-${randomId}`} width='50' height='50'></canvas>
|
||||
}
|
||||
|
||||
const mapStateToProps = (state: GlobalState) => {
|
||||
return {
|
||||
theme: state.theme.theme
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps)(WeatherIcon);
|
||||
Reference in New Issue
Block a user