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 set first day of week and remove manual translation files #409

Merged
merged 4 commits into from
Jun 3, 2021
Merged

DatePicker set first day of week and remove manual translation files #409

merged 4 commits into from
Jun 3, 2021

Conversation

tanthammar
Copy link
Contributor

This PR suggests the following changes to the DatePicker field:

  • Remove the need for manual translation files
  • Set any weekday as first day of week
  • Datepicker language defaults to app()->getLocale()
  • config option: first-day-of-week

Added methods:

/**
     * Default = app()->getLocale()
     * DayJS i18 via browser: https://day.js.org/docs/en/i18n/loading-into-browser
     * Available methods: https://day.js.org/docs/en/plugin/locale-data
     * Supported locales: https://github.com/iamkun/dayjs/tree/dev/src/locale
     * @param string $dayJSlocale
     * @return $this
     */
    public function locale(string $dayJSlocale): self
    {
        $this->locale = $dayJSlocale;
        return $this;
    }

    /**
     * 0 to 7 are allowed. Monday = 1, Sunday = 0 or 7
     * @param int $day
     * @return $this
     */
    public function firstDayOfWeek(int $day = 1): self
    {
        if($day < 0 || $day > 7) $day = 1;
        $this->firstDayOfWeek = $day;
        return $this;
    }

    /**
     * Set Sunday as first day of week
     * @return $this
     */
    public function weekStartSunday(): self
    {
        $this->firstDayOfWeek = 7;
        return $this;
    }

    /**
     * This method is otiose because Monday is default
     * <br>But sometimes you want it for code readability
     * @return $this
     */
    public function weekStartMonday(): self
    {
        $this->firstDayOfWeek = 1;
        return $this;
    }


// + equivalent getters...

Remove the need for manual translation files
Set any weekday as first day of week
Defaults to app()->getLocale()
@@ -425,20 +435,7 @@ class="absolute z-10 w-64 p-4 my-1 bg-white border border-gray-300 rounded shado
x-model="focusedMonth"
class="flex-grow p-0 text-lg font-medium text-gray-800 border-0 cursor-pointer focus:ring-0 focus:outline-none"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch, forgot to add class "capitalize"

@danharrin danharrin added enhancement New feature or request pending review labels May 6, 2021
@danharrin
Copy link
Member

Thanks Tina! I've removed the unnecessary translation strings as well.

@danharrin danharrin changed the base branch from main to develop June 3, 2021 20:54
@danharrin danharrin merged commit b9462ba into filamentphp:develop Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request i18n
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants