Nuxt
Install CLI
Install the Elements CLI to your system. This will add the nve command to your path and provide several helpful commands for working with Elements.
curl -fsSL https://nvidia.github.io/elements/install.sh | bash
curl -fsSL https://nvidia.github.io/elements/install.cmd -o install.cmd && install.cmd && del install.cmd
# install the CLI
npm install -g @nvidia-elements/cli
Create a New Project
Use the Elements CLI to quickly bootstrap a new nuxt project with the necessary dependencies:
nve project.create --type=nuxt
Setup an Existing Project
Setup an existing project to use Elements you can use the setup command to add the necessary dependencies and configure the MCP server.
nve project.setup
If not yet done, install NodeJS. NodeJS is a JavaScript runtime that has a large ecosystem of tooling and packages for Web Development. Once installed the Node Package Manager (NPM) will be available for use.
Manual Integration
If installing to an existing project, install the core dependencies:
# install core dependencies
npm install @nvidia-elements/themes @nvidia-elements/styles @nvidia-elements/core
Once installed import and use Elements within Nuxt Vue SFC files. Since Nuxt builds on top of Vue, the same Vue template syntax applies.
TypeScript types
To get type checking and autocomplete for Elements in templates (and to have invalid props reported by the IDE and build), add a reference to the custom-elements Vue types.
Create or update env.d.ts in your project root:
/// <reference path="./node_modules/@nvidia-elements/core/dist/custom-elements-vue.d.ts" />
Nuxt includes this file when running nuxi typecheck. To fail the build on type errors, run type checking before the build:
// package.json
{
"scripts": {
"build": "nuxi typecheck && nuxt build"
}
}
Configuration
Configure nuxt.config.ts to recognize Elements as custom elements and set up the global theme attributes.
// nuxt.config.ts
export default defineNuxtConfig({
vue: {
compilerOptions: {
isCustomElement: tag => tag.startsWith('nve-')
}
},
app: {
head: {
htmlAttrs: {
lang: 'en',
'nve-theme': 'dark',
'nve-transition': 'auto'
}
}
}
});
Styles
Import the Elements theme and utility styles in your app.vue file. This ensures styles are available globally throughout your application.
<style>
@import '@nvidia-elements/themes/fonts/inter.css';
@import '@nvidia-elements/themes/index.css';
@import '@nvidia-elements/themes/dark.css';
@import '@nvidia-elements/styles/layout.css';
@import '@nvidia-elements/styles/typography.css';
@import '@nvidia-elements/styles/view-transitions.css';
</style>
Usage
Import element definitions in the <script setup> block of your Vue SFC files.
import '@nvidia-elements/core/alert/define.js';
Properties and events then work via the standard Vue template syntax.
// - status - HTML attribute
// - :closable - can update via attributes or JavaScript property binding
// - @close - event listener binding for 'close' custom event
<nve-alert-group status="success">
<nve-alert :closable="true" @close="closeAlert">hello there!</nve-alert>
</nve-alert-group>
Layouts
Use Elements within Nuxt layouts to create consistent page structures.
<!-- layouts/default.vue -->
<template>
<nve-page>
<nve-page-header slot="header">
<nve-logo slot="prefix" size="sm"></nve-logo>
<h2 slot="prefix">My App</h2>
</nve-page-header>
<main nve-layout="column gap:lg pad:lg">
<slot />
</main>
</nve-page>
</template>
<script setup lang="ts">
import '@nvidia-elements/core/page/define.js';
import '@nvidia-elements/core/page-header/define.js';
import '@nvidia-elements/core/logo/define.js';
</script>
Routing
Elements work seamlessly with Nuxt's built-in routing. Use NuxtLink within Elements components for client-side navigation.
<nve-tabs>
<nve-tabs-item selected>
<NuxtLink to="/">Home</NuxtLink>
</nve-tabs-item>
<nve-tabs-item>
<NuxtLink to="/about">About</NuxtLink>
</nve-tabs-item>
</nve-tabs>