From: Sven Schöling Date: Fri, 19 Mar 2021 17:59:52 +0000 (+0100) Subject: MaterialComponents: select_tag Komponente X-Git-Tag: kivitendo-mebil_0.1-0~9^2~95 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=291ad5ec33ddeb657c2fc7035a0177d39d73be9b;p=kivitendo-erp.git MaterialComponents: select_tag Komponente --- diff --git a/SL/Presenter/MaterialComponents.pm b/SL/Presenter/MaterialComponents.pm index 9b698476b..a4eacc8d3 100644 --- a/SL/Presenter/MaterialComponents.pm +++ b/SL/Presenter/MaterialComponents.pm @@ -3,9 +3,11 @@ package SL::Presenter::MaterialComponents; use strict; use SL::HTML::Restrict; +use SL::MoreCommon qw(listify); use SL::Presenter::EscapedText qw(escape); use SL::Presenter::Tag qw(html_tag); use Scalar::Util qw(blessed); +use List::UtilsBy qw(partition_by); use Exporter qw(import); our @EXPORT_OK = qw( @@ -49,6 +51,13 @@ my %optional_classes = ( small => SMALL, tiny => TINY, }, + size => { + map { $_ => $_ } + qw(col row), + (map { "s$_" } 1..12), + (map { "m$_" } 1..12), + (map { "l$_" } 1..12), + }, ); use Carp; @@ -95,6 +104,17 @@ sub _extract_attribute_classes { @classes; } +# used to extract material classes that are passed directly as classes +sub _extract_classes { + my ($attributes, $type) = @_; + + my @classes = map { split / / } listify($attributes->{class}); + my %classes = partition_by { !!$optional_classes{$type}{$_} } @classes; + + $attributes->{class} = $classes{''}; + $classes{1}; +} + sub _set_id_attribute { my ($attributes, $name, $unique) = @_; @@ -239,8 +259,30 @@ sub date_tag { $label, class => [ grep $_, @classes, INPUT_FIELD ], ); +} +sub select_tag { + my ($name, $collection, %attributes) = @_; + + _set_id_attribute(\%attributes, $name); + my @size_classes = _extract_classes(\%attributes, "size"); + + + my $icon = $attributes{icon} + ? icon(delete $attributes{icon}, class => 'prefix') + : ''; + + my $label = $attributes{label} + ? html_tag('label', delete $attributes{label}, for => $attributes{id}) + : ''; + + my $select_html = SL::Presenter::Tag::select_tag($name, $collection, %attributes); + + html_tag('div', + $icon . $select_html . $label, + class => [ INPUT_FIELD, @size_classes ], + ); } diff --git a/js/kivi.Materialize.js b/js/kivi.Materialize.js index 8232d5b9c..83e4efb7f 100644 --- a/js/kivi.Materialize.js +++ b/js/kivi.Materialize.js @@ -68,6 +68,7 @@ namespace("kivi.Materialize", function(ns) { ns.reinit_widgets = function() { $('.sidenav').sidenav(); + $('select').formSelect(); $('.datepicker').datepicker({ firstDay: 1, format: kivi.myconfig.dateformat,