Revision fcf05923
Von Sven Schöling vor mehr als 3 Jahren hinzugefügt
SL/Presenter/MaterialComponents.pm | ||
---|---|---|
3 | 3 |
use strict; |
4 | 4 |
|
5 | 5 |
use SL::HTML::Restrict; |
6 |
use SL::MoreCommon qw(listify); |
|
6 | 7 |
use SL::Presenter::EscapedText qw(escape); |
7 | 8 |
use SL::Presenter::Tag qw(html_tag); |
8 | 9 |
use Scalar::Util qw(blessed); |
10 |
use List::UtilsBy qw(partition_by); |
|
9 | 11 |
|
10 | 12 |
use Exporter qw(import); |
11 | 13 |
our @EXPORT_OK = qw( |
... | ... | |
49 | 51 |
small => SMALL, |
50 | 52 |
tiny => TINY, |
51 | 53 |
}, |
54 |
size => { |
|
55 |
map { $_ => $_ } |
|
56 |
qw(col row), |
|
57 |
(map { "s$_" } 1..12), |
|
58 |
(map { "m$_" } 1..12), |
|
59 |
(map { "l$_" } 1..12), |
|
60 |
}, |
|
52 | 61 |
); |
53 | 62 |
|
54 | 63 |
use Carp; |
... | ... | |
95 | 104 |
@classes; |
96 | 105 |
} |
97 | 106 |
|
107 |
# used to extract material classes that are passed directly as classes |
|
108 |
sub _extract_classes { |
|
109 |
my ($attributes, $type) = @_; |
|
110 |
|
|
111 |
my @classes = map { split / / } listify($attributes->{class}); |
|
112 |
my %classes = partition_by { !!$optional_classes{$type}{$_} } @classes; |
|
113 |
|
|
114 |
$attributes->{class} = $classes{''}; |
|
115 |
$classes{1}; |
|
116 |
} |
|
117 |
|
|
98 | 118 |
sub _set_id_attribute { |
99 | 119 |
my ($attributes, $name, $unique) = @_; |
100 | 120 |
|
... | ... | |
239 | 259 |
$label, |
240 | 260 |
class => [ grep $_, @classes, INPUT_FIELD ], |
241 | 261 |
); |
262 |
} |
|
242 | 263 |
|
264 |
sub select_tag { |
|
265 |
my ($name, $collection, %attributes) = @_; |
|
243 | 266 |
|
267 |
|
|
268 |
_set_id_attribute(\%attributes, $name); |
|
269 |
my @size_classes = _extract_classes(\%attributes, "size"); |
|
270 |
|
|
271 |
|
|
272 |
my $icon = $attributes{icon} |
|
273 |
? icon(delete $attributes{icon}, class => 'prefix') |
|
274 |
: ''; |
|
275 |
|
|
276 |
my $label = $attributes{label} |
|
277 |
? html_tag('label', delete $attributes{label}, for => $attributes{id}) |
|
278 |
: ''; |
|
279 |
|
|
280 |
my $select_html = SL::Presenter::Tag::select_tag($name, $collection, %attributes); |
|
281 |
|
|
282 |
html_tag('div', |
|
283 |
$icon . $select_html . $label, |
|
284 |
class => [ INPUT_FIELD, @size_classes ], |
|
285 |
); |
|
244 | 286 |
} |
245 | 287 |
|
246 | 288 |
|
Auch abrufbar als: Unified diff
MaterialComponents: select_tag Komponente