Skip to content
Halorav0.1.0

Components

Code

A readable code block in both themes.

Block#

app.js
import { initTheme } from '@originlabsbr/halora/theme';
// keep the key this site already uses
initTheme({ storageKey: 'theme' });
HTML
<figure class="ha-code" style="width:100%;margin:0">
  <div class="ha-code__bar"><span>app.js</span></div>
  <pre tabindex="0"><code><span class="ha-tok-keyword">import</span> <span class="ha-tok-punct">{</span> initTheme <span class="ha-tok-punct">}</span> <span class="ha-tok-keyword">from</span> <span class="ha-tok-string">'@originlabsbr/halora/theme'</span><span class="ha-tok-punct">;</span>
<span class="ha-tok-comment">// keep the key this site already uses</span>
<span class="ha-tok-function">initTheme</span><span class="ha-tok-punct">({</span> storageKey<span class="ha-tok-punct">:</span> <span class="ha-tok-string">'theme'</span> <span class="ha-tok-punct">});</span></code></pre>
</figure>

Give the pre tabindex="0" so keyboard users can scroll long lines. Add your own copy button inside .ha-code__bar; this site uses an ha-icon-button.

Inline code#

Set data-theme on the root element.

HTML
<p>Set <code class="ha-inline-code">data-theme</code> on the root element.</p>

Token classes#

ClassPrism equivalentToken
ha-tok-keyword.token.keyword, .tag, .selectorcode-keyword
ha-tok-string.token.string, .attr-valuecode-string
ha-tok-function.token.function, .class-namecode-function
ha-tok-number.token.number, .booleancode-number
ha-tok-constant.token.property, .attr-name, .variablecode-constant
ha-tok-comment.token.commentcode-comment
ha-tok-punct.token.punctuation, .operatorcode-punct

Inside .ha-code, Prism and Gatsby Remark class names are styled too, so a Prism-based blog can adopt the colors without changing its markup.

Accessibility#

  • Every token color reaches 4.5:1 on the code background in light and dark, for both brands. The contrast gate checks them.
  • Never rely on color alone to carry meaning in code samples.

Edit this page on GitHub

Type to search.