Sha256: bb8c582341732faa5b135491908b53c161a7b7277a5f73c061d7d20d3a7f0adb

Contents?: true

Size: 1.63 KB

Versions: 1194

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

module Playbook
  module PbDateRangeInline
    class DateRangeInline < Playbook::KitBase
      prop :end_date, type: Playbook::Props::Date, required: true
      prop :start_date, type: Playbook::Props::Date, required: true
      prop :icon, required: false
      prop :dark, type: Playbook::Props::Boolean,
                  default: false
      prop :size, type: Playbook::Props::Enum,
                  values: %w[xs sm],
                  default: "sm"
      prop :align, type: Playbook::Props::Enum,
                   values: %w[left center right],
                   default: "left"

      def classname
        generate_classname("pb_date_range_inline_kit", dark_class, align)
      end

      def text_kit
        case size
        when "xs"
          "caption"
        when "sm"
          "body"
        end
      end

      def icon_color
        size == "sm" ? "light" : nil
      end

      def dates_in_current_year?
        current_year = Time.current.year
        start_date.year == current_year && end_date.year == current_year
      end

      def time_display(time)
        content_tag(:time, datetime: time.to_iso) do
          if dates_in_current_year?
            "#{time.to_month_downcase} #{time.to_day}"
          else
            "#{time.to_month_downcase} #{time.to_day}, #{time.to_year}"
          end
        end
      end

      def end_date_display
        time_display(Playbook::PbKit::PbDateTime.new(end_date))
      end

      def start_date_display
        time_display(Playbook::PbKit::PbDateTime.new(start_date))
      end

      def dark_class
        dark ? "dark" : nil
      end
    end
  end
end

Version data entries

1,194 entries across 1,194 versions & 1 rubygems

Version Path
playbook_ui-14.11.0.pre.rc.17 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.11.0 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.11.0.pre.rc.16 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.10.0.pre.alpha.play16825301 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.11.0.pre.rc.15 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.11.0.pre.rc.14 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.11.0.pre.rc.13 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.11.0.pre.rc.12 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.10.0.pre.alpha.PLAY1774timelinelabelstepspacing5274 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.10.0.pre.alpha.play1465attempt25272 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.10.0.pre.alpha.play16825244 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.11.0.pre.rc.11 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.11.0.pre.rc.10 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.10.0.pre.alpha.play1662cssbargraph5214 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.10.0.pre.alpha.play1662cssbargraph5213 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.10.0.pre.alpha.play1662cssbargraph5210 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.10.0.pre.alpha.play1662cssbargraph5208 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.10.0.pre.alpha.play1662cssbargraph5207 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.10.0.pre.alpha.play16825206 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.10.0.pre.alpha.play1662cssbargraph5204 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb