diff --git a/internals/ui/pages/datepicker.templ b/internals/ui/pages/datepicker.templ
index 3d94d59..f167d51 100644
--- a/internals/ui/pages/datepicker.templ
+++ b/internals/ui/pages/datepicker.templ
@@ -13,8 +13,33 @@ templ Datepicker() {
Description: templ.Raw("A date picker component."),
}) {
@modules.ExampleWrapper(modules.ExampleWrapperProps{
- ShowcaseFile: showcase.Datepicker(),
- PreviewCodeFile: "datepicker.templ",
+ SectionName: "Default",
+ ShowcaseFile: showcase.DatepickerDefault(),
+ PreviewCodeFile: "datepicker_default.templ",
+ ComponentCodeFile: "datepicker.templ",
+ })
+ @modules.ExampleWrapper(modules.ExampleWrapperProps{
+ SectionName: "Custom Placeholder",
+ ShowcaseFile: showcase.DatepickerCustomPlaceholder(),
+ PreviewCodeFile: "datepicker_custom_placeholder.templ",
+ ComponentCodeFile: "datepicker.templ",
+ })
+ @modules.ExampleWrapper(modules.ExampleWrapperProps{
+ SectionName: "Selected Date",
+ ShowcaseFile: showcase.DatepickerSelectedDate(),
+ PreviewCodeFile: "datepicker_selected_date.templ",
+ ComponentCodeFile: "datepicker.templ",
+ })
+ @modules.ExampleWrapper(modules.ExampleWrapperProps{
+ SectionName: "Disabled",
+ ShowcaseFile: showcase.DatepickerDisabled(),
+ PreviewCodeFile: "datepicker_disabled.templ",
+ ComponentCodeFile: "datepicker.templ",
+ })
+ @modules.ExampleWrapper(modules.ExampleWrapperProps{
+ SectionName: "Formats",
+ ShowcaseFile: showcase.DatepickerFormats(),
+ PreviewCodeFile: "datepicker_formats.templ",
ComponentCodeFile: "datepicker.templ",
})
}
diff --git a/internals/ui/pages/themes.templ b/internals/ui/pages/themes.templ
index 2e8b9d1..210e4b4 100644
--- a/internals/ui/pages/themes.templ
+++ b/internals/ui/pages/themes.templ
@@ -96,7 +96,6 @@ templ ThemePreview() {
ID: "birthdate",
Name: "birthdate",
Placeholder: "Select your birth date",
- Format: "YYYY-MM-DD",
})
diff --git a/internals/ui/showcase/datepicker_custom_placeholder.templ b/internals/ui/showcase/datepicker_custom_placeholder.templ
new file mode 100644
index 0000000..65d6e03
--- /dev/null
+++ b/internals/ui/showcase/datepicker_custom_placeholder.templ
@@ -0,0 +1,12 @@
+package showcase
+
+import "github.com/axzilla/goilerplate/pkg/components"
+
+templ DatepickerCustomPlaceholder() {
+ @components.Datepicker(components.DatepickerProps{
+ ID: "date",
+ Name: "date",
+ Placeholder: "When is your birthday?",
+ Class: "w-full max-w-xs",
+ })
+}
diff --git a/internals/ui/showcase/datepicker_default.templ b/internals/ui/showcase/datepicker_default.templ
new file mode 100644
index 0000000..dc52ea3
--- /dev/null
+++ b/internals/ui/showcase/datepicker_default.templ
@@ -0,0 +1,11 @@
+package showcase
+
+import "github.com/axzilla/goilerplate/pkg/components"
+
+templ DatepickerDefault() {
+ @components.Datepicker(components.DatepickerProps{
+ ID: "my-datepicker",
+ Name: "selected-date",
+ Class: "w-full max-w-xs",
+ })
+}
diff --git a/internals/ui/showcase/datepicker_disabled.templ b/internals/ui/showcase/datepicker_disabled.templ
new file mode 100644
index 0000000..e95593c
--- /dev/null
+++ b/internals/ui/showcase/datepicker_disabled.templ
@@ -0,0 +1,29 @@
+package showcase
+
+import (
+ "github.com/axzilla/goilerplate/pkg/components"
+ "time"
+)
+
+templ DatepickerDisabled() {
+
+ // Disabled using attributes
+ @components.Datepicker(components.DatepickerProps{
+ ID: "my-datepicker",
+ Name: "selected-date",
+ Placeholder: "Select a date",
+ Value: time.Now(),
+ Class: "w-full max-w-xs",
+ Attributes: templ.Attributes{"disabled": true},
+ })
+ // Disabled using props
+ @components.Datepicker(components.DatepickerProps{
+ ID: "my-datepicker-2",
+ Name: "selected-date-2",
+ Placeholder: "Select a date",
+ Value: time.Now(),
+ Class: "w-full max-w-xs",
+ Disabled: true,
+ })
+
+}
diff --git a/internals/ui/showcase/datepicker_formats.templ b/internals/ui/showcase/datepicker_formats.templ
new file mode 100644
index 0000000..fbf6831
--- /dev/null
+++ b/internals/ui/showcase/datepicker_formats.templ
@@ -0,0 +1,76 @@
+package showcase
+
+import (
+ "github.com/axzilla/goilerplate/pkg/components"
+ "time"
+)
+
+templ DatepickerFormats() {
+
+ // Default ISO
+ @components.Datepicker(components.DatepickerProps{
+ ID: "date-iso",
+ Name: "date_iso",
+ Config: components.DatePickerISO,
+ Value: time.Now(),
+ })
+ // Default EU
+ @components.Datepicker(components.DatepickerProps{
+ ID: "date-eu",
+ Name: "date_eu",
+ Config: components.DatePickerEU,
+ Value: time.Now(),
+ })
+ // Default UK
+ @components.Datepicker(components.DatepickerProps{
+ ID: "date-uk",
+ Name: "date_uk",
+ Config: components.DatePickerUK,
+ Value: time.Now(),
+ })
+ // Default US
+ @components.Datepicker(components.DatepickerProps{
+ ID: "date-us",
+ Name: "date_us",
+ Config: components.DatePickerUS,
+ Value: time.Now(),
+ })
+ // Default LONG
+ @components.Datepicker(components.DatepickerProps{
+ ID: "date-long",
+ Name: "date_long",
+ Config: components.DatePickerLONG,
+ Value: time.Now(),
+ })
+ // Custom Config
+ @components.Datepicker(components.DatepickerProps{
+ ID: "date-es",
+ Name: "date_es",
+ Config: components.NewDatepickerConfig(
+ components.DateFormatLONG,
+ components.DateLocaleSpanish,
+ ),
+ Value: time.Now().AddDate(0, 0, -30), // 30 days ago
+ Placeholder: "Seleccionar fecha",
+ })
+ // Custom Format (Japanese LONG)
+ @components.Datepicker(components.DatepickerProps{
+ ID: "date-custom",
+ Name: "date_custom",
+ Config: components.NewDatepickerConfig(
+ components.DateFormatLONG,
+ components.DateLocale{
+ MonthNames: []string{
+ "1月", "2月", "3月", "4月", "5月", "6月",
+ "7月", "8月", "9月", "10月", "11月", "12月",
+ },
+ DayNames: []string{
+ "日", "月", "火", "水", "木", "金", "土",
+ },
+ },
+ ),
+ Value: time.Now().AddDate(0, 0, -30), // 30 days ago
+ Placeholder: "Seleccionar fecha",
+ })
+
+}
diff --git a/internals/ui/showcase/datepicker.templ b/internals/ui/showcase/datepicker_selected_date.templ
similarity index 61%
rename from internals/ui/showcase/datepicker.templ
rename to internals/ui/showcase/datepicker_selected_date.templ
index f9edbbd..e7878b8 100644
--- a/internals/ui/showcase/datepicker.templ
+++ b/internals/ui/showcase/datepicker_selected_date.templ
@@ -1,13 +1,16 @@
package showcase
-import "github.com/axzilla/goilerplate/pkg/components"
+import (
+ "github.com/axzilla/goilerplate/pkg/components"
+ "time"
+)
-templ Datepicker() {
+templ DatepickerSelectedDate() {
@components.Datepicker(components.DatepickerProps{
ID: "my-datepicker",
Name: "selected-date",
Placeholder: "Select a date",
- Format: "YYYY-MM-DD",
+ Value: time.Now(),
Class: "w-full max-w-xs",
})
}
diff --git a/pkg/components/datepicker.templ b/pkg/components/datepicker.templ
index fb50823..6ed33d6 100644
--- a/pkg/components/datepicker.templ
+++ b/pkg/components/datepicker.templ
@@ -3,247 +3,369 @@ package components
import (
"github.com/axzilla/goilerplate/pkg/icons"
"github.com/axzilla/goilerplate/pkg/utils"
+ "time"
)
+// DateFormat defines the available date formatting styles
+type DateFormat string
+
+const (
+ // DateFormatISO represents ISO format (YYYY-MM-DD)
+ DateFormatISO DateFormat = "iso"
+ // DateFormatEU represents European format (DD.MM.YYYY)
+ DateFormatEU DateFormat = "eu"
+ // DateFormatUK represents UK format (DD/MM/YYYY)
+ DateFormatUK DateFormat = "uk"
+ // DateFormatUS represents US format (MM/DD/YYYY)
+ DateFormatUS DateFormat = "us"
+ // DateFormatLONG represents long format (Month DD, YYYY)
+ DateFormatLONG DateFormat = "long"
+)
+
+// dateFormatMapping maps DateFormat to Go time format strings
+var dateFormatMapping = map[DateFormat]string{
+ DateFormatISO: "2006-01-02",
+ DateFormatEU: "02.01.2006",
+ DateFormatUK: "02/01/2006",
+ DateFormatUS: "01/02/2006",
+ DateFormatLONG: "January 2, 2006",
+}
+
+// DateLocale defines localization settings for the datepicker
+type DateLocale struct {
+ // MonthNames contains the localized names of months
+ MonthNames []string
+ // DayNames contains the localized abbreviated day names
+ DayNames []string
+}
+
+// DateLocaleDefault provides English localization
+var DateLocaleDefault = DateLocale{
+ MonthNames: []string{"January", "February", "March", "April", "May", "June",
+ "July", "August", "September", "October", "November", "December"},
+ DayNames: []string{"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"},
+}
+
+// Pre-defined locales for different languages
+var (
+ // DateLocaleSpanish provides Spanish localization
+ DateLocaleSpanish = DateLocale{
+ MonthNames: []string{"Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio",
+ "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"},
+ DayNames: []string{"Lu", "Ma", "Mi", "Ju", "Vi", "Sa", "Do"},
+ }
+
+ // DateLocaleGerman provides German localization
+ DateLocaleGerman = DateLocale{
+ MonthNames: []string{"Januar", "Februar", "März", "April", "Mai", "Juni",
+ "Juli", "August", "September", "Oktober", "November", "Dezember"},
+ DayNames: []string{"Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"},
+ }
+
+ // DateLocaleFrench provides French localization
+ DateLocaleFrench = DateLocale{
+ MonthNames: []string{"Janvier", "Février", "Mars", "Avril", "Mai", "Juin",
+ "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"},
+ DayNames: []string{"Lu", "Ma", "Me", "Je", "Ve", "Sa", "Di"},
+ }
+
+ // DateLocaleItalian provides Italian localization
+ DateLocaleItalian = DateLocale{
+ MonthNames: []string{"Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno",
+ "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"},
+ DayNames: []string{"Lu", "Ma", "Me", "Gi", "Ve", "Sa", "Do"},
+ }
+)
+
+// DatepickerConfig combines format and locale settings
+type DatepickerConfig struct {
+ Format DateFormat
+ Locale DateLocale
+}
+
+// Pre-defined datepicker configurations
+var (
+ // DatePickerISO provides ISO format with default locale
+ DatePickerISO = DatepickerConfig{
+ Format: DateFormatISO,
+ Locale: DateLocaleDefault,
+ }
+
+ // DatePickerEU provides European format with default locale
+ DatePickerEU = DatepickerConfig{
+ Format: DateFormatEU,
+ Locale: DateLocaleDefault,
+ }
+
+ // DatePickerUK provides UK format with default locale
+ DatePickerUK = DatepickerConfig{
+ Format: DateFormatUK,
+ Locale: DateLocaleDefault,
+ }
+
+ // DatePickerUS provides US format with default locale
+ DatePickerUS = DatepickerConfig{
+ Format: DateFormatUS,
+ Locale: DateLocaleDefault,
+ }
+
+ // DatePickerUS provides US format with default locale
+ DatePickerLONG = DatepickerConfig{
+ Format: DateFormatLONG,
+ Locale: DateLocaleDefault,
+ }
+)
+
+// NewDatepickerConfig creates a new configuration with specified format and locale
+func NewDatepickerConfig(format DateFormat, locale DateLocale) DatepickerConfig {
+ return DatepickerConfig{
+ Format: format,
+ Locale: locale,
+ }
+}
+
+// GetGoFormat returns the Go time format string for the current configuration
+func (c DatepickerConfig) GetGoFormat() string {
+ if format, ok := dateFormatMapping[c.Format]; ok {
+ return format
+ }
+ return dateFormatMapping[DateFormatISO] // Default to ISO
+}
+
+// DatepickerProps defines all available props for the Datepicker component
type DatepickerProps struct {
- // ID uniquely identifies the datepicker input
+ // ID sets the input element's ID
ID string
-
- // Name sets the form field name
+ // Name sets the input element's name
Name string
-
- // Placeholder shows helper text when empty
+ // Value sets the initial date
+ Value time.Time
+ // Config provides format and locale settings
+ Config DatepickerConfig
+ // Placeholder sets the input placeholder text
Placeholder string
-
- // Format controls date string presentation
- // Supported formats:
- // - "M d, Y" (Jan 1, 2024)
- // - "MM-DD-YYYY" (01-01-2024)
- // - "DD-MM-YYYY" (01-01-2024)
- // - "YYYY-MM-DD" (2024-01-01)
- // - "D d M, Y" (Mon 1 Jan, 2024)
- Format string
-
+ // Disabled controls whether the datepicker can be interacted with
+ Disabled bool
// Class adds custom CSS classes
Class string
-
- Value string
-
- // Attributes for additional HTML attributes and Alpine.js bindings
+ // Attributes allows additional HTML attributes
Attributes templ.Attributes
}
-// Datepicker renders a calendar input component with popup date selection.
-// Uses Alpine.js for interactions and supports dark mode via Tailwind.
-// For detailed examples and usage guides, visit https://goilerplate.com/docs/components/datepicker
+// Datepicker renders a localized date picker component with configurable formatting.
+// Features:
+// - Multiple date formats (ISO, EU, US, UK, Long)
+// - Localization support for months and weekdays
+// - Popup calendar for date selection
+// - Keyboard navigation support
+// - Responsive positioning
+// - Custom styling support
//
// Props:
-// - ID: Unique identifier for the input
+// - ID: Input element identifier
// - Name: Form field name
-// - Placeholder: Helper text when empty
-// - Format: Date display format
+// - Value: Initial date value
+// - Config: Format and locale settings
+// - Placeholder: Input placeholder text
+// - Disabled: Interactivity state
// - Class: Additional CSS classes
// - Attributes: Additional HTML attributes
templ Datepicker(props DatepickerProps) {
-
@icons.Calendar(icons.IconProps{})
-
+
-
-
-
-
-
-
-