Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Get started

Next.js, Angular & Vue

The components are built with React, but they work inside Angular and Vue 3 apps too. You mount each one in a small wrapper component that passes props in and sends events back out. In Next.js and other React Server Components frameworks they work as they are; see [Next.js and Server Components](#nextjs).

How it works

Each wrapper does three things:

  1. Creates a React root on an element it renders, with createRoot.
  2. Renders the component into it with createElement, passing the wrapper's inputs as props. It renders again whenever an input changes.
  3. Unmounts the React root when the wrapper is destroyed, so nothing leaks.

Install React alongside the library (npm install @vjdesigns/vjdesigns-ui react react-dom). The wrappers use createElement instead of JSX, so you don't need to change your compiler settings.

Angular

Add the stylesheet

Add the library's CSS to the styles array in angular.json:

angular.jsonjson
"styles": [
  "node_modules/@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css",
  "src/styles.css"
]

Create a wrapper

This standalone component renders the library's Button into its host element. Its inputs become props, and the click comes back out as an Angular output.

vj-button.component.tsts
import {
  AfterViewInit,
  Component,
  ElementRef,
  EventEmitter,
  Input,
  OnChanges,
  OnDestroy,
  Output,
  ViewChild,
} from "@angular/core";
import { createElement, type MouseEvent as ReactMouseEvent, type ReactElement } from "react";
import { createRoot, Root } from "react-dom/client";
import {
  Button,
  type ButtonProps,
  type ButtonVariant,
  type Size,
  type Tone,
} from "@vjdesigns/vjdesigns-ui";

// Button has overloaded types (for `href` and `as`). Narrowing it here lets createElement type-check.
const ReactButton = Button as (props: ButtonProps) => ReactElement;

@Component({
  selector: "vj-button",
  standalone: true,
  template: `<span #host></span>`,
})
export class VjButtonComponent implements AfterViewInit, OnChanges, OnDestroy {
  @ViewChild("host", { static: true }) host!: ElementRef<HTMLElement>;

  @Input() label = "";
  @Input() variant: ButtonVariant = "solid";
  @Input() tone: Tone = "primary";
  @Input() size: Size = "md";
  @Input() disabled = false;
  @Output() clicked = new EventEmitter<MouseEvent>();

  private root?: Root;

  ngAfterViewInit() {
    this.root = createRoot(this.host.nativeElement);
    this.render();
  }

  ngOnChanges() {
    this.render();
  }

  ngOnDestroy() {
    this.root?.unmount();
  }

  private render() {
    this.root?.render(
      createElement(
        ReactButton,
        {
          variant: this.variant,
          tone: this.tone,
          size: this.size,
          disabled: this.disabled,
          onClick: (event: ReactMouseEvent) => this.clicked.emit(event.nativeEvent),
        },
        this.label // the button's text is passed as children
      )
    );
  }
}

Use it

app.component.tsts
import { Component } from "@angular/core";
import { VjButtonComponent } from "./vj-button.component";

@Component({
  selector: "app-root",
  standalone: true,
  imports: [VjButtonComponent],
  template: `<vj-button label="Submit" tone="primary" (clicked)="onSubmit()" />`,
})
export class AppComponent {
  onSubmit() {
    console.log("Submitted");
  }
}

Use the examples from these docs

Every example in these docs has an Angular tab with ready-to-paste files: the example itself (a React .tsx file), an Angular component that mounts it, and how to use it. To compile the .tsx file, add one line to tsconfig.json:

tsconfig.jsonjson
"compilerOptions": {
  "jsx": "react-jsx"
}

Vue 3

Add the stylesheet

main.tsts
import "@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css";

Create a wrapper

This component mounts the React Button when it loads and re-renders it whenever its props change. The click is sent back out as a Vue event.

VjButton.vuevue
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref, watch } from "vue";
import { createElement, type MouseEvent as ReactMouseEvent, type ReactElement } from "react";
import { createRoot, type Root } from "react-dom/client";
import {
  Button,
  type ButtonProps,
  type ButtonVariant,
  type Size,
  type Tone,
} from "@vjdesigns/vjdesigns-ui";

// Button has overloaded types (for `href` and `as`). Narrowing it here lets createElement type-check.
const ReactButton = Button as (props: ButtonProps) => ReactElement;

const props = withDefaults(
  defineProps<{
    label: string;
    variant?: ButtonVariant;
    tone?: Tone;
    size?: Size;
    disabled?: boolean;
  }>(),
  { variant: "solid", tone: "primary", size: "md", disabled: false }
);

const emit = defineEmits<{ click: [event: MouseEvent] }>();

const host = ref<HTMLElement | null>(null);
let root: Root | undefined;

function render() {
  root?.render(
    createElement(
      ReactButton,
      {
        variant: props.variant,
        tone: props.tone,
        size: props.size,
        disabled: props.disabled,
        onClick: (event: ReactMouseEvent) => emit("click", event.nativeEvent),
      },
      props.label // the button's text is passed as children
    )
  );
}

onMounted(() => {
  root = createRoot(host.value!);
  render();
});

watch(() => ({ ...props }), render);

onBeforeUnmount(() => root?.unmount());
</script>

<template>
  <span ref="host" />
</template>

Use it

App.vuevue
<script setup lang="ts">
import VjButton from "./VjButton.vue";

const onSubmit = () => console.log("Submitted");
</script>

<template>
  <VjButton label="Submit" tone="primary" @click="onSubmit" />
</template>

Use the examples from these docs

Every example in these docs has a Vue tab with ready-to-paste files: the example itself (a React .tsx file), a Vue component that mounts it, and how to use it. To compile the .tsx file as React, add two lines to tsconfig.app.json (Vue templates aren't affected):

tsconfig.app.jsonjson
"compilerOptions": {
  "jsx": "react-jsx",
  "jsxImportSource": "react"
}

Wrapping other components

Every component wraps the same way. Pass its props into createElement, and send its callbacks back out as Angular outputs or Vue emits. For CheckBox, that means sending onCheckedChange back out; for Select, onValueChange.

Compound components

For components made of parts, such as Tabs or Modal, wrap the whole composition in one React component and mount that, rather than wrapping each part separately.

Next.js and Server Components

From 2.5.0 the library works in React Server Components, such as the Next.js App Router. No wrapper is needed. Interactive components (anything with state, effects or context, such as Button, DataGrid or Modal) are marked "use client", so you can render them from a Server Component like any client component. Utilities such as cx, sortRows and getLocaleDirection have no directive, so you can call them on the server too. Every component also renders on the server for the first paint.

Put the providers in a small client file of your own, and render it from the root layout:

app/providers.tsxtsx
"use client";
import { LocaleProvider, ToastProvider } from "@vjdesigns/vjdesigns-ui";
import es from "@vjdesigns/vjdesigns-ui/locales/es";
import type { ReactNode } from "react";

export function Providers({ children }: { children: ReactNode }) {
  return (
    <LocaleProvider locale="es" messages={es}>
      <ToastProvider>{children}</ToastProvider>
    </LocaleProvider>
  );
}
app/layout.tsxtsx
// A Server Component
import "@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css";
import { getLocaleDirection } from "@vjdesigns/vjdesigns-ui";
import { Providers } from "./providers";

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="es" dir={getLocaleDirection("es")}>
      <body>
        <Providers>{children}</Providers>
      </body>
    </html>
  );
}

Two rules of Server Components

  • Functions can't be passed from a Server Component to a client one. That includes event handlers like onClick, DataGrid columns with cell or value functions, and the locale catalogs (their plural messages are functions, which is why LocaleProvider goes in the providers file). Render those components from your own "use client" file.
  • Compound parts can't be reached with a dot from a Server Component (Tabs.List, Menu.Item): Next.js reports "You cannot dot into a client module". Use them inside a "use client" file, or use the named exports where they exist (CardHeader, CardBody, NavbarBrand).

Pro components are marked "use client" too. Pro's toCsv and getGridRows work on the server; downloadCsv saves a file, so it runs in the browser.