Skip to content
Ginga UI
Ginga UI
日本語

Getting started

  • Overview
  • Quick start
  • Theme generation
  • Custom rendering
  • All components

Forms

  • Button
  • Checkbox
  • Input
  • Radio
  • Questionnaire
  • SegmentedControl
  • Select
  • ComboBox
  • NumberField
  • SearchField
  • Slider
  • Switch
  • FormControl

Display

  • Accordion
  • Alert
  • AlertDialog
  • Badge
  • CodeBlock
  • Card
  • Dialog
  • Drawer
  • Image
  • List
  • Popover
  • Menu
  • Tooltip
  • Table
  • Tab
  • Toast
  • Trace

Typography

  • Heading
  • Paragraph

Navigation

  • Anchor

Layout

  • Box

Resources

  • Changelog
  • GitHub (opens in a new tab)

Logo: Twemoji (opens in a new tab) (CC-BY 4.0)

Custom rendering

Every component accepts render. Pass a function to draw the root element with another component such as next/link while keeping ginga-ui's styles and behavior.

Basic usage

Pass render a function that receives the props needed for rendering and returns an element. The following example draws Anchor with the Next.js Link so that it navigates on the client side.

import { Anchor } from "@ginga-ui/core";
import NextLink from "next/link";

export function DocsLink() {
  return (
    <Anchor href="/docs" render={(props) => <NextLink {...props} />}>
      Docs
    </Anchor>
  );
}

A link that looks like a button works the same way. To use Button as a link, use <Anchor variant="button"> instead.

<Anchor
  href="/signup"
  variant="button"
  render={(props) => <NextLink {...props} />}
>
  Sign up
</Anchor>

Requirements

  • Render the same kind of element as the default, such as an a element for Anchor or a button element for Button. A different kind of element breaks keyboard interaction and screen reader output
  • Pass all received props, including ref, to the element. Dropping the ref breaks focus management and events
  • Return a single element, not a fragment

Merging your own props

The received props include ginga-ui's class names and data attributes. When adding your own class name, combine it instead of overwriting it.

<Box
  render={({ className, ...props }) => (
    <div {...props} className={`${className} my-layout`} />
  )}
>
  …
</Box>

Reading state

Components built on React Aria Components pass state such as pressed or selected as the second argument. For components built on plain HTML elements, such as Box and Card, it is undefined.

<Button
  render={(props, { isPressed }) => (
    <button {...props} data-pressed-label={isPressed ? "pressed" : undefined} />
  )}
>
  Submit
</Button>

Which element is replaced

render is passed to the element that receives className. These components made of several elements need attention.

ComponentReplaced element
AnchorThe a element. Without href, render is not used and a span is drawn
ModalThe inner modal. The backdrop overlay is not replaced
Drawer / PopoverThe outer element. Elements added inside are not replaced
TableThe table element. The outer scroll container is not replaced
AccordionTriggerThe inner button. The outer heading is not replaced
ToastRegionThe region that lists toasts. Individual toasts are not replaced
DialogTrigger / PopoverTriggerThey have no DOM element and do not accept render