frontend: one component = one dir for hive-btn/hive-dialog/hive-toast
Splits the shadow-DOM custom elements out of the flat shared/src layout
into per-component directories:
hive-btn/hive-btn.{js,css}
hive-dialog/hive-dialog.{js,css}
hive-toast/hive-toast.{js,css}
hive-dialog and hive-toast were previously defined inline inside
modal.js alongside the openDialog/themedConfirm/themedPrompt/themedToast
orchestration helpers; modal.js is now a slim entry point that imports
the two component modules for their customElements.define side effect
and keeps only the orchestration functions, which aren't components
themselves. hive-dialog.js now imports hive-btn.js directly (it's the
actual consumer that creates <hive-btn> elements), instead of modal.js
importing it on hive-dialog's behalf.
Pulled the identical shadow-root-plus-adopted-stylesheet boilerplate
(previously duplicated between modal.js's local attachShadow() and
hive-btn.js's inline version) into a shared shadow-css.js helper,
attachShadowCss(host, cssText, shadowInit), used by all three
components. Behaviorally identical — same attachShadow() options per
component, just deduplicated.
No external import paths changed: every consumer only ever imported
the package-level @hive/shared/modal.js entry point, never the
component internals directly, so this is fully internal to the shared
package. Verified with a full frontend build (dashboard + agent
bundles).
This commit is contained in:
parent
44651544a8
commit
edf1c5a17f
8 changed files with 172 additions and 169 deletions
15
frontend/packages/shared/src/shadow-css.js
Normal file
15
frontend/packages/shared/src/shadow-css.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// attachShadowCss(host, cssText, shadowInit) — attach an open shadow root
|
||||
// to `host`, adopt `cssText` as a constructed stylesheet, and return the
|
||||
// root. Shared by every shadow-DOM custom element (hive-dialog, hive-toast,
|
||||
// hive-btn) so the CSSStyleSheet-adoption boilerplate lives in one place
|
||||
// instead of being copy-pasted per component. `shadowInit` extends the
|
||||
// `attachShadow()` options past `mode: 'open'` — e.g. `hive-btn` passes
|
||||
// `{ delegatesFocus: true }` so `.focus()` on the host reaches the inner
|
||||
// `<button>`.
|
||||
export function attachShadowCss(host, cssText, shadowInit = {}) {
|
||||
const root = host.attachShadow({ mode: 'open', ...shadowInit });
|
||||
const sheet = new CSSStyleSheet();
|
||||
sheet.replaceSync(cssText);
|
||||
root.adoptedStyleSheets = [sheet];
|
||||
return root;
|
||||
}
|
||||
Loading…
Reference in a new issue