Sha256: c14ee407d51fb08375fbb485ea120a71326e6d0a8df69e16ad63c528fde4e1f1
Contents?: true
Size: 981 Bytes
Versions: 2
Compression:
Stored size: 981 Bytes
Contents
module GOVUKDesignSystemFormBuilder module Containers class CharacterCount < Base def initialize(builder, max_words:, max_chars:, threshold:) @builder = builder fail ArgumentError, 'limit can be words or chars' if max_words && max_chars @max_words = max_words @max_chars = max_chars @threshold = threshold end def html return yield unless limit? content_tag('div', **options) { yield } end private def options { class: %(#{brand}-character-count), data: { module: %(#{brand}-character-count) }.merge(**limit, **threshold).compact } end def limit if @max_words { maxwords: @max_words } elsif @max_chars { maxlength: @max_chars } end end def threshold { threshold: @threshold } end def limit? @max_words || @max_chars end end end end
Version data entries
2 entries across 2 versions & 1 rubygems