Independent themes and nested overlays
Two workspaces share one document with independent tokens, direction and motion. Dialogs, nested choices and an external portal inherit the owning workspace.
Keyboard
- Open either workspace dialog, then open its nested confirmation. Escape returns focus to the owning trigger.
- Tab remains within an open modal. Choice popups keep the same theme and reading direction.
States covered
- Local light and dark scopes
- Nested modal focus
- External portal container
- Live token changes
- Scoped reduced motion
Install this complete example and its component dependencies.
npx shadcn@latest add https://ui.bld8.dev/r/example-scoped-workspaces-overlays.jsonComplete source
/*!
MIT License
Copyright (c) 2026 Jaison
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import '@bld8/ui/styles.css';
import {useRef,useState} from 'react';
import {Button,Dialog,DialogClose,Popover,Select,UIProvider,useUIConfig,useReducedMotionPreference} from '@bld8/ui';
function ScopeReadout(){const ui=useUIConfig(),reduced=useReducedMotionPreference();return <p className="bui-hint" data-scope-readout>{ui.locale+' | '+ui.direction+' | '+(reduced?'reduced':'system')}</p>;}
function Review({arabic=false}:{arabic?:boolean}){return <div style={{display:'grid',gap:16,padding:24,background:'var(--bui-surface)',borderRadius:12}}>
<h3>{arabic?'مساحة المراجعة':'Review workspace'}</h3><ScopeReadout/>
<Dialog title={arabic?'لوحة المراجعة':'Review panel'} description={arabic?'تخصيص محلي دون تغيير الصفحة.':'Local configuration stays with this workspace.'} trigger={<Button variant="accent">{arabic?'فتح المراجعة':'Open review panel'}</Button>}>
<div style={{display:'grid',gap:20}}><Select label={arabic?'الحالة':'Review status'} defaultValue="in-review" options={[{value:'in-review',label:arabic?'قيد المراجعة':'In review'},{value:'approved',label:arabic?'معتمد':'Approved'}]}/>
<Popover title={arabic?'ملاحظات':'Review notes'} trigger={<Button variant="secondary">{arabic?'تفاصيل إضافية':'More review details'}</Button>}><p>{arabic?'الخيارات تحتفظ بنفس الاتجاه والألوان.':'Popup tokens follow this workspace.'}</p></Popover>
<Dialog title={arabic?'تأكيد المراجعة':'Confirm review'} trigger={<Button>{arabic?'تأكيد':'Open confirmation'}</Button>}><DialogClose>{arabic?'رجوع':'Back to review'}</DialogClose></Dialog>
<DialogClose/>
</div>
</Dialog>
</div>;}
export default function ScopedWorkspaceExample(){
const external=useRef<HTMLDivElement>(null),[alternate,setAlternate]=useState(false);
return <div style={{display:'grid',gap:20}}><Button variant="secondary" onClick={()=>setAlternate(value=>!value)}>Change local accent</Button>
<div style={{display:'grid',gridTemplateColumns:'repeat(auto-fit,minmax(min(100%,260px),1fr))',gap:20}}>
<UIProvider theme="light" locale="en-AU" direction="ltr" tokens={{'--bui-accent':alternate?'#B7E4CD':'#FFD900'}}><div data-scope-workspace="light"><Review/></div></UIProvider>
<UIProvider theme="dark" locale="ar" direction="rtl" motion="reduced" tokens={{'--bui-accent':'#FFD900'}} portalContainer={external}><div data-scope-workspace="dark"><Review arabic/></div></UIProvider>
</div><div ref={external} data-external-scope-portals=""/>
</div>;
}