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-rrule-builder-ts

v0.0.16

Published

rrule component for react with mui

Downloads

632

Readme

react-rrule-builder-ts

npm version

Storybook

NPM

Overview

react-rrule-builder-ts is a React component that generates RRULE strings for use in iCalendar events, built with TypeScript. This package is inspired by the original react-rrule-generator, which is now deprecated.

You can view the demo and explore component functionality in the storybook.

Status

Semi-Pre-Release: This package is currently in pre-release. Although it's available on npm, it is not yet stable for production use. The package is under active development and testing. Once it reaches stability, this note will be removed.

Features

  • Generates RRULE strings compliant with iCalendar standards.
  • Supports all RRULE options.
  • Includes form validation using Yup.
  • Integrates with MUI (Material-UI) components.
  • Manages state using Zustand, making state observable and accessible for external validation.

Installation

To install the package, run:

npm install react-rrule-builder-ts

Usage

import RRuleBuilder from 'react-rrule-builder-ts';
import {AdapterLuxon} from "@mui/x-date-pickers/AdapterLuxon"; // ** YOUR DATE ADAPTER **
import {DateTime} from "luxon"; // ** BASED ON YOUR DATE ADAPTER **

const MyComponent = () => {
  const handleRRuleChange = (rruleString) => {
    console.log(rruleString);
  };

  return (
    <RRuleBuilder
      dateAdapter={AdapterLuxon} // ** YOUR DATE ADAPTER **
      datePickerInitialDate={DateTime.now()} // ** BASED ON YOUR DATE ADAPTER ** 
      onChange={handleRRuleChange}
      enableYearlyInterval={true}
    />
  );
};

API

RRuleBuilder Props

🛠️ = Coming soon / in progress

  • dateAdapter (new (...args: any[]) => MuiPickersAdapter<TDate>;) This is an instance of the date adapter used by the date picker component. Such as AdapterDateFns, AdapterLuxon, AdapterDayjs, etc.

  • datePickerInitialDate (TDate)
    Initial date for the date picker component, the type of this needs to match the date adapter used.

  • onChange ((rruleString: string) => void)
    Callback function triggered when the RRULE string changes.

  • rruleString (string)
    Initial RRULE string to initialize the component state.

  • enableOpenOnClickDatePicker (boolean)
    When enabled, the date picker will open when the input field is clicked. This is true by default.

  • enableYearlyInterval (boolean)
    Enables the yearly interval option in the frequency selector.

  • showStartDate (boolean)
    Shows or hides the start date picker.

  • defaultFrequency (Frequency)
    Sets the default frequency of the recurrence rule (e.g., daily, weekly).

  • inputSize (TextFieldProps["size"])
    Specifies the size of the input fields (e.g., small, medium).

  • inputVariant (TextFieldProps["variant"])
    Specifies the variant of the input fields (e.g., outlined, filled).

  • lang (Lang)
    Localization options for date picker labels.
    Lang object structure:

    • startDatePickerLabel (string)
      Label for the start date picker.
    • endDatePickerLabel (string)
      Label for the end date picker.
  • timezone (string)
    Timezone to use for the date picker and RRULE string. Default is 'UTC'. This is also largely dependent on the date adapter used, read MUIs documentation for more information.

  • enableSmallScreenDetection (boolean) 🛠️ Enables detection of the parent container to adjust the layout accordingly for better responsiveness. If set to true, the component will monitor the screen size and adjust its design elements to fit smaller parents

  • smallScreenBreakpoint (number) 🛠️ Defines the breakpoint (in pixels) for small containers. When the parent container width is below this value, the component will switch to a layout optimized for smaller containers. Default is typically set to 350 pixels.

  • dense (boolean) 🛠️ Enables a denser layout with reduced padding and margins, suitable for compact displays or when conserving screen space is desired.

Store and Actions

The component uses a Zustand store for state management, with the following state and actions:

BuilderState

🛠️ = Coming soon / in progress

  • repeatDetails: Manages details for repeat rules.
  • frequency: Current frequency of the RRULE.
  • startDate: The selected start date.
  • validationErrors: 🛠️ Holds validation errors.
  • endDetails: Manages end conditions for the RRULE.
  • RRuleString: The generated RRULE string.
  • radioValue: Option for monthly and yearly rule settings.
  • minEndDate: Minimum end date based on the start date. This is always the start date plus one day, an RRULE cannot have an end date before or on the start date, it would not run.

BuilderActions

🛠️ = Coming soon / in progress

  • setFrequency(frequency: Frequency): Sets the frequency and resets relevant state.
  • setRepeatDetails(details: AllRepeatDetails): Updates repeat rule details and rebuilds the RRULE string.
  • validateForm(): 🛠️ Validates the form using Yup and returns a boolean indicating success.
  • setEndDetails(details: EndDetails): Updates the end details of the rule.
  • setStartDate(startDate: TDate | null): Sets the start date and adjusts end date if necessary, needs to be the Date type of the date adapter used.
  • buildRRuleString(): Constructs the RRULE string from the current state.
  • setOnChange(onChange: (rruleString: string) => void): Sets the onChange callback function.
  • setStoreFromRRuleString(rruleString: string): Populates the store state from an existing RRULE string.
  • setRadioValue(radioValue: MonthBy | YearlyBy | null): Sets the radio value for monthly/yearly repeat details.

Other Notes

  • MUI is currently a peer dependency and is used for UI components.
  • The package uses MUI's DatePicker for date selection, you can use your own Adapter for the date picker.
  • Zustand is used to manage state, making it observable and enabling external validation, which is beneficial for complex form interactions.