feat: custom time/date format in clock widget (#2180)
* feat: custom time/date format in clock widget * feat: add customFormat variables for old-imports * fix: added missing comma for old-import --------- Co-authored-by: Meier Lukas <meierschlumpf@gmail.com>
This commit is contained in:
@@ -56,6 +56,8 @@ const optionMapping: OptionMapping = {
|
|||||||
showSeconds: () => undefined,
|
showSeconds: () => undefined,
|
||||||
timezone: (oldOptions) => oldOptions.timezone,
|
timezone: (oldOptions) => oldOptions.timezone,
|
||||||
useCustomTimezone: () => true,
|
useCustomTimezone: () => true,
|
||||||
|
customTimeFormat: () => undefined,
|
||||||
|
customDateFormat: () => undefined,
|
||||||
},
|
},
|
||||||
downloads: {
|
downloads: {
|
||||||
activeTorrentThreshold: (oldOptions) =>
|
activeTorrentThreshold: (oldOptions) =>
|
||||||
|
|||||||
@@ -1193,6 +1193,14 @@
|
|||||||
"dateFormat": {
|
"dateFormat": {
|
||||||
"label": "Date Format",
|
"label": "Date Format",
|
||||||
"description": "How the date should look like"
|
"description": "How the date should look like"
|
||||||
|
},
|
||||||
|
"customTimeFormat": {
|
||||||
|
"label": "Custom time format",
|
||||||
|
"description": "Use ISO 8601 to format time (this will override other options)"
|
||||||
|
},
|
||||||
|
"customDateFormat": {
|
||||||
|
"label": "Custom date format",
|
||||||
|
"description": "Use ISO 8601 to format date (this will override other options)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ export default function ClockWidget({ options }: WidgetComponentProps<"clock">)
|
|||||||
const secondsFormat = options.showSeconds ? ":ss" : "";
|
const secondsFormat = options.showSeconds ? ":ss" : "";
|
||||||
const timeFormat = options.is24HourFormat ? `HH:mm${secondsFormat}` : `h:mm${secondsFormat} A`;
|
const timeFormat = options.is24HourFormat ? `HH:mm${secondsFormat}` : `h:mm${secondsFormat} A`;
|
||||||
const dateFormat = options.dateFormat;
|
const dateFormat = options.dateFormat;
|
||||||
|
const customTimeFormat = options.customTimeFormat;
|
||||||
|
const customDateFormat = options.customDateFormat;
|
||||||
const timezone = options.useCustomTimezone ? options.timezone : Intl.DateTimeFormat().resolvedOptions().timeZone;
|
const timezone = options.useCustomTimezone ? options.timezone : Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||||
const time = useCurrentTime(options);
|
const time = useCurrentTime(options);
|
||||||
return (
|
return (
|
||||||
@@ -27,11 +29,15 @@ export default function ClockWidget({ options }: WidgetComponentProps<"clock">)
|
|||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
<Text className="clock-time-text" fw={700} size="22.5cqmin" lh="1">
|
<Text className="clock-time-text" fw={700} size="22.5cqmin" lh="1">
|
||||||
{dayjs(time).tz(timezone).format(timeFormat)}
|
{options.customTimeFormat
|
||||||
|
? dayjs(time).tz(timezone).format(customTimeFormat)
|
||||||
|
: dayjs(time).tz(timezone).format(timeFormat)}
|
||||||
</Text>
|
</Text>
|
||||||
{options.showDate && (
|
{options.showDate && (
|
||||||
<Text className="clock-date-text" size="12.5cqmin" p="1cqmin" lineClamp={1}>
|
<Text className="clock-date-text" size="12.5cqmin" p="1cqmin" lineClamp={1}>
|
||||||
{dayjs(time).tz(timezone).format(dateFormat)}
|
{options.customDateFormat
|
||||||
|
? dayjs(time).tz(timezone).format(customDateFormat)
|
||||||
|
: dayjs(time).tz(timezone).format(dateFormat)}
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|||||||
@@ -46,6 +46,14 @@ export const { definition, componentLoader } = createWidgetDefinition("clock", {
|
|||||||
defaultValue: "dddd, MMMM D",
|
defaultValue: "dddd, MMMM D",
|
||||||
withDescription: true,
|
withDescription: true,
|
||||||
}),
|
}),
|
||||||
|
customTimeFormat: factory.text({
|
||||||
|
defaultValue: "",
|
||||||
|
withDescription: true,
|
||||||
|
}),
|
||||||
|
customDateFormat: factory.text({
|
||||||
|
defaultValue: "",
|
||||||
|
withDescription: true,
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
customTitle: {
|
customTitle: {
|
||||||
|
|||||||
Reference in New Issue
Block a user