Files
wordpress-theme-aksrt/src/WidgetSystem/CommonFields.php
T

95 lines
5.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace AKSRT\WidgetSystem;
defined('ABSPATH') || exit;
/**
* Reference-equivalent fields shared by all modern widgets.
*/
final class CommonFields {
public static function for_definition(array $flags): array {
$fields = [];
if (!empty($flags['title'])) {
$fields = array_merge($fields, self::title_fields());
}
if (!empty($flags['affix'])) {
$fields[] = ['id' => 'sidebar_affix', 'type' => 'switcher', 'label' => '侧栏随动', 'description' => '仅在侧边栏有效', 'default' => false];
}
if (!empty($flags['visibility'])) {
$fields = array_merge($fields, self::visibility_fields());
}
if (!empty($flags['animation'])) {
$fields = array_merge($fields, self::animation_fields());
}
if (!empty($flags['layout'])) {
$fields = array_merge($fields, self::layout_fields());
}
return $fields;
}
private static function title_fields(): array {
$link = static fn(string $id, string $label) => ['id' => $id, 'type' => 'link', 'label' => $label, 'default' => ['url' => '', 'text' => '', 'target' => '']];
return [
['id' => 'title', 'type' => 'textarea', 'label' => '模块标题', 'default' => ''],
['id' => 'subtitle', 'type' => 'textarea', 'label' => '副标题', 'default' => '', 'dependency' => ['title', '!=', '']],
['id' => 'title_style', 'type' => 'radio', 'label' => '标题样式', 'default' => '', 'options' => ['' => '简约', 'big' => '居中大标题'], 'dependency' => ['title', '!=', '']],
['id' => 'title_highlight', 'type' => 'text', 'label' => '标题选字高亮', 'default' => '', 'dependency' => ['title', '!=', '']],
['id' => 'title_highlight_color', 'type' => 'palette', 'label' => '高亮颜色', 'default' => 'focus-color', 'options' => self::palette()],
$link('title_link', '标题链接'),
$link('title_link2', '标题链接 2'),
$link('title_link3', '标题链接 3'),
[
'id' => 'title_link_style', 'type' => 'accordion', 'label' => '标题链接样式',
'fields' => [
['id' => 'color_1', 'type' => 'palette', 'label' => '链接 1 颜色', 'default' => 'jb-blue', 'options' => self::palette()],
['id' => 'color_2', 'type' => 'palette', 'label' => '链接 2 颜色', 'default' => 'jb-yellow', 'options' => self::palette()],
['id' => 'color_3', 'type' => 'palette', 'label' => '链接 3 颜色', 'default' => 'jb-green', 'options' => self::palette()],
],
],
];
}
private static function visibility_fields(): array {
return [
['id' => 'show_type', 'type' => 'radio', 'label' => '显示规则', 'default' => 'all', 'options' => ['all' => '全部显示', 'only_pc' => '仅 PC 端', 'only_sm' => '仅移动端']],
['id' => 'show_id_type', 'type' => 'radio', 'label' => '按 ID 显示或隐藏', 'default' => '', 'options' => ['' => '不限制', 'show' => '仅指定 ID 显示', 'hide' => '指定 ID 隐藏']],
['id' => 'show_ids', 'type' => 'text', 'label' => '文章 ID', 'description' => '多个 ID 使用逗号分隔', 'default' => '', 'sanitize' => 'ids', 'dependency' => ['show_id_type', '!=', '']],
];
}
private static function animation_fields(): array {
return [
['id' => 'animation_in', 'type' => 'select', 'label' => '模块入场动画', 'default' => '', 'options' => ['' => '无动画', 'fade' => '淡入', 'slideup' => '从下往上', 'slidedown' => '从上往下', 'slideright' => '从左往右', 'slideleft' => '从右往左', 'zoomin' => '由小变大', 'zoomout' => '由大变小']],
['id' => 'animation_repeat', 'type' => 'switcher', 'label' => '重复动画', 'default' => false],
];
}
private static function layout_fields(): array {
return [
['id' => 'layout_pin_pc', 'type' => 'spacing', 'label' => '模块额外间距(PC)', 'default' => ['top' => '', 'right' => '', 'bottom' => '', 'left' => '']],
['id' => 'layout_pin_m', 'type' => 'spacing', 'label' => '模块额外间距(移动端)', 'default' => ['top' => '', 'right' => '', 'bottom' => '', 'left' => '']],
[
'id' => 'layout_bg', 'type' => 'accordion', 'label' => '区块背景',
'fields' => [
['id' => 'light', 'type' => 'background', 'label' => '日间模式背景', 'default' => []],
['id' => 'dark', 'type' => 'background', 'label' => '夜间模式背景', 'default' => []],
],
],
];
}
public static function palette(): array {
return [
'focus-color' => '主题色', 'key-color' => '主要文字', 'muted-color' => '次要文字',
'c-red' => '红色', 'c-red-2' => '深红', 'c-yellow' => '黄色', 'c-yellow-2' => '深黄',
'c-cyan' => '青色', 'c-blue' => '蓝色', 'c-blue-2' => '深蓝', 'c-green' => '绿色', 'c-green-2' => '深绿',
'c-purple' => '紫色', 'c-purple-2' => '深紫', 'b-red' => '红色背景', 'b-yellow' => '黄色背景',
'b-cyan' => '青色背景', 'b-blue' => '蓝色背景', 'b-green' => '绿色背景', 'b-purple' => '紫色背景', 'b-black' => '黑色背景',
'jb-blue' => '渐变蓝', 'jb-cyan' => '渐变青', 'jb-green' => '渐变绿', 'jb-yellow' => '渐变黄',
'jb-red' => '渐变红', 'jb-pink' => '渐变粉', 'jb-purple' => '渐变紫', 'jb-vip1' => '会员金', 'jb-vip2' => '会员黑',
];
}
}