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.10.0.pre.rc.23 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.10.0.pre.rc.22 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.10.0.pre.rc.21 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.9.0.pre.alpha.play1703errorstatealignment5060 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.10.0.pre.rc.20 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.10.0.pre.rc.19 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.10.0.pre.rc.18 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.9.0.pre.alpha.PLAY1660reactdropzone5020 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.10.0.pre.rc.17 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.10.0.pre.rc.16 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.9.0.pre.alpha.play17004992 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.9.0.pre.alpha.play1703errorstatealignment4991 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.10.0.pre.rc.15 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.9.0.pre.alpha.PLAY16264952 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.9.0.pre.alpha.PLAY1731inputmasking4927 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.9.0.pre.alpha.play1742globalheightfixes4926 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.9.0.pre.alpha.play1742globalheightfixes4925 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.10.0.pre.rc.14 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.10.0.pre.rc.13 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb
playbook_ui-14.9.0.pre.alpha.PBNTR746datepickerdefaultbug4903 app/pb_kits/playbook/pb_date_range_inline/date_range_inline.rb