shadcn.io is not affiliated with official shadcn/ui
Environment Switcher Navbar Block for React
An app bar with a Production, Staging and Development segment control that shows the environment's base URL with a copy button and asks for confirmation before switching to Production.
Installation
Overview
An environment switch for React with Base UI, in the app bar of a release-management tool called Launchlane. One bar between the page's rails, cut into cells by solid dividers that meet the top rule: the wordmark, a segment control (Production with a warning icon, Staging, Development), a cell that shows the chosen environment's base URL in monospace behind a status dot with a copy button, and Releases, Pipelines and Settings from xl up. Choosing Staging or Development switches at once. Choosing Production first opens an alert dialog, "Switch to Production?", with Cancel and Continue; the control only moves once you continue, and a polite line says what changed or that the switch was cancelled. On a phone the bar shows the environment's name behind its dot, and a sheet from the top holds the same segment control, the URL with its copy button and the links. It's built from Segment Group, Alert Dialog, Copy Button, Status, Sheet, Guides, Shine Button and Button, with your theme's tokens for every colour. For release and operations tools where one wrong click on the live environment is expensive.
FAQ
How do I change the environments and their URLs?
Edit ENVIRONMENTS at the top of the file: an id, a label and the base URL. The segments, the URL cell (drawn over an unseen copy of every URL, so its width never changes) and the polite lines are built from it. needsConfirm decides which environments ask first; it is "production" here, and returning true for another id adds the same dialog to it. The URLs use the reserved .example domain. In an app, replace commit with your own switch (a cookie, a route, a context).
What does the confirmation do?
Production is a segment like the others, but choosing it only opens the dialog: the control keeps showing the environment you are in until you press Continue. Cancel, Escape and the overlay's dismissal all leave things as they were and say "Switch cancelled. Still in Staging." Continue switches, updates the URL and the dot (the warning token on Production, the foreground colour elsewhere) and says "Environment: Production. Base URL api.launchlane.example." Nothing is stored or sent. Focus goes back to the segment you chose from.
How does it work with a keyboard and a screen reader?
The segment control is a labelled radio group named Environment. The arrow keys move to a segment and choose it, so arriving on Production opens the dialog. The warning icon is decoration; the word Production is what is read. The URL is read as "Base URL: staging.api.launchlane.example" and the copy button, named "Copy base URL", says "Base URL copied" once the text is on the clipboard (or that it couldn't copy, if the browser refuses). The alert dialog traps focus, is named by its title and description, and returns focus when it closes.
How does it work on a phone?
Below the md breakpoint the bar shows the wordmark's icon, the environment's name behind its dot, and a menu button; nothing wraps at 320 pixels. The sheet from the top holds the same segment control, the URL with its copy button and the links. Choosing Production there opens the same dialog above the sheet; Cancel brings you back to the sheet. Escape or the close button closes the sheet and focus goes back to the menu button.
Does it work right to left?
Yes. The bar mirrors, the dividers stay between the cells and the segment control's thumb follows the direction. The URL is always read left to right, as web addresses are, and so is the wordmark.
Wrap the block in your direction provider (the catalog's DirectionProvider) so the dialog and the sheet follow the page.
Related
- Pro
Workspace Switcher Navbar
Accounts and scopesAn app bar whose switcher button opens a searchable list of workspaces: recent ones first with number keys, a plan badge on every row, a check on the current one and a Create workspace button in the foot.
- Pro
Multi-Tenant Navbar
Accounts and scopesAn app bar with two chained scopes, organization then project: choosing an organization rewrites the project list, and a role badge sits beside the organization's name.
- Pro
Role-Based Navbar
Accounts and scopesAn app bar with a View as toggle (Admin, Editor, Viewer) that swaps the bar's links in one cell, so its width never moves, with a role badge that says what the role can do.
- a1f9c2Pro
A staging pill for a deploy platform: a status dot and the environment's name, the branch and the commit hash in mono, and a copy button for the hash.
- Pro
Split Layout Navbar
Cells and splitsAn app bar split by a solid divider that meets the top rule: navigation at the start, and at the end a help link and an avatar whose menu sets your presence (Active, Away, Do not disturb) and recolours its dot.
- Pro
SaaS Marketing Navbar
Mega menusA one-bar marketing navbar for a product roadmap tool: a wordmark, a Product menu of four areas with icons and one-line descriptions, plain links with the current page marked, Sign in and a Shine Button, and a sheet with the same links on phones.