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

Datepicker: implement change of firstDayOfWeek #540

Conversation

silviokennecke
Copy link

@silviokennecke silviokennecke commented Nov 17, 2022

Short summary

Currently the first day of the week for the datepicker is always set to Sunday. This PR allows you to change the first day of the week.

What does this PR exactly to?

It adds a new configuration firstDayOfWeek. The value is an integer between 0 (Sunday) and 6 (Saturday). The default is 0.

Example code

<!-- date-picker-example.blade.php -->
<div>
    <form wire:submit.prevent="save">
        <!-- change first day to monday -->
        <x-datetime-picker
            first-day-of-week="1"
        />
    </form>
</div>

Associated issues

Documentation

The documentation has been updated. See https://github.com/wireui/docs/pull/40

@silviokennecke silviokennecke marked this pull request as ready for review November 17, 2022 23:13
@silviokennecke silviokennecke changed the title implement change of firstDay Datepicker: implement change of firstDayOfWeek Nov 17, 2022
@alonsofdez23
Copy link

When implement this feature? I need this! 😄

@silviokennecke
Copy link
Author

Hi @alonsofdez23, last week I noticed the issue #502.
According to that, new features for v1 will not be processed until v2 is released.

Anyway, I plan to create a second PR for v2, so the feature is probably directly included in v2.

@nohumans
Copy link

Hi!
Until v2.

npm install flatpickr --save

app.js

import flatpickr from "flatpickr";
import { Spanish } from "flatpickr/dist/l10n/es"

(select your language...)

app.css

@import 'flatpickr/dist/flatpickr.css';

Create a simple component (no code for display errors...)
components\input\datepicker.blade.php

php
$options = array_merge([
'dateFormat' => 'Y-m-d h:i K',
'enableTime' => true,
'altFormat' => 'j F Y',
'altInput' => false,
'locale' => 'es',
], $options);
@endphp


<div class="@if($disabled) opacity-60 @endif">
    @if ($label )
    <div class="flex {{ !$label ? 'justify-end' : 'justify-between items-end' }} mb-1">
        @if ($label)

        @endif
        <p class="block text-sm font-medium text-gray-700 dark:text-gray-400 ">{{ $label }}</p>

    </div>
    @endif

    <div wire:ignore class="relative">
        <input x-data="{
             value: @entangle($attributes->wire('model')), 
             instance: undefined,
             init() {
                 $watch('value', value => this.instance.setDate(value, false));
                 this.instance = flatpickr(this.$refs.input, {{ json_encode((object)$options) }});
             }
        }" x-ref="input" x-bind:value="value" type="text" {{ $attributes->merge(['class' => 'form-input w-full
        placeholder-secondary-400 dark:bg-secondary-800 dark:text-secondary-400 dark:placeholder-secondary-500 border
        border-secondary-300 focus:ring-primary-500 focus:border-primary-500 dark:border-secondary-600 form-input block
        w-full sm:text-sm rounded-md transition ease-in-out duration-100 focus:outline-none shadow-sm']) }}
        autocomplete="off" placeholder = {{ $placeholder }}
        />
        <div class="absolute inset-y-0 right-0 pr-2.5 flex items-center pointer-events-none text-secondary-400">
            <x-dynamic-component :component="WireUi::component('icon')" name="calendar" class="w-5 h-5" />
        </div>
    </div>
</div>
´´´

That is all!!!


<img width="464" alt="Captura de pantalla 2023-06-13 a las 7 12 33" src="https://github.com/wireui/wireui/assets/10484641/2fc4a067-a05c-4b64-82bb-01be9133c459">

@joaopalopes24
Copy link
Member

This was implemented in v2 stable.

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

Successfully merging this pull request may close these issues.

None yet

5 participants