为 Liturgical Calendar API 提供的可重用前端组件

v1.0.5 2024-10-01 10:58 UTC

This package is auto-updated.

Last update: 2024-10-01 18:54:27 UTC


README

一组与 Liturgical Calendar API(目前托管在 https://litcal.johnromanodorazio.com/api/dev/)一起工作的可重用前端组件。

安装包

在项目中安装包非常简单,只需运行 composer install liturgical-calendar/components

使用 include_once 'vendor/autoload.php'; 在项目中包含包(根据需要调整 vendor/autoload.php 的路径)。

CalendarSelect

生成一个 HTML 选择元素,其选项由 Liturgical Calendar API 的 /calendars 路由中的数据填充。可以通过具有以下键的选项数组实例化:

  • url:宗教日历元数据 API 端点的 URL。默认为 https://litcal.johnromanodorazio.com/api/dev/calendars
  • locale:用于日历选择的区域设置。默认为 'en'。这是用于翻译和排序国家名称的区域设置。这应该是一个有效的 PHP 区域字符串,例如 'en' 或 'es' 或 'en_US' 或 'es_ES'。

要生成 <select> 元素,请在 CalendarSelect 实例上调用 ->getSelect() 方法。您可以选择传递一个具有以下键的选项数组:

  • class:要应用到选择元素的类或类列表。
  • id:要应用到选择元素的 ID。
  • options:要返回的选择选项类型。有效值是 'nations''diocesesGrouped''all'
  • label:一个布尔值,表示是否包括标签元素。
  • labelStr:用于标签元素的字符串。

示例

<?php
include_once 'vendor/autoload.php';
use LiturgicalCalendar\Components\CalendarSelect;

$options = ['locale' => 'it']; // set the locale to Italian
$CalendarSelect = new CalendarSelect($options); // use the default API url, but set the locale to Italian

echo $CalendarSelect->getSelect([
                        'class'    => 'form-select',
                        'id'       => 'calendarSelect',
                        'options'  => 'all',
                        'label'    => true,
                        'labelStr' => _("Select calendar")
                    ]);