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

@mblancodev/react-ts-timeline-range-picker

v0.0.1

Published

React/Typescript Timeline Range Component

Downloads

3

Readme

react-ts-timeline-range-picker

This is an updated fork of @marenaud/react-timeline-range-slider

Installation

npm install @mblancodev/react-ts-timeline-range-picker

or

yarn add @mblancodev/react-ts-timeline-range-picker

Usage

Basic Example

import React from 'react';
import { startOfDay, endOfDay } from 'date-fns'
import { TimelineRangePicker } from '@mblancodev/react-ts-timeline-range-picker';

function App() {
  return (
    <div>
      <TimelineRangePicker
        value={[]}
        onChange={() => {}}
        timelineInterval={[startOfDay(new Date()), endOfDay(new Date())]} />
    </div>
  );
}

export default App;

Importing default styles

import React from 'react';
import { addDays } from 'date-fns'
import { TimelineRangePicker } from '@mblancodev/react-ts-timeline-range-picker';
import "@mblancodev/react-ts-timeline-range-picker/assets/main.css"

[...]

Advance example

import { DateValuesType } from "@mblancodev/react-ts-timeline-range-picker/dist/src/types";
import { TimelineRangePicker } from "@mblancodev/react-ts-timeline-range-picker";
import "@mblancodev/react-ts-timeline-range-picker/dist/assets/main.css";
import { startOfDay, endOfDay, addHours } from "date-fns";
import { DateTime } from "luxon";
import { useState } from "react";

export const RangeTestPage = () => {
  const now = new Date();

  const [value, setValue] = useState<DateValuesType>([
    addHours(now, 2).getTime(),
    addHours(now, 4).getTime(),
  ]);

  function handleChange(values: DateValuesType) {
    setValue(values);
  }

  const [start, end] = value.map((t) =>
    DateTime.fromJSDate(new Date(t)).toFormat("HH:mm")
  );

  return (
    <div className="container my-12 p-4">
      <p className="px-8 translate-x-24">
        Selected: {DateTime.fromJSDate(now).toFormat("LLL dd")} at {start} - {end}
      </p>
      <TimelineRangePicker
        step={30}
        value={value}
        disabledIntervals={[
          {
            start: addHours(startOfDay(now), 2),
            end: addHours(startOfDay(now), 3),
          },
        ]}
        onChange={handleChange}
        timelineInterval={[startOfDay(now), endOfDay(now)]}
      />
    </div>
  );
};

Expectations for the future

I intent to add the following features in the near future:

  • Drag. For moving the whole range value without afectting only the start of end values

I'm open to suggestions since I only needed this component for a very specific use :)

API Reference

TimelineRangePicker(props) - Required

| Parameter | Type | Description | | :-------- | :------ | :----------------------- | | timelineInterval | [Date, Date]| [date start, date end] for the timeline range | | value | DateValuesType| Component controlled value | | onChange | (value: DateValuesType) => void| onChange value handler |

TimelineRangePicker(props) - Optional

| Parameter | Type | Description | | :-------- | :------ | :----------------------- | | step | number| Defaults to 10 | | ticksCount | number| Ticks labels to show | | mode | number| [Long description] | | disabledIntervals | Array<{ start: Date; end: Date }>| Disabled slots inside the range | | weekStartsOn | Day | Defaults to 0. Sunday to Saturday in numbers. Count starts at 0 just like in date-fns | | onUpdateCallback | (p: { error: boolean; time: readonly Date[] }) => void| Functions like an onInput change event |

Types

| Type | Description | | :-------- | :----------------------- | | Date | new Date() | DateValuesType | number[] | | ticksCount | number - Defaults to 48 | | mode | number | | disabledIntervals | Array<{ start: Date; end: Date }> | | weekStartsOn | Day - Defaults to 0 | | onUpdateCallback | (p: { error: boolean; time: readonly Date[] }) => void |

Contributing

I'm open to contributions, I'm new when it comes to developing pkgs so I do expect pull requests for errors that I've not seem yet.

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

Specify the license. For example, if your package is licensed under the MIT license, you could add:

MIT License

Copyright (c) 2023 Manuel Blanco.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software.

Support

If you need help setting up the package or would like to recommend some future updates you can email me at: [email protected]

Changelog

  • 0.0.1: Basic functionality. Display range dates, change values and non-update callback on errors if a disabledIntervals prop is given and value falls under those disabled slots.