Class: NitroKit::Sheet
- Defined in:
- app/components/nitro_kit/sheet.rb
Constant Summary collapse
- SIDES =
%i[left right].freeze
- SIZES =
%i[sm md lg].freeze
Constants inherited from Component
Component::ADDITIVE_DATA_ATTRIBUTES, Component::COMPONENT_OWNED_DATA_ATTRIBUTES, Component::FORBIDDEN_ATTRIBUTES, Component::RESERVED_DATA_ATTRIBUTES
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#side ⇒ Object
readonly
Returns the value of attribute side.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
-
#initialize(id:, side: :right, size: :md, close_label: I18n.t("nitro_kit.sheet.close"), html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ Sheet
constructor
A new instance of Sheet.
- #panel(title:, description: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil, &content) ⇒ Object
- #trigger(text = nil, variant: :default, size: :md, icon: nil, icon_end: nil, label: nil, disabled: false, html: {}, aria: {}, data: {}, desperately_need_a_class: nil, &content) ⇒ Object
- #view_template(&declarations) ⇒ Object
Constructor Details
#initialize(id:, side: :right, size: :md, close_label: I18n.t("nitro_kit.sheet.close"), html: {}, aria: {}, data: {}, desperately_need_a_class: nil) ⇒ Sheet
Returns a new instance of Sheet.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/components/nitro_kit/sheet.rb', line 14 def initialize( id:, side: :right, size: :md, close_label: I18n.t("nitro_kit.sheet.close"), html: {}, aria: {}, data: {}, desperately_need_a_class: nil ) unless id.is_a?(String) && id.present? && !id.match?(/\s/) raise ArgumentError, "Sheet id: must be a non-blank String without whitespace" end unless close_label.is_a?(String) && close_label.present? raise ArgumentError, "Sheet close_label: must be a non-blank String" end @id = id @side = validate_choice!(:side, side, SIDES) @size = validate_choice!(:size, size, SIZES) @close_label = close_label super( component: :sheet, attributes: { id:, data: { controller: "nk--dialog", action: [ "click->nk--dialog#invoke", "turbo:before-cache@document->nk--dialog#closeForCache" ].join(" "), side: @side, nk__dialog_dismissible_value: true } }, html:, aria:, data:, size:, desperately_need_a_class: ) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
58 59 60 |
# File 'app/components/nitro_kit/sheet.rb', line 58 def id @id end |
#side ⇒ Object (readonly)
Returns the value of attribute side.
58 59 60 |
# File 'app/components/nitro_kit/sheet.rb', line 58 def side @side end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
58 59 60 |
# File 'app/components/nitro_kit/sheet.rb', line 58 def size @size end |
Instance Method Details
#panel(title:, description: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil, &content) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/components/nitro_kit/sheet.rb', line 103 def panel( title:, description: nil, html: {}, aria: {}, data: {}, desperately_need_a_class: nil, &content ) ensure_collecting! raise ArgumentError, "Sheet accepts exactly one panel" if @panel unless title.is_a?(String) && title.present? raise ArgumentError, "Sheet title: must be a non-blank String" end unless description.nil? || (description.is_a?(String) && description.present?) raise ArgumentError, "Sheet description: must be nil or a non-blank String" end @panel = Panel.new(title:, description:, html:, aria:, data:, css_class: desperately_need_a_class, content:) nil end |
#trigger(text = nil, variant: :default, size: :md, icon: nil, icon_end: nil, label: nil, disabled: false, html: {}, aria: {}, data: {}, desperately_need_a_class: nil, &content) ⇒ Object
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 |
# File 'app/components/nitro_kit/sheet.rb', line 69 def trigger( text = nil, variant: :default, size: :md, icon: nil, icon_end: nil, label: nil, disabled: false, html: {}, aria: {}, data: {}, desperately_need_a_class: nil, &content ) ensure_collecting! raise ArgumentError, "Sheet accepts exactly one trigger" if @trigger @trigger = Trigger.new( text:, variant:, size:, icon:, icon_end:, label:, disabled: validate_boolean!(:disabled, disabled), html:, aria:, data:, css_class: desperately_need_a_class, content: ) nil end |
#view_template(&declarations) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'app/components/nitro_kit/sheet.rb', line 60 def view_template(&declarations) collect_declarations(&declarations) div(**root_attributes) do render_trigger render_panel end end |