用于日期选择的灵活日历组件。支持单选、多选与日期范围。非常适合排程与预订系统。
|  | 
<flux:calendar /><flux:calendar value="2025-10-07" /><flux:calendar wire:model="date" /><?phpuse Illuminate\Support\Carbon;use Livewire\Component;class BookAppointment extends Component {    public Carbon $date;    public function mount() {        $this->date = now();    }}选择多个非连续日期。
|  | 
<flux:calendar multiple /><flux:calendar    multiple    value="2025-10-02,2025-10-05,2025-10-15"/><flux:calendar multiple wire:model="dates" /><?phpuse Illuminate\Support\Carbon;use Livewire\Component;class RequestTimeOff extends Component {    public array $dates = [];    public function mount() {        $this->dates = [            now()->format('Y-m-d'),            now()->addDays(1)->format('Y-m-d'),        ];    }}选择一段日期范围。
|  | 
<flux:calendar mode="range" /><flux:calendar mode="range" value="2025-10-02/2025-10-06" /><flux:calendar mode="range" wire:model="range" /><?phpuse Livewire\Component;class BookFlight extends Component {    public ?array $range;    public function book() {        // ...        $flight->depart_on = $this->range['start'];        $flight->return_on = $this->range['end'];        // ...    }}<?phpuse Livewire\Component;use Flux\DateRange;class BookFlight extends Component {    public ?DateRange $range;    public function book() {        // ...        $flight->depart_on = $this->range->start();        $flight->return_on = $this->range->end();        // ...    }}<!-- Set minimum and maximum range limits --><flux:calendar mode="range" min-range="3" max-range="10" /><!-- Control number of months shown --><flux:calendar mode="range" months="2" />通过设置最小值和最大值来限制可选日期范围。
|  | 
<flux:calendar max="2025-10-07" /><!-- Prevent selection before today... --><flux:calendar min="today" /><!-- Prevent selection after today... --><flux:calendar max="today" />默认情况下,日历会使用浏览器的语言环境(例如 navigator.language)。
你可以通过设置 locale 属性为任意有效的本地化字符串(例如法语的 fr、英语的 en-US 等)来覆盖此行为:
|  | 
<flux:calendar locale="ja-JP" /><flux:calendar wire:model.live="range" /><?phpuse Livewire\Component;use Flux\DateRange;class Dashboard extends Component {    public DateRange $range;}<?phpuse Livewire\Component;use Flux\DateRange;class Dashboard extends Component {    public DateRange $range;    public function mount() {        $this->range = new DateRange(now(), now()->addDays(7));    }}<?phpuse Livewire\Attributes\Session;use Livewire\Component;use Flux\DateRange;class Dashboard extends Component {    #[Session]    public DateRange $range;}<?phpuse Livewire\Attributes\Computed;use Livewire\Component;use App\Models\Order;use Flux\DateRange;class Dashboard extends Component {    public ?DateRange $range;    #[Computed]    public function orders() {        return $this->range            ? Order::whereBetween('created_at', $this->range)->get()            : Order::all();    }}$range = new Flux\DateRange(    now()->subDays(1),    now()->addDays(1),);// Get the start and end dates as Carbon instances...$start = $range->start();$end = $range->end();// Check if the range contains a date...$range->contains(now());// Get the number of days in the range...$range->length();// Loop over the range by day...foreach ($range as $date) {    // $date is a Carbon instance...}// Get the range as an array of Carbon instances representing each day in the range...$range->toArray();$orders = Order::whereBetween('created_at', $range)->get();| 属性 | 说明 | 
|---|---|
| wire:model | 将日历绑定到一个 Livewire 属性。更多信息请参阅 wire:model 文档。 | 
| value | 选中的日期。其格式取决于 mode:单选(Y-m-d)、多选(逗号分隔的 Y-m-d),或范围(Y-m-d/Y-m-d)。 | 
| mode | 选择模式。可选项:single(默认)、multiple、range。 | 
| min | 可选择的最早日期。可为日期字符串或 “today”。 | 
| max | 可选择的最晚日期。可为日期字符串或 “today”。 | 
| size | 日历尺寸。可选项:base(默认)、xs、sm、lg、xl、2xl。 | 
| start-day | 设定周起始的星期。可选:0(周日)至 6(周六)。默认:基于用户的语言环境。 | 
| months | 显示的月份数量。默认:单选/多选模式为 1,范围模式为 2。 | 
| min-range | 范围模式下可选择的最少天数。 | 
| max-range | 范围模式下可选择的最多天数。 | 
| navigation | 为 false 时,隐藏月份导航控件。默认:true。 | 
| static | 为 true 时,日历为非交互(仅展示)。默认:false。 | 
| multiple | If true, enables multiple date selection mode. Default: false. | 
| week-numbers | If true, displays week numbers in the calendar. Default: false. | 
| selectable-header | If true, displays month and year dropdowns for quick navigation. Default: false. | 
| with-today | If true, displays a button to quickly navigate to today's date. Default: false. | 
| with-inputs | 为 true 时,在日历顶部显示日期输入框以便手动输入。默认:false。 | 
| locale | 设置日历的本地化。示例:fr、en-US、ja-JP。 | 
| 属性 | 说明 | 
|---|---|
| data-flux-calendar | 应用于根元素,用于样式与标识。 | 
在使用 `mode="range"` 时用于处理日期范围的专用对象。
| 方法 | 说明 | 
|---|---|
| $range->start() | 以 Carbon 实例的形式获取起始日期。 | 
| $range->end() | 以 Carbon 实例的形式获取结束日期。 | 
| $range->days() | 获取该范围内的天数。 | 
| $range->contains(date) | 检查范围内是否包含某个特定日期。 | 
| $range->length() | 以“天”为单位获取范围长度。 | 
| $range->toArray() | 以数组形式获取范围,包含 start 和 end 键。 | 
| $range->preset() | 获取当前预设(若存在)作为 DateRangePreset 枚举值。 | 
| 静态方法 | 说明 | 
|---|---|
| DateRange::today() | 创建一个表示“今天”的 DateRange。 | 
| DateRange::yesterday() | 创建一个表示“昨天”的 DateRange。 | 
| DateRange::thisWeek() | 创建一个表示“本周”的 DateRange。 | 
| DateRange::lastWeek() | 创建一个表示“上周”的 DateRange。 | 
| DateRange::last7Days() | 创建一个表示“过去 7 天”的 DateRange。 | 
| DateRange::thisMonth() | 创建一个表示“本月”的 DateRange。 | 
| DateRange::lastMonth() | 创建一个表示“上月”的 DateRange。 | 
| DateRange::thisYear() | 创建一个表示“本年”的 DateRange。 | 
| DateRange::lastYear() | 创建一个表示“去年”的 DateRange。 | 
| DateRange::yearToDate() | 创建一个从 1 月 1 日到今天的 DateRange。 |