Passed
Push — master ( 16a53c...ab92ed )
by Bruno
05:36
created

Upload::getMetadata()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Formularium\Frontend\Buefy\Element;
4
5
use Formularium\Element;
6
use Formularium\HTMLNode;
7
use Formularium\Frontend\HTML\Element\Upload as HTMLUpload;
8
use Formularium\Frontend\HTML\Framework as HTMLFramework;
9
use Formularium\Metadata;
10
use Formularium\MetadataParameter;
11
12
class Upload extends Element
13
{
14
    public function render(array $parameters, HTMLNode $previous): HTMLNode
15
    {
16
        $id = 'upload' . HTMLFramework::counter();
17
        $vmodel = 'file';  // TODO: test
18
        return HTMLNode::factory(
19
            'b-field',
20
            [
21
                'class' => 'formularium-upload file'
22
            ],
23
            [
24
                HTMLNode::factory(
25
                    'b-upload',
26
                    [ 'v-model' => $vmodel ],
27
                    [
28
                        HTMLNode::factory(
29
                            'a',
30
                            [
31
                                'id' => $id,
32
                                'class' => 'button is-primary',
33
                            ],
34
                            [
35
                                HTMLNode::factory(
36
                                    'b-icon',
37
                                    [ 'icon' => 'upload']
38
                                ),
39
                                HTMLNode::factory(
40
                                    'span',
41
                                    [],
42
                                    $parameters[self::LABEL] ?? 'Click to upload'
43
                                )
44
                            ]
45
                        ),
46
                    ]
47
                ),
48
                HTMLNode::factory(
49
                    'span',
50
                    [
51
                        'class' => 'file-name',
52
                        'v-if' => $vmodel
53
                    ],
54
                    "{{{$vmodel}.name}}",
55
                    true
56
                )
57
            ]
58
        );
59
    }
60
61
    public static function getMetadata(): Metadata
62
    {
63
        $metadata = HTMLUpload::getMetadata();
64
        return $metadata;
65
    }
66
}
67