Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

* text=auto eol=lf

*.php text eol=lf
*.blade.php text eol=lf

# Ignore all test and documentation with "export-ignore".
/.github export-ignore
/.gitattributes export-ignore
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/fix-php-code-style-issues.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "Fix PHP Code Styling"

on:
push:
pull_request:
paths:
- '**.php'

Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ name: PHPStan

on:
push:
branches: [main]
paths:
- '**.php'
- 'phpstan.neon.dist'
pull_request:
paths:
- '**.php'
- 'phpstan.neon.dist'
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ jobs:
- name: Checkout code
uses: actions/checkout@v5

- name: Configure Git line endings
if: runner.os == 'Windows'
shell: bash
run: git config --global core.autocrlf false

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand All @@ -54,5 +59,8 @@ jobs:
- name: List Installed Dependencies
run: composer show -D

- name: Check code style
run: vendor/bin/pint --test

- name: Execute tests
run: vendor/bin/pest --ci --coverage --min=0
14 changes: 9 additions & 5 deletions .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:

permissions:
contents: write
pull-requests: write

jobs:
update:
Expand All @@ -23,9 +24,12 @@ jobs:
latest-version: ${{ github.event.release.name }}
release-notes: ${{ github.event.release.body }}

- name: Commit updated CHANGELOG
uses: stefanzweifel/git-auto-commit-action@v7
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
branch: main
commit_message: Update CHANGELOG
file_pattern: CHANGELOG.md
commit-message: Update CHANGELOG
title: Update CHANGELOG for ${{ github.event.release.name }}
body: |
Automated changelog update for release ${{ github.event.release.name }}.
branch: changelog/${{ github.event.release.tag_name }}
delete-branch: true
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
],
"require": {
"php": "^8.2",
"filament/filament": "^4.0|^5.0",
"filament/forms": "^4.0|^5.0",
"filament/support": "^4.0|^5.0",
"spatie/laravel-package-tools": "^1.15.0"
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^3.5",
"filament/filament": "^4.0|^5.0",
"laravel/pint": "^1.0",
"nunomaduro/larastan": "^3.1.0",
"orchestra/testbench": "^9.12",
Expand Down
4 changes: 3 additions & 1 deletion config/flatpickr.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Coolsam\Flatpickr\Enums\FlatpickrTheme;

return [
'theme' => \Coolsam\Flatpickr\Enums\FlatpickrTheme::DEFAULT, // Recommended: Use DEFAULT theme for better compatibility with Filament Styling and dark mode
'theme' => FlatpickrTheme::DEFAULT, // Recommended: Use DEFAULT theme for better compatibility with Filament Styling and dark mode
];
2 changes: 0 additions & 2 deletions resources/css/filament-theme.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
@import '../../vendor/filament/filament/resources/css/theme.css';

@source '../../src/**/*';
@source '../../resources/views/**/*';
@source '../../vendor/filament/**/*';

:root {
--flatpickr-padding-y: 0.5rem;
Expand Down
12 changes: 6 additions & 6 deletions resources/css/index.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
@import "flatpickr/dist/flatpickr.min.css";
@import "flatpickr/dist/plugins/monthSelect/style.css";
@import '../../vendor/filament/filament/resources/css/theme.css';

@source '../../src/**/*';
@source '../../resources/views/**/*';
@source '../../vendor/filament/**/*';

.flatpickr-calendar {
opacity: 1 !important;
@apply bg-white dark:bg-gray-800 opacity-100;
background-color: #fff;
}

.dark .flatpickr-calendar {
background-color: rgb(31 41 55);
}

.flatpickr-confirm {
display: inline-flex;
align-items: center;
Expand Down
4 changes: 2 additions & 2 deletions resources/dist/components/flatpickr.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/dist/flatpickr.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/dist/themes/default.css

Large diffs are not rendered by default.

158 changes: 122 additions & 36 deletions resources/js/components/flatpickr.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import localeData from 'dayjs/plugin/localeData'
import timezone from 'dayjs/plugin/timezone'
import utc from 'dayjs/plugin/utc'
import flatpickr from 'flatpickr'
import flatpickrLocales from "flatpickr/dist/l10n"
import flatpickrLocales from 'flatpickr/dist/l10n'

import ConfirmDate from "flatpickr/dist/esm/plugins/confirmDate/confirmDate.js"
import MonthSelect from "flatpickr/dist/esm/plugins/monthSelect/index.js"
import WeekSelect from "flatpickr/dist/esm/plugins/weekSelect/weekSelect.js"
// import rangePlugin from 'flatpickr/dist/plugins/rangePlugin.js'
import MonthSelect from 'flatpickr/dist/esm/plugins/monthSelect/index.js'
import WeekSelect from 'flatpickr/dist/esm/plugins/weekSelect/weekSelect.js'

dayjs.extend(advancedFormat)
dayjs.extend(customParseFormat)
Expand All @@ -20,6 +18,48 @@ dayjs.extend(utc)

window.dayjs = dayjs

function resolveLocale(localeConfig) {
if (localeConfig === null || localeConfig === undefined) {
return flatpickrLocales.en
}

if (typeof localeConfig === 'string') {
return flatpickrLocales[localeConfig] ?? flatpickrLocales.en
}

if (typeof localeConfig === 'object') {
const localeCode = localeConfig.locale ?? 'en'
const baseLocale = flatpickrLocales[localeCode] ?? flatpickrLocales.en

return {
...baseLocale,
...localeConfig,
}
}

return flatpickrLocales.en
}

function resolveDayjsLocale(localeConfig) {
if (typeof localeConfig === 'string') {
return locales[localeConfig] ?? locales.en
}

if (typeof localeConfig === 'object' && localeConfig?.locale) {
return locales[localeConfig.locale] ?? locales.en
}

return locales.en
}

function normalizeState(state) {
if (state === null || state === undefined || state === '') {
return null
}

return state
}

export default function flatpickrComponent(state, attrs) {
const timezone = dayjs.tz.guess()

Expand All @@ -28,52 +68,98 @@ export default function flatpickrComponent(state, attrs) {
attrs,
timezone,

locale: String(attrs.locale),

fp: null,

init: function() {
console.log('INit flatpickr', this.state, this.attrs)
Livewire.on('attributes-updated', (props) => {
console.log('Attributes updated', props)
init: function () {
this.initFlatpickr()

this.$watch('state', (value) => {
this.syncPickerFromState(value)
})
const customLocale = flatpickrLocales[this.locale] ?? flatpickrLocales['en'];
const plugins = [
// new ConfirmDate({
// showAlways: false,
// }),
];
},

initFlatpickr: function () {
if (this.fp) {
this.fp.destroy()
this.fp = null
}

const localeConfig = this.attrs.locale ?? 'en'
const customLocale = resolveLocale(localeConfig)
const plugins = []

if (this.attrs.monthPicker) {
plugins.push(new MonthSelect({
shorthand: this.attrs.monthPickerShorthand || false,
dateFormat: this.attrs.dateFormat || 'Y-m',
altFormat: this.attrs.altFormat || 'F Y',
}))
plugins.push(
new MonthSelect({
shorthand: this.attrs.monthPickerShorthand || false,
dateFormat: this.attrs.dateFormat || 'Y-m',
altFormat: this.attrs.altFormat || 'F Y',
}),
)
} else if (this.attrs.weekPicker) {
plugins.push(new WeekSelect({
}))
}
if (this.attrs.rangePicker) {
// plugins.push(new rangePlugin({
// }))
plugins.push(new WeekSelect({}))
}

const config = {
disableMobile: true,
initialDate: this.state,
defaultDate: this.state,
initialDate: normalizeState(this.state),
defaultDate: normalizeState(this.state),
static: false,
altInput: true,
...this.attrs,
locale: customLocale,
plugins,
onChange: (selectedDates, dateStr) => {
this.state = selectedDates.length === 0 ? null : dateStr
},
onClose: () => {
if (!this.fp || !this.attrs.allowInput) {
return
}

const inputValue = this.fp.altInput?.value ?? this.fp.input.value

if (inputValue === '') {
this.fp.clear()
this.state = null

return
}

const parsed = this.fp.parseDate(inputValue, this.fp.config.dateFormat)

if (parsed) {
this.fp.setDate(parsed, false)
this.state = this.fp.input.value
}
},
}
dayjs.locale(locales[this.locale] ?? locales['en'])

dayjs.locale(resolveDayjsLocale(localeConfig))
flatpickr.localize(customLocale)
this.fp = flatpickr(this.$refs.input, config);
this.fp.parseDate(this.state, this.fp.config.dateFormat);

this.fp = flatpickr(this.$refs.input, config)

if (this.state) {
this.syncPickerFromState(this.state)
}
},

syncPickerFromState: function (value) {
if (!this.fp) {
return
}

const normalized = normalizeState(value)

if (normalized === null) {
this.fp.clear()

return
}

this.fp.setDate(normalized, false)
},
updateAttributes(attrs) {
console.log('Update attributes', attrs)
}
}
}

Expand Down
11 changes: 2 additions & 9 deletions resources/views/forms/components/flatpickr.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
>
<link rel="stylesheet" id="pickr-theme" type="text/css" href="{{$getThemeAsset()}}">
<x-filament::input.wrapper
wire:ignore
:disabled="$isDisabled"
:inline-prefix="$isPrefixInline"
:inline-suffix="$isSuffixInline"
Expand Down Expand Up @@ -69,6 +68,7 @@
/>
@else
<div
wire:ignore
@if (FilamentView::hasSpaMode())
{{-- format-ignore-start --}}x-load="visible || event (ax-modal-opened)"
{{-- format-ignore-end --}}
Expand Down Expand Up @@ -120,11 +120,4 @@
@endforeach
</datalist>
@endif
</x-dynamic-component>
@script
<script>
$wire.on('attributes-updated', (args) => {
console.log(`Attributes have been updated. What to do?`, args);
})
</script>
@endscript
</x-dynamic-component>
5 changes: 4 additions & 1 deletion src/FlatpickrServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ public function configurePackage(Package $package): void
}
}

public function packageRegistered(): void {}
public function packageRegistered(): void
{
// No package-level bindings are registered for this plugin.
}

public function packageBooted(): void
{
Expand Down
Loading
Loading