2020-02-14 08:31:24 -06:00
|
|
|
<template>
|
2022-05-28 00:28:12 -05:00
|
|
|
<MkContainer :naked="widgetProps.transparent" :show-header="false" class="mkw-clock">
|
2022-08-06 00:02:03 -05:00
|
|
|
<div class="vubelbmv" :class="widgetProps.size">
|
2022-08-06 04:15:13 -05:00
|
|
|
<div v-if="widgetProps.label === 'tz' || widgetProps.label === 'timeAndTz'" class="_monospace label a abbrev">{{ tzAbbrev }}</div>
|
2022-08-06 00:02:03 -05:00
|
|
|
<MkAnalogClock
|
|
|
|
class="clock"
|
|
|
|
:thickness="widgetProps.thickness"
|
|
|
|
:offset="tzOffset"
|
|
|
|
:graduations="widgetProps.graduations"
|
2022-08-06 02:39:09 -05:00
|
|
|
:fade-graduations="widgetProps.fadeGraduations"
|
2022-08-06 00:02:03 -05:00
|
|
|
:twentyfour="widgetProps.twentyFour"
|
|
|
|
/>
|
2022-08-06 04:15:13 -05:00
|
|
|
<MkDigitalClock v-if="widgetProps.label === 'time' || widgetProps.label === 'timeAndTz'" class="_monospace label c time" :show-s="false" :offset="tzOffset"/>
|
|
|
|
<div v-if="widgetProps.label === 'tz' || widgetProps.label === 'timeAndTz'" class="_monospace label d offset">{{ tzOffsetLabel }}</div>
|
2020-07-10 20:13:11 -05:00
|
|
|
</div>
|
2020-10-17 06:12:00 -05:00
|
|
|
</MkContainer>
|
2020-02-14 08:31:24 -06:00
|
|
|
</template>
|
|
|
|
|
2022-01-08 05:30:01 -06:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { } from 'vue';
|
|
|
|
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget';
|
2022-08-05 09:51:15 -05:00
|
|
|
import { GetFormResultType } from '@/scripts/form';
|
2021-11-11 11:02:25 -06:00
|
|
|
import MkContainer from '@/components/ui/container.vue';
|
2022-08-30 10:24:33 -05:00
|
|
|
import MkAnalogClock from '@/components/MkAnalogClock.vue';
|
|
|
|
import MkDigitalClock from '@/components/MkDigitalClock.vue';
|
2022-08-05 09:51:15 -05:00
|
|
|
import { timezones } from '@/scripts/timezones';
|
2022-08-06 00:02:03 -05:00
|
|
|
import { i18n } from '@/i18n';
|
2020-10-17 06:12:00 -05:00
|
|
|
|
2022-01-08 05:30:01 -06:00
|
|
|
const name = 'clock';
|
|
|
|
|
|
|
|
const widgetPropsDef = {
|
|
|
|
transparent: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: false,
|
2020-02-14 08:31:24 -06:00
|
|
|
},
|
2022-08-06 00:02:03 -05:00
|
|
|
size: {
|
|
|
|
type: 'radio' as const,
|
|
|
|
default: 'medium',
|
|
|
|
options: [{
|
|
|
|
value: 'small', label: i18n.ts.small,
|
|
|
|
}, {
|
|
|
|
value: 'medium', label: i18n.ts.medium,
|
|
|
|
}, {
|
|
|
|
value: 'large', label: i18n.ts.large,
|
|
|
|
}],
|
|
|
|
},
|
2022-01-08 05:30:01 -06:00
|
|
|
thickness: {
|
|
|
|
type: 'radio' as const,
|
2022-08-06 02:39:09 -05:00
|
|
|
default: 0.2,
|
2022-01-08 05:30:01 -06:00
|
|
|
options: [{
|
2022-08-05 09:51:15 -05:00
|
|
|
value: 0.1, label: 'thin',
|
2022-01-08 05:30:01 -06:00
|
|
|
}, {
|
2022-08-05 09:51:15 -05:00
|
|
|
value: 0.2, label: 'medium',
|
2022-01-08 05:30:01 -06:00
|
|
|
}, {
|
2022-08-05 09:51:15 -05:00
|
|
|
value: 0.3, label: 'thick',
|
|
|
|
}],
|
|
|
|
},
|
2022-08-06 00:02:03 -05:00
|
|
|
graduations: {
|
|
|
|
type: 'radio' as const,
|
2022-08-06 02:39:09 -05:00
|
|
|
default: 'numbers',
|
2022-08-06 00:02:03 -05:00
|
|
|
options: [{
|
|
|
|
value: 'none', label: 'None',
|
|
|
|
}, {
|
|
|
|
value: 'dots', label: 'Dots',
|
|
|
|
}, {
|
|
|
|
value: 'numbers', label: 'Numbers',
|
|
|
|
}],
|
2022-08-05 09:51:15 -05:00
|
|
|
},
|
2022-08-06 02:39:09 -05:00
|
|
|
fadeGraduations: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
|
|
|
},
|
2022-08-05 09:51:15 -05:00
|
|
|
twentyFour: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: false,
|
|
|
|
},
|
2022-08-06 04:15:13 -05:00
|
|
|
label: {
|
|
|
|
type: 'radio' as const,
|
|
|
|
default: 'none',
|
|
|
|
options: [{
|
|
|
|
value: 'none', label: 'None',
|
|
|
|
}, {
|
|
|
|
value: 'time', label: 'Time',
|
|
|
|
}, {
|
|
|
|
value: 'tz', label: 'TZ',
|
|
|
|
}, {
|
|
|
|
value: 'timeAndTz', label: 'Time + TZ',
|
|
|
|
}],
|
2022-08-05 09:51:15 -05:00
|
|
|
},
|
|
|
|
timezone: {
|
|
|
|
type: 'enum' as const,
|
|
|
|
default: null,
|
|
|
|
enum: [...timezones.map((tz) => ({
|
|
|
|
label: tz.name,
|
|
|
|
value: tz.name.toLowerCase(),
|
|
|
|
})), {
|
|
|
|
label: '(auto)',
|
|
|
|
value: null,
|
2022-01-08 05:30:01 -06:00
|
|
|
}],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
|
|
|
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
|
|
|
|
//const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
//const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
|
|
|
const props = defineProps<{ widget?: Widget<WidgetProps>; }>();
|
2022-05-25 02:43:12 -05:00
|
|
|
const emit = defineEmits<{ (ev: 'updateProps', props: WidgetProps); }>();
|
2022-01-08 05:30:01 -06:00
|
|
|
|
|
|
|
const { widgetProps, configure } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
2022-08-05 09:51:15 -05:00
|
|
|
const tzAbbrev = $computed(() => (widgetProps.timezone === null
|
|
|
|
? timezones.find((tz) => tz.name.toLowerCase() === Intl.DateTimeFormat().resolvedOptions().timeZone.toLowerCase())?.abbrev
|
|
|
|
: timezones.find((tz) => tz.name.toLowerCase() === widgetProps.timezone)?.abbrev) ?? '?');
|
|
|
|
|
|
|
|
const tzOffset = $computed(() => widgetProps.timezone === null
|
|
|
|
? 0 - new Date().getTimezoneOffset()
|
|
|
|
: timezones.find((tz) => tz.name.toLowerCase() === widgetProps.timezone)?.offset ?? 0);
|
|
|
|
|
|
|
|
const tzOffsetLabel = $computed(() => (tzOffset >= 0 ? '+' : '-') + Math.floor(tzOffset / 60).toString().padStart(2, '0') + ':' + (tzOffset % 60).toString().padStart(2, '0'));
|
|
|
|
|
2022-01-08 05:30:01 -06:00
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-02-14 08:31:24 -06:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2020-02-14 08:55:13 -06:00
|
|
|
.vubelbmv {
|
2022-08-05 09:51:15 -05:00
|
|
|
position: relative;
|
|
|
|
|
|
|
|
> .label {
|
2022-08-06 04:15:13 -05:00
|
|
|
position: absolute;
|
2022-08-05 09:51:15 -05:00
|
|
|
opacity: 0.7;
|
|
|
|
|
2022-08-06 04:15:13 -05:00
|
|
|
&.a {
|
2022-08-05 09:51:15 -05:00
|
|
|
top: 14px;
|
|
|
|
left: 14px;
|
|
|
|
}
|
|
|
|
|
2022-08-06 04:15:13 -05:00
|
|
|
&.b {
|
|
|
|
top: 14px;
|
|
|
|
right: 14px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.c {
|
|
|
|
bottom: 14px;
|
|
|
|
left: 14px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.d {
|
2022-08-05 09:51:15 -05:00
|
|
|
bottom: 14px;
|
|
|
|
right: 14px;
|
|
|
|
}
|
|
|
|
}
|
2020-02-14 08:55:13 -06:00
|
|
|
|
|
|
|
> .clock {
|
|
|
|
margin: auto;
|
2020-02-14 08:31:24 -06:00
|
|
|
}
|
2022-08-06 00:02:03 -05:00
|
|
|
|
|
|
|
&.small {
|
2022-08-06 04:15:13 -05:00
|
|
|
padding: 12px;
|
2022-08-06 00:02:03 -05:00
|
|
|
|
|
|
|
> .clock {
|
|
|
|
height: 100px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&.medium {
|
2022-08-06 04:15:13 -05:00
|
|
|
padding: 14px;
|
2022-08-06 00:02:03 -05:00
|
|
|
|
|
|
|
> .clock {
|
|
|
|
height: 150px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&.large {
|
|
|
|
padding: 16px;
|
|
|
|
|
|
|
|
> .clock {
|
|
|
|
height: 200px;
|
|
|
|
}
|
|
|
|
}
|
2020-02-14 08:31:24 -06:00
|
|
|
}
|
|
|
|
</style>
|