Sha256: 12280b0b2d930816f307fff663bd2a775a8d4f0c0669ca88137fd3a2117f2f50
Contents?: true
Size: 955 Bytes
Versions: 18
Compression:
Stored size: 955 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', class: 'govuk-character-count', data: { module: 'govuk-character-count' }.merge(**limit, **threshold).compact ) do yield end end private 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
18 entries across 18 versions & 1 rubygems