Skip to content
Norn
Menu

norn-search

Site search: a search landmark with a field that lists results as the visitor types, from a Pagefind index. Without a script, or before the index is built, it is a plain form that searches the site on the web: @action with the query as q, limited to @site. The field has a magnifier at its start, and its label as the placeholder once the script runs. The results float over the page on a raised surface. The status texts are in the page, hidden, and the script shows them. Each falls back to the site's componentStrings, then English. The script picks the status for a count by the plural rules of the nearest lang, with Intl.PluralRules, and formats the number for it. An empty form falls back to results-other. Build the index with Pagefind after Eleventy. Results read their title and excerpt from the index; the excerpt keeps only Pagefind's <mark> highlights.

<norn-search> a component, from @allons-y/webc-patterns

Examples

Color scheme
Width

Open on its own

Source
<norn-search @site="example.com" :@bundle="url('/assets/no-index.js')"></norn-search>

Props

Write them with the @ prefix, and :@ for an expression.

NameTypeDescription
@bundle string Pagefind's script. Pass url('/pagefind/pagefind.js') under a path prefix. Falls back to /pagefind/pagefind.js.
@action string Where the plain form sends the query. Falls back to https://duckduckgo.com/.
@site string The site's host, sent with the plain form as sites, to keep results on the site.

Slots

NameDescription
label The field's label, the button's text, and the landmark's name, as one element. Falls back to "Search".
none The status when nothing matches. Falls back to "No results".
results-one The status for a count in the one plural category, with {count} for the number. Falls back to "{count} result", or to results-other when the site's strings set only that.
results-other The status for any other count. Falls back to "{count} results".
results-zero The status for the zero category.
results-two The status for the two category.
results-few The status for the few category.
results-many The status for the many category.

Tokens

The global tokens from tokens.json the component reads. Set one in a project's tokens.css to change it everywhere.

Type a value to try it in every example above. Reset puts the default back.

Token Type Default Override
--norn-ui-accentThe brand color, shared by every component. <color> #2346d4
--norn-ui-border-strongEdge of a control, such as a field. At least 3:1 on the page surface, which WCAG 1.4.11 asks of a control's boundary. <color> light-dark(#7a8194, #6f7789)
--norn-ui-border-radiusCorner radius. <length> 6px
--norn-ui-state-hoverShare of the text color mixed into the background while the pointer is over a control. <percentage> 8%
--norn-ui-state-pressShare of the text color mixed into the background while a control is pressed, and of the accent on a selected or current item. <percentage> 12%
--norn-ui-motion-durationLength of a state change, such as a hover layer. <time> 150ms
--norn-ui-motion-easingEasing for every transition. <easing-function> cubic-bezier(0.2, 0, 0, 1)
--norn-ui-control-heightHeight of a button, field, or tab. A component raises it to 2.75rem for a coarse pointer. <length> 2.25rem
--norn-ui-icon-sIcon size beside text. It follows the font size. <length> 1em
--norn-ui-shadowElevation shadow. For things that float, such as search results. <shadow> 0 6px 20px light-dark(rgb(22 24 29 / 0.08), rgb(0 0 0 / 0.4))
--norn-surface-basePage surface. Light and dark values. <color> light-dark(#ffffff, #101216)
--norn-surface-raisedRaised surface. <color> light-dark(hsl(40, 14%, 96%), #242932)
--norn-text-baseText color. <color> light-dark(#16181d, #eceef3)
--norn-text-mutedSecondary text color. <color> light-dark(#4b5160, #a4abba)
--norn-font-size-sSmall text: captions, code, navigation, and notes. <length> 0.875rem
--norn-space-2xsSmallest spacing step. <length> 0.25rem
--norn-space-xsExtra small spacing step. <length> 0.5rem
--norn-space-sSmall spacing step. <length> 0.75rem