shadcn.io is not affiliated with official shadcn/ui
Price Alert Dialog Block for React
A price tracker's product page with an alert dialog shown open: a chart of the last 30 daily prices with a dashed target line that moves as you type, dots where the alert would have fired, and the form that sets it.
Installation
Overview
Let people wait for a price instead of checking it, with this price-alert dialog for React with Base UI. It opens from a speaker's page on Dipwatch, a gadget price tracker: the page's header holds an outline Set price alert Button, and the product page, the speaker drawn from three shapes, its price and a bell, is drawn under a soft scrim inside a hairline frame with a plus mark on each corner. The dialog starts with a hand-built chart of the last 30 daily prices. The target is a dashed line that moves as you change it, dots mark the days an alert at that price would have fired, and one sentence counts them from the same prices ("This alert would have fired 3 times in the last 30 days."). Under the chart the target price is an Input in a Field, a Segment Group says whether to wait for a drop or a rise, two Checkboxes pick email, push or both, and a Native Select keeps the alert on for 7, 30 or 90 days. Create alert, the only Shine Button, keeps the alert in this tab, and the drawn bell fills and the price row reads Alert at $219. For preview the dialog is drawn open in place when the page loads; the header button opens the real Dialog, with the same chart and the same state. For price trackers, shops, travel and stock apps and anything with a number worth waiting for.
FAQ
Why is the dialog already open, and what do I keep?
So you can see it without a click. On load the dialog is a copy drawn in place over the page: a native dialog element that isn't modal, so nothing is trapped, hidden or focused, and the page around the preview keeps working. The Set price alert button opens the real Dialog, modal, with its focus trap, Escape and focus return, and the copy stays closed until a reload. Both show the same AlertFields component and share the block's state, so a target typed in the copy is there in the real one. In your app keep the Dialog and drop the copy: the "in-place" state, the scrim and the dialog element inside the frame.
How is the chart drawn, and how do I get the same facts as text?
From DAILY, 30 typed prices in whole dollars with today's last, mapped to percentages of a fixed scale from $200 to $280 and drawn as one SVG path with a lighter area under it; the target line and the dots are plain boxes placed by CSS variables, so they move with a transition that reduced motion switches off. No chart library is used. The chart is decorative and hidden from assistive technology, and its caption carries the same facts in text: the low, the high and today's price, then the sentence that counts the days. Swap DAILY for your own series and keep the scale in step.
How is the number of times it would have fired counted?
By firesOf, a pure function of the target, the direction and the prices: a day counts when its price meets the target (at or below for a drop, at or above for a rise) and the day before did not, so a long run below the target is one alert, not many. Change the target or the direction and the dots, the line and the sentence all follow, and the new sentence is spoken about 600 ms after you stop, only when its text changed.
What is checked before the alert is created?
The target must be a price like 219 or 219.50; for a drop it must be under today's price and for a rise over it, and the message says so ("Choose a price under today's $249.00."). At least one of email and push must be on. Each message sits in a slot that is always there, with an icon, so the chart and the form never move; once it shows it follows your typing and clears as soon as it is fixed, and pressing Create alert with a problem keeps the dialog open and puts focus on the field it belongs to.
Does anything watch the price, and how do I wire it up?
No. Create alert keeps the target, direction, channels and days in this tab, closes the dialog, fills the drawn bell, writes Alert at $219 on the page and says in a polite status message that nothing is watched and nothing will be sent; opening it again shows the alert you made, ready to update. In your app post the alert to your server in create, let a job compare each new price with it, and send the email or push from there, ending it when the days run out.
Is it accessible from the keyboard?
Yes. The real dialog is named by its title and described by its sentence, focus starts in the target field and stays inside until it closes, and Escape, Cancel and the close button all return focus to the header button. The trigger is passed to DialogTrigger through render, and the dialog is controlled with open and onOpenChange. The direction is a group you move through with the arrow keys, the two ways to hear are ordinary checkboxes in a fieldset, and the days are a native select. The copy shown on load moves no focus; Escape inside it, Cancel and its close button close it and put focus on the header button.
Related
- Pro
Alert Rules Settings
Alerts and auditAn alert rules panel where each rule is a sentence you edit in place with menus and a number field, beside a framed chart of its metric with the threshold line and a computed count of how often it would have fired.
- Pro
A team chat inbox with a settings dialog shown open: a real table of notification kinds by channel with a switch in every cell, mixed-state column masters, reset and save, and a chip on the inbox that reports the saved count.
- Pro
Set Reminder Dialog
Time and schedulingA 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
Media Upload Dialog
Media and widgetsA video library with its upload dialog shown open: a drop zone for images, video and audio that names the files it turns away and why, tiles for the ones that pass with a check each, bulk removal, a total and an Add button that puts the clips in the library.
- Pro
QR Scanner Dialog
Media and widgetsAn event check-in page with a simulated scanner dialog shown open: a viewfinder around a real sample QR code, a Wi-Fi, link and ticket payload read in turn, a result card that names the kind and cuts it into parts, a typed-code tab and a recent-scans strip.
- Pro
Quick Calculator Dialog
Media and widgetsA contractor's quote with a calculator dialog shown open: a display with the sum above its result, a four by five keypad, memory keys, a history of the last five sums, working keyboard keys and a Use result button that writes the figure on the quote.