-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathseparator.rb
More file actions
38 lines (30 loc) · 827 Bytes
/
separator.rb
File metadata and controls
38 lines (30 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
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
# frozen_string_literal: true
module RubyUI
class Separator < Base
ORIENTATIONS = %i[horizontal vertical].freeze
def initialize(as: :div, orientation: :horizontal, decorative: true, **attrs)
raise ArgumentError, "Invalid orientation: #{orientation}" unless ORIENTATIONS.include?(orientation.to_sym)
@as = as
@orientation = orientation.to_sym
@decorative = decorative
super(**attrs)
end
def view_template(&)
tag(@as, **attrs, &)
end
private
def default_attrs
{
role: (@decorative ? "none" : "separator"),
class: [
"shrink-0 bg-border",
orientation_classes
]
}
end
def orientation_classes
return "h-[1px] w-full" if @orientation == :horizontal
"h-full w-[1px]"
end
end
end