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
@@ -19,63 +19,86 @@ module NitroKit
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def trigger(text = nil, **attrs, &block)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
def trigger(text = nil, as: Button, **attrs, &block)
|
23
|
+
builder do
|
24
|
+
trigger_attrs = mattr(
|
25
|
+
attrs,
|
26
|
+
data: {
|
27
|
+
nk__dialog_target: "trigger",
|
28
|
+
action: "click->nk--dialog#open"
|
29
|
+
}
|
30
|
+
)
|
31
|
+
|
32
|
+
case as
|
33
|
+
when Symbol
|
34
|
+
send(as, **trigger_attrs) do
|
35
|
+
text_or_block(text, &block)
|
36
|
+
end
|
37
|
+
else
|
38
|
+
render(as.new(**trigger_attrs)) do
|
39
|
+
text_or_block(text, &block)
|
40
|
+
end
|
41
|
+
end
|
27
42
|
end
|
28
43
|
end
|
29
44
|
|
30
45
|
alias :html_dialog :dialog
|
31
46
|
|
32
47
|
def dialog(**attrs)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
48
|
+
builder do
|
49
|
+
html_dialog(
|
50
|
+
**mattr(
|
51
|
+
attrs,
|
52
|
+
class: dialog_class,
|
53
|
+
data: {nk__dialog_target: "dialog"},
|
54
|
+
aria: {
|
55
|
+
labelledby: id(:title),
|
56
|
+
describedby: id(:description)
|
57
|
+
}
|
58
|
+
)
|
59
|
+
) do
|
60
|
+
yield
|
61
|
+
end
|
45
62
|
end
|
46
63
|
end
|
47
64
|
|
48
65
|
def close_button(**attrs)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
66
|
+
builder do
|
67
|
+
render(
|
68
|
+
Button.new(
|
69
|
+
**mattr(
|
70
|
+
attrs,
|
71
|
+
variant: :ghost,
|
72
|
+
size: :sm,
|
73
|
+
class: "absolute top-2 right-2",
|
74
|
+
data: {action: "nk--dialog#close"}
|
75
|
+
)
|
57
76
|
)
|
58
|
-
)
|
59
|
-
|
60
|
-
|
77
|
+
) do
|
78
|
+
render(Icon.new(:x))
|
79
|
+
end
|
61
80
|
end
|
62
81
|
end
|
63
82
|
|
64
83
|
def title(text = nil, **attrs, &block)
|
65
|
-
|
66
|
-
|
84
|
+
builder do
|
85
|
+
h2(**mattr(attrs, id: id(:title), class: "text-lg font-semibold mb-2")) do
|
86
|
+
text_or_block(text, &block)
|
87
|
+
end
|
67
88
|
end
|
68
89
|
end
|
69
90
|
|
70
91
|
def description(text = nil, **attrs, &block)
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
92
|
+
builder do
|
93
|
+
div(
|
94
|
+
**mattr(
|
95
|
+
attrs,
|
96
|
+
id: id(:description),
|
97
|
+
class: "text-muted-content mb-6 text-sm leading-relaxed"
|
98
|
+
)
|
99
|
+
) do
|
100
|
+
text_or_block(text, &block)
|
101
|
+
end
|
79
102
|
end
|
80
103
|
end
|
81
104
|
|
@@ -27,60 +27,68 @@ module NitroKit
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def trigger(text = nil, as: NitroKit::Button, **attrs, &block)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
builder do
|
31
|
+
trigger_attrs = mattr(
|
32
|
+
attrs,
|
33
|
+
aria: {haspopup: "true", expanded: "false"},
|
34
|
+
data: {nk__dropdown_target: "trigger", action: "click->nk--dropdown#toggle"}
|
35
|
+
)
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
37
|
+
case as
|
38
|
+
when Symbol
|
39
|
+
send(as, **trigger_attrs) do
|
40
|
+
text_or_block(text, &block)
|
41
|
+
end
|
42
|
+
else
|
43
|
+
render(as.new(**trigger_attrs)) do
|
44
|
+
text_or_block(text, &block)
|
45
|
+
end
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|
47
49
|
|
48
50
|
def content(as: :div, **attrs)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
51
|
+
builder do
|
52
|
+
div(
|
53
|
+
**mattr(
|
54
|
+
attrs,
|
55
|
+
role: "menu",
|
56
|
+
aria: {hidden: "true"},
|
57
|
+
class: content_class,
|
58
|
+
data: {nk__dropdown_target: "content"},
|
59
|
+
popover: true
|
60
|
+
)
|
61
|
+
) do
|
62
|
+
yield
|
63
|
+
end
|
60
64
|
end
|
61
65
|
end
|
62
66
|
|
63
67
|
def title(text = nil, **attrs, &block)
|
64
|
-
|
65
|
-
|
68
|
+
builder do
|
69
|
+
div(**mattr(attrs, class: title_class)) do
|
70
|
+
text_or_block(text, &block)
|
71
|
+
end
|
66
72
|
end
|
67
73
|
end
|
68
74
|
|
69
75
|
def item(text = nil, href: nil, variant: :default, **attrs, &block)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
+
builder do
|
77
|
+
common_attrs = mattr(
|
78
|
+
attrs,
|
79
|
+
role: "menuitem",
|
80
|
+
tabindex: "-1",
|
81
|
+
class: [item_class, item_variant_class(variant)]
|
82
|
+
)
|
76
83
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
+
if href
|
85
|
+
link_to(href, **common_attrs) do
|
86
|
+
text_or_block(text, &block)
|
87
|
+
end
|
88
|
+
else
|
89
|
+
div(**common_attrs) do
|
90
|
+
text_or_block(text, &block)
|
91
|
+
end
|
84
92
|
end
|
85
93
|
end
|
86
94
|
end
|
@@ -91,28 +99,40 @@ module NitroKit
|
|
91
99
|
**attrs,
|
92
100
|
&block
|
93
101
|
)
|
94
|
-
|
95
|
-
|
102
|
+
builder do
|
103
|
+
if block_given?
|
104
|
+
href = text_or_href
|
105
|
+
text_or_href = nil
|
106
|
+
end
|
107
|
+
|
108
|
+
item(text_or_href, href: href, **attrs, &block)
|
109
|
+
end
|
96
110
|
end
|
97
111
|
|
98
112
|
def destructive_item(*args, **attrs, &block)
|
99
|
-
|
113
|
+
builder do
|
114
|
+
item(*args, **attrs, variant: :destructive, &block)
|
115
|
+
end
|
100
116
|
end
|
101
117
|
|
102
118
|
def destructive_item_to(text_or_block, href = nil, **attrs, &block)
|
103
|
-
|
104
|
-
|
119
|
+
builder do
|
120
|
+
href = args.shift if block_given?
|
121
|
+
destructive_item(text_or_block, href: href, **attrs, &block)
|
122
|
+
end
|
105
123
|
end
|
106
124
|
|
107
125
|
def separator
|
108
|
-
|
126
|
+
builder do
|
127
|
+
hr(class: separator_class)
|
128
|
+
end
|
109
129
|
end
|
110
130
|
|
111
131
|
private
|
112
132
|
|
113
133
|
def content_class
|
114
134
|
[
|
115
|
-
"
|
135
|
+
"isolate w-max-content absolute top-0 left-0",
|
116
136
|
"p-1 bg-background text-foreground rounded-md border shadow-sm",
|
117
137
|
"w-fit max-w-sm flex-col text-left",
|
118
138
|
"[&[aria-hidden=true]]:hidden flex"
|
@@ -124,14 +144,15 @@ module NitroKit
|
|
124
144
|
end
|
125
145
|
|
126
146
|
def title_class
|
127
|
-
"px-3 pt-2 pb-1.5 text-muted-
|
147
|
+
"px-3 pt-2 pb-1.5 text-muted-content text-sm"
|
128
148
|
end
|
129
149
|
|
130
150
|
def item_class
|
131
151
|
[
|
132
152
|
"px-3 py-1.5 rounded",
|
133
153
|
"font-medium truncate",
|
134
|
-
"cursor-default"
|
154
|
+
"cursor-default",
|
155
|
+
"flex gap-2 items-center [&>span]:truncate"
|
135
156
|
]
|
136
157
|
end
|
137
158
|
|
@@ -140,7 +161,7 @@ module NitroKit
|
|
140
161
|
when :default
|
141
162
|
"[&[href]]:hover:bg-muted"
|
142
163
|
when :destructive
|
143
|
-
"text-destructive [&[href]]:hover:bg-destructive [&[href]]:hover:text-white"
|
164
|
+
"text-destructive-content [&[href]]:hover:bg-destructive [&[href]]:hover:text-white"
|
144
165
|
else
|
145
166
|
raise ArgumentError, "Unknown variant: #{variant.inspect}"
|
146
167
|
end
|
@@ -9,26 +9,30 @@ module NitroKit
|
|
9
9
|
label: nil,
|
10
10
|
description: nil,
|
11
11
|
errors: nil,
|
12
|
+
wrapper: {},
|
13
|
+
options: nil,
|
12
14
|
**attrs
|
13
15
|
)
|
14
16
|
@form = form
|
15
17
|
@field_name = field_name.to_s
|
16
|
-
@as = as.to_sym
|
18
|
+
@as = as.is_a?(String) ? as.to_sym : as
|
17
19
|
|
18
20
|
@name = attrs[:name] || form&.field_name(field_name)
|
19
21
|
@id = attrs[:id] || form&.field_id(field_name)
|
20
22
|
|
21
|
-
# select
|
22
|
-
@options =
|
23
|
+
# select, radio group
|
24
|
+
@options = options
|
23
25
|
|
24
26
|
@field_attrs = attrs
|
25
27
|
@field_label = label.nil? ? field_name.to_s.humanize : label
|
26
28
|
@field_description = description
|
27
29
|
@field_error_messages = errors
|
28
30
|
|
31
|
+
@wrapper = wrapper
|
32
|
+
|
29
33
|
super(
|
30
|
-
|
31
|
-
data: {as: @as},
|
34
|
+
wrapper,
|
35
|
+
data: {as: @as.to_s},
|
32
36
|
class: base_class
|
33
37
|
)
|
34
38
|
end
|
@@ -57,75 +61,85 @@ module NitroKit
|
|
57
61
|
alias :html_label :label
|
58
62
|
|
59
63
|
def label(text = nil, **attrs)
|
60
|
-
|
64
|
+
builder do
|
65
|
+
text ||= field_label
|
61
66
|
|
62
|
-
|
67
|
+
return unless text
|
63
68
|
|
64
|
-
|
65
|
-
|
69
|
+
render(Label.new(**mattr(attrs, for: id, data: {slot: "label"}))) do
|
70
|
+
text
|
71
|
+
end
|
66
72
|
end
|
67
73
|
end
|
68
74
|
|
69
75
|
def description(text = nil, **attrs, &block)
|
70
|
-
|
76
|
+
builder do
|
77
|
+
text ||= field_description
|
71
78
|
|
72
|
-
|
79
|
+
return unless text || block_given?
|
73
80
|
|
74
|
-
|
75
|
-
|
81
|
+
div(**mattr(attrs, data: {slot: "description"}, class: description_class)) do
|
82
|
+
text_or_block(text, &block)
|
83
|
+
end
|
76
84
|
end
|
77
85
|
end
|
78
86
|
|
79
87
|
def errors(error_messages = nil, **attrs)
|
80
|
-
|
88
|
+
builder do
|
89
|
+
error_messages ||= field_error_messages
|
81
90
|
|
82
|
-
|
91
|
+
return unless error_messages&.any?
|
83
92
|
|
84
|
-
|
85
|
-
|
86
|
-
|
93
|
+
ul(**mattr(attrs, data: {slot: "error"}, class: error_class)) do |msg|
|
94
|
+
error_messages.each do |msg|
|
95
|
+
li { msg }
|
96
|
+
end
|
87
97
|
end
|
88
98
|
end
|
89
99
|
end
|
90
100
|
|
91
101
|
def control(**attrs)
|
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
|
-
select
|
117
|
-
|
118
|
-
textarea
|
119
|
-
|
120
|
-
checkbox
|
121
|
-
|
122
|
-
combobox
|
123
|
-
|
124
|
-
radio_group
|
125
|
-
|
126
|
-
switch
|
127
|
-
|
128
|
-
|
102
|
+
builder do
|
103
|
+
case as
|
104
|
+
when :string
|
105
|
+
input(**attrs)
|
106
|
+
when
|
107
|
+
:button,
|
108
|
+
:color,
|
109
|
+
:date,
|
110
|
+
:datetime,
|
111
|
+
:datetime_local,
|
112
|
+
:email,
|
113
|
+
:file,
|
114
|
+
:hidden,
|
115
|
+
:month,
|
116
|
+
:number,
|
117
|
+
:password,
|
118
|
+
:range,
|
119
|
+
:search,
|
120
|
+
:tel,
|
121
|
+
:text,
|
122
|
+
:time,
|
123
|
+
:url,
|
124
|
+
:week
|
125
|
+
input(type: as, **attrs)
|
126
|
+
when :select
|
127
|
+
select(**attrs)
|
128
|
+
when :textarea
|
129
|
+
textarea(**attrs)
|
130
|
+
when :checkbox
|
131
|
+
checkbox(**attrs)
|
132
|
+
when :combobox
|
133
|
+
combobox(**attrs)
|
134
|
+
when :radio, :radio_button, :radio_group
|
135
|
+
radio_group(**attrs)
|
136
|
+
when :switch
|
137
|
+
switch(**attrs)
|
138
|
+
when Class
|
139
|
+
component(**attrs)
|
140
|
+
else
|
141
|
+
raise ArgumentError, "Invalid field type `#{as}'"
|
142
|
+
end
|
129
143
|
end
|
130
144
|
end
|
131
145
|
|
@@ -197,19 +211,16 @@ module NitroKit
|
|
197
211
|
end
|
198
212
|
|
199
213
|
def checkbox(**attrs)
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
**attrs
|
205
|
-
)
|
206
|
-
)
|
207
|
-
)
|
214
|
+
control_attrs(**field_attrs, **attrs).tap do |attrs|
|
215
|
+
input(type: "hidden", **attrs, id: nil, value: "0")
|
216
|
+
render(Checkbox.new(checked: checked?, **attrs, value: "1"))
|
217
|
+
end
|
208
218
|
end
|
209
219
|
|
210
220
|
def combobox(**attrs)
|
211
221
|
render(
|
212
222
|
Combobox.new(
|
223
|
+
options: @options,
|
213
224
|
**control_attrs(
|
214
225
|
**field_attrs,
|
215
226
|
**attrs
|
@@ -242,6 +253,17 @@ module NitroKit
|
|
242
253
|
)
|
243
254
|
end
|
244
255
|
|
256
|
+
def component(**attrs)
|
257
|
+
render(
|
258
|
+
as.new(
|
259
|
+
**control_attrs(
|
260
|
+
**field_attrs,
|
261
|
+
**attrs
|
262
|
+
)
|
263
|
+
)
|
264
|
+
)
|
265
|
+
end
|
266
|
+
|
245
267
|
private
|
246
268
|
|
247
269
|
def base_class
|
@@ -256,11 +278,11 @@ module NitroKit
|
|
256
278
|
end
|
257
279
|
|
258
280
|
def description_class
|
259
|
-
"text-sm text-muted-
|
281
|
+
"text-sm text-muted-content"
|
260
282
|
end
|
261
283
|
|
262
284
|
def error_class
|
263
|
-
"text-sm text-destructive"
|
285
|
+
"text-sm text-destructive-content"
|
264
286
|
end
|
265
287
|
|
266
288
|
def value
|
@@ -284,5 +306,21 @@ module NitroKit
|
|
284
306
|
value
|
285
307
|
end
|
286
308
|
end
|
309
|
+
|
310
|
+
def checked?
|
311
|
+
return unless object = form&.object
|
312
|
+
value = object.public_send(@field_name)
|
313
|
+
|
314
|
+
case value
|
315
|
+
when true, false
|
316
|
+
value
|
317
|
+
when String
|
318
|
+
value == "1"
|
319
|
+
when Numeric
|
320
|
+
value == 1
|
321
|
+
else
|
322
|
+
false
|
323
|
+
end
|
324
|
+
end
|
287
325
|
end
|
288
326
|
end
|
@@ -23,21 +23,28 @@ module NitroKit
|
|
23
23
|
alias :html_legend :legend
|
24
24
|
|
25
25
|
def legend(text = nil, **attrs, &block)
|
26
|
-
|
27
|
-
|
26
|
+
builder do
|
27
|
+
html_legend(**mattr(attrs, class: legend_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, data: {slot: "text"})) do
|
36
|
+
text_or_block(text, &block)
|
37
|
+
end
|
34
38
|
end
|
35
39
|
end
|
36
40
|
|
37
41
|
private
|
38
42
|
|
39
43
|
def base_class
|
40
|
-
|
44
|
+
[
|
45
|
+
"[&>*+[data-slot=control]]:mt-6 [&>*+[data-slot=text]]:mt-1",
|
46
|
+
"[&+&]:mt-8"
|
47
|
+
]
|
41
48
|
end
|
42
49
|
|
43
50
|
def legend_class
|
@@ -45,7 +52,7 @@ module NitroKit
|
|
45
52
|
end
|
46
53
|
|
47
54
|
def description_class
|
48
|
-
"text-sm text-muted-
|
55
|
+
"text-sm text-muted-content"
|
49
56
|
end
|
50
57
|
end
|
51
58
|
end
|
@@ -14,7 +14,9 @@ module NitroKit
|
|
14
14
|
end
|
15
15
|
|
16
16
|
if errors.nil?
|
17
|
-
errors =
|
17
|
+
errors = object && object.respond_to?(:errors) && object.errors.include?(field_name) ? object
|
18
|
+
.errors
|
19
|
+
.full_messages_for(field_name) : nil
|
18
20
|
end
|
19
21
|
|
20
22
|
@template.render(NitroKit::Field.new(self, field_name, label:, errors:, **attrs), &block)
|
@@ -27,7 +29,6 @@ module NitroKit
|
|
27
29
|
# Input types
|
28
30
|
|
29
31
|
%i[
|
30
|
-
checkbox
|
31
32
|
color_field
|
32
33
|
date_field
|
33
34
|
datetime_field
|
@@ -56,16 +57,34 @@ module NitroKit
|
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
60
|
+
def radio_button(method, value = "1", **attrs)
|
61
|
+
field(method, as: :radio_button, label: false, value:, **attrs)
|
62
|
+
end
|
63
|
+
|
64
|
+
def checkbox(method, checked_value = "1", unchecked_value = "0", *args, include_hidden: true, **attrs)
|
65
|
+
if include_hidden
|
66
|
+
@template.concat(hidden_field(method, value: unchecked_value))
|
67
|
+
end
|
68
|
+
|
69
|
+
field(method, *args, as: :checkbox, label: false, value: checked_value, **attrs)
|
70
|
+
end
|
71
|
+
|
59
72
|
# Buttons
|
60
73
|
|
61
|
-
def submit(value =
|
62
|
-
|
63
|
-
|
74
|
+
def submit(value = nil, **attrs, &block)
|
75
|
+
if value.nil? && !block_given?
|
76
|
+
value = "Save changes"
|
77
|
+
end
|
78
|
+
|
79
|
+
@template.render(NitroKit::Button.new(value, variant: :primary, type: :submit, **attrs), &block)
|
64
80
|
end
|
65
81
|
|
66
|
-
def button(value =
|
67
|
-
|
68
|
-
|
82
|
+
def button(value = nil, **attrs, &block)
|
83
|
+
if value.nil? && !block_given?
|
84
|
+
value = "Save changes"
|
85
|
+
end
|
86
|
+
|
87
|
+
@template.render(NitroKit::Button.new(value, **attrs), &block)
|
69
88
|
end
|
70
89
|
end
|
71
90
|
end
|
@@ -2,8 +2,7 @@
|
|
2
2
|
|
3
3
|
module NitroKit
|
4
4
|
class Icon < Component
|
5
|
-
|
6
|
-
include LucideRails::RailsHelper
|
5
|
+
register_output_helper :lucide_icon
|
7
6
|
|
8
7
|
def initialize(name, size: :md, **attrs)
|
9
8
|
@name = name
|
@@ -26,6 +25,8 @@ module NitroKit
|
|
26
25
|
|
27
26
|
def size_class
|
28
27
|
case size
|
28
|
+
when :xs
|
29
|
+
"size-3"
|
29
30
|
when :sm
|
30
31
|
"size-4"
|
31
32
|
when :md
|
@@ -19,7 +19,7 @@ module NitroKit
|
|
19
19
|
[
|
20
20
|
"block rounded-md border bg-background border-border text-base px-3 py-2 h-10",
|
21
21
|
# Focus
|
22
|
-
"focus:outline-none ring-ring ring-offset-2 ring-offset-background focus-visible:ring-2"
|
22
|
+
"focus-visible:outline-none ring-ring ring-offset-2 ring-offset-background focus-visible:ring-2"
|
23
23
|
]
|
24
24
|
end
|
25
25
|
end
|