flowbite-svelte-admin-dashboard

repository·main·Indexed 19 days ago

https://github.com/themesberg/flowbite-svelte-admin-dashboard

A pre-built admin dashboard template (version 2.1.1) built with Svelte and Flowbite-Svelte. It provides a comprehensive library of UI components including authentication pages (SignIn, SignUp), data visualization widgets (Charts, Stats), and layout elements (Footer, AppsMenu). The package includes TypeScript types for product and customer data structures, utility functions for image path resolution, and configurations for ESLint and Playwright e2e testing.

Tokens
3.9K
Snippets
16
Records
17
Agent score
68%

What's inside flowbite-svelte-admin-dashboard

  1. Install flowbite-svelte-admin-dashboard

    main

    To use the flowbite-svelte-admin-dashboard in a new Svelte project, follow these steps:

    1. Create a new Svelte project using sv: npx sv create my-app
    2. Navigate to your project directory: cd my-app
    3. Install the dashboard package as a development dependency using pnpm: pnpm i -D flowbite-svelte-admin-dashboard
    4. Update your dependencies to ensure compatibility: pnpm update
    5. Start the development server: pnpm dev
    npx sv create my-app
    cd my-app
    pnpm i -D flowbite-svelte-admin-dashboard
    pnpm update
    pnpm dev
  2. Manage Dashboard Time Slots

    main

    The dashboard provides a predefined set of time slots via DEFAULT_TIMESLOTS. You can use the TimeSlot type to ensure compatibility with components like DateRangeSelector.

    export const DEFAULT_TIMESLOTS = {
      Yesterday: -1,
      Today: 0,
      'Last 7 days': 7,
      'Last 30 days': 30,
      'Last 90 days': 90
    };
    
    export type TimeSlot = keyof typeof DEFAULT_TIMESLOTS;
  3. Configure Playwright end-to-end testing

    main

    The project uses Playwright for end-to-end (e2e) testing. The configuration defines where tests are located and how the local development server should be started before running tests.

    • testDir: Set to e2e, meaning all Playwright test files should be placed in the e2e directory.
    • webServer: Configures the local server used during testing. It runs npm run build && npm run preview and listens on port 4173.
    import { defineConfig } from '@playwright/test';
    
    export default defineConfig({
      webServer: {
        command: 'npm run build && npm run preview',
        port: 4173
      },
      testDir: 'e2e'
    });
  4. Configure ESLint for Svelte and TypeScript

    main

    The project uses a flat configuration file (eslint.config.js) that integrates ESLint with TypeScript, Svelte, and Prettier. It is configured to recognize .svelte files and uses the project's svelte.config.js for parsing.

    Key configuration features include:

    • Recommended Rules: Includes recommended configurations for JavaScript, TypeScript, and Svelte.
    • Prettier Integration: Uses eslint-config-prettier and svelte.configs.prettier to disable ESLint rules that conflict with Prettier.
    • Global Variables: Configures both browser and node environments.
    • Svelte Parsing: Specifically targets **/*.svelte, **/*.svelte.ts, and **/*.svelte.js files, utilizing typescript-eslint as the parser and passing the local svelteConfig to the parser options.
    import prettier from 'eslint-config-prettier';
    import js from '@eslint/js';
    import { includeIgnoreFile } from '@eslint/compat';
    import svelte from 'eslint-plugin-svelte';
    import globals from 'globals';
    import ts from 'typescript-eslint';
    import svelteConfig from './svelte.config.js';
    
    export default ts.config(
      includeIgnoreFile(gitignorePath),
      js.configs.recommended,
      ...ts.configs.recommended,
      ...svelte.configs.recommended,
      prettier,
      ...svelte.configs.prettier,
      {
        languageOptions: {
          globals: { ...globals.browser, ...globals.node }
        },
        rules: { 'no-undef': 'off' }
      },
      {
        files: ['**/*.svelte', '**/*.svelte.ts', '**/*.svelte.js'],
        languageOptions: {
          parserOptions: {
            projectService: true,
            extraFileExtensions: ['.svelte'],
            parser: ts.parser,
            svelteConfig
          }
        }
      }
    );
  5. Import Svelte components from flowbite-svelte-admin-dashboard

    main

    The library exports a wide range of pre-built Svelte components for building admin dashboards, including UI elements (Cards, Badges, Modals), data visualization (Charts, Stats), and full-page views (SignIn, SignUp, NotFound). You can import these components directly from the library entry point.

    <script>
      import { 
        Accounts, 
        CardWidget, 
        ChartWidget, 
        StatusBadge, 
        SignIn, 
        UserMenu 
      } from 'flowbite-svelte-admin-dashboard';
    </script>
    
    <StatusBadge>Active</StatusBadge>
    <CardWidget>
      <ChartWidget />
    </CardWidget>
  6. Resolve image paths using imagesPath and avatarPath

    main

    The project provides utility functions to construct full URLs for images based on the configured MY_IMG_DIR.

    • avatarPath(src: string): Returns the full path to a user avatar located in the /users/ subdirectory.
    • imagesPath(src: string, ...subdirs: string[]): Returns a joined path starting from MY_IMG_DIR, followed by any provided subdirectories, and ending with the filename. It automatically filters out empty segments.
    import { avatarPath, imagesPath } from '$lib/variables';
    
    // Get avatar URL
    const avatar = avatarPath('user-1.png'); 
    // Result: https://flowbite-admin-dashboard.vercel.app/images/users/user-1.png
    
    // Get custom image URL with subdirectories
    const logo = imagesPath('logo.png', 'branding', 'assets');
    // Result: https://flowbite-admin-dashboard.vercel.app/images/branding/assets/logo.png
  7. Access utility functions and types

    main

    In addition to components, the library exports utility functions and TypeScript types. Specifically, getChartOptions is available for configuring chart behavior, and all core types are exported for use in your own component props or data structures.

    import { getChartOptions, type SomeType } from 'flowbite-svelte-admin-dashboard';
    
    const options = getChartOptions();
  8. Map user objects with full avatar URLs using mapUsersWithAvatars

    main

    The mapUsersWithAvatars function takes an array of user objects and ensures their avatar property is a full URL.

    If the avatar string already starts with http, it remains unchanged. Otherwise, it prepends the MY_IMG_DIR and the /users/ path to the filename. This is useful for transforming raw data from an API into UI-ready data.

    import { mapUsersWithAvatars } from '$lib/variables';
    
    const rawUsers = [
      { name: 'John Doe', avatar: 'john.jpg' },
      { name: 'External User', avatar: 'https://other-site.com/photo.png' }
    ];
    
    const usersWithFullUrls = mapUsersWithAvatars(rawUsers);
    /*
    [
      { name: 'John Doe', avatar: 'https://flowbite-admin-dashboard.vercel.app/images/users/john.jpg' },
      { name: 'External User', avatar: 'https://other-site.com/photo.png' }
    ]
    */
  9. Reference list of exported components

    main

    The following components are available for direct import:

    • Auth & User: Accounts, ForgotPassword, ProfileLock, ResetPassword, SignIn, SignUp, UserMenu, UserModal, UserProfile
    • Data & Analytics: ActivityList, CategorySalesReport, ChartWidget, ComparisonTable, DarkChart, ProductMetricCard, Stats, Traffic
    • UI Elements: CardList, CardWidget, EmptyCard, IconAvatar, Notification, NotificationCard, NotificationList, PriceCard, PriceCardPrice, PriceCardListItem, SmallPanel, StatusBadge
    • Layout & Navigation: AppsMenu, Footer, LanguageTime, More, UserMenu
    • Feedback & Overlays: DeleteDrawer, DeleteModal, Drawer (via ProductDrawer), NotFound, ServerError, Maintenance
    • Widgets & Specialized: ChatMsg, DateRangeSelector, GeneralInfo, Faq, Playground
  10. Configure Authentication Page Components

    main

    The dashboard provides several specialized props interfaces for authentication flows. Most extend HTMLFormAttributes and allow customization of the UI via CSS classes:

    • SingInProps: For login pages. Includes options for rememberMe, lostPassword, and createAccount links.
    • SingUpProps: For registration pages. Includes haveAccount and acceptTerms options.
    • ForgotPasswordProps: For password recovery flows.
    • ProfileLockProps / RestPasswordProps: For security-related user actions.
    // Example of SingInProps structure
    export interface SingInProps extends HTMLFormAttributes {
      children: Snippet;
      site?: SiteType;
      rememberMe?: boolean;
      title?: string;
      lostPassword?: boolean;
      createAccount?: boolean;
      // ... other styling and link props
    }
  11. Define Footer Structure

    main

    The FooterProps interface defines the layout for the site footer, requiring a brand (name, link, image) and an array of menus. Each menu contains a title and a list of FooterLinkType items.

    export type BrandType = {
      name: string;
      href: string;
      src: string;
      alt: string;
    };
    
    export type FooterLinkType = {
      className: string;
      href: string;
      item: string;
    };
    
    export type Menu = {
      title: string;
      links: FooterLinkType[];
    };
    
    export interface FooterProps {
      brand: BrandType;
      description?: Snippet;
      menus: Menu[];
    }