@htmlbricks/hb-area-code
v0.76.5
Published
Frameless code area (no Bulma `box`): copy + optional success tag floated top-right over the `<pre><code>` snippet; `:host` and root wrapper have no margin or padding. Copy dispatches `clipboardCopyText` with `{ text }`. Theme follows `bulma-wc-host-theme
Readme
hb-area-code
Category: utilities · Tags: utilities, developer
Summary
hb-area-code renders content in a frameless root (no Bulma box): copy + optional “Copied” tag are positioned top-right over the <pre><code> snippet. Copy uses navigator.clipboard.writeText and emits clipboardCopyText with { text }. The host and root wrapper have no extra margin or padding; spacing around the snippet is up to the parent or ::part(content).
Behaviour
- Copy: each click writes
contentto the clipboard, shows confirmation (~1.6s, timer resets on repeat), and dispatchesclipboardCopyTextwithdetail.text. content: single source for display and clipboard.id: optional; when set, it is applied to the roothb-area-codewrapper inside the shadow tree.
Markup
- Root:
hb-area-code(nobox/ outer card frame; no margin or padding on the host root wrapper). - Wrapper
hb-area-code-body(position: relative): floatinghb-area-code-float(absolute top-right) with optionaltag is-success is-size-7, thenbutton is-small(theme-default fill, nois-light) with Bootstrap Iconsbi-clipboard/bi-clipboard-check. - Snippet:
<pre part="content" class="hb-area-code-snippet">and<code class="hb-area-code-snippet-code">(uniform insets; extrapadding-inline-endkeeps long first lines clear of the copy controls).
Custom element
hb-area-code
Attributes
| Attribute | Notes |
| --- | --- |
| content | Shown in the snippet and copied (string). |
| id | Optional string on the inner root hb-area-code element. |
Events
| Event | detail |
| --- | --- |
| clipboardCopyText | { text: string } |
Styling
- Parts:
content→<pre>(seeextra/docs.ts). - Theme: same stack as other hb-* components (
bulma-wc-host-theme-tokenson the shadow:host): systemprefers-color-scheme, thendata-theme/.theme-*onhtml,body, or the custom element host.color-schemeon the host follows that order so native chrome stays coherent. The snippet background and border are built withhsl(var(--bulma-scheme-h), var(--bulma-scheme-s), var(--bulma-scheme-main-bis-l))andborder-lprimitives so the surface stays valid in the shadow tree; text prefers--bulma-textwith the samehsl(…, --bulma-text-l)fallback. - Corners: snippet, copy button, and tag use
border-radius: 0(no rounded corners inside this component). - Dark mode: the default strip follows Bulma tokens on the shadow
:host(systemprefers-color-schemeis handled bybulma-wc-host-theme-tokens, somain-bis-lis already a dark gray on a dark scheme). The deeper “well” (scheme-main-l,border-l, inset highlight) applies only when dark is explicit —data-theme="dark"or.theme-darkonhtml,body, or the host — so we never mix OS dark with light-tokenscheme-main-l(that would read as white).
TypeScript
types/webcomponent.type.d.ts
Example
<hb-area-code content="npm install @htmlbricks/hb-area-code"></hb-area-code>