Sha256: c7e5233d02c51e248bf306bdd28d7811782f999b78fd4a26f600d4cbc1b86468

Contents?: true

Size: 1.7 KB

Versions: 90

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

module Playbook
  module PbBody
    class Body < Playbook::KitBase
      prop :color, type: Playbook::Props::Enum,
                   values: %w[default light lighter link success error],
                   default: "default"
      prop :status, type: Playbook::Props::Enum,
                    values: %w[neutral positive negative],
                    default: "neutral",
                    deprecated: true
      prop :tag, type: Playbook::Props::Enum,
                 values: %w[h1 h2 h3 h4 h5 h6 p span div],
                 default: "div"
      prop :text
      prop :highlighting, type: Playbook::Props::Boolean,
                          default: false
      prop :highlighted_text, type: Playbook::Props::Array,
                              default: []
      prop :truncate, type: Playbook::Props::Enum,
                      values: [nil, "1", "2", "3", "4", "5"],
                      default: nil

      def classname
        generate_classname("pb_body_kit", color_class, status_class, is_truncated)
      end

      def content
        body_text = super.presence || text
        highlighting ? apply_highlight(body_text) : body_text
      end

      def is_truncated
        truncate ? "truncate_#{truncate}" : nil
      end

    private

      def apply_highlight(text)
        pb_highlight_output = pb_rails("highlight") { "|" }
        highlight_tags = pb_highlight_output.split("|")
        highlight(text, highlighted_text, highlighter: "#{highlight_tags.first.html_safe} \\1 #{highlight_tags.last.html_safe}")
      end

      def color_class
        color == "default" ? nil : color
      end

      def status_class
        status == "neutral" ? nil : status
      end
    end
  end
end

Version data entries

90 entries across 90 versions & 1 rubygems

Version Path
playbook_ui-13.14.0.pre.alpha.PLAY1109bugdisplaypropblocksfontcolor1784 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-13.14.0.pre.alpha.play1106filter1751 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-13.14.0.pre.alpha.play1106filter1748 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-13.14.0 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-13.13.0.pre.alpha.PLAY1097linterenhancedelement1728 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-13.13.0.pre.alpha.play10821727 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-13.13.0.pre.alpha.play10821726 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-13.13.0.pre.alpha.play10221678 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-13.13.0.pre.alpha.PLAY1090csstokens1675 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-13.13.0.pre.alpha.play900startratingasinput1657 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-13.13.0 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-13.12.0.pre.alpha.PLAY880cardkithighlightzindex1655 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-13.12.0.pre.alpha.PLAY1081exportingtypes1627 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-13.12.0.pre.alpha.PLAY1081exportingtypes1626 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-13.12.0.pre.alpha.PLAY1081exporttypes1624 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-13.12.0.pre.alpha.PLAY1081exporttypes1623 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-13.12.0.pre.alpha.play900startratingasinput1612 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-13.12.0.pre.alpha.PLAY1081exporttypes1611 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-13.12.0.pre.alpha.PLAY1081exporttypes1609 app/pb_kits/playbook/pb_body/body.rb
playbook_ui-13.12.0.pre.alpha.PLAY1081exporttypes1608 app/pb_kits/playbook/pb_body/body.rb