-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
button.block
88 lines (80 loc) · 2.96 KB
/
button.block
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: winter.blocks::lang.blocks.button.name
description: winter.blocks::lang.blocks.button.description
icon: icon-caret-square-o-right
tags: ["pages"]
fields:
config:
type: nestedform
usePanelStyles: false
form:
fields:
label:
label: winter.blocks::lang.fields.label
span: full
type: text
tabs:
icons:
winter.blocks::lang.fields.actions: 'icon-arrow-pointer'
winter.blocks::lang.tabs.display: 'icon-brush'
fields:
actions:
type: repeater
tab: winter.blocks::lang.fields.actions
prompt: winter.blocks::lang.fields.actions_prompt
groups: $/winter/blocks/meta/actions.yaml
color:
label: winter.blocks::lang.fields.color
tab: winter.blocks::lang.tabs.display
span: auto
type: colorpicker
icon:
label: winter.blocks::lang.fields.icon
tab: winter.blocks::lang.tabs.display
span: auto
type: iconpicker
==
<?php
use System\Classes\MediaLibrary;
function onStart()
{
$this->controller->addJs(Url::asset('/plugins/winter/blocks/assets/dist/js/blocks.js'), 'Winter.Blocks');
$data = $this['data']['config'];
// Ensure actions are 0 indexed
$data['actions'] = array_values($data['actions'] ?? []);
if (!empty($data['actions'])) {
foreach ($data['actions'] as &$config) {
$action = $config['_group'] ?? '';
unset($config['_group']);
switch ($action) {
case 'open_media':
$config['href'] = MediaLibrary::url($config['media_file']);
$action = 'open_url';
break;
}
$config = [
'data' => $config,
'action' => $action,
];
}
}
$this['data'] = array_merge($this['data'], [
'config' => $data
]);
}
?>
==
<button
type="button"
{% if data.config.actions %}
onclick="Snowboard.actions().doActions({{ data.config.actions | json_encode }}, event)"
{% endif %}
class="text-white {{ (data.width is defined) ? data.width : "" }} inline-flex items-center justify-center bg-primary hover:opacity-90 focus:ring-4 focus:outline-none focus:ring-primary-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800"
{% if data.config.color != '' %}
style="background-color: {{ data.config.color }};"
{% endif %}
>
{% if data.config.icon != '' %}
<i class="fas {{ data.config.icon }} mr-2"></i>
{% endif %}
{{ data.config.label }}
</button>