shadcn-timeline

repository·main·Indexed 43 days ago

https://github.com/timdehof/shadcn-timeline

An accessible and customizable timeline component built on shadcn/ui using React, Tailwind CSS, and Framer Motion. Version 0.1.0 features a Timeline container and TimelineItem components with support for various statuses (completed, in-progress, pending), custom icons, and SSR compatibility.

Tokens
2.4K
Snippets
9
Records
13
Agent score
55%

What's inside shadcn-timeline

  1. Install the Shadcn Timeline component

    main

    To use this component, clone the repository, install the dependencies, and run Storybook to view the documentation and examples locally.

    # Clone the repository
    git clone https://github.com/timDeHof/shadcn-timeline.git
    
    # Install dependencies
    npm install
    
    # Run Storybook locally
    npm run storybook
    git clone https://github.com/timDeHof/shadcn-timeline.git
    npm install
    npm run storybook
  2. Use the Timeline component

    main

    The Timeline component acts as a container for TimelineItem components. You can customize the overall size and icon size via the Timeline props.

    import { Timeline, TimelineItem } from '@/components/timeline';
    import { Check } from 'lucide-react';
    
    export default function Example() {
      return (
        <Timeline>
          <TimelineItem
            date={new Date('2024-01-01')}
            title="Feature Released"
            description="New timeline component is now available"
            icon={<Check />}
            status="completed"
          />
          <TimelineItem
            date={new Date('2024-01-02')}
            title="In Progress"
            description="Working on documentation"
            status="in-progress"
          />
          <TimelineItem
            date={new Date('2024-01-03')}
            title="Upcoming"
            description="Planning future updates"
            status="pending"
          />
        </Timeline>
      );
    }
  3. TimelineTime component props

    main

    The TimelineTime component is used for displaying and formatting dates.

    PropTypeDefaultDescription
    dateDate | string | number-Date to display
    formatstring | Intl.DateTimeFormatOptions-Date formatting options
    classNamestring-Additional CSS classes
  4. TimelineItem component props

    main

    The TimelineItem component represents an individual event within the timeline.

    PropTypeDefaultDescription
    dateDate | string | number-Date of the event
    titlestring-Title of the event
    descriptionstring-Description of the event
    iconReactNode-Custom icon
    iconColor'primary' | 'secondary' | 'muted' | 'accent''primary'Color theme of the icon
    status'completed' | 'in-progress' | 'pending''completed'Current status
    loadingbooleanfalseShow loading state
    errorstring-Show error state
  5. Configure next-sitemap settings

    main

    The next-sitemap.config.js file defines how sitemaps and robots.txt are generated for the project. It uses the IConfig type from the next-sitemap package.

    Key configuration options include:

    • siteUrl: The base URL of your site (defaults to http://localhost:3000 if process.env.SITE_URL is not set).
    • exclude: An array of paths to exclude from the sitemap (e.g., static assets like /favicon.ico).
    • generateRobotsTxt: A boolean indicating whether to generate a robots.txt file.
    • generateIndexSitemap: A boolean indicating whether to generate an index sitemap (useful for very large sites).
    • robotsTxtOptions: Configuration for the robots.txt file, specifically the policies array which defines userAgent and allow/disallow rules.
    /** @type {import('next-sitemap').IConfig} */
    module.exports = {
      siteUrl: process.env.SITE_URL || 'http://localhost:3000',
      exclude: ['/next.svg', '/vercel.svg', '/favicon.ico'],
      generateRobotsTxt: true,
      generateIndexSitemap: false,
      robotsTxtOptions: {
        policies: [
          {
            userAgent: '*',
            allow: '/',
          },
        ],
      },
    };
  6. Run tests for Shadcn Timeline

    main

    Use the following commands to run the test suite, including Storybook tests and coverage reports.

    # Run tests
    npm run test
    
    # Run Storybook tests
    npm run test-storybook
    
    # Run Storybook tests with coverage
    npm run test-storybook:coverage
    npm run test
    npm run test-storybook
    npm run test-storybook:coverage
  7. Reference TimelineSize, TimelineStatus, and TimelineColor types

    main

    The timeline component uses specific union types for sizing, status, and color themes to ensure consistency with Shadcn UI patterns.

    TimelineSize

    • sm
    • md
    • lg

    TimelineStatus

    • completed
    • in-progress
    • pending

    TimelineColor

    • primary
    • secondary
    • muted
    • accent
    • destructive
    export type TimelineSize = 'sm' | 'md' | 'lg';
    export type TimelineStatus = 'completed' | 'in-progress' | 'pending';
    export type TimelineColor = 'primary' | 'secondary' | 'muted' | 'accent' | 'destructive';
  8. Configure the Timeline component with TimelineProps

    main

    The TimelineProps interface defines the configuration options for the main Timeline component. You must provide an items array of TimelineElement objects. You can also customize the global size, animation behavior, iconColor, connectorColor, and CSS className.

    import { TimelineElement, TimelineSize, TimelineColor } from './types';
    
    export interface TimelineProps {
      items: TimelineElement[];
      size?: TimelineSize;
      animate?: boolean;
      iconColor?: TimelineColor;
      connectorColor?: TimelineColor;
      className?: string;
    }
  9. Define TimelineElement data structure

    main

    The TimelineElement interface defines the shape of an individual item within the timeline. Each element requires an id, date, title, and description. Optional properties allow for customization of the visual state and content, including icons, status, color, and loading states.

    import { ReactNode } from 'react';
    import { TimelineStatus, TimelineColor, TimelineSize } from './types';
    
    export interface TimelineElement {
      id: number;
      date: string;
      title: string;
      description: string;
      icon?: ReactNode | (() => ReactNode);
      status?: TimelineStatus;
      color?: TimelineColor;
      size?: TimelineSize;
      loading?: boolean;
      error?: string;
    }