Sha256: bee1b14a23cb6339d5663872af337b8bb8977d268ab65398f548871ebf9f9822
Contents?: true
Size: 970 Bytes
Versions: 15
Compression:
Stored size: 970 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? 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
15 entries across 15 versions & 1 rubygems