Time Clock
A clock face that picks the hours, the minutes and the seconds of a time.
<script setup lang="ts">
import { TimeClock } from '@vase-ui/vue/time-clock';
import styles from '../../_index.module.css';
const time = Temporal.PlainTime.from('10:30');
</script>
<template>
<TimeClock.Root
:class="styles.Clock"
aria-label="Meeting time"
locale="en-US"
:default-value="time"
>
<div :class="styles.Header">
<TimeClock.ViewTrigger view="hour" :class="styles.Trigger" />
<span aria-hidden="true" :class="styles.Separator">:</span>
<TimeClock.ViewTrigger view="minute" :class="styles.Trigger" />
<TimeClock.DayPeriod value="am" :class="styles.DayPeriod" />
<TimeClock.DayPeriod value="pm" :class="styles.DayPeriod" />
</div>
<TimeClock.Face :class="styles.Face">
<TimeClock.Hand :class="styles.Hand" />
<template #number="{ number }">
<TimeClock.Number :number="number" :class="styles.Number" />
</template>
</TimeClock.Face>
</TimeClock.Root>
</template>.Clock {
display: flex;
flex-direction: column;
align-items: center;
gap: 0.75rem;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Header {
display: flex;
align-items: center;
gap: 0.25rem;
}
.Separator {
font-size: 1.25rem;
font-weight: 700;
}
.Trigger,
.DayPeriod {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
min-width: 2.5rem;
height: 2.5rem;
margin: 0;
padding: 0 0.5rem;
border: 1px solid oklch(14.5% 0 0deg);
border-radius: 0;
background-color: white;
color: oklch(14.5% 0 0deg);
font-family: inherit;
font-size: 1.25rem;
line-height: 1.5rem;
font-variant-numeric: tabular-nums;
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not(:disabled, [aria-pressed='true']) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:focus-visible {
z-index: 1;
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: 2px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
&[aria-pressed='true'] {
background-color: oklch(14.5% 0 0deg);
color: white;
@media (prefers-color-scheme: dark) {
background-color: white;
color: oklch(14.5% 0 0deg);
}
}
&:disabled {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
}
.DayPeriod {
font-size: 0.875rem;
}
/*
* The face is the containing block of the hand, the numbers and the range input of the part. The
* parts write the angle and the radius as variables and set no position, so each rule below places
* them.
*/
.Face {
--radius: 5.5rem;
position: relative;
box-sizing: border-box;
width: 14rem;
height: 14rem;
border: 1px solid oklch(14.5% 0 0deg);
border-radius: 50%;
background-color: oklch(97% 0 0deg);
cursor: pointer;
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(26.9% 0 0deg);
}
&:has(:focus-visible) {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: 2px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
&[data-disabled],
&[data-readonly] {
cursor: default;
}
}
.Hand {
position: absolute;
bottom: 50%;
left: 50%;
width: 2px;
height: calc(var(--time-clock-hand-length) * var(--radius));
background-color: oklch(14.5% 0 0deg);
translate: -50% 0;
transform-origin: 50% 100%;
transform: rotate(var(--time-clock-hand-angle));
pointer-events: none;
@media (prefers-color-scheme: dark) {
background-color: white;
}
/* A time between two numbers has a tip and no selected number under it. */
&[data-between-numbers]::after {
content: '';
position: absolute;
top: -0.25rem;
left: 50%;
width: 0.5rem;
height: 0.5rem;
translate: -50% 0;
border-radius: 50%;
background-color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: white;
}
}
}
.Number {
position: absolute;
top: 50%;
left: 50%;
display: flex;
align-items: center;
justify-content: center;
width: 2rem;
height: 2rem;
margin: -1rem 0 0 -1rem;
border-radius: 50%;
font-size: 0.875rem;
font-variant-numeric: tabular-nums;
pointer-events: none;
/* Turn to the angle, move out by the radius, and turn back so that the digits stay upright. */
transform: rotate(var(--time-clock-number-angle))
translateY(calc(var(--time-clock-number-radius) * var(--radius) * -1))
rotate(calc(var(--time-clock-number-angle) * -1));
&[data-inner] {
width: 1.75rem;
height: 1.75rem;
margin: -0.875rem 0 0 -0.875rem;
font-size: 0.75rem;
}
&[data-selected] {
background-color: oklch(14.5% 0 0deg);
color: white;
@media (prefers-color-scheme: dark) {
background-color: white;
color: oklch(14.5% 0 0deg);
}
}
&[data-disabled] {
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
}<script setup lang="ts">
import { TimeClock } from '@vase-ui/vue/time-clock';
const time = Temporal.PlainTime.from('10:30');
const buttonClass =
'flex h-10 min-w-10 items-center justify-center border border-neutral-950 bg-white px-2 leading-6 text-neutral-950 tabular-nums select-none focus-visible:z-1 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:focus-visible:outline-white dark:disabled:border-neutral-400 dark:disabled:text-neutral-400';
const triggerClass =
'text-xl hover:not-disabled:not-aria-pressed:bg-neutral-100 aria-pressed:bg-neutral-950 aria-pressed:not-disabled:text-white dark:hover:not-disabled:not-aria-pressed:bg-neutral-800 dark:aria-pressed:bg-white dark:aria-pressed:not-disabled:text-neutral-950';
const dayPeriodClass =
'text-sm hover:not-disabled:not-aria-pressed:bg-neutral-100 aria-pressed:bg-neutral-950 aria-pressed:not-disabled:text-white dark:hover:not-disabled:not-aria-pressed:bg-neutral-800 dark:aria-pressed:bg-white dark:aria-pressed:not-disabled:text-neutral-950';
</script>
<template>
<TimeClock.Root
class="flex flex-col items-center gap-3 text-neutral-950 dark:text-white"
aria-label="Meeting time"
locale="en-US"
:default-value="time"
>
<div class="flex items-center gap-1">
<TimeClock.ViewTrigger view="hour" :class="[buttonClass, triggerClass]" />
<span aria-hidden="true" class="text-xl font-bold">:</span>
<TimeClock.ViewTrigger view="minute" :class="[buttonClass, triggerClass]" />
<TimeClock.DayPeriod value="am" :class="[buttonClass, dayPeriodClass]" />
<TimeClock.DayPeriod value="pm" :class="[buttonClass, dayPeriodClass]" />
</div>
<TimeClock.Face
class="relative size-56 cursor-pointer rounded-full border border-neutral-950 bg-neutral-100 select-none [--radius:5.5rem] has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-neutral-950 data-disabled:cursor-default data-readonly:cursor-default dark:border-white dark:bg-neutral-800 dark:has-focus-visible:outline-white"
>
<TimeClock.Hand
class="pointer-events-none absolute bottom-1/2 left-1/2 h-[calc(var(--time-clock-hand-length)*var(--radius))] w-0.5 origin-bottom -translate-x-1/2 rotate-(--time-clock-hand-angle) bg-neutral-950 data-between-numbers:after:absolute data-between-numbers:after:-top-1 data-between-numbers:after:left-1/2 data-between-numbers:after:size-2 data-between-numbers:after:-translate-x-1/2 data-between-numbers:after:rounded-full data-between-numbers:after:bg-neutral-950 data-between-numbers:after:content-[''] dark:bg-white dark:data-between-numbers:after:bg-white"
/>
<template #number="{ number }">
<TimeClock.Number
:number="number"
class="pointer-events-none absolute top-1/2 left-1/2 -mt-4 -ml-4 flex size-8 items-center justify-center rounded-full text-sm tabular-nums transform-[rotate(var(--time-clock-number-angle))_translateY(calc(var(--time-clock-number-radius)*var(--radius)*-1))_rotate(calc(var(--time-clock-number-angle)*-1))] data-disabled:text-neutral-600 data-inner:-mt-3.5 data-inner:-ml-3.5 data-inner:size-7 data-inner:text-xs data-selected:bg-neutral-950 data-selected:not-data-disabled:text-white dark:data-disabled:text-neutral-400 dark:data-selected:bg-white dark:data-selected:not-data-disabled:text-neutral-950"
/>
</template>
</TimeClock.Face>
</TimeClock.Root>
</template>Usage guidelines
- Load
Temporalfirst: An engine with noTemporalneeds a polyfill, and TypeScript before 6.0 needsskipLibCheck. Dates and times gives the steps. - Name the clock: The root is a
groupwith no name of its own. Give it anaria-label, or anaria-labelledbythat names a heading, to say what the time is for. - Place the hand and the numbers: The parts set no position. Give the face
position: relative, because its range input hasposition: absolute. Place the hand and the numbers in the face with their CSS variables. The style sheet of each demo is a model.
Anatomy
Import the component and assemble its parts:
<script setup lang="ts">
import { TimeClock } from '@vase-ui/vue/time-clock';
</script>
<template>
<TimeClock.Root>
<TimeClock.ViewTrigger view="hour" />
<TimeClock.ViewTrigger view="minute" />
<TimeClock.DayPeriod value="am" />
<TimeClock.DayPeriod value="pm" />
<TimeClock.Face>
<TimeClock.Hand />
<template #number="{ number }">
<TimeClock.Number :number="number" />
</template>
</TimeClock.Face>
</TimeClock.Root>
</template>Examples
24-hour face
Set :hour-cycle="24" for a face with two rings. The outer ring has the hours 1 to 12, and the inner ring has the hours 13 to 23 and 00. A press nearer to the center than the middle between the two rings selects the inner ring. TimeClock.DayPeriod renders nothing on a 24-hour face.
<script setup lang="ts">
import { TimeClock } from '@vase-ui/vue/time-clock';
import styles from '../../_index.module.css';
const time = Temporal.PlainTime.from('15:00');
</script>
<template>
<TimeClock.Root
:class="styles.Clock"
aria-label="Meeting time"
locale="en-US"
:hour-cycle="24"
:default-value="time"
>
<div :class="styles.Header">
<TimeClock.ViewTrigger view="hour" :class="styles.Trigger" />
<span aria-hidden="true" :class="styles.Separator">:</span>
<TimeClock.ViewTrigger view="minute" :class="styles.Trigger" />
</div>
<TimeClock.Face :class="styles.Face">
<TimeClock.Hand :class="styles.Hand" />
<template #number="{ number }">
<TimeClock.Number :number="number" :class="styles.Number" />
</template>
</TimeClock.Face>
</TimeClock.Root>
</template>.Clock {
display: flex;
flex-direction: column;
align-items: center;
gap: 0.75rem;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Header {
display: flex;
align-items: center;
gap: 0.25rem;
}
.Separator {
font-size: 1.25rem;
font-weight: 700;
}
.Trigger,
.DayPeriod {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
min-width: 2.5rem;
height: 2.5rem;
margin: 0;
padding: 0 0.5rem;
border: 1px solid oklch(14.5% 0 0deg);
border-radius: 0;
background-color: white;
color: oklch(14.5% 0 0deg);
font-family: inherit;
font-size: 1.25rem;
line-height: 1.5rem;
font-variant-numeric: tabular-nums;
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not(:disabled, [aria-pressed='true']) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:focus-visible {
z-index: 1;
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: 2px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
&[aria-pressed='true'] {
background-color: oklch(14.5% 0 0deg);
color: white;
@media (prefers-color-scheme: dark) {
background-color: white;
color: oklch(14.5% 0 0deg);
}
}
&:disabled {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
}
.DayPeriod {
font-size: 0.875rem;
}
/*
* The face is the containing block of the hand, the numbers and the range input of the part. The
* parts write the angle and the radius as variables and set no position, so each rule below places
* them.
*/
.Face {
--radius: 5.5rem;
position: relative;
box-sizing: border-box;
width: 14rem;
height: 14rem;
border: 1px solid oklch(14.5% 0 0deg);
border-radius: 50%;
background-color: oklch(97% 0 0deg);
cursor: pointer;
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(26.9% 0 0deg);
}
&:has(:focus-visible) {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: 2px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
&[data-disabled],
&[data-readonly] {
cursor: default;
}
}
.Hand {
position: absolute;
bottom: 50%;
left: 50%;
width: 2px;
height: calc(var(--time-clock-hand-length) * var(--radius));
background-color: oklch(14.5% 0 0deg);
translate: -50% 0;
transform-origin: 50% 100%;
transform: rotate(var(--time-clock-hand-angle));
pointer-events: none;
@media (prefers-color-scheme: dark) {
background-color: white;
}
/* A time between two numbers has a tip and no selected number under it. */
&[data-between-numbers]::after {
content: '';
position: absolute;
top: -0.25rem;
left: 50%;
width: 0.5rem;
height: 0.5rem;
translate: -50% 0;
border-radius: 50%;
background-color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: white;
}
}
}
.Number {
position: absolute;
top: 50%;
left: 50%;
display: flex;
align-items: center;
justify-content: center;
width: 2rem;
height: 2rem;
margin: -1rem 0 0 -1rem;
border-radius: 50%;
font-size: 0.875rem;
font-variant-numeric: tabular-nums;
pointer-events: none;
/* Turn to the angle, move out by the radius, and turn back so that the digits stay upright. */
transform: rotate(var(--time-clock-number-angle))
translateY(calc(var(--time-clock-number-radius) * var(--radius) * -1))
rotate(calc(var(--time-clock-number-angle) * -1));
&[data-inner] {
width: 1.75rem;
height: 1.75rem;
margin: -0.875rem 0 0 -0.875rem;
font-size: 0.75rem;
}
&[data-selected] {
background-color: oklch(14.5% 0 0deg);
color: white;
@media (prefers-color-scheme: dark) {
background-color: white;
color: oklch(14.5% 0 0deg);
}
}
&[data-disabled] {
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
}<script setup lang="ts">
import { TimeClock } from '@vase-ui/vue/time-clock';
const time = Temporal.PlainTime.from('15:00');
const buttonClass =
'flex h-10 min-w-10 items-center justify-center border border-neutral-950 bg-white px-2 leading-6 text-neutral-950 tabular-nums select-none focus-visible:z-1 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:focus-visible:outline-white dark:disabled:border-neutral-400 dark:disabled:text-neutral-400';
const triggerClass =
'text-xl hover:not-disabled:not-aria-pressed:bg-neutral-100 aria-pressed:bg-neutral-950 aria-pressed:not-disabled:text-white dark:hover:not-disabled:not-aria-pressed:bg-neutral-800 dark:aria-pressed:bg-white dark:aria-pressed:not-disabled:text-neutral-950';
</script>
<template>
<TimeClock.Root
class="flex flex-col items-center gap-3 text-neutral-950 dark:text-white"
aria-label="Meeting time"
locale="en-US"
:hour-cycle="24"
:default-value="time"
>
<div class="flex items-center gap-1">
<TimeClock.ViewTrigger view="hour" :class="[buttonClass, triggerClass]" />
<span aria-hidden="true" class="text-xl font-bold">:</span>
<TimeClock.ViewTrigger view="minute" :class="[buttonClass, triggerClass]" />
</div>
<TimeClock.Face
class="relative size-56 cursor-pointer rounded-full border border-neutral-950 bg-neutral-100 select-none [--radius:5.5rem] has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-neutral-950 data-disabled:cursor-default data-readonly:cursor-default dark:border-white dark:bg-neutral-800 dark:has-focus-visible:outline-white"
>
<TimeClock.Hand
class="pointer-events-none absolute bottom-1/2 left-1/2 h-[calc(var(--time-clock-hand-length)*var(--radius))] w-0.5 origin-bottom -translate-x-1/2 rotate-(--time-clock-hand-angle) bg-neutral-950 data-between-numbers:after:absolute data-between-numbers:after:-top-1 data-between-numbers:after:left-1/2 data-between-numbers:after:size-2 data-between-numbers:after:-translate-x-1/2 data-between-numbers:after:rounded-full data-between-numbers:after:bg-neutral-950 data-between-numbers:after:content-[''] dark:bg-white dark:data-between-numbers:after:bg-white"
/>
<template #number="{ number }">
<TimeClock.Number
:number="number"
class="pointer-events-none absolute top-1/2 left-1/2 -mt-4 -ml-4 flex size-8 items-center justify-center rounded-full text-sm tabular-nums transform-[rotate(var(--time-clock-number-angle))_translateY(calc(var(--time-clock-number-radius)*var(--radius)*-1))_rotate(calc(var(--time-clock-number-angle)*-1))] data-disabled:text-neutral-600 data-inner:-mt-3.5 data-inner:-ml-3.5 data-inner:size-7 data-inner:text-xs data-selected:bg-neutral-950 data-selected:not-data-disabled:text-white dark:data-disabled:text-neutral-400 dark:data-selected:bg-white dark:data-selected:not-data-disabled:text-neutral-950"
/>
</template>
</TimeClock.Face>
</TimeClock.Root>
</template>A press measures the outer ring from the boxes of the numbers, so the rings can have any size. With no numbers, the outer ring is at the edge of the face.
Seconds
The face shows one unit at a time. A commit shows the next unit, up to granularity. Set granularity="second" to go on to the seconds after the minutes.
<script setup lang="ts">
import { TimeClock } from '@vase-ui/vue/time-clock';
import styles from '../../_index.module.css';
const time = Temporal.PlainTime.from('10:30:45');
</script>
<template>
<TimeClock.Root
:class="styles.Clock"
aria-label="Timer"
locale="en-US"
granularity="second"
:hour-cycle="24"
:default-value="time"
>
<div :class="styles.Header">
<TimeClock.ViewTrigger view="hour" :class="styles.Trigger" />
<span aria-hidden="true" :class="styles.Separator">:</span>
<TimeClock.ViewTrigger view="minute" :class="styles.Trigger" />
<span aria-hidden="true" :class="styles.Separator">:</span>
<TimeClock.ViewTrigger view="second" :class="styles.Trigger" />
</div>
<TimeClock.Face :class="styles.Face">
<TimeClock.Hand :class="styles.Hand" />
<template #number="{ number }">
<TimeClock.Number :number="number" :class="styles.Number" />
</template>
</TimeClock.Face>
</TimeClock.Root>
</template>.Clock {
display: flex;
flex-direction: column;
align-items: center;
gap: 0.75rem;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Header {
display: flex;
align-items: center;
gap: 0.25rem;
}
.Separator {
font-size: 1.25rem;
font-weight: 700;
}
.Trigger,
.DayPeriod {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
min-width: 2.5rem;
height: 2.5rem;
margin: 0;
padding: 0 0.5rem;
border: 1px solid oklch(14.5% 0 0deg);
border-radius: 0;
background-color: white;
color: oklch(14.5% 0 0deg);
font-family: inherit;
font-size: 1.25rem;
line-height: 1.5rem;
font-variant-numeric: tabular-nums;
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not(:disabled, [aria-pressed='true']) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:focus-visible {
z-index: 1;
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: 2px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
&[aria-pressed='true'] {
background-color: oklch(14.5% 0 0deg);
color: white;
@media (prefers-color-scheme: dark) {
background-color: white;
color: oklch(14.5% 0 0deg);
}
}
&:disabled {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
}
.DayPeriod {
font-size: 0.875rem;
}
/*
* The face is the containing block of the hand, the numbers and the range input of the part. The
* parts write the angle and the radius as variables and set no position, so each rule below places
* them.
*/
.Face {
--radius: 5.5rem;
position: relative;
box-sizing: border-box;
width: 14rem;
height: 14rem;
border: 1px solid oklch(14.5% 0 0deg);
border-radius: 50%;
background-color: oklch(97% 0 0deg);
cursor: pointer;
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(26.9% 0 0deg);
}
&:has(:focus-visible) {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: 2px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
&[data-disabled],
&[data-readonly] {
cursor: default;
}
}
.Hand {
position: absolute;
bottom: 50%;
left: 50%;
width: 2px;
height: calc(var(--time-clock-hand-length) * var(--radius));
background-color: oklch(14.5% 0 0deg);
translate: -50% 0;
transform-origin: 50% 100%;
transform: rotate(var(--time-clock-hand-angle));
pointer-events: none;
@media (prefers-color-scheme: dark) {
background-color: white;
}
/* A time between two numbers has a tip and no selected number under it. */
&[data-between-numbers]::after {
content: '';
position: absolute;
top: -0.25rem;
left: 50%;
width: 0.5rem;
height: 0.5rem;
translate: -50% 0;
border-radius: 50%;
background-color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: white;
}
}
}
.Number {
position: absolute;
top: 50%;
left: 50%;
display: flex;
align-items: center;
justify-content: center;
width: 2rem;
height: 2rem;
margin: -1rem 0 0 -1rem;
border-radius: 50%;
font-size: 0.875rem;
font-variant-numeric: tabular-nums;
pointer-events: none;
/* Turn to the angle, move out by the radius, and turn back so that the digits stay upright. */
transform: rotate(var(--time-clock-number-angle))
translateY(calc(var(--time-clock-number-radius) * var(--radius) * -1))
rotate(calc(var(--time-clock-number-angle) * -1));
&[data-inner] {
width: 1.75rem;
height: 1.75rem;
margin: -0.875rem 0 0 -0.875rem;
font-size: 0.75rem;
}
&[data-selected] {
background-color: oklch(14.5% 0 0deg);
color: white;
@media (prefers-color-scheme: dark) {
background-color: white;
color: oklch(14.5% 0 0deg);
}
}
&[data-disabled] {
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
}<script setup lang="ts">
import { TimeClock } from '@vase-ui/vue/time-clock';
const time = Temporal.PlainTime.from('10:30:45');
const buttonClass =
'flex h-10 min-w-10 items-center justify-center border border-neutral-950 bg-white px-2 leading-6 text-neutral-950 tabular-nums select-none focus-visible:z-1 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:focus-visible:outline-white dark:disabled:border-neutral-400 dark:disabled:text-neutral-400';
const triggerClass =
'text-xl hover:not-disabled:not-aria-pressed:bg-neutral-100 aria-pressed:bg-neutral-950 aria-pressed:not-disabled:text-white dark:hover:not-disabled:not-aria-pressed:bg-neutral-800 dark:aria-pressed:bg-white dark:aria-pressed:not-disabled:text-neutral-950';
</script>
<template>
<TimeClock.Root
class="flex flex-col items-center gap-3 text-neutral-950 dark:text-white"
aria-label="Timer"
locale="en-US"
granularity="second"
:hour-cycle="24"
:default-value="time"
>
<div class="flex items-center gap-1">
<TimeClock.ViewTrigger view="hour" :class="[buttonClass, triggerClass]" />
<span aria-hidden="true" class="text-xl font-bold">:</span>
<TimeClock.ViewTrigger view="minute" :class="[buttonClass, triggerClass]" />
<span aria-hidden="true" class="text-xl font-bold">:</span>
<TimeClock.ViewTrigger view="second" :class="[buttonClass, triggerClass]" />
</div>
<TimeClock.Face
class="relative size-56 cursor-pointer rounded-full border border-neutral-950 bg-neutral-100 select-none [--radius:5.5rem] has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-neutral-950 data-disabled:cursor-default data-readonly:cursor-default dark:border-white dark:bg-neutral-800 dark:has-focus-visible:outline-white"
>
<TimeClock.Hand
class="pointer-events-none absolute bottom-1/2 left-1/2 h-[calc(var(--time-clock-hand-length)*var(--radius))] w-0.5 origin-bottom -translate-x-1/2 rotate-(--time-clock-hand-angle) bg-neutral-950 data-between-numbers:after:absolute data-between-numbers:after:-top-1 data-between-numbers:after:left-1/2 data-between-numbers:after:size-2 data-between-numbers:after:-translate-x-1/2 data-between-numbers:after:rounded-full data-between-numbers:after:bg-neutral-950 data-between-numbers:after:content-[''] dark:bg-white dark:data-between-numbers:after:bg-white"
/>
<template #number="{ number }">
<TimeClock.Number
:number="number"
class="pointer-events-none absolute top-1/2 left-1/2 -mt-4 -ml-4 flex size-8 items-center justify-center rounded-full text-sm tabular-nums transform-[rotate(var(--time-clock-number-angle))_translateY(calc(var(--time-clock-number-radius)*var(--radius)*-1))_rotate(calc(var(--time-clock-number-angle)*-1))] data-disabled:text-neutral-600 data-inner:-mt-3.5 data-inner:-ml-3.5 data-inner:size-7 data-inner:text-xs data-selected:bg-neutral-950 data-selected:not-data-disabled:text-white dark:data-disabled:text-neutral-400 dark:data-selected:bg-white dark:data-selected:not-data-disabled:text-neutral-950"
/>
</template>
</TimeClock.Face>
</TimeClock.Root>
</template>Step and limits
minuteStep and secondStep set the step of the minutes and of the seconds, and a number that is not on a step is disabled. min and max limit the time, and disabledTimes disables a time. A press or a key does not select a disabled number.
<script setup lang="ts">
import { TimeClock } from '@vase-ui/vue/time-clock';
import styles from '../../_index.module.css';
const time = Temporal.PlainTime.from('09:15');
const minTime = Temporal.PlainTime.from('09:00');
const maxTime = Temporal.PlainTime.from('17:00');
</script>
<template>
<TimeClock.Root
:class="styles.Clock"
aria-label="Appointment time"
locale="en-US"
default-view="minute"
:minute-step="15"
:min="minTime"
:max="maxTime"
:default-value="time"
>
<div :class="styles.Header">
<TimeClock.ViewTrigger view="hour" :class="styles.Trigger" />
<span aria-hidden="true" :class="styles.Separator">:</span>
<TimeClock.ViewTrigger view="minute" :class="styles.Trigger" />
<TimeClock.DayPeriod value="am" :class="styles.DayPeriod" />
<TimeClock.DayPeriod value="pm" :class="styles.DayPeriod" />
</div>
<TimeClock.Face :class="styles.Face">
<TimeClock.Hand :class="styles.Hand" />
<template #number="{ number }">
<TimeClock.Number :number="number" :class="styles.Number" />
</template>
</TimeClock.Face>
</TimeClock.Root>
</template>.Clock {
display: flex;
flex-direction: column;
align-items: center;
gap: 0.75rem;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Header {
display: flex;
align-items: center;
gap: 0.25rem;
}
.Separator {
font-size: 1.25rem;
font-weight: 700;
}
.Trigger,
.DayPeriod {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
min-width: 2.5rem;
height: 2.5rem;
margin: 0;
padding: 0 0.5rem;
border: 1px solid oklch(14.5% 0 0deg);
border-radius: 0;
background-color: white;
color: oklch(14.5% 0 0deg);
font-family: inherit;
font-size: 1.25rem;
line-height: 1.5rem;
font-variant-numeric: tabular-nums;
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not(:disabled, [aria-pressed='true']) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:focus-visible {
z-index: 1;
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: 2px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
&[aria-pressed='true'] {
background-color: oklch(14.5% 0 0deg);
color: white;
@media (prefers-color-scheme: dark) {
background-color: white;
color: oklch(14.5% 0 0deg);
}
}
&:disabled {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
}
.DayPeriod {
font-size: 0.875rem;
}
/*
* The face is the containing block of the hand, the numbers and the range input of the part. The
* parts write the angle and the radius as variables and set no position, so each rule below places
* them.
*/
.Face {
--radius: 5.5rem;
position: relative;
box-sizing: border-box;
width: 14rem;
height: 14rem;
border: 1px solid oklch(14.5% 0 0deg);
border-radius: 50%;
background-color: oklch(97% 0 0deg);
cursor: pointer;
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(26.9% 0 0deg);
}
&:has(:focus-visible) {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: 2px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
&[data-disabled],
&[data-readonly] {
cursor: default;
}
}
.Hand {
position: absolute;
bottom: 50%;
left: 50%;
width: 2px;
height: calc(var(--time-clock-hand-length) * var(--radius));
background-color: oklch(14.5% 0 0deg);
translate: -50% 0;
transform-origin: 50% 100%;
transform: rotate(var(--time-clock-hand-angle));
pointer-events: none;
@media (prefers-color-scheme: dark) {
background-color: white;
}
/* A time between two numbers has a tip and no selected number under it. */
&[data-between-numbers]::after {
content: '';
position: absolute;
top: -0.25rem;
left: 50%;
width: 0.5rem;
height: 0.5rem;
translate: -50% 0;
border-radius: 50%;
background-color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: white;
}
}
}
.Number {
position: absolute;
top: 50%;
left: 50%;
display: flex;
align-items: center;
justify-content: center;
width: 2rem;
height: 2rem;
margin: -1rem 0 0 -1rem;
border-radius: 50%;
font-size: 0.875rem;
font-variant-numeric: tabular-nums;
pointer-events: none;
/* Turn to the angle, move out by the radius, and turn back so that the digits stay upright. */
transform: rotate(var(--time-clock-number-angle))
translateY(calc(var(--time-clock-number-radius) * var(--radius) * -1))
rotate(calc(var(--time-clock-number-angle) * -1));
&[data-inner] {
width: 1.75rem;
height: 1.75rem;
margin: -0.875rem 0 0 -0.875rem;
font-size: 0.75rem;
}
&[data-selected] {
background-color: oklch(14.5% 0 0deg);
color: white;
@media (prefers-color-scheme: dark) {
background-color: white;
color: oklch(14.5% 0 0deg);
}
}
&[data-disabled] {
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
}<script setup lang="ts">
import { TimeClock } from '@vase-ui/vue/time-clock';
const time = Temporal.PlainTime.from('09:15');
const minTime = Temporal.PlainTime.from('09:00');
const maxTime = Temporal.PlainTime.from('17:00');
const buttonClass =
'flex h-10 min-w-10 items-center justify-center border border-neutral-950 bg-white px-2 leading-6 text-neutral-950 tabular-nums select-none focus-visible:z-1 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-950 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:focus-visible:outline-white dark:disabled:border-neutral-400 dark:disabled:text-neutral-400';
const triggerClass =
'text-xl hover:not-disabled:not-aria-pressed:bg-neutral-100 aria-pressed:bg-neutral-950 aria-pressed:not-disabled:text-white dark:hover:not-disabled:not-aria-pressed:bg-neutral-800 dark:aria-pressed:bg-white dark:aria-pressed:not-disabled:text-neutral-950';
const dayPeriodClass =
'text-sm hover:not-disabled:not-aria-pressed:bg-neutral-100 aria-pressed:bg-neutral-950 aria-pressed:not-disabled:text-white dark:hover:not-disabled:not-aria-pressed:bg-neutral-800 dark:aria-pressed:bg-white dark:aria-pressed:not-disabled:text-neutral-950';
</script>
<template>
<TimeClock.Root
class="flex flex-col items-center gap-3 text-neutral-950 dark:text-white"
aria-label="Appointment time"
locale="en-US"
default-view="minute"
:minute-step="15"
:min="minTime"
:max="maxTime"
:default-value="time"
>
<div class="flex items-center gap-1">
<TimeClock.ViewTrigger view="hour" :class="[buttonClass, triggerClass]" />
<span aria-hidden="true" class="text-xl font-bold">:</span>
<TimeClock.ViewTrigger view="minute" :class="[buttonClass, triggerClass]" />
<TimeClock.DayPeriod value="am" :class="[buttonClass, dayPeriodClass]" />
<TimeClock.DayPeriod value="pm" :class="[buttonClass, dayPeriodClass]" />
</div>
<TimeClock.Face
class="relative size-56 cursor-pointer rounded-full border border-neutral-950 bg-neutral-100 select-none [--radius:5.5rem] has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-neutral-950 data-disabled:cursor-default data-readonly:cursor-default dark:border-white dark:bg-neutral-800 dark:has-focus-visible:outline-white"
>
<TimeClock.Hand
class="pointer-events-none absolute bottom-1/2 left-1/2 h-[calc(var(--time-clock-hand-length)*var(--radius))] w-0.5 origin-bottom -translate-x-1/2 rotate-(--time-clock-hand-angle) bg-neutral-950 data-between-numbers:after:absolute data-between-numbers:after:-top-1 data-between-numbers:after:left-1/2 data-between-numbers:after:size-2 data-between-numbers:after:-translate-x-1/2 data-between-numbers:after:rounded-full data-between-numbers:after:bg-neutral-950 data-between-numbers:after:content-[''] dark:bg-white dark:data-between-numbers:after:bg-white"
/>
<template #number="{ number }">
<TimeClock.Number
:number="number"
class="pointer-events-none absolute top-1/2 left-1/2 -mt-4 -ml-4 flex size-8 items-center justify-center rounded-full text-sm tabular-nums transform-[rotate(var(--time-clock-number-angle))_translateY(calc(var(--time-clock-number-radius)*var(--radius)*-1))_rotate(calc(var(--time-clock-number-angle)*-1))] data-disabled:text-neutral-600 data-inner:-mt-3.5 data-inner:-ml-3.5 data-inner:size-7 data-inner:text-xs data-selected:bg-neutral-950 data-selected:not-data-disabled:text-white dark:data-disabled:text-neutral-400 dark:data-selected:bg-white dark:data-selected:not-data-disabled:text-neutral-950"
/>
</template>
</TimeClock.Face>
</TimeClock.Root>
</template>A selection puts the time into the limits. An hour is in the limits when one of its minutes is, and a minute is in the limits when one of its seconds is.
Render on the server
The server HTML has the angle variables of the hand and of each number, so the face is correct before the page hydrates. The clock never reads the locale of the visitor: give locale or a LocaleProvider, or the text is en-US. A server and a browser can still have other Intl data, such as other digits or another hour cycle. The hydration then writes the texts and the attributes of the browser, and a face with another count of numbers logs one message of Vue. Give hourCycle to keep the same face on the server and in the browser.
An element of the element slot, or of a component in as, keeps the attributes of the server. TimeClock.Root has data-allow-mismatch="children", so Vue also gives no warning for your own content in the clock.
Keyboard
| Key | Action |
|---|---|
| Tab | Moves the focus to the range input of the face. |
| Right Arrow, Up Arrow | Selects the next number. The step of the view sets the distance, and the last number goes to the first. A right-to-left document does not swap the arrow keys. |
| Left Arrow, Down Arrow | Selects the number before. The first number goes to the last. |
| Page Up | Adds 2 hours, 15 minutes or 15 seconds, rounded up to a whole number of steps. |
| Page Down | Takes away 2 hours, 15 minutes or 15 seconds, rounded up to a whole number of steps. |
| Home, End | Selects the first or the last number of the view. |
| Enter, Space | Commits the time and shows the next view. |
API reference
TimeClock.Root
Groups the parts of a clock and holds its time.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
defaultValue | Value | null | undefined | The first value of a clock with no modelValue. | |
defaultView | TimeClockView | undefined | 'hour' | The first view of a clock with no view. |
disabled | boolean | undefined | false | The user cannot change the time or the view, and no part of the clock takes the focus. |
disabledTimes | ((time: Temporal.PlainTime, view: TimeClockView) => boolean) | undefined | Returns true for a time that the user cannot select in the view. | |
granularity | TimeClockView | undefined | 'minute' | The last unit that the user selects. A commit shows the next view, up to this one. |
hourCycle | 12 | 24 | undefined | The hour cycle of the face. The default is the hour cycle of the locale. | |
locale | Intl.LocalesArgument | The locale of the texts and of the hour cycle. The default is the locale of the nearest
LocaleProvider, else en-US. | |
max | Temporal.PlainTime | undefined | The latest time that the user can select. | |
min | Temporal.PlainTime | undefined | The earliest time that the user can select. | |
minuteStep | number | undefined | 1 | The step of the minutes. |
modelValue | Value | null | undefined | The value: a Temporal.PlainTime, PlainDateTime or ZonedDateTime, or null for no value.
A new value has the kind, the date and the time zone of the value. It keeps each unit that the
user does not pick, unless min or max changes the time. | |
readonly | boolean | undefined | false | The user cannot change the time. The range input takes the focus, and the view triggers work. |
referenceDate | Value | undefined | The time that the face shows with no value, and the kind, the date and the time zone of a first
value. With none, the face shows 00:00, and the first value is a Temporal.PlainTime. | |
secondStep | number | undefined | 1 | The step of the seconds. |
view | TimeClockView | undefined | The unit that the face shows. v-model:view uses it. | |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: TimeClockRootState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: TimeClockRootState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Events
| Event | Arguments | Description |
|---|---|---|
valueChange | [value: Value, details: TimeClockRootChangeEventDetails] | The user selects a time. The value has the date and the time zone of the value.
details.cancel() keeps the time as it was. |
update:modelValue | [value: Value] | Comes after the change event with the new value, unless a listener cancels the change. v-model uses it. |
valueCommitted | [value: Value, details: TimeClockRootCommitEventDetails] | The user commits the time: a press that selects a number ends, or Enter or Space on the face. |
viewChange | [view: TimeClockView, details: TimeClockRootViewChangeEventDetails] | The view changes: a trigger, or a commit that shows the next view. details.cancel() keeps the view. |
update:view | [view: TimeClockView] | Comes after the change event of the view, unless a listener cancels it. v-model:view uses it. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-view] | The unit that the face shows: hour, minute or second. |
[data-disabled] | The clock is disabled. |
[data-readonly] | The clock is read-only. |
[data-dragging] | The user presses or drags on the face. |
[data-empty] | The clock has no value. |
TimeClock.Face
Shows the numbers of the view, and takes a press, a drag and the keys. The id and each aria-*
attribute of the face go to its range input. The face has no element slot, because its element
holds the range input.
Renders a <div> element with a range <input> element in it.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
getAriaValueText | ((value: number, view: TimeClockView) => string) | undefined | The aria-valuetext of the range input, for the number that the face shows. The default is
the number with its unit, such as 30 minutes. An aria-valuetext attribute wins. | |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: TimeClockFaceState | The content of the part. |
number | number: TimeClockFaceNumberindex: number | Renders one number of the face. The face has no numbers without it. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
inputElement | HTMLInputElement | null | The range input of the face, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-view] | The unit that the face shows: hour, minute or second. |
[data-disabled] | The clock is disabled. |
[data-readonly] | The clock is read-only. |
[data-dragging] | The user presses or drags on the face. |
[data-empty] | The clock has no value. |
TimeClock.Hand
Points at the number of the time.
Renders a <div> element while the clock has a value.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: TimeClockHandState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: TimeClockHandState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-inner] | The hand points at the inner ring of a 24-hour face. |
[data-between-numbers] | The hand points between two numbers, such as at the minute 37. |
[data-view] | The unit that the face shows: hour, minute or second. |
[data-disabled] | The clock is disabled. |
[data-readonly] | The clock is read-only. |
[data-dragging] | The user presses or drags on the face. |
CSS variables
| Variable | Description |
|---|---|
--time-clock-hand-angle | The angle of the hand, in degrees clockwise from 12 o'clock. |
--time-clock-hand-length | The length of the hand, as a ratio of the radius of the outer ring: 1, or 0.64 for the inner ring. |
TimeClock.Number
Shows one number of the face.
Renders a <span> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
number | TimeClockFaceNumber | Required | The number that the part shows. The number slot of TimeClock.Face gives it. |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: TimeClockNumberState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: TimeClockNumberState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-selected] | The time of the clock selects the number. |
[data-disabled] | The user cannot select the number, or the clock is disabled. |
[data-inner] | The number is on the inner ring of a 24-hour face. |
[data-view] | The unit that the face shows: hour, minute or second. |
[data-readonly] | The clock is read-only. |
[data-dragging] | The user presses or drags on the face. |
[data-empty] | The clock has no value. |
CSS variables
| Variable | Description |
|---|---|
--time-clock-number-angle | The angle of the number, in degrees clockwise from 12 o'clock. |
--time-clock-number-radius | The distance of the number from the center, as a ratio of the radius of the outer ring: 1, or 0.64 for the inner ring. |
TimeClock.DayPeriod
Moves the time to its half of the day.
Renders a <button> element on a face of 12 hours.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | TimeClockDayPeriodValue | Required | The day period that the button selects. Its text is that period in the locale. |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: TimeClockDayPeriodState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: TimeClockDayPeriodState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[aria-pressed="true"] | The time of the clock is in the day period. |
:disabled | The button is a native button, and the clock is disabled or no hour of the day period is allowed. |
[aria-disabled="true"] | The button is another element, and it is disabled. |
[data-view] | The unit that the face shows: hour, minute or second. |
[data-readonly] | The clock is read-only. |
[data-dragging] | The user presses or drags on the face. |
[data-empty] | The clock has no value. |
TimeClock.ViewTrigger
Shows its view on the face, also in a read-only clock. With no content of its own, its name is
the unit and the number, such as hour 10.
Renders a <button> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
view | TimeClockView | Required | The unit that the face shows after a press. The text is that unit of the time. |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: TimeClockViewTriggerState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: TimeClockViewTriggerState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[aria-pressed="true"] | The face shows the unit of the trigger. |
:disabled | The trigger is a native button, and the clock is disabled. |
[aria-disabled="true"] | The trigger is another element, and the clock is disabled. |
[data-view] | The unit that the face shows: hour, minute or second. |
[data-readonly] | The clock is read-only. |
[data-dragging] | The user presses or drags on the face. |
[data-empty] | The clock has no value. |
TimeClockView
A unit of the face.
'hour' | 'minute' | 'second'
TimeClockFaceNumber
A number of the face, as the number slot of TimeClock.Face gives it.
| Property | Type | Description |
|---|---|---|
inner | boolean | Whether the number is on the inner ring of a 24-hour face. The inner ring has the hours 0 and 13 to 23. |
value | number | The number that the face shows. On a 12-hour face, an hour is from 1 to 12. On a 24-hour face, an hour is from 0 to 23. A minute or a second is a multiple of 5. |
TimeClockDayPeriodValue
A half of the day.
'am' | 'pm'
TimeClock.Root.ChangeEventReason
The reason of the details of valueChange: item-press is a press on TimeClock.DayPeriod, and input-change is a change of the range input by assistive technology.
'drag' | 'keyboard' | 'input-change' | 'item-press'
TimeClock.Root.CommitEventReason
The reason of the details of a commit.
'drag' | 'keyboard'
TimeClock.Root.ViewChangeEventReason
The reason of the details of a change of the view.
'trigger-press' | 'drag' | 'keyboard'
Differences from Base UI
Base UI has no Time Clock. A clock face is a common touch control for a time of day. The WAI-ARIA Authoring Practices have no clock pattern, so the face is a slider.
Behavior
| Vase UI | Evidence |
|---|---|
| A repeat button stops after one step when that step releases the press. Base UI starts its repeat timer after the first step returns, even if a pointer release ended the press during that step. |
The handbook gives the differences that all components share: Styling, Animation, Composition, Customization, Forms and TypeScript.