mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-15 09:46:19 +01:00
✨ display location name on a weather tile
This commit is contained in:
@@ -7,6 +7,9 @@
|
|||||||
"displayInFahrenheit": {
|
"displayInFahrenheit": {
|
||||||
"label": "Display in Fahrenheit"
|
"label": "Display in Fahrenheit"
|
||||||
},
|
},
|
||||||
|
"displayCityName":{
|
||||||
|
"label":"Display City Name"
|
||||||
|
},
|
||||||
"location": {
|
"location": {
|
||||||
"label": "Weather location"
|
"label": "Weather location"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
import { Center, Group, Skeleton, Stack, Text, Title } from '@mantine/core';
|
import { Center, Flex, Group, Skeleton, Stack, Text, Title } from '@mantine/core';
|
||||||
import { useElementSize } from '@mantine/hooks';
|
import { useElementSize } from '@mantine/hooks';
|
||||||
import { IconArrowDownRight, IconArrowUpRight, IconCloudRain } from '@tabler/icons-react';
|
import {
|
||||||
|
IconArrowDownRight,
|
||||||
|
IconArrowUpRight,
|
||||||
|
IconCloudRain,
|
||||||
|
IconCurrentLocation,
|
||||||
|
} from '@tabler/icons-react';
|
||||||
import { api } from '~/utils/api';
|
import { api } from '~/utils/api';
|
||||||
|
|
||||||
import { defineWidget } from '../helper';
|
import { defineWidget } from '../helper';
|
||||||
import { IWidget } from '../widgets';
|
import { IWidget } from '../widgets';
|
||||||
import { WeatherIcon } from './WeatherIcon';
|
import { WeatherIcon } from './WeatherIcon';
|
||||||
@@ -14,6 +20,10 @@ const definition = defineWidget({
|
|||||||
type: 'switch',
|
type: 'switch',
|
||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
},
|
},
|
||||||
|
displayCityName: {
|
||||||
|
type: 'switch',
|
||||||
|
defaultValue: false,
|
||||||
|
},
|
||||||
location: {
|
location: {
|
||||||
type: 'location',
|
type: 'location',
|
||||||
defaultValue: {
|
defaultValue: {
|
||||||
@@ -80,15 +90,16 @@ function WeatherTile({ widget }: WeatherTileProps) {
|
|||||||
align="center"
|
align="center"
|
||||||
style={{ height: '100%', width: '100%' }}
|
style={{ height: '100%', width: '100%' }}
|
||||||
>
|
>
|
||||||
<Group align="center" position="center" spacing="xs">
|
<Flex align="center" gap={'xs'} justify={'center'} direction={width < 200 ? 'column' : 'row'}>
|
||||||
<WeatherIcon code={weather.current_weather.weathercode} />
|
<WeatherIcon code={weather.current_weather.weathercode} />
|
||||||
<Title>
|
<Title size={width < 200 ? 'h4' : 'h2'}>
|
||||||
{getPerferedUnit(
|
{getPerferedUnit(
|
||||||
weather.current_weather.temperature,
|
weather.current_weather.temperature,
|
||||||
widget.properties.displayInFahrenheit
|
widget.properties.displayInFahrenheit
|
||||||
)}
|
)}
|
||||||
</Title>
|
</Title>
|
||||||
</Group>
|
</Flex>
|
||||||
|
|
||||||
{width > 200 && (
|
{width > 200 && (
|
||||||
<Group noWrap spacing="xs">
|
<Group noWrap spacing="xs">
|
||||||
<IconArrowUpRight />
|
<IconArrowUpRight />
|
||||||
@@ -103,6 +114,13 @@ function WeatherTile({ widget }: WeatherTileProps) {
|
|||||||
)}
|
)}
|
||||||
</Group>
|
</Group>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{widget.properties.displayCityName && (
|
||||||
|
<Group noWrap spacing="5px" align="center">
|
||||||
|
<IconCurrentLocation height={15} width={15} />
|
||||||
|
<Text style={{ whiteSpace: 'nowrap' }}>{widget.properties.location.name}</Text>
|
||||||
|
</Group>
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user