Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the date clicked from the InlineCalendar view #150

Open
mylastore opened this issue Feb 2, 2022 · 3 comments
Open

How to get the date clicked from the InlineCalendar view #150

mylastore opened this issue Feb 2, 2022 · 3 comments

Comments

@mylastore
Copy link

How do I get the date that was clicked from the InlineCalendar view?

Can you enable discussion here on GitHub for this type of question?

@mylastore
Copy link
Author

mylastore commented Feb 2, 2022

I figure this out but not sure if there is a better way, anyways here's the code.

<script>
  import dayjs from 'dayjs'
  import {InlineCalendar} from 'svelte-calendar'

  let store

  const theme = {
    calendar: {
      width: '600px',
      shadow: '0px 0px 5px rgba(0, 0, 0, 0.25)'
    }
  }
</script>

<div class="container mt-5">
  <div class="d-flex justify-content-center">
    <InlineCalendar {theme} bind:store/>
  </div>
  {#if $store?.hasChosen}
    <div class="text-center mt-3">
      <strong>DATE SELECTED:</strong> {dayjs($store.selected).format('MMM D, YYYY')}
    </div>
  {/if}
</div>

@gevera
Copy link

gevera commented May 10, 2022

That's the correct way

@devluxca
Copy link

My abstraction to this component is

// name of component: DatePicker.svelte
<script>
    import 'dayjs/locale/pt-br.js';
    import dayjs from 'dayjs';
	import { InlineCalendar, Swappable } from 'svelte-calendar';

    export let onChange

	const theme = {
		calendar: {
			width: '600px',
			shadow: '0px 0px 5px rgba(0, 0, 0, 0.25)',
            colors: {
				background: {
					highlight: '#68B096'
				}
			}
		}
	};

    let store
    let locale = 'pt-br'
    dayjs.locale(locale)

    $: $store?.selected ? onChange(new Date($store?.selected)) : () => {}
</script>

<Swappable value={{ locale }} vertical={false}>
    <InlineCalendar {theme} format={'DD/MM/YYYY'} start={new Date()} bind:store />
</Swappable>

and use:

<script>

let date
const changeDate = (newDate) => { date = newDate }
</script>

<DatePicker onChange={changeDate}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants