@gluonjs/quarks


@gluonjs/quarks / packages/quarks/src / quark

Function: quark()

quark<TagName>(tagName): QuarkFactory<TagName, ElementFor<TagName>>

Type Parameters

TagName

TagName extends string

Parameters

tagName

TagName

Returns

QuarkFactory<TagName, ElementFor<TagName>>

Example

Create and cache a typed native-element factory that accepts explicit property, boolean, event, ARIA, data, class, style, and ref bindings:

ts
import { html } from '@gluonjs/core';
import {
  fragment,
  htmlTagNames,
  q,
  quark,
  unsafeQuarkProps,
  type AriaAttributeName,
  type QuarkAriaProps,
  type QuarkAttributeValue,
  type QuarkCommonProps,
  type QuarkDataProps,
  type QuarkMap,
  type QuarkProps,
  type UnsafeQuarkProps,
} from '@gluonjs/quarks';

const ariaName: AriaAttributeName = 'label';
const attributeValue: QuarkAttributeValue = 'Add to bag';
const aria = { [ariaName]: attributeValue } satisfies QuarkAriaProps;
const data = { analyticsAction: 'purchase' } satisfies QuarkDataProps;
const common = { id: 'add-to-bag', class: 'primary' } satisfies QuarkCommonProps<HTMLButtonElement>;
const props = { ...common, type: 'button', aria, data, children: 'Add to bag' } satisfies QuarkProps<HTMLButtonElement>;
const future = unsafeQuarkProps<HTMLButtonElement>({ 'vendor-future-key': true });
const unsafe: UnsafeQuarkProps<HTMLButtonElement> = future;
const Button = quark('button');
const tags: QuarkMap = q;
const actions = fragment([Button(props), Button(unsafe), tags.a({ href: '/bag', children: html`View bag` })]);
console.log(Button.tagName, htmlTagNames.includes('button'), actions);