Giter Club home page Giter Club logo

svelte-scheduler's Introduction

Beyonk

Svelte Scheduler

js-standard-style CircleCI svelte-v3

Calendaring component in Svelte

This project is a work-in-progress. It doesn't work as advertised right now, we're just assessing the shape of things. You might consider avoiding it entirely, or opening a lot of PRs :)

Installation

npm install --save-dev @beyonk/svelte-scheduler

Usage

Create an instance of the Scheduler, and pass it a method to fetch your monthly schedules.

In the example below this is a simple JSON file which has nested years, months, and days.

Inside each day is a reference to a component which should be rendered for that day, and a series of props to pass to it.

Basic usage

// App.svelte
<Scheduler bind:fetchSchedule />

<script>
  import Scheduler from '@beyonk/svelte-scheduler'
  import Popdown from './Popdown.svelte'
  import get from 'just-safe-get'

  async function fetchSchedule (year, month) {
    return get(schedules, [ year, month ])
  }

  const schedules = {
    2019: {
      8: {
        22: {
          component: EventList,
          props: {}
        }
      }
    }
  }
</script>

Our EventList component responsively shows a quick day overview.

// EventList.svelte
<p>
  ... whatever you want here.
</p>

Each render, and each time the month is changed, the fetchSchedule method will be called again. fetchSchedule returns a simple json object of days of the month.

Events

The scheduler fires a select event when a valid day is clicked, and sets the class 'is-selected' on that day in the calendar.

// App.svelte
<Scheduler on:select={select} />

<script>
  import Scheduler from '@beyonk/svelte-scheduler'
  import get from 'just-safe-get'

  function select (e) {
    const { year, month, day } = e.details
    // You can use year/month/day to fetch full information about an event.
  }
</script>

Overview

The scheduler can show a day-overview component when a day is clicked. Specify the 'overview' property on your month data.

The overview component receives the same props as your day component.

// App.svelte
<Scheduler bind:fetchSchedule />

<script>
  import Scheduler from '@beyonk/svelte-scheduler'
  import Popdown from './Popdown.svelte'
  import EventList from './EventList.svelte'
  import get from 'just-safe-get'

  async function fetchSchedule (year, month) {
    return get(schedules, [ year, month ])
  }

  const schedules = {
    2019: {
      8: {
        22: {
          component: EventList,
          overview: Popdown
          props: {}
        }
      }
    }
  }
</script>

Our Popdown component lists full event detail.

// Popdown.svelte
<p>
  ... whatever you want here.
</p>

svelte-scheduler's People

Contributors

antony avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.