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, &content) ⇒ Object
- #trigger(text = nil, variant: :default, size: :md, icon: nil, icon_end: nil, label: nil, disabled: false, html: {}, aria: {}, data: {}, &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 |
# 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", 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.
54 55 56 |
# File 'app/components/nitro_kit/sheet.rb', line 54 def id @id end |
#side ⇒ Object (readonly)
Returns the value of attribute side.
54 55 56 |
# File 'app/components/nitro_kit/sheet.rb', line 54 def side @side end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
54 55 56 |
# File 'app/components/nitro_kit/sheet.rb', line 54 def size @size end |
Instance Method Details
#panel(title:, description: nil, &content) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/components/nitro_kit/sheet.rb', line 97 def panel(title:, description: 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:, content:) nil end |
#trigger(text = nil, variant: :default, size: :md, icon: nil, icon_end: nil, label: nil, disabled: false, html: {}, aria: {}, data: {}, &content) ⇒ Object
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 |
# File 'app/components/nitro_kit/sheet.rb', line 65 def trigger( text = nil, variant: :default, size: :md, icon: nil, icon_end: nil, label: nil, disabled: false, html: {}, aria: {}, data: {}, &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:, content: ) nil end |
#view_template(&declarations) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'app/components/nitro_kit/sheet.rb', line 56 def view_template(&declarations) collect_declarations(&declarations) div(**root_attributes) do render_trigger render_panel end end |