Sakai Nuxt Admin Template

repository·main·Indexed 43 days ago

https://github.com/who-jonson/sakai-nuxt

An admin template for Nuxt 3 featuring a pre-configured layout, menu system, and integration with PrimeVue. It includes a PrimeVue Nuxt module for granular component registration, a theme-switching composable via useAppTheme(), and a dashboard implementation using PrimeFlex, PrimeIcons, and PrimeVue components like DataTable and Chart.

Tokens
2.5K
Snippets
7
Records
14
Agent score
55%

What's inside Sakai Nuxt

  1. Understand the Sakai project structure

    main

    The project is organized into two primary areas:

    1. Application Layout: Managed via src/app.vue, which serves as the main component containing the base layout logic (menu state, layout modes, etc.).
    2. Resources: Static assets and styling, located in the src/assets/ folder (e.g., SASS structures).

    The main layout in app.vue is composed of child components including topbar, menu, and footer.

  2. Configure the application menu

    main

    The menu is a separate component defined in AppMenu.vue and follows the PrimeVue MenuModel API.

    To customize the menu items, navigate to the data section of the app.vue file and define your own nested structure using the menu property.

  3. Get started with Sakai Nuxt

    main

    To set up the Sakai Admin Template locally, clone the repository and install dependencies using your preferred package manager. After installation, start the development server to view the application at http://localhost:3000/.

    Installation

    pnpm install
    # or
    npm install
    # or
    yarn install

    Running the development server

    pnpm dev
    # or
    npm run dev
    # or
    yarn dev
    pnpm install
    pnpm dev
  4. Customize the PrimeVue theme and SASS variables

    main

    Sakai is compatible with any PrimeVue theme (such as Material, Tailwind, or Bootstrap) because layout colors are derived from the theme via CSS variables. By default, it uses the free Saga, Arya, and Vela themes.

    To customize specific layout variables, modify the _variables.scss file located in src/layout/.

    Available variables in src/assets/_variables.scss:

    $fontSize: 1rem;
    $borderRadius: 12px;
    $transitionDuration: .2s;
    $maskBg: rgba(0, 0, 0, 0.4);
  5. Manage PrimeVue component registration

    main

    The module provides granular control over which PrimeVue components are registered in your Nuxt application. By default, it attempts to register a large set of standard PrimeVue components.

    Inclusion and Exclusion

    • To include only specific components: Use the components.include array. You can pass a simple string name or an object to control the global status of that specific component.
    • To exclude specific components: Use the components.exclude array to remove components from the default set.
    • Global vs Local: Certain components like ConfirmDialog, ConfirmPopup, Toast, and Tooltip are automatically treated as global by the module logic.

    Supported Component Names

    Common components include: Accordion, AutoComplete, Avatar, Button, Calendar, Card, Checkbox, DataTable, Dialog, Dropdown, InputText, Menu, ProgressBar, Sidebar, SelectButton, Slider, SplitButton, Toast, and many others.

  6. Implement a dashboard with PrimeVue components

    main

    The dashboard page demonstrates how to compose various PrimeVue components within a Nuxt 3 application using PrimeFlex for layout. Key components used include:

    • DataTable: Displays product lists with features like pagination (:paginator="true"), sorting (:sortable="true"), and custom body templates for images and formatted currency.
    • Chart: Renders data visualizations (e.g., type="line") using a lineData object containing labels and datasets.
    • Menu: Used as a popup menu via the :popup="true" prop, triggered by a button using $refs.menuName.toggle($event).
    • Button: Provides interactive elements, often styled with PrimeIcons (e.g., icon="pi pi-search").
    • ClientOnly: Wraps components like Menu that may rely on browser-specific APIs to prevent SSR (Server-Side Rendering) mismatches.

    Layout is managed using a grid system (e.g., class="grid", class="col-12 lg:col-6") provided by PrimeFlex.

    <template>
      <div class="grid">
        <!-- Stat Cards -->
        <div class="col-12 lg:col-6 xl:col-3">
          <div class="card mb-0">
            <!-- Card Content -->
          </div>
        </div>
    
        <!-- Data Table -->
        <div class="col-12 xl:col-6">
          <div class="card">
            <DataTable :value="products" :rows="5" :paginator="true" responsive-layout="scroll">
              <Column field="name" header="Name" :sortable="true" />
            </DataTable>
          </div>
        </div>
    
        <!-- Chart -->
        <div class="col-12 xl:col-6">
          <div class="card">
            <Chart type="line" :data="lineData" />
          </div>
        </div>
      </div>
    </template>
  7. Configure the PrimeVue Nuxt module

    main

    The primevue module allows you to configure PrimeVue within a Nuxt 3 application. You can control component registration (including/excluding specific components), global settings, ripple effects, and input styles via the primevue configuration key in your nuxt.config.ts.

    Configuration Options

    OptionTypeDefaultDescription
    components.globalbooleantrueWhether to register components globally.
    components.includeArray<PrimevueComponents | { name: PrimevueComponents, global?: boolean }>undefinedA list of specific components to include. If provided, only these components will be registered.
    components.excludeArray<PrimevueComponents>undefinedA list of components to exclude from the default registration list.
    ripplebooleantrueEnables or disables the PrimeVue ripple effect.
    inputStyle'outlined' | 'filled''outlined'Sets the default input style.
    export interface PrimeVueOptions extends PrimeVueConfig {
      components?:
        exclude?: Array<PrimevueComponents>,
        include?: Array<PrimevueComponents | { name: PrimevueComponents, global?: boolean }>,
        global?: boolean
      ;
    }
  8. Configure the Sakai Nuxt application settings

    main

    The app.config.ts file is used to define global application metadata and routing settings for the Sakai Nuxt template. You can customize the page title, description, and the base URL for the application.

    export default defineAppConfig({
      title: 'Sakai Nuxt',
      description: '',
      baseURL: '/'
    });
  9. Use Nuxi CLI scripts for development and deployment

    main

    Sakai provides standard Nuxt/Nuxi scripts for managing the application lifecycle:

    CommandDescription
    pnpm run devStarts the development server
    pnpm run buildBuilds the application for deployment
    pnpm run generateBuilds the application for static deployment
    pnpm run startRuns the production server

    Note: Replace pnpm run with npm run or yarn as needed.

  10. Use ProductService to fetch data

    main

    The ProductService class is used to interact with product-related data. In the dashboard implementation, it is instantiated and its getProductsSmall() method is called within the onMounted lifecycle hook to populate the products reactive state.

    To use it, instantiate the service and call its data fetching methods, which return Promises that resolve to the requested data.

    import ProductService from '~~/services/ProductService';
    
    const productService = new ProductService();
    
    onMounted(() => {
      productService.getProductsSmall().then((data) => {
        products.value = data;
      });
    });
  11. Use usePrimeVue in your application

    main

    The module automatically adds the usePrimeVue import to your Nuxt application, allowing you to access the PrimeVue configuration instance within your composables or components.

    import { usePrimeVue } from 'primevue/config';
    
    // Inside a setup function or component
    const primevue = usePrimeVue();