Add optional boxed styling and error component to information widgets

Signed-off-by: Denis Papec <denis.papec@gmail.com>
This commit is contained in:
Denis Papec 2023-04-16 00:05:50 +01:00
parent 3e01fc12e4
commit c5b6dcc1e0
No known key found for this signature in database
GPG key ID: DE0912C69A47222C
14 changed files with 153 additions and 122 deletions

View file

@ -1,9 +1,11 @@
import useSWR from "swr";
import { useState } from "react";
import { BiError } from "react-icons/bi";
import { WiCloudDown } from "react-icons/wi";
import { MdLocationDisabled, MdLocationSearching } from "react-icons/md";
import { useTranslation } from "next-i18next";
import classNames from "classnames";
import Error from "../error";
import Icon from "./icon";
@ -15,24 +17,15 @@ function Widget({ options }) {
);
if (error || data?.error) {
return (
<div className="flex flex-col justify-center first:ml-0 ml-4 mr-2">
<div className="flex flex-row items-center justify-end">
<div className="flex flex-col items-center">
<BiError className="w-8 h-8 text-theme-800 dark:text-theme-200" />
<div className="flex flex-col ml-3 text-left">
<span className="text-theme-800 dark:text-theme-200 text-sm">{t("widget.api_error")}</span>
<span className="text-theme-800 dark:text-theme-200 text-xs">-</span>
</div>
</div>
</div>
</div>
);
return <Error options={options} />
}
if (!data) {
return (
<div className="flex flex-col justify-center first:ml-0 ml-4 mr-2">
<div className={classNames(
"flex flex-col justify-center first:ml-0 ml-4 mr-2",
options?.styleBoxed === true && " ml-4 mt-2 m:mb-0 rounded-md shadow-md shadow-theme-900/10 dark:shadow-theme-900/20 bg-theme-100/20 dark:bg-white/5 p-3",
)}>
<div className="flex flex-row items-center justify-end">
<div className="flex flex-col items-center">
<WiCloudDown className="w-8 h-8 text-theme-800 dark:text-theme-200" />
@ -50,7 +43,10 @@ function Widget({ options }) {
const timeOfDay = data.current_weather.time > data.daily.sunrise[0] && data.current_weather.time < data.daily.sunset[0] ? "day" : "night";
return (
<div className="flex flex-col justify-center first:ml-0 ml-4 mr-2">
<div className={classNames(
"flex flex-col justify-center first:ml-0 ml-4 mr-2",
options?.styleBoxed === true && " ml-4 mt-2 m:mb-0 rounded-md shadow-md shadow-theme-900/10 dark:shadow-theme-900/20 bg-theme-100/20 dark:bg-white/5 p-3",
)}>
<div className="flex flex-row items-center justify-end">
<div className="flex flex-col items-center">
<Icon condition={data.current_weather.weathercode} timeOfDay={timeOfDay} />
@ -107,8 +103,10 @@ export default function OpenMeteo({ options }) {
<button
type="button"
onClick={() => requestLocation()}
className="flex flex-col justify-center first:ml-0 ml-4 mr-2"
>
className={classNames(
"flex flex-col justify-center first:ml-0 ml-4 mr-2",
options?.styleBoxed === true && " ml-4 mt-2 m:mb-0 rounded-md shadow-md shadow-theme-900/10 dark:shadow-theme-900/20 bg-theme-100/20 dark:bg-white/5 p-3",
)}>
<div className="flex flex-row items-center justify-end">
<div className="flex flex-col items-center">
{requesting ? (