Class: Fluxbit::DrawerComponent

Inherits:
Component
  • Object
show all
Includes:
Config::DrawerComponent
Defined in:
app/components/fluxbit/drawer_component.rb

Overview

The ‘Fluxbit::DrawerComponent` is a customizable alert component that extends `Fluxbit::Component`. It provides various options to display alert messages with different styles, icons, and behaviors such as close functionality and animations.

Example usage:

= render Fluxbit::DrawerComponent.new(
  placement: :left,
  sizing: :md,
  show_close_button: true,
  swipeable: false,
  shadow: true
) do |drawer|
  drawer.with_header do |header|
    "Header Content"
  end
end

Instance Method Summary collapse

Methods inherited from Component

#add, #add_popover_or_tooltip, #anyicon, #element_name, #fx_id, #icon, #options, #popover?, #random_id, #remove_class, #remove_class_from_props, #render_popover_or_tooltip, #target, #tooltip?

Methods included from IconHelpers

#chevron_double_left, #chevron_double_right, #chevron_down, #chevron_left, #chevron_right, #chevron_up, #close_icon, #ellipsis_horizontal, #eye_icon, #eye_slash_icon, #plus_icon

Constructor Details

#initialize(**props) ⇒ Fluxbit::DrawerComponent

Initializes the table component with the given properties.

Examples:

= render Fluxbit::DrawerComponent.new(
  placement: :left,
  sizing: :md,
  show_close_button: true,
  swipeable: false,
  shadow: true
) do |drawer|
  drawer.with_header do |header|
    "Header Content"
  end
end

Parameters:

  • props (Hash)

    The properties to customize the table.

Options Hash (**props):

  • :striped (Boolean) — default: false

    Determines if the table rows should be striped.

  • :bordered (Boolean) — default: false

    Determines if the table should have borders.

  • :hover (Boolean) — default: false

    Determines if the table rows should highlight on hover.

  • :shadow (Boolean) — default: false

    Determines if the table should have a shadow effect.

  • :wrapper_html (Hash)

    Additional HTML attributes for the wrapper div.

  • :thead_html (Hash)

    Additional HTML attributes for the table header.

  • :tbody_html (Hash)

    Additional HTML attributes for the table body.

  • :tr_html (Hash)

    Additional HTML attributes for the table rows.

  • :cells_html (Hash)

    Additional HTML attributes for the table cells.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'app/components/fluxbit/drawer_component.rb', line 61

def initialize(**props)
  super
  @props = props
  @placement = options(@props.delete(:placement), collection: styles[:placements].keys, default: @@placement).to_sym
  @sizing = options(@props.delete(:sizing), collection: styles[:sizes][:horizontal].keys, default: @@sizing).to_sym
  @show_close_button = options @props.delete(:show_close_button), default: @@show_close_button
  @swipeable = options @props.delete(:swipeable), default: @@swipeable
  @shadow = options @props.delete(:shadow), default: @@shadow
  @backdrop = options @props.delete(:backdrop), default: @@backdrop
  @auto_show = options @props.delete(:auto_show), default: @@auto_show
  @body_scrolling = options @props.delete(:body_scrolling), default: @@body_scrolling
  @edge_offset = @props.delete(:edge_offset)
  @backdrop_classes = @props.delete(:backdrop_classes)

  if @swipeable
    @placement = :bottom
    @show_close_button = false
  end

  @props[:id] ||= fx_id
  @props[:tabindex] = "-1"
  @props["aria-labelledby"] = "#{@props[:id]}-label"

  @using_stimulus = @props["data-fx-drawer-target"].present? || @props["data-controller"].to_s.include?("fx-drawer") ||
                    (
                      @props[:data].present? && (
                        @props[:data][:"fx-drawer-target"].present? || (@props[:data][:controller] || "").to_s.include?("fx-drawer")
                      )
                    )

  if @using_stimulus
    if @props["data-controller"].to_s.include?("fx-drawer") || @props[:data][:controller].to_s.include?("fx-drawer")
      @props["data-fx-drawer-auto-show-value"] = @auto_show
      @props["data-fx-drawer-placement-value"] = @placement.to_s
      @props["data-fx-drawer-backdrop-value"] = @backdrop
      @props["data-fx-drawer-body-scrolling-value"] = @body_scrolling
      @props["data-fx-drawer-edge-value"] = @swipeable
      @props["data-fx-drawer-edge-offset-value"] = @edge_offset if @edge_offset.present? && @swipeable
      @props["data-fx-drawer-backdrop-classes-value"] = @backdrop_classes if @backdrop_classes.present?
    else
      @props["data-auto-show"] = @auto_show
      @props["data-placement"] = @placement.to_s
      @props["data-backdrop"] = @backdrop
      @props["data-body-scrolling"] = @body_scrolling
      @props["data-edge"] = @swipeable
      @props["data-edge-offset"] = @edge_offset if @edge_offset.present? && @swipeable
      @props["data-backdrop-classes"] = @backdrop_classes if @backdrop_classes.present?
    end
  end

  add(
    class: [ styles[:root],
            styles[:placements][@placement],
            styles[:color],
            @swipeable ? styles[:swipeable][:default] : nil,
            @shadow ? styles[:shadow] : nil,
            size_class ],
    to: @props
  )
end

Instance Method Details

#size_classObject



122
123
124
# File 'app/components/fluxbit/drawer_component.rb', line 122

def size_class
  styles[:sizes][@placement.in?([ :left, :right ]) ? :horizontal : :vertical][@sizing]
end