npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-headless-timeline

v0.3.4

Published

⚡️ Headless components for building custom timelines for React

Downloads

459

Readme

⚡️ React Headless Timeline

Headless components for building custom timelines for React. Headless means it doesn't provide any UI for the timeline but only handles the logic. Supports both horizontal and vertical timelines.

🚀 Test, build and publish

Features


  • ⚡️ Highly performant and efficient
  • 🔒 Type safe - written in TypeScript
  • 🫧 Doesn't render any UI - it's totally up to you how you're going to style your timeline
  • 🏃‍ Small bundle size

Overview


See what library does and what doesn't for you to decide whether it's a good fit for you or not.

👍 What it does for you:

  • Handles the timeline logic
  • Helps you render timeline components in correct position and size

👎 What it doesn't for you:

  • It doesn't provide any pre-made UI components for you (no need to overwrite any styles to make timeline looks like in designer's dream)

Still not sure? Check some examples ⬇️

📖 Content


Install


npm install react-headless-timeline

Quick start


import Timeline from 'react-headless-timeline';

function App() {
  const timelineConfig = {
    startDate: new Date(1651201447127), // 29th Apr 2022 05:04:07 CET
    endDate: new Date(1651221447127), // 29th Apr 2022 10:37:27 CET
  }

  const events = [
    { 
      startDate: new Date(1651204649127), // 29th Apr 2022 05:57:29 CET
      endDate: new Date(1651214649127), // 29th Apr 2022 08:44:09 CET
    },
  ];
  
  return (
    <Timeline.Provider {...timelineConfig}>
      <>
        <Timeline.Headers
          render={({ headers, getHeaderStyles }) => (
            <div style={{ position: 'relative', width: '100%', height: 30 }}>
              {headers.map((header) => (
                <span key={header.getTime()} style={getHeaderStyles(header)}>
                  {header.getTime()}
                </span>
              ))}
            </div>
          )}
        />

        <Timeline.Events
          render={({ getEventStyles }) => (
            <div style={{ position: 'relative', width: '100%', height: 30 }}>
              {events.map((evt, i) => (
                <span key={i} style={getEventStyles(evt)}>
                  Event
                </span>
              ))}
            </div>
          )}
        />
      </>
    </Timeline.Provider>
  );
}

API


  • Timeline.Provider

    Core timeline component. You have to wrap all of your timeline components inside provider.

    Props: (* - these are required)

    | Name | Type | Default | Description | |---------|-----------------------------------------|---------------|-----------------------| | startDate * | Date | | | | endDate * | Date | | | | direction | "horizontal" / "vertical" | "horizontal" | Determines timeline direction |

    Example:

    import Timeline from 'react-headless-timeline';
      
    // ...
      
    <Timeline.Provider startDate={startDate} endDate={endDate} direction="horizontal">
      {children}
    </Timeline.Provider>

    Other examples: See all ⬇️


  • Timeline.Headers

    Provides headers and helper function to generate headers CSS styles (size and position).

    Props: (* - these are required)

    | Name | Type | Default | Description | | --- |------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------| | cells | number | 2 | Determines how many headers/cells you want to render. For example if you have a timeline with startDate set to today 10AM and endDate set to today 4PM, by default headers will be an array with startDate and endDate. But let's say you want to display headers every 1 hour, you should then set cells to 7 - [10AM, 11AM, 12AM, 1PM, 2PM, 3PM, 4PM]. The minimum value is 2 | | render * | function | | Render your UI inside this function. See example below... |

    Example:

    import Timeline from 'react-headless-timeline';
      
    // ...
      
    <Timeline.Headers
      render={({ headers, getHeaderStyles }) => (
        <div>
          {headers.map((header) => (
            <span key={header.getTime()} style={getHeaderStyles(header)}>
              {header.getTime()}
            </span>
          ))}
        </div>
      )}
    />

    Other examples: See all ⬇️


  • Timeline.Events

    Provides helper function to generate event CSS styles (size and position).

    Props: (* - these are required)

    | Name | Type | Default | Description | | --- |-----------|------------|------------------------------------------------------| | render * | function | | Render your UI inside this function. See example below... |

    Example:

    import Timeline from 'react-headless-timeline';
      
    // ...
      
    <Timeline.Events
      render={({ getEventStyles }) => (
        <div>
          {events.map((evt, i) => (
            <span key={i} style={getEventStyles(evt)}>
              Event
            </span>
          ))}
        </div>
      )}
    />

    Other examples: See all ⬇️


  • Timeline.Indicators.CurrentTime

    Provides current time indicator with updates (re-renders) every second or full minute. This component will re-render itself.

    Update every full minute means update at 10:45:00, 10:46:00 and so on...

    Props: (* - these are required)

    | Name | Type | Default | Description | | --- | --- | --- | --- | | updateInterval | "second" / "minute" | "minute" | Determines update interval. In most cases you'll want to use "minute" option to limit re-renders | | render * | function | | Render your UI inside this function. See example below... |

    Example:

    import Timeline from 'react-headless-timeline';
      
    // ...
      
    <Timeline.Indicators.CurrentTime
      render={({ currentTime, styles }) => (
        <div style={{ height: '100%', ...styles }}>
          <StyledHeader>{currentTime.getTime()}</StyledHeader>
        </div>
      )}
    />

    Other examples:

  • Timeline.Indicators.Time

    This indicator exposes function to position your component properly. It's useful for events without end date.

    Props: (* - these are required)

    | Name | Type | Default | Description | | --- | --- | --- | --- | | render * | function | | Render your UI inside this function. See example below... |

    Example:

    import Timeline from 'react-headless-timeline';
      
    // ...
      
    <Timeline.Indicators.Time
      render={({ getIndicatorStyles }) => (
        <div style={{ height: '100%', ...getIndicatorStyles(date) }}>
          <StyledHeader>
            {label}
          </StyledHeader>
        </div>
      )}
    />

    Other examples:


General rules


  • You should use CSS box-sizing: border-box on your timeline components to prevent sizing bugs.

Examples


License


MIT