nitro_kit 0.5.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/components/nitro_kit/accordion.rb +35 -29
- data/app/components/nitro_kit/alert.rb +8 -4
- data/app/components/nitro_kit/avatar.rb +4 -2
- data/app/components/nitro_kit/avatar_stack.rb +23 -0
- data/app/components/nitro_kit/badge.rb +48 -4
- data/app/components/nitro_kit/button.rb +8 -2
- data/app/components/nitro_kit/card.rb +20 -10
- data/app/components/nitro_kit/checkbox.rb +23 -12
- data/app/components/nitro_kit/checkbox_group.rb +8 -4
- data/app/components/nitro_kit/combobox.rb +11 -2
- data/app/components/nitro_kit/component.rb +48 -23
- data/app/components/nitro_kit/dialog.rb +61 -38
- data/app/components/nitro_kit/dropdown.rb +70 -49
- data/app/components/nitro_kit/field.rb +103 -65
- data/app/components/nitro_kit/fieldset.rb +13 -6
- data/app/components/nitro_kit/form_builder.rb +27 -8
- data/app/components/nitro_kit/icon.rb +3 -2
- data/app/components/nitro_kit/input.rb +1 -1
- data/app/components/nitro_kit/pagination.rb +42 -34
- data/app/components/nitro_kit/radio_button.rb +33 -18
- data/app/components/nitro_kit/radio_button_group.rb +20 -16
- data/app/components/nitro_kit/select.rb +10 -8
- data/app/components/nitro_kit/table.rb +38 -11
- data/app/components/nitro_kit/tabs.rb +47 -41
- data/app/components/nitro_kit/textarea.rb +6 -2
- data/app/components/nitro_kit/toast.rb +26 -3
- data/app/components/nitro_kit/tooltip.rb +13 -11
- data/app/helpers/nitro_kit/accordion_helper.rb +1 -1
- data/app/helpers/nitro_kit/alert_helper.rb +1 -1
- data/app/helpers/nitro_kit/avatar_helper.rb +5 -1
- data/app/helpers/nitro_kit/badge_helper.rb +1 -1
- data/app/helpers/nitro_kit/button_group_helper.rb +1 -1
- data/app/helpers/nitro_kit/button_helper.rb +3 -3
- data/app/helpers/nitro_kit/card_helper.rb +1 -1
- data/app/helpers/nitro_kit/checkbox_helper.rb +25 -2
- data/app/helpers/nitro_kit/combobox_helper.rb +1 -1
- data/app/helpers/nitro_kit/datepicker_helper.rb +1 -1
- data/app/helpers/nitro_kit/dialog_helper.rb +1 -1
- data/app/helpers/nitro_kit/dropdown_helper.rb +1 -1
- data/app/helpers/nitro_kit/field_group_helper.rb +1 -1
- data/app/helpers/nitro_kit/field_helper.rb +1 -1
- data/app/helpers/nitro_kit/fieldset_helper.rb +1 -1
- data/app/helpers/nitro_kit/icon_helper.rb +1 -1
- data/app/helpers/nitro_kit/input_helper.rb +1 -1
- data/app/helpers/nitro_kit/label_helper.rb +1 -1
- data/app/helpers/nitro_kit/pagination_helper.rb +1 -1
- data/app/helpers/nitro_kit/radio_button_helper.rb +2 -2
- data/app/helpers/nitro_kit/select_helper.rb +1 -1
- data/app/helpers/nitro_kit/switch_helper.rb +1 -1
- data/app/helpers/nitro_kit/table_helper.rb +1 -1
- data/app/helpers/nitro_kit/tabs_helper.rb +1 -1
- data/app/helpers/nitro_kit/textarea_helper.rb +1 -1
- data/app/helpers/nitro_kit/toast_helper.rb +2 -13
- data/app/helpers/nitro_kit/tooltip_helper.rb +1 -1
- data/lib/nitro_kit/version.rb +1 -1
- metadata +6 -6
- data/MIT-LICENSE +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43de49498356e50a1fbcac794f988fdcb36c4032bea949316aee19483c1b9208
|
4
|
+
data.tar.gz: 3b4d2a3cdaae5730e46a5880e0ed7d05e0d824bda868d4200d76785c14087ca0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62f3abbfcc402e5a97b2223f91f95601655ec3a5f6824514ad27e2160d093fb62f458b6caccee302bd948717a29e8d89c248cc0e7f760ec03e870f06bb1dab00
|
7
|
+
data.tar.gz: f00b678398e9430ca799ca92f5331a1e62a1fb459237929aed658d24a6ec98836adde8617cbc01add48ac7d5bf66834ca5094fb2307378447e265203d2e306a3
|
@@ -17,41 +17,47 @@ module NitroKit
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def item(**attrs)
|
20
|
-
|
21
|
-
|
20
|
+
builder do
|
21
|
+
div(**attrs) do
|
22
|
+
yield
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
27
|
def trigger(text = nil, **attrs)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
28
|
+
builder do
|
29
|
+
button(
|
30
|
+
**mattr(
|
31
|
+
attrs,
|
32
|
+
type: "button",
|
33
|
+
class: trigger_class,
|
34
|
+
data: {
|
35
|
+
action: "nk--accordion#toggle",
|
36
|
+
nk__accordion_target: "trigger"
|
37
|
+
},
|
38
|
+
aria: {expanded: "false"}
|
39
|
+
)
|
40
|
+
) do
|
41
|
+
block_given? ? yield : plain(text)
|
42
|
+
chevron_icon
|
43
|
+
end
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
43
47
|
def content(**attrs)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
48
|
+
builder do
|
49
|
+
div(
|
50
|
+
**mattr(
|
51
|
+
attrs,
|
52
|
+
class: content_class,
|
53
|
+
data: {
|
54
|
+
nk__accordion_target: "content"
|
55
|
+
},
|
56
|
+
aria: {hidden: "true"}
|
57
|
+
)
|
58
|
+
) do
|
59
|
+
div(class: "pb-4") { yield }
|
60
|
+
end
|
55
61
|
end
|
56
62
|
end
|
57
63
|
|
@@ -78,12 +84,12 @@ module NitroKit
|
|
78
84
|
end
|
79
85
|
|
80
86
|
def arrow_class
|
81
|
-
"transition-transform duration-200 text-muted-
|
87
|
+
"transition-transform duration-200 text-muted-content group-hover/accordion-trigger:text-primary"
|
82
88
|
end
|
83
89
|
|
84
90
|
def chevron_icon
|
85
91
|
svg(
|
86
|
-
class: "transition-transform duration-200 size-4 self-center place-self-end mr-2 pointer-events-none text-muted-
|
92
|
+
class: "transition-transform duration-200 size-4 self-center place-self-end mr-2 pointer-events-none text-muted-content group-hover/accordion-trigger:text-primary",
|
87
93
|
viewbox: "0 0 24 24",
|
88
94
|
fill: "none",
|
89
95
|
stroke: "currentColor",
|
@@ -23,14 +23,18 @@ module NitroKit
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def title(text = nil, **attrs, &block)
|
26
|
-
|
27
|
-
|
26
|
+
builder do
|
27
|
+
h5(**mattr(attrs, class: title_class)) do
|
28
|
+
text_or_block(text, &block)
|
29
|
+
end
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
31
33
|
def description(text = nil, **attrs, &block)
|
32
|
-
|
33
|
-
|
34
|
+
builder do
|
35
|
+
div(**mattr(attrs, class: description_class)) do
|
36
|
+
text_or_block(text, &block)
|
37
|
+
end
|
34
38
|
end
|
35
39
|
end
|
36
40
|
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module NitroKit
|
4
4
|
class Avatar < Component
|
5
|
+
include Phlex::Rails::Helpers::ImageTag
|
6
|
+
|
5
7
|
def initialize(src_arg = nil, src: nil, size: :md, **attrs)
|
6
8
|
@src = src_arg || src
|
7
9
|
@size = size
|
@@ -20,8 +22,8 @@ module NitroKit
|
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
|
-
def image
|
24
|
-
|
25
|
+
builder_method def image
|
26
|
+
image_tag(src, class: image_class)
|
25
27
|
end
|
26
28
|
|
27
29
|
private
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NitroKit
|
4
|
+
class AvatarStack < Component
|
5
|
+
def initialize(size: :md, **attrs)
|
6
|
+
@size = size
|
7
|
+
|
8
|
+
super(attrs)
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :size
|
12
|
+
|
13
|
+
def view_template
|
14
|
+
div(**mattr(attrs, class: "flex items-center -space-x-3 [&>div]:ring-2 [&>div]:ring-background")) do
|
15
|
+
yield
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
builder_method def avatar(*args, **attrs, &block)
|
20
|
+
render(Avatar.new(*args, size:, **attrs, &block))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -4,10 +4,11 @@ module NitroKit
|
|
4
4
|
class Badge < Component
|
5
5
|
VARIANTS = %i[default outline]
|
6
6
|
|
7
|
-
def initialize(text = nil, variant: :default, size: :md, **attrs)
|
7
|
+
def initialize(text = nil, variant: :default, size: :md, color: :gray, **attrs)
|
8
8
|
@text = text
|
9
9
|
@variant = variant
|
10
10
|
@size = size
|
11
|
+
@color = color
|
11
12
|
|
12
13
|
super(
|
13
14
|
attrs,
|
@@ -19,7 +20,7 @@ module NitroKit
|
|
19
20
|
)
|
20
21
|
end
|
21
22
|
|
22
|
-
attr_reader :text, :variant, :size
|
23
|
+
attr_reader :text, :variant, :size, :color
|
23
24
|
|
24
25
|
def view_template(&block)
|
25
26
|
span(**attrs) do
|
@@ -30,13 +31,13 @@ module NitroKit
|
|
30
31
|
private
|
31
32
|
|
32
33
|
def base_class
|
33
|
-
"inline-flex items-center gap-x-1.5 rounded-md font-medium"
|
34
|
+
"inline-flex items-center gap-x-1.5 rounded-md font-medium whitespace-nowrap"
|
34
35
|
end
|
35
36
|
|
36
37
|
def variant_class
|
37
38
|
case variant
|
38
39
|
when :default
|
39
|
-
|
40
|
+
color_class
|
40
41
|
when :outline
|
41
42
|
"border"
|
42
43
|
else
|
@@ -54,5 +55,48 @@ module NitroKit
|
|
54
55
|
raise ArgumentError, "Invalid size: #{size}"
|
55
56
|
end
|
56
57
|
end
|
58
|
+
|
59
|
+
def color_class
|
60
|
+
case color
|
61
|
+
when :gray
|
62
|
+
"text-zinc-700 dark:text-zinc-200 bg-zinc-400/15 dark:bg-zinc-400/40"
|
63
|
+
when :red
|
64
|
+
"text-red-900 dark:text-red-200 bg-red-300/50 dark:bg-red-400/40"
|
65
|
+
when :orange
|
66
|
+
"text-orange-700 dark:text-orange-200 bg-orange-400/20 dark:bg-orange-400/40"
|
67
|
+
when :amber
|
68
|
+
"text-amber-700 dark:text-amber-200 bg-amber-400/20 dark:bg-amber-400/40"
|
69
|
+
when :yellow
|
70
|
+
"text-yellow-900 dark:text-yellow-200 bg-yellow-400/40 dark:bg-yellow-400/40"
|
71
|
+
when :lime
|
72
|
+
"text-lime-700 dark:text-lime-200 bg-lime-400/20 dark:bg-lime-400/40"
|
73
|
+
when :green
|
74
|
+
"text-green-800 dark:text-green-200 bg-green-500/20 dark:bg-green-400/40"
|
75
|
+
when :emerald
|
76
|
+
"text-emerald-700 dark:text-emerald-200 bg-emerald-400/20 dark:bg-emerald-400/40"
|
77
|
+
when :teal
|
78
|
+
"text-teal-700 dark:text-teal-200 bg-teal-400/20 dark:bg-teal-400/40"
|
79
|
+
when :cyan
|
80
|
+
"text-cyan-700 dark:text-cyan-200 bg-cyan-400/20 dark:bg-cyan-400/40"
|
81
|
+
when :sky
|
82
|
+
"text-sky-700 dark:text-sky-200 bg-sky-400/20 dark:bg-sky-400/40"
|
83
|
+
when :blue
|
84
|
+
"text-blue-700 dark:text-blue-200 bg-blue-400/20 dark:bg-blue-400/40"
|
85
|
+
when :indigo
|
86
|
+
"text-indigo-700 dark:text-indigo-200 bg-indigo-400/20 dark:bg-indigo-400/40"
|
87
|
+
when :violet
|
88
|
+
"text-violet-700 dark:text-violet-200 bg-violet-400/20 dark:bg-violet-400/40"
|
89
|
+
when :purple
|
90
|
+
"text-purple-700 dark:text-purple-200 bg-purple-400/20 dark:bg-purple-400/40"
|
91
|
+
when :fuchsia
|
92
|
+
"text-fuchsia-700 dark:text-fuchsia-200 bg-fuchsia-400/20 dark:bg-fuchsia-400/40"
|
93
|
+
when :pink
|
94
|
+
"text-pink-700 dark:text-pink-200 bg-pink-400/20 dark:bg-pink-400/40"
|
95
|
+
when :rose
|
96
|
+
"text-rose-700 dark:text-rose-200 bg-rose-400/20 dark:bg-rose-400/40"
|
97
|
+
else
|
98
|
+
raise ArgumentError, "Unknown color `#{color}'"
|
99
|
+
end
|
100
|
+
end
|
57
101
|
end
|
58
102
|
end
|
@@ -105,7 +105,7 @@ module NitroKit
|
|
105
105
|
[
|
106
106
|
"bg-transparent text-foreground border-transparent",
|
107
107
|
"hover:bg-zinc-200/50 dark:hover:bg-zinc-900",
|
108
|
-
"disabled:text-muted-
|
108
|
+
"disabled:text-muted-content"
|
109
109
|
]
|
110
110
|
else
|
111
111
|
raise ArgumentError, "Unknown variant `#{variant}'"
|
@@ -118,7 +118,7 @@ module NitroKit
|
|
118
118
|
"px-1.5 h-6 text-xs [&_svg]:size-3"
|
119
119
|
when :sm
|
120
120
|
[
|
121
|
-
"px-2.5 h-7 text-sm [&_svg]:size-
|
121
|
+
"px-2.5 h-7 text-sm [&_svg]:size-4",
|
122
122
|
"[&_svg:first-child:last-child]:-mx-1"
|
123
123
|
]
|
124
124
|
when :md
|
@@ -133,6 +133,12 @@ module NitroKit
|
|
133
133
|
# If icon only, make square
|
134
134
|
"[&_svg:first-child:last-child]:-mx-2"
|
135
135
|
]
|
136
|
+
when :xl
|
137
|
+
[
|
138
|
+
"px-8 h-14 text-2xl [&_svg]:size-5 gap-x-4",
|
139
|
+
# If icon only, make square
|
140
|
+
"[&_svg:first-child:last-child]:-mx-8"
|
141
|
+
]
|
136
142
|
else
|
137
143
|
raise ArgumentError, "Unknown size `#{size}'"
|
138
144
|
end
|
@@ -16,32 +16,42 @@ module NitroKit
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def title(text = nil, **attrs, &block)
|
19
|
-
|
20
|
-
|
19
|
+
builder do
|
20
|
+
h2(**mattr(attrs, class: "text-lg font-bold -mb-2")) do
|
21
|
+
text_or_block(text, &block)
|
22
|
+
end
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
26
|
def body(text = nil, **attrs, &block)
|
25
|
-
|
26
|
-
|
27
|
+
builder do
|
28
|
+
div(**mattr(attrs, class: "text-muted-content text-sm leading-relaxed")) do
|
29
|
+
text_or_block(text, &block)
|
30
|
+
end
|
27
31
|
end
|
28
32
|
end
|
29
33
|
|
30
34
|
def footer(text = nil, **attrs, &block)
|
31
|
-
|
32
|
-
|
35
|
+
builder do
|
36
|
+
div(**mattr(attrs, class: "flex gap-2 items-center")) do
|
37
|
+
text_or_block(text, &block)
|
38
|
+
end
|
33
39
|
end
|
34
40
|
end
|
35
41
|
|
36
42
|
def divider(**attrs)
|
37
|
-
|
38
|
-
|
43
|
+
builder do
|
44
|
+
full_width do
|
45
|
+
hr(**attrs)
|
46
|
+
end
|
39
47
|
end
|
40
48
|
end
|
41
49
|
|
42
50
|
def full_width(**attrs)
|
43
|
-
|
44
|
-
|
51
|
+
builder do
|
52
|
+
div(**mattr(attrs, data: {slot: "full"}, class: "-mx-(--gap)")) do
|
53
|
+
yield
|
54
|
+
end
|
45
55
|
end
|
46
56
|
end
|
47
57
|
|
@@ -1,8 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module NitroKit
|
2
4
|
class Checkbox < Component
|
3
|
-
def initialize(label: nil, id: nil, **attrs)
|
5
|
+
def initialize(label: nil, id: nil, wrapper: {}, **attrs)
|
4
6
|
@id = id || "nk--" + SecureRandom.hex(4)
|
5
7
|
@label = label
|
8
|
+
@wrapper = wrapper
|
6
9
|
|
7
10
|
super(
|
8
11
|
attrs,
|
@@ -14,12 +17,12 @@ module NitroKit
|
|
14
17
|
|
15
18
|
alias :html_label :label
|
16
19
|
|
17
|
-
attr_reader :label, :id
|
20
|
+
attr_reader :label, :id, :wrapper
|
18
21
|
|
19
22
|
def view_template
|
20
|
-
div(class: wrapper_class) do
|
23
|
+
div(**mattr(wrapper, class: wrapper_class)) do
|
21
24
|
html_label(
|
22
|
-
class: "inline-grid *:[grid-area:1/1] shrink-0 place-items-center group/checkbox"
|
25
|
+
class: "inline-grid *:[grid-area:1/1] shrink-0 place-items-center group/checkbox has-checked:not-has-indeterminate:[&>[data-check]]:visible has-indeterminate:[&>[data-indeterminate]]:visible"
|
23
26
|
) do
|
24
27
|
input(**attrs)
|
25
28
|
checkmark
|
@@ -27,7 +30,9 @@ module NitroKit
|
|
27
30
|
end
|
28
31
|
|
29
32
|
if label.present? || block_given?
|
30
|
-
render(Label.new(for: id))
|
33
|
+
render(Label.new(for: id)) do
|
34
|
+
label || (block_given? ? yield : nil)
|
35
|
+
end
|
31
36
|
end
|
32
37
|
end
|
33
38
|
end
|
@@ -36,13 +41,14 @@ module NitroKit
|
|
36
41
|
|
37
42
|
def checkmark
|
38
43
|
svg(
|
39
|
-
class: merge_class(svg_class, "
|
44
|
+
class: merge_class(svg_class, "invisible"),
|
40
45
|
viewbox: "0 0 16 16",
|
41
46
|
fill: "none",
|
42
47
|
stroke: "currentColor",
|
43
48
|
stroke_linecap: "round",
|
44
49
|
stroke_linejoin: "round",
|
45
|
-
stroke_width: 3
|
50
|
+
stroke_width: 3,
|
51
|
+
data: {check: ""}
|
46
52
|
) do |svg|
|
47
53
|
svg.path(d: "M 3 8 L 6 12 L 13 5")
|
48
54
|
end
|
@@ -50,12 +56,13 @@ module NitroKit
|
|
50
56
|
|
51
57
|
def dash
|
52
58
|
svg(
|
53
|
-
class: merge_class(svg_class, "
|
59
|
+
class: merge_class(svg_class, "invisible"),
|
54
60
|
viewbox: "0 0 16 16",
|
55
61
|
fill: "none",
|
56
62
|
stroke: "currentColor",
|
57
63
|
stroke_linecap: "round",
|
58
|
-
stroke_width: 3
|
64
|
+
stroke_width: 3,
|
65
|
+
data: {indeterminate: ""}
|
59
66
|
) do |svg|
|
60
67
|
svg.line(x1: "3", y1: "8", x2: "13", y2: "8")
|
61
68
|
end
|
@@ -65,16 +72,20 @@ module NitroKit
|
|
65
72
|
[
|
66
73
|
"appearance-none shadow-sm size-4 rounded-sm border text-foreground",
|
67
74
|
"checked:bg-primary checked:border-primary indeterminate:bg-primary indeterminate:border-primary",
|
68
|
-
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring ring-offset-2 ring-offset-background"
|
75
|
+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring ring-offset-2 ring-offset-background",
|
76
|
+
"disabled:pointer-events-none"
|
69
77
|
]
|
70
78
|
end
|
71
79
|
|
72
80
|
def svg_class
|
73
|
-
"size-3 text-zinc-50
|
81
|
+
"size-3 text-zinc-50 dark:text-zinc-950 pointer-events-none invisible"
|
74
82
|
end
|
75
83
|
|
76
84
|
def wrapper_class
|
77
|
-
|
85
|
+
[
|
86
|
+
"isolate inline-flex items-center gap-2",
|
87
|
+
"has-disabled:opacity-70"
|
88
|
+
]
|
78
89
|
end
|
79
90
|
end
|
80
91
|
end
|
@@ -24,14 +24,18 @@ module NitroKit
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def title(text = nil, **attrs, &block)
|
27
|
-
|
28
|
-
|
27
|
+
builder do
|
28
|
+
render(Label.new(**attrs)) do
|
29
|
+
text_or_block(text, &block)
|
30
|
+
end
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
32
34
|
def item(text = nil, **attrs, &block)
|
33
|
-
|
34
|
-
|
35
|
+
builder do
|
36
|
+
render(Checkbox.new(**attrs)) do
|
37
|
+
text_or_block(text, &block)
|
38
|
+
end
|
35
39
|
end
|
36
40
|
end
|
37
41
|
end
|
@@ -67,7 +67,7 @@ module NitroKit
|
|
67
67
|
}
|
68
68
|
) do
|
69
69
|
span(class: wrapper_class) do
|
70
|
-
render(Input.new(**attrs))
|
70
|
+
render(Input.new(**attrs, value: display_value))
|
71
71
|
chevron_icon
|
72
72
|
end
|
73
73
|
|
@@ -76,6 +76,7 @@ module NitroKit
|
|
76
76
|
input(
|
77
77
|
type: "hidden",
|
78
78
|
value: attrs[:value],
|
79
|
+
name: attrs[:name],
|
79
80
|
data: {nk__combobox_target: "hiddenField"}
|
80
81
|
)
|
81
82
|
|
@@ -102,6 +103,14 @@ module NitroKit
|
|
102
103
|
"#{@id}-#{suffix}"
|
103
104
|
end
|
104
105
|
|
106
|
+
def display_value
|
107
|
+
selected = options.find do |(key, value)|
|
108
|
+
value.to_s == attrs[:value].to_s
|
109
|
+
end
|
110
|
+
|
111
|
+
selected&.first || attrs[:value]
|
112
|
+
end
|
113
|
+
|
105
114
|
def wrapper_class
|
106
115
|
"inline-grid *:[grid-area:1/1] group/combobox"
|
107
116
|
end
|
@@ -125,7 +134,7 @@ module NitroKit
|
|
125
134
|
|
126
135
|
def chevron_icon
|
127
136
|
svg(
|
128
|
-
class: "size-4 self-center place-self-end mr-2 pointer-events-none text-muted-
|
137
|
+
class: "size-4 self-center place-self-end mr-2 pointer-events-none text-muted-content group-hover/combobox:text-foreground",
|
129
138
|
viewbox: "0 0 24 24",
|
130
139
|
fill: "none",
|
131
140
|
stroke: "currentColor",
|
@@ -2,28 +2,49 @@
|
|
2
2
|
|
3
3
|
module NitroKit
|
4
4
|
class Component < Phlex::HTML
|
5
|
-
def initialize(
|
6
|
-
@attrs = merge_attrs(
|
5
|
+
def initialize(attrs = {}, **defaults)
|
6
|
+
@attrs = merge_attrs(attrs, **defaults)
|
7
7
|
end
|
8
8
|
|
9
9
|
attr_reader :attrs
|
10
10
|
|
11
|
+
def self.from_template(*args, **attrs, &block)
|
12
|
+
new(*args, **attrs, &block).tap { |instance| instance.instance_variable_set(:@_nk_from_template, true) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def builder(&block)
|
16
|
+
@_nk_from_template ? capture(&block) : yield
|
17
|
+
end
|
18
|
+
|
11
19
|
private
|
12
20
|
|
21
|
+
# Class-level helper method for builder style components.
|
22
|
+
# When called from erb or templates, we need to wrap the return value
|
23
|
+
# in capture so we don't write to the output buffer immediately.
|
24
|
+
# However when called from other components, we don't.
|
25
|
+
def self.builder_method(method_name)
|
26
|
+
warn(
|
27
|
+
"[DEPRECATION] builder_method is deprecated. Please migrate to using the builder(&) pattern. See https://github.com/mikker/nitro_kit/issues/35 for details."
|
28
|
+
)
|
29
|
+
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
|
13
33
|
# Merge attributes with some special cases for matching keys
|
14
34
|
def merge_attrs(*hashes, **defaults)
|
15
|
-
defaults
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
35
|
+
defaults
|
36
|
+
.merge(*hashes) do |key, old_value, new_value|
|
37
|
+
case key
|
38
|
+
when :class
|
39
|
+
# Use TailwindMerge to merge class names
|
40
|
+
merge_class(old_value, new_value)
|
41
|
+
when :data
|
42
|
+
# Merge data hashes with some special cases for Stimulus
|
43
|
+
merge_data(old_value, new_value)
|
44
|
+
else
|
45
|
+
new_value
|
46
|
+
end
|
25
47
|
end
|
26
|
-
end
|
27
48
|
end
|
28
49
|
|
29
50
|
alias :mattr :merge_attrs
|
@@ -34,22 +55,26 @@ module NitroKit
|
|
34
55
|
end
|
35
56
|
|
36
57
|
def merge_data(*hashes)
|
37
|
-
hashes
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
58
|
+
hashes
|
59
|
+
.compact
|
60
|
+
.reduce({}) do |acc, hash|
|
61
|
+
acc.deep_merge(hash) do |key, old_val, new_val|
|
62
|
+
# Concat Stimulus actions
|
63
|
+
case key
|
64
|
+
when :action, :controller
|
65
|
+
[new_val, old_val].compact.join(" ")
|
66
|
+
else
|
67
|
+
new_val
|
68
|
+
end
|
45
69
|
end
|
46
70
|
end
|
47
|
-
end
|
48
71
|
end
|
49
72
|
|
50
73
|
def text_or_block(text = nil, &block)
|
51
|
-
if text
|
74
|
+
if text && text.is_a?(ActiveSupport::SafeBuffer)
|
52
75
|
plain(text)
|
76
|
+
elsif text
|
77
|
+
text
|
53
78
|
elsif block_given?
|
54
79
|
yield
|
55
80
|
else
|