shadcn.io is not affiliated with official shadcn/ui
Environment Pill Banner Block for React
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.
Installation
Overview
An environment pill for React with Base UI, so engineers always know which deployment they are looking at. A start-aligned capsule sits in a muted shell between the page's rails: a warning-coloured status dot and "Staging", a hairline, the branch name and the commit hash (the hash in an outline Badge, both in mono) and a ghost copy button that puts the hash on the clipboard, swaps its icon for a check and says "Commit hash copied" to screen readers. The pill is named for its environment, "Staging environment". On phones it wraps to a rounded card with the environment and the copy button on top and the build under them. It follows your theme, and the status colour stays on the dot. It's built from Guides, Status, Badge and Copy Button.
FAQ
How do I fill in the environment, branch and commit?
They are constants at the top of the file (DEPLOY). Fill them from your build: pass them as props from a server component, or read them from environment variables your host exposes at build time, such as a branch name and a commit SHA, and shorten the SHA to seven characters. Never read the date at render time: it makes the server and the browser disagree.
How do I change the colour per environment?
Swap the variant on Status: warning for staging, info for preview, success for production, destructive for a broken build. The word beside the dot always says what the environment is, so the colour is never the only signal. Keep the text in the foreground colours.
What does the copy button do when the clipboard refuses?
Copy Button writes the hash with navigator.clipboard. If the browser refuses it (no permission, or a page that isn't served over HTTPS) the icon turns into a cross and the status line says "Couldn't copy" instead of "Commit hash copied". After three seconds the copy icon comes back. The button's accessible name includes the hash, "Copy commit hash a3f7c2e".
How do I hide it in production?
Render the block only when your environment isn't production: wrap it in a condition on the server (if (env === "production") return null). Because it holds no state of its own, it stays a server component apart from the copy button.
How do I pin it to the bottom corner of the screen?
The pill renders in flow so the preview and a stack of blocks can see it. To float it, add fixed inset-x-4 bottom-4 z-50 mx-auto to the pill (the section named for the environment) and remove the block's wrapper padding if the pill lives on its own. To keep it at the start corner instead of the centre, use fixed bottom-4 start-4 z-50 and drop inset-x-4 and mx-auto. Keep room for the home indicator with bottom-[max(1rem,env(safe-area-inset-bottom))].
How does it fit on a phone?
Below sm the pill is a rounded card: the dot and "Staging" with the copy button at the end on the first row, the branch and the hash under them (they wrap rather than overflow). From sm it is one row with a hairline between the environment and the build. At 320 pixels nothing scrolls sideways, and in a right-to-left layout it mirrors.
Related
- Pro
A release pill for a knowledge base: a New badge, one sentence about semantic search, a small Try it link and a dismiss button that folds the block away.
- Pro
API Health Live Banner
Live statusA live-health callout for an API gateway: a green status dot, an all-operational heading, a sentence with the median response time and the one slow minute, a status-page link, and a framed figure of the last 30 minutes as slim latency bars.
- v3.9v4.0Pro
Full-Bleed Version Banner
Top barsAn upgrade band for a UI kit: a tinted strip that shows the version you run next to the latest, v3.9.2 to v4.0, a short note and a link to the changelog.
- 3Pro
An unsaved-changes pill for a form builder: a rolling count of changes, a small Save button and a ghost Discard, settling on a saved or discarded message.
- Pro
Saved Draft Top Bar Banner
Utility barsA top bar for a writing tool that reports its autosave with a green dot and a ticking time, and a Restore previous button that swaps in place to Restored with an Undo.
- Pro
An install pill for a plant-care app: a greyscale app tile, the name, a row of stars with its score, a small Get link and a dismiss button that folds the block away.