Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Sleep Timer Dialog Block for React

A podcast player with its sleep timer drawer shown open: presets and a fine-tune slider, the stop time worked out from a typed clock, a fade switch, a linear track with the fade zone hatched, and a running state with the time left.

Framework
UI library

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

Stop the sound after a while and say when, with this sleep timer drawer for React with Base UI. It opens from the Now playing screen of Lullbarn, a podcast player: the screen's header holds an outline Sleep timer Button, and the player, a cover, a seek bar, three transport controls and a moon chip, is drawn under a soft scrim inside a hairline frame with a plus mark on each corner. The bottom Drawer has presets in a Segment Group (15, 30, 45, 60 and 90 minutes, End of episode), a Slider to fine-tune from 5 to 120 minutes, the stop time worked out from a typed clock of 22:40 ("Stops at 23:10"), a Switch to fade out over the last 30 seconds and a linear track of the whole span with the fade zone hatched at its end. Start timer is the only Shine Button; it turns the drawer into the running state, the time left from the catalog Timer over the same track draining, with Cancel timer beside it. The moon chip on the player counts too. For preview the drawer is drawn open in place when the screen loads; the header's button opens the real drawer.

FAQ

Why is the drawer already open, and what do I keep?

So you can see it without a click. On load the drawer is a copy drawn in place over the screen: a native dialog element docked to the foot of the frame that isn't modal, so nothing is trapped, hidden or focused, and the page around the preview keeps working. The Sleep timer button opens the real Drawer, with its focus trap, swipe, Escape and focus return, and the copy stays closed until a reload. Both show the same SleepFields component and share the block's state, including a timer that is already running. In your app keep the Drawer and drop the copy: the "in-place" state, the scrim and the dialog element inside the frame.

How is the stop time worked out?

From a typed "now" of 22:40 plus the minutes you chose, wrapped at midnight: 30 minutes is "Stops at 23:10" and 90 is "Stops at 00:10, after midnight". The presets and the slider are one value: moving the slider to 45 lights the 45 preset, and any other value lights none. End of episode is the 20 minutes left in the typed episode. In your app use the device's clock when the timer starts, and the player's own position for the end of the episode.

What does the track show, and does it respect reduced motion?

The whole span as one bar read left to right in every language: the solid part is what is left, the quiet part has gone, and with the fade on the last 30 seconds are hatched with fine stripes, so no colour is needed. While the timer runs the bar updates once a second, and under reduced motion it steps instead of gliding while the digits keep running. The fade zone grows to the whole bar when less than 30 seconds are left.

What stays local, and how do I wire it for real?

Everything. Nothing plays and nothing stops: Start timer starts the catalog Timer, kept out of sight, and the moon chip on the drawn player and the drawer show what is left; at zero the status says the sound would stop there. In your app pause or fade the player from the Timer's onComplete and from the last 30 seconds, and keep the timer in the player's own state so it survives the drawer closing, as it does here.

Is it accessible from the keyboard?

Yes. The real drawer is named by its title and described by its sentence, and Escape, Close and a swipe down return focus to the Sleep timer button; a running timer goes on. The presets are one group you move through with the arrow keys, the slider has arrow, Home and End keys and a value text in minutes, and starting or cancelling moves focus to the button that takes its place. The status line speaks when the timer starts, is cancelled or ends, and never counts the seconds. The trigger is passed to DrawerTrigger through render, and the drawer is controlled with open and onOpenChange.

How does it look on a phone?

A bottom drawer is already the phone pattern: the copy shown on load and the real drawer both come up from the foot of the screen at full width, with Close and the main button pinned under the content, which scrolls when the screen is short. On larger screens both are a centred panel at the foot of the frame.

  • Pro

    Pomodoro Timer Dialog

    Time and scheduling

    A focus timer's Today page with its dialog shown open: a Focus, Short break and Long break switch, a ring that fills with the digits inside it, Start and Pause, four session dots and durations that apply at the next start.

  • Pro

    Audio Player Dialog

    Drawers and popovers

    An ambient-sound library's page with its mini player shown open over it: a floating panel with the track, a seek slider and its time, Previous, Play and Next, and a volume slider with mute. It isn't modal, so the page stays usable, and nothing really plays.

  • Pro

    Set Reminder Dialog

    Time and scheduling

    A to-do list with its reminder dialog shown open: five quick chips, an inline calendar and a time in quarter hours, repeat and notify choices, and one plain sentence that always reads the choice back.

  • Pro

    App Rating Dialog

    Drawers and popovers

    A water tracker's Today screen with its rating drawer shown open over a drawn phone: five stars with a word each, then a branch, where four or five stars offers the store and one to three asks what could be better, with topics and a note.

  • Pro

    Cookie Consent Dialog

    Drawers and popovers

    A recipe blog's first-visit cookie card shown open over its page: two sentences, then Reject all and Accept all as two equal outline buttons side by side, with no primary. It isn't modal, so the page stays readable, and the choice is written on the page's foot.

  • Pro

    Feedback Form Dialog

    Drawers and popovers

    A documentation page with a feedback card docked to its end and shown open: a kind, a message of up to 400 characters with a count, the page it is about, and an optional email that turns on when you let the team reply.