nitro_kit 0.5.2 → 0.6.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 +5 -5
- data/app/components/nitro_kit/alert.rb +2 -2
- data/app/components/nitro_kit/avatar.rb +4 -2
- data/app/components/nitro_kit/badge.rb +48 -4
- data/app/components/nitro_kit/button.rb +2 -2
- data/app/components/nitro_kit/card.rb +6 -6
- data/app/components/nitro_kit/checkbox.rb +21 -12
- data/app/components/nitro_kit/checkbox_group.rb +2 -2
- data/app/components/nitro_kit/combobox.rb +11 -2
- data/app/components/nitro_kit/component.rb +48 -20
- data/app/components/nitro_kit/dialog.rb +23 -10
- data/app/components/nitro_kit/dropdown.rb +14 -10
- data/app/components/nitro_kit/field.rb +30 -9
- data/app/components/nitro_kit/fieldset.rb +3 -3
- data/app/components/nitro_kit/form_builder.rb +20 -4
- data/app/components/nitro_kit/icon.rb +3 -2
- data/app/components/nitro_kit/pagination.rb +5 -5
- data/app/components/nitro_kit/radio_button.rb +33 -18
- data/app/components/nitro_kit/radio_button_group.rb +2 -2
- data/app/components/nitro_kit/select.rb +4 -4
- data/app/components/nitro_kit/table.rb +26 -9
- data/app/components/nitro_kit/tabs.rb +4 -4
- data/app/components/nitro_kit/toast.rb +22 -3
- data/app/components/nitro_kit/tooltip.rb +1 -1
- data/app/helpers/nitro_kit/checkbox_helper.rb +23 -0
- data/app/helpers/nitro_kit/toast_helper.rb +1 -12
- data/lib/nitro_kit/version.rb +1 -1
- metadata +5 -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: 48fd5bb40a38df4f675dae9e43f25512fc18331ec77fc1af4a4defbd6b2c6e69
|
4
|
+
data.tar.gz: 1f0cbd3330d866afbe39169042fb7985c39760a8625ff788e01ac9a508537ceb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a5f656c6ee81fb4a8ab95e1fbc79f8d8231dca1f51aa25c9c175ecd7dd71cfa57fd1202da71e51be864c6678668616852c7de7e3fed15518fc785b1dacc896c
|
7
|
+
data.tar.gz: f1afe2248dc6c83777782f9800006ff88220cb4bedcf9deacfd826efb8ad2a97281b8c845c1024549f71aa26ca93463593ed81c24984109b939dd322caaa3628
|
@@ -16,13 +16,13 @@ module NitroKit
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
def item(**attrs)
|
19
|
+
builder_method def item(**attrs)
|
20
20
|
div(**attrs) do
|
21
21
|
yield
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def trigger(text = nil, **attrs)
|
25
|
+
builder_method def trigger(text = nil, **attrs)
|
26
26
|
button(
|
27
27
|
**mattr(
|
28
28
|
attrs,
|
@@ -40,7 +40,7 @@ module NitroKit
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
def content(**attrs)
|
43
|
+
builder_method def content(**attrs)
|
44
44
|
div(
|
45
45
|
**mattr(
|
46
46
|
attrs,
|
@@ -78,12 +78,12 @@ module NitroKit
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def arrow_class
|
81
|
-
"transition-transform duration-200 text-muted-
|
81
|
+
"transition-transform duration-200 text-muted-content group-hover/accordion-trigger:text-primary"
|
82
82
|
end
|
83
83
|
|
84
84
|
def chevron_icon
|
85
85
|
svg(
|
86
|
-
class: "transition-transform duration-200 size-4 self-center place-self-end mr-2 pointer-events-none text-muted-
|
86
|
+
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
87
|
viewbox: "0 0 24 24",
|
88
88
|
fill: "none",
|
89
89
|
stroke: "currentColor",
|
@@ -22,13 +22,13 @@ module NitroKit
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def title(text = nil, **attrs, &block)
|
25
|
+
builder_method def title(text = nil, **attrs, &block)
|
26
26
|
h5(**mattr(attrs, class: title_class)) do
|
27
27
|
text_or_block(text, &block)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
def description(text = nil, **attrs, &block)
|
31
|
+
builder_method def description(text = nil, **attrs, &block)
|
32
32
|
div(**mattr(attrs, class: description_class)) do
|
33
33
|
text_or_block(text, &block)
|
34
34
|
end
|
@@ -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
|
@@ -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
|
@@ -15,31 +15,31 @@ module NitroKit
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def title(text = nil, **attrs, &block)
|
18
|
+
builder_method def title(text = nil, **attrs, &block)
|
19
19
|
h2(**mattr(attrs, class: "text-lg font-bold -mb-2")) do
|
20
20
|
text_or_block(text, &block)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
def body(text = nil, **attrs, &block)
|
25
|
-
div(**mattr(attrs, class: "text-muted-
|
24
|
+
builder_method def body(text = nil, **attrs, &block)
|
25
|
+
div(**mattr(attrs, class: "text-muted-content text-sm leading-relaxed")) do
|
26
26
|
text_or_block(text, &block)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def footer(text = nil, **attrs, &block)
|
30
|
+
builder_method def footer(text = nil, **attrs, &block)
|
31
31
|
div(**mattr(attrs, class: "flex gap-2 items-center")) do
|
32
32
|
text_or_block(text, &block)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
def divider(**attrs)
|
36
|
+
builder_method def divider(**attrs)
|
37
37
|
full_width do
|
38
38
|
hr(**attrs)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
def full_width(**attrs)
|
42
|
+
builder_method def full_width(**attrs)
|
43
43
|
div(**mattr(attrs, data: {slot: "full"}, class: "-mx-(--gap)")) do
|
44
44
|
yield
|
45
45
|
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
module NitroKit
|
2
2
|
class Checkbox < Component
|
3
|
-
def initialize(label: nil, id: nil, **attrs)
|
3
|
+
def initialize(label: nil, id: nil, wrapper: {}, **attrs)
|
4
4
|
@id = id || "nk--" + SecureRandom.hex(4)
|
5
5
|
@label = label
|
6
|
+
@wrapper = wrapper
|
6
7
|
|
7
8
|
super(
|
8
9
|
attrs,
|
@@ -14,12 +15,12 @@ module NitroKit
|
|
14
15
|
|
15
16
|
alias :html_label :label
|
16
17
|
|
17
|
-
attr_reader :label, :id
|
18
|
+
attr_reader :label, :id, :wrapper
|
18
19
|
|
19
20
|
def view_template
|
20
|
-
div(class: wrapper_class) do
|
21
|
+
div(**mattr(wrapper, class: wrapper_class)) do
|
21
22
|
html_label(
|
22
|
-
class: "inline-grid *:[grid-area:1/1] shrink-0 place-items-center group/checkbox"
|
23
|
+
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
24
|
) do
|
24
25
|
input(**attrs)
|
25
26
|
checkmark
|
@@ -27,7 +28,9 @@ module NitroKit
|
|
27
28
|
end
|
28
29
|
|
29
30
|
if label.present? || block_given?
|
30
|
-
render(Label.new(for: id))
|
31
|
+
render(Label.new(for: id)) do
|
32
|
+
label || (block_given? ? yield : nil)
|
33
|
+
end
|
31
34
|
end
|
32
35
|
end
|
33
36
|
end
|
@@ -36,13 +39,14 @@ module NitroKit
|
|
36
39
|
|
37
40
|
def checkmark
|
38
41
|
svg(
|
39
|
-
class: merge_class(svg_class, "
|
42
|
+
class: merge_class(svg_class, "invisible"),
|
40
43
|
viewbox: "0 0 16 16",
|
41
44
|
fill: "none",
|
42
45
|
stroke: "currentColor",
|
43
46
|
stroke_linecap: "round",
|
44
47
|
stroke_linejoin: "round",
|
45
|
-
stroke_width: 3
|
48
|
+
stroke_width: 3,
|
49
|
+
data: {check: ""}
|
46
50
|
) do |svg|
|
47
51
|
svg.path(d: "M 3 8 L 6 12 L 13 5")
|
48
52
|
end
|
@@ -50,12 +54,13 @@ module NitroKit
|
|
50
54
|
|
51
55
|
def dash
|
52
56
|
svg(
|
53
|
-
class: merge_class(svg_class, "
|
57
|
+
class: merge_class(svg_class, "invisible"),
|
54
58
|
viewbox: "0 0 16 16",
|
55
59
|
fill: "none",
|
56
60
|
stroke: "currentColor",
|
57
61
|
stroke_linecap: "round",
|
58
|
-
stroke_width: 3
|
62
|
+
stroke_width: 3,
|
63
|
+
data: {indeterminate: ""}
|
59
64
|
) do |svg|
|
60
65
|
svg.line(x1: "3", y1: "8", x2: "13", y2: "8")
|
61
66
|
end
|
@@ -65,16 +70,20 @@ module NitroKit
|
|
65
70
|
[
|
66
71
|
"appearance-none shadow-sm size-4 rounded-sm border text-foreground",
|
67
72
|
"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"
|
73
|
+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring ring-offset-2 ring-offset-background",
|
74
|
+
"disabled:pointer-events-none"
|
69
75
|
]
|
70
76
|
end
|
71
77
|
|
72
78
|
def svg_class
|
73
|
-
"size-3 text-zinc-50
|
79
|
+
"size-3 text-zinc-50 dark:text-zinc-950 pointer-events-none invisible"
|
74
80
|
end
|
75
81
|
|
76
82
|
def wrapper_class
|
77
|
-
|
83
|
+
[
|
84
|
+
"isolate inline-flex items-center gap-2",
|
85
|
+
"has-disabled:opacity-70"
|
86
|
+
]
|
78
87
|
end
|
79
88
|
end
|
80
89
|
end
|
@@ -23,13 +23,13 @@ module NitroKit
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
def title(text = nil, **attrs, &block)
|
26
|
+
builder_method def title(text = nil, **attrs, &block)
|
27
27
|
render(Label.new(**attrs)) do
|
28
28
|
text_or_block(text, &block)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def item(text = nil, **attrs, &block)
|
32
|
+
builder_method def item(text = nil, **attrs, &block)
|
33
33
|
render(Checkbox.new(**attrs)) do
|
34
34
|
text_or_block(text, &block)
|
35
35
|
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",
|
@@ -10,20 +10,46 @@ module NitroKit
|
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
+
# Class-level helper method for builder style components.
|
14
|
+
# When called from erb or templates, we need to wrap the return value
|
15
|
+
# in capture so we don't write to the output buffer immediately.
|
16
|
+
# However when called from other components, we don't.
|
17
|
+
def self.builder_method(method_name)
|
18
|
+
mod = Module.new
|
19
|
+
mod.module_eval(
|
20
|
+
<<~RUBY,
|
21
|
+
# frozen_string_literal: true
|
22
|
+
|
23
|
+
def #{method_name}(...)
|
24
|
+
if caller_locations(1, 1).first.path.end_with?(".rb")
|
25
|
+
super
|
26
|
+
else
|
27
|
+
capture { super }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
RUBY
|
31
|
+
__FILE__,
|
32
|
+
__LINE__ + 1
|
33
|
+
)
|
34
|
+
|
35
|
+
prepend(mod)
|
36
|
+
end
|
37
|
+
|
13
38
|
# Merge attributes with some special cases for matching keys
|
14
39
|
def merge_attrs(*hashes, **defaults)
|
15
|
-
defaults
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
40
|
+
defaults
|
41
|
+
.merge(*hashes) do |key, old_value, new_value|
|
42
|
+
case key
|
43
|
+
when :class
|
44
|
+
# Use TailwindMerge to merge class names
|
45
|
+
merge_class(old_value, new_value)
|
46
|
+
when :data
|
47
|
+
# Merge data hashes with some special cases for Stimulus
|
48
|
+
merge_data(old_value, new_value)
|
49
|
+
else
|
50
|
+
new_value
|
51
|
+
end
|
25
52
|
end
|
26
|
-
end
|
27
53
|
end
|
28
54
|
|
29
55
|
alias :mattr :merge_attrs
|
@@ -34,17 +60,19 @@ module NitroKit
|
|
34
60
|
end
|
35
61
|
|
36
62
|
def merge_data(*hashes)
|
37
|
-
hashes
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
63
|
+
hashes
|
64
|
+
.compact
|
65
|
+
.reduce({}) do |acc, hash|
|
66
|
+
acc.deep_merge(hash) do |key, old_val, new_val|
|
67
|
+
# Concat Stimulus actions
|
68
|
+
case key
|
69
|
+
when :action, :controller
|
70
|
+
[new_val, old_val].compact.join(" ")
|
71
|
+
else
|
72
|
+
new_val
|
73
|
+
end
|
45
74
|
end
|
46
75
|
end
|
47
|
-
end
|
48
76
|
end
|
49
77
|
|
50
78
|
def text_or_block(text = nil, &block)
|
@@ -19,17 +19,30 @@ module NitroKit
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def trigger(text = nil, **attrs, &block)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
builder_method def trigger(text = nil, as: Button, **attrs, &block)
|
23
|
+
trigger_attrs = mattr(
|
24
|
+
attrs,
|
25
|
+
data: {
|
26
|
+
nk__dialog_target: "trigger",
|
27
|
+
action: "click->nk--dialog#open"
|
28
|
+
}
|
29
|
+
)
|
30
|
+
|
31
|
+
case as
|
32
|
+
when Symbol
|
33
|
+
send(as, **trigger_attrs) do
|
34
|
+
text_or_block(text, &block)
|
35
|
+
end
|
36
|
+
else
|
37
|
+
render(as.new(**trigger_attrs)) do
|
38
|
+
text_or_block(text, &block)
|
39
|
+
end
|
27
40
|
end
|
28
41
|
end
|
29
42
|
|
30
43
|
alias :html_dialog :dialog
|
31
44
|
|
32
|
-
def dialog(**attrs)
|
45
|
+
builder_method def dialog(**attrs)
|
33
46
|
html_dialog(
|
34
47
|
**mattr(
|
35
48
|
attrs,
|
@@ -45,7 +58,7 @@ module NitroKit
|
|
45
58
|
end
|
46
59
|
end
|
47
60
|
|
48
|
-
def close_button(**attrs)
|
61
|
+
builder_method def close_button(**attrs)
|
49
62
|
render(
|
50
63
|
Button.new(
|
51
64
|
**mattr(
|
@@ -61,18 +74,18 @@ module NitroKit
|
|
61
74
|
end
|
62
75
|
end
|
63
76
|
|
64
|
-
def title(text = nil, **attrs, &block)
|
77
|
+
builder_method def title(text = nil, **attrs, &block)
|
65
78
|
h2(**mattr(attrs, id: id(:title), class: "text-lg font-semibold mb-2")) do
|
66
79
|
text_or_block(text, &block)
|
67
80
|
end
|
68
81
|
end
|
69
82
|
|
70
|
-
def description(text = nil, **attrs, &block)
|
83
|
+
builder_method def description(text = nil, **attrs, &block)
|
71
84
|
div(
|
72
85
|
**mattr(
|
73
86
|
attrs,
|
74
87
|
id: id(:description),
|
75
|
-
class: "text-muted-
|
88
|
+
class: "text-muted-content mb-6 text-sm leading-relaxed"
|
76
89
|
)
|
77
90
|
) do
|
78
91
|
text_or_block(text, &block)
|
@@ -26,7 +26,7 @@ module NitroKit
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
def trigger(text = nil, as: NitroKit::Button, **attrs, &block)
|
29
|
+
builder_method def trigger(text = nil, as: NitroKit::Button, **attrs, &block)
|
30
30
|
trigger_attrs = mattr(
|
31
31
|
attrs,
|
32
32
|
aria: {haspopup: "true", expanded: "false"},
|
@@ -45,7 +45,7 @@ module NitroKit
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
def content(as: :div, **attrs)
|
48
|
+
builder_method def content(as: :div, **attrs)
|
49
49
|
div(
|
50
50
|
**mattr(
|
51
51
|
attrs,
|
@@ -60,13 +60,13 @@ module NitroKit
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
def title(text = nil, **attrs, &block)
|
63
|
+
builder_method def title(text = nil, **attrs, &block)
|
64
64
|
div(**mattr(attrs, class: title_class)) do
|
65
65
|
text_or_block(text, &block)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
def item(text = nil, href: nil, variant: :default, **attrs, &block)
|
69
|
+
builder_method def item(text = nil, href: nil, variant: :default, **attrs, &block)
|
70
70
|
common_attrs = mattr(
|
71
71
|
attrs,
|
72
72
|
role: "menuitem",
|
@@ -85,26 +85,30 @@ module NitroKit
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
def item_to(
|
88
|
+
builder_method def item_to(
|
89
89
|
text_or_href,
|
90
90
|
href = nil,
|
91
91
|
**attrs,
|
92
92
|
&block
|
93
93
|
)
|
94
|
-
|
94
|
+
if block_given?
|
95
|
+
href = text_or_href
|
96
|
+
text_or_href = nil
|
97
|
+
end
|
98
|
+
|
95
99
|
item(text_or_href, href: href, **attrs, &block)
|
96
100
|
end
|
97
101
|
|
98
|
-
def destructive_item(*args, **attrs, &block)
|
102
|
+
builder_method def destructive_item(*args, **attrs, &block)
|
99
103
|
item(*args, **attrs, variant: :destructive, &block)
|
100
104
|
end
|
101
105
|
|
102
|
-
def destructive_item_to(text_or_block, href = nil, **attrs, &block)
|
106
|
+
builder_method def destructive_item_to(text_or_block, href = nil, **attrs, &block)
|
103
107
|
href = args.shift if block_given?
|
104
108
|
destructive_item(text_or_block, href: href, **attrs, &block)
|
105
109
|
end
|
106
110
|
|
107
|
-
def separator
|
111
|
+
builder_method def separator
|
108
112
|
hr(class: separator_class)
|
109
113
|
end
|
110
114
|
|
@@ -124,7 +128,7 @@ module NitroKit
|
|
124
128
|
end
|
125
129
|
|
126
130
|
def title_class
|
127
|
-
"px-3 pt-2 pb-1.5 text-muted-
|
131
|
+
"px-3 pt-2 pb-1.5 text-muted-content text-sm"
|
128
132
|
end
|
129
133
|
|
130
134
|
def item_class
|
@@ -9,6 +9,8 @@ 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
|
@@ -18,16 +20,18 @@ module NitroKit
|
|
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
|
-
|
34
|
+
wrapper,
|
31
35
|
data: {as: @as},
|
32
36
|
class: base_class
|
33
37
|
)
|
@@ -56,7 +60,7 @@ module NitroKit
|
|
56
60
|
|
57
61
|
alias :html_label :label
|
58
62
|
|
59
|
-
def label(text = nil, **attrs)
|
63
|
+
builder_method def label(text = nil, **attrs)
|
60
64
|
text ||= field_label
|
61
65
|
|
62
66
|
return unless text
|
@@ -66,7 +70,7 @@ module NitroKit
|
|
66
70
|
end
|
67
71
|
end
|
68
72
|
|
69
|
-
def description(text = nil, **attrs, &block)
|
73
|
+
builder_method def description(text = nil, **attrs, &block)
|
70
74
|
text ||= field_description
|
71
75
|
|
72
76
|
return unless text || block_given?
|
@@ -76,7 +80,7 @@ module NitroKit
|
|
76
80
|
end
|
77
81
|
end
|
78
82
|
|
79
|
-
def errors(error_messages = nil, **attrs)
|
83
|
+
builder_method def errors(error_messages = nil, **attrs)
|
80
84
|
error_messages ||= field_error_messages
|
81
85
|
|
82
86
|
return unless error_messages&.any?
|
@@ -88,7 +92,7 @@ module NitroKit
|
|
88
92
|
end
|
89
93
|
end
|
90
94
|
|
91
|
-
def control(**attrs)
|
95
|
+
builder_method def control(**attrs)
|
92
96
|
case as
|
93
97
|
when :string
|
94
98
|
input(**attrs)
|
@@ -199,6 +203,7 @@ module NitroKit
|
|
199
203
|
def checkbox(**attrs)
|
200
204
|
render(
|
201
205
|
Checkbox.new(
|
206
|
+
checked: checked?,
|
202
207
|
**control_attrs(
|
203
208
|
**field_attrs,
|
204
209
|
**attrs
|
@@ -256,11 +261,11 @@ module NitroKit
|
|
256
261
|
end
|
257
262
|
|
258
263
|
def description_class
|
259
|
-
"text-sm text-muted-
|
264
|
+
"text-sm text-muted-content"
|
260
265
|
end
|
261
266
|
|
262
267
|
def error_class
|
263
|
-
"text-sm text-destructive"
|
268
|
+
"text-sm text-destructive-content"
|
264
269
|
end
|
265
270
|
|
266
271
|
def value
|
@@ -284,5 +289,21 @@ module NitroKit
|
|
284
289
|
value
|
285
290
|
end
|
286
291
|
end
|
292
|
+
|
293
|
+
def checked?
|
294
|
+
return unless object = form&.object
|
295
|
+
value = object.public_send(@field_name)
|
296
|
+
|
297
|
+
case value
|
298
|
+
when true, false
|
299
|
+
value
|
300
|
+
when String
|
301
|
+
value == "1"
|
302
|
+
when Numeric
|
303
|
+
value == 1
|
304
|
+
else
|
305
|
+
false
|
306
|
+
end
|
307
|
+
end
|
287
308
|
end
|
288
309
|
end
|
@@ -22,13 +22,13 @@ module NitroKit
|
|
22
22
|
|
23
23
|
alias :html_legend :legend
|
24
24
|
|
25
|
-
def legend(text = nil, **attrs, &block)
|
25
|
+
builder_method def legend(text = nil, **attrs, &block)
|
26
26
|
html_legend(**mattr(attrs, class: legend_class)) do
|
27
27
|
text_or_block(text, &block)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
def description(text = nil, **attrs, &block)
|
31
|
+
builder_method def description(text = nil, **attrs, &block)
|
32
32
|
div(**mattr(attrs, class: description_class, data: {slot: "text"})) do
|
33
33
|
text_or_block(text, &block)
|
34
34
|
end
|
@@ -45,7 +45,7 @@ module NitroKit
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def description_class
|
48
|
-
"text-sm text-muted-
|
48
|
+
"text-sm text-muted-content"
|
49
49
|
end
|
50
50
|
end
|
51
51
|
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,10 +57,25 @@ module NitroKit
|
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
60
|
+
def checkbox(method, checked_value = "1", unchecked_value = "0", *args, include_hidden: true, **attrs)
|
61
|
+
if include_hidden
|
62
|
+
@template.concat(hidden_field(method, value: unchecked_value))
|
63
|
+
end
|
64
|
+
|
65
|
+
field(method, *args, as: :checkbox, label: false, value: checked_value, **attrs)
|
66
|
+
end
|
67
|
+
|
59
68
|
# Buttons
|
60
69
|
|
61
|
-
def submit(value =
|
62
|
-
|
70
|
+
def submit(value = nil, **attrs, &block)
|
71
|
+
if value
|
72
|
+
content = value
|
73
|
+
elsif block_given?
|
74
|
+
content = @template.capture(&block)
|
75
|
+
else
|
76
|
+
content = I18n.t("save_changes")
|
77
|
+
end
|
78
|
+
|
63
79
|
@template.render(NitroKit::Button.new(variant: :primary, type: :submit, **attrs)) { content }
|
64
80
|
end
|
65
81
|
|
@@ -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
|
@@ -16,7 +16,7 @@ module NitroKit
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
def prev(text = nil, **attrs, &block)
|
19
|
+
builder_method def prev(text = nil, **attrs, &block)
|
20
20
|
page_link(**mattr(attrs, aria: {label: "Previous page"})) do
|
21
21
|
if text || block_given?
|
22
22
|
text_or_block(text, &block)
|
@@ -27,7 +27,7 @@ module NitroKit
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def next(text = nil, **attrs, &block)
|
30
|
+
builder_method def next(text = nil, **attrs, &block)
|
31
31
|
page_link(**mattr(attrs, aria: {label: "Next page"})) do
|
32
32
|
if text || block_given?
|
33
33
|
text_or_block(text, &block)
|
@@ -38,7 +38,7 @@ module NitroKit
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
def page(text = nil, current: false, **attrs, &block)
|
41
|
+
builder_method def page(text = nil, current: false, **attrs, &block)
|
42
42
|
page_link(
|
43
43
|
**mattr(
|
44
44
|
attrs,
|
@@ -53,7 +53,7 @@ module NitroKit
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
def ellipsis(**attrs)
|
56
|
+
builder_method def ellipsis(**attrs)
|
57
57
|
render(
|
58
58
|
Button.new(
|
59
59
|
**mattr(
|
@@ -88,7 +88,7 @@ module NitroKit
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def link_class
|
91
|
-
"inline-flex items-center justify-center rounded-md border font-medium h-9 px-3 gap-2 border-transparent aria-disabled:text-muted-
|
91
|
+
"inline-flex items-center justify-center rounded-md border font-medium h-9 px-3 gap-2 border-transparent aria-disabled:text-muted-content [&>svg]:size-4"
|
92
92
|
end
|
93
93
|
|
94
94
|
def page_class
|
@@ -2,34 +2,27 @@
|
|
2
2
|
|
3
3
|
module NitroKit
|
4
4
|
class RadioButton < Component
|
5
|
-
def initialize(label: nil, **attrs)
|
5
|
+
def initialize(label: nil, id: nil, wrapper: {}, size: :md, **attrs)
|
6
6
|
@label = label
|
7
|
-
@id = id || SecureRandom.hex(4)
|
8
|
-
|
9
|
-
@
|
7
|
+
@id = id || "nk--" + SecureRandom.hex(4)
|
8
|
+
@size = size
|
9
|
+
@wrapper = wrapper
|
10
10
|
|
11
11
|
super(
|
12
12
|
attrs,
|
13
|
-
type: "radio",
|
14
13
|
id: @id,
|
15
|
-
|
16
|
-
|
17
|
-
"[&[aria-checked='true']]:bg-primary",
|
18
|
-
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
19
|
-
]
|
14
|
+
type: "radio",
|
15
|
+
class: input_class
|
20
16
|
)
|
21
17
|
end
|
22
18
|
|
23
19
|
alias :html_label :label
|
24
20
|
|
25
|
-
attr_reader
|
26
|
-
:id,
|
27
|
-
:label
|
28
|
-
)
|
21
|
+
attr_reader :id, :label, :size, :wrapper
|
29
22
|
|
30
23
|
def view_template
|
31
|
-
div(
|
32
|
-
html_label(class: "inline-grid *:[grid-area:1/1] place-items-center") do
|
24
|
+
div(**mattr(wrapper, class: wrapper_class)) do
|
25
|
+
html_label(class: merge_class("inline-grid *:[grid-area:1/1] shrink-0 place-items-center", size_class)) do
|
33
26
|
input(**attrs)
|
34
27
|
dot
|
35
28
|
end
|
@@ -47,8 +40,7 @@ module NitroKit
|
|
47
40
|
def dot
|
48
41
|
svg(
|
49
42
|
class: merge_class(
|
50
|
-
"
|
51
|
-
"size-2.5 text-primay opacity-0 pointer-events-none",
|
43
|
+
"text-primary opacity-0 pointer-events-none",
|
52
44
|
"peer-checked:opacity-100"
|
53
45
|
),
|
54
46
|
viewbox: "0 0 20 20",
|
@@ -58,5 +50,28 @@ module NitroKit
|
|
58
50
|
svg.circle(cx: 10, cy: 10, r: 10)
|
59
51
|
end
|
60
52
|
end
|
53
|
+
|
54
|
+
def wrapper_class
|
55
|
+
"inline-flex items-center gap-2"
|
56
|
+
end
|
57
|
+
|
58
|
+
def input_class
|
59
|
+
[
|
60
|
+
"peer appearance-none shadow-sm rounded-full border text-foreground bg-background",
|
61
|
+
"[&[aria-checked='true']]:bg-primary",
|
62
|
+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
63
|
+
]
|
64
|
+
end
|
65
|
+
|
66
|
+
def size_class
|
67
|
+
case size
|
68
|
+
when :md
|
69
|
+
"[&>input]:size-5 [&>svg]:size-2.5"
|
70
|
+
when :lg
|
71
|
+
"[&>input]:size-7 [&>svg]:size-[calc(var(--spacing)*3+1px)]"
|
72
|
+
else
|
73
|
+
raise ArgumentError, "Unknown size `#{size}'"
|
74
|
+
end
|
75
|
+
end
|
61
76
|
end
|
62
77
|
end
|
@@ -27,13 +27,13 @@ module NitroKit
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def title(text = nil, **attrs, &block)
|
30
|
+
builder_method def title(text = nil, **attrs, &block)
|
31
31
|
render(Label.new(**attrs)) do
|
32
32
|
text_or_block(text, &block)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
def item(text = nil, value_as_arg = nil, value: nil, **attrs, &block)
|
36
|
+
builder_method def item(text = nil, value_as_arg = nil, value: nil, **attrs, &block)
|
37
37
|
value ||= value_as_arg
|
38
38
|
|
39
39
|
render(
|
@@ -4,7 +4,7 @@ module NitroKit
|
|
4
4
|
class Select < Component
|
5
5
|
def initialize(options = nil, value: nil, include_empty: false, prompt: nil, index: nil, **attrs)
|
6
6
|
@options = options
|
7
|
-
@value = value
|
7
|
+
@value = value.to_s
|
8
8
|
@include_empty = include_empty
|
9
9
|
@prompt = prompt
|
10
10
|
@index = index
|
@@ -30,10 +30,10 @@ module NitroKit
|
|
30
30
|
|
31
31
|
alias :html_option :option
|
32
32
|
|
33
|
-
def option(key_or_value = nil, value = nil, **attrs, &block)
|
33
|
+
builder_method def option(key_or_value = nil, value = nil, **attrs, &block)
|
34
34
|
value ||= key_or_value
|
35
35
|
|
36
|
-
html_option(
|
36
|
+
html_option(value:, selected: @value == value.to_s, **attrs) do
|
37
37
|
if block_given?
|
38
38
|
yield
|
39
39
|
else
|
@@ -58,7 +58,7 @@ module NitroKit
|
|
58
58
|
|
59
59
|
def chevron_icon
|
60
60
|
svg(
|
61
|
-
class: "size-4 self-center place-self-end mr-1.5 text-muted-
|
61
|
+
class: "size-4 self-center place-self-end mr-1.5 text-muted-content pointer-events-none group-hover/select:text-foreground",
|
62
62
|
viewbox: "0 0 24 24",
|
63
63
|
fill: "none",
|
64
64
|
stroke: "currentColor",
|
@@ -10,7 +10,7 @@ module NitroKit
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def view_template
|
13
|
-
div(class: "
|
13
|
+
div(class: "w-full overflow-x-scroll") do
|
14
14
|
table(**attrs) do
|
15
15
|
yield
|
16
16
|
end
|
@@ -23,34 +23,51 @@ module NitroKit
|
|
23
23
|
alias :html_th :th
|
24
24
|
alias :html_td :td
|
25
25
|
|
26
|
-
def thead(**attrs)
|
26
|
+
builder_method def thead(**attrs)
|
27
27
|
html_thead(**attrs) { yield }
|
28
28
|
end
|
29
29
|
|
30
|
-
def tbody(**attrs)
|
30
|
+
builder_method def tbody(**attrs)
|
31
31
|
html_tbody(**mattr(attrs, class: "[&_tr:last-child]:border-0")) { yield }
|
32
32
|
end
|
33
33
|
|
34
|
-
def tr(**attrs)
|
34
|
+
builder_method def tr(**attrs)
|
35
35
|
html_tr(**mattr(attrs, class: "border-b")) { yield }
|
36
36
|
end
|
37
37
|
|
38
|
-
def th(text = nil, **attrs, &block)
|
39
|
-
html_th(**mattr(attrs, class: [cell_classes, "font-medium
|
38
|
+
builder_method def th(text = nil, align: :left, **attrs, &block)
|
39
|
+
html_th(**mattr(attrs, class: [header_cell_classes, cell_classes, align_classes(align), "font-medium"])) do
|
40
40
|
text_or_block(text, &block)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
def td(text = nil, **attrs, &block)
|
45
|
-
html_td(**mattr(attrs, class: cell_classes)) do
|
44
|
+
builder_method def td(text = nil, align: nil, **attrs, &block)
|
45
|
+
html_td(**mattr(attrs, class: [cell_classes, align_classes(align)])) do
|
46
46
|
text_or_block(text, &block)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
private
|
51
51
|
|
52
|
+
def header_cell_classes
|
53
|
+
""
|
54
|
+
end
|
55
|
+
|
52
56
|
def cell_classes
|
53
|
-
"py-
|
57
|
+
"whitespace-nowrap py-2 min-h-10 px-2"
|
58
|
+
end
|
59
|
+
|
60
|
+
def align_classes(align = nil)
|
61
|
+
case align
|
62
|
+
when :left
|
63
|
+
"text-left"
|
64
|
+
when :center
|
65
|
+
"text-center"
|
66
|
+
when :right
|
67
|
+
"text-right"
|
68
|
+
else
|
69
|
+
nil
|
70
|
+
end
|
54
71
|
end
|
55
72
|
end
|
56
73
|
end
|
@@ -21,13 +21,13 @@ module NitroKit
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
def tabs(**attrs)
|
24
|
+
builder_method def tabs(**attrs)
|
25
25
|
div(**mattr, role: "tabtabs", class: tabs_class) do
|
26
26
|
yield
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def tab(key, text = nil, **attrs, &block)
|
30
|
+
builder_method def tab(key, text = nil, **attrs, &block)
|
31
31
|
button(
|
32
32
|
**mattr(
|
33
33
|
attrs,
|
@@ -51,7 +51,7 @@ module NitroKit
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
def panel(key, **attrs)
|
54
|
+
builder_method def panel(key, **attrs)
|
55
55
|
div(
|
56
56
|
**mattr(
|
57
57
|
attrs,
|
@@ -88,7 +88,7 @@ module NitroKit
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def tab_class
|
91
|
-
"border-b-2 border-transparent hover:border-primary focus-visible:border-primary cursor-pointer text-muted-
|
91
|
+
"border-b-2 border-transparent hover:border-primary focus-visible:border-primary cursor-pointer text-muted-content aria-[selected=true]:text-foreground font-medium aria-[selected=true]:border-primary -mb-px px-2"
|
92
92
|
end
|
93
93
|
|
94
94
|
def panel_class
|
@@ -2,6 +2,25 @@
|
|
2
2
|
|
3
3
|
module NitroKit
|
4
4
|
class Toast < Component
|
5
|
+
class FlashMessages < Component
|
6
|
+
def initialize(flash)
|
7
|
+
@flash = flash
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :flash
|
11
|
+
|
12
|
+
def view_template
|
13
|
+
flash.each do |severity, message|
|
14
|
+
render(
|
15
|
+
Toast::Item.new(
|
16
|
+
description: message,
|
17
|
+
variant: severity.to_sym == :alert ? :error : :default
|
18
|
+
)
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
5
24
|
class Item < Component
|
6
25
|
VARIANTS = %i[default warning error success]
|
7
26
|
|
@@ -85,13 +104,13 @@ module NitroKit
|
|
85
104
|
end
|
86
105
|
end
|
87
106
|
|
88
|
-
def item(title: nil, description: nil, **attrs, &block)
|
107
|
+
builder_method def item(title: nil, description: nil, **attrs, &block)
|
89
108
|
render(Item.new(title:, description:, **attrs), &block)
|
90
109
|
end
|
91
110
|
|
92
|
-
def flash_sink
|
111
|
+
builder_method def flash_sink
|
93
112
|
div(id: "nk--toast-sink", data: {nk__toast_target: "sink"}, hidden: true) do
|
94
|
-
|
113
|
+
render(FlashMessages.new(view_context.flash))
|
95
114
|
end
|
96
115
|
end
|
97
116
|
|
@@ -20,6 +20,29 @@ module NitroKit
|
|
20
20
|
render(Checkbox.new(name:, label:, value: compat_checked_value, checked:, **attrs))
|
21
21
|
end
|
22
22
|
|
23
|
+
def nk_checkbox_tag(name, *args)
|
24
|
+
if args.length >= 4
|
25
|
+
raise ArgumentError, "wrong number of arguments (given #{args.length + 1}, expected 1..4)"
|
26
|
+
end
|
27
|
+
|
28
|
+
options = args.extract_options!
|
29
|
+
value, checked = args.empty? ? ["1", false] : [*args, false]
|
30
|
+
attrs = {
|
31
|
+
type: "checkbox",
|
32
|
+
name: name,
|
33
|
+
id: sanitize_to_id(name),
|
34
|
+
value: value
|
35
|
+
}.update(
|
36
|
+
options.symbolize_keys
|
37
|
+
)
|
38
|
+
|
39
|
+
attrs[:checked] = "checked" if checked
|
40
|
+
|
41
|
+
render(Checkbox.new(name:, **attrs))
|
42
|
+
end
|
43
|
+
|
44
|
+
alias :nk_check_box_tag :nk_checkbox_tag
|
45
|
+
|
23
46
|
def nk_checkbox_group(**attrs, &block)
|
24
47
|
render(CheckboxGroup.new(**attrs), &block)
|
25
48
|
end
|
@@ -15,18 +15,7 @@ module NitroKit
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def nk_toast_flash_messages
|
18
|
-
|
19
|
-
flash.each do |severity, message|
|
20
|
-
concat(
|
21
|
-
render(
|
22
|
-
Toast::Item.new(
|
23
|
-
description: message,
|
24
|
-
variant: severity.to_sym == :alert ? :error : :default
|
25
|
-
)
|
26
|
-
)
|
27
|
-
)
|
28
|
-
end
|
29
|
-
end
|
18
|
+
render(Toast::FlashMessages.new(flash))
|
30
19
|
end
|
31
20
|
|
32
21
|
def nk_toast_turbo_stream_refresh
|
data/lib/nitro_kit/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nitro_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikkel Malmberg
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-02
|
10
|
+
date: 2025-04-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rails
|
@@ -43,14 +43,14 @@ dependencies:
|
|
43
43
|
requirements:
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 2.
|
46
|
+
version: 2.1.0
|
47
47
|
type: :runtime
|
48
48
|
prerelease: false
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 2.
|
53
|
+
version: 2.1.0
|
54
54
|
description: WIP, not usable yet
|
55
55
|
email:
|
56
56
|
- mikkel@brnbw.com
|
@@ -58,7 +58,6 @@ executables: []
|
|
58
58
|
extensions: []
|
59
59
|
extra_rdoc_files: []
|
60
60
|
files:
|
61
|
-
- MIT-LICENSE
|
62
61
|
- README.md
|
63
62
|
- Rakefile
|
64
63
|
- app/components/nitro_kit/accordion.rb
|
@@ -157,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
156
|
- !ruby/object:Gem::Version
|
158
157
|
version: '0'
|
159
158
|
requirements: []
|
160
|
-
rubygems_version: 3.6.
|
159
|
+
rubygems_version: 3.6.6
|
161
160
|
specification_version: 4
|
162
161
|
summary: WIP, not usable yet
|
163
162
|
test_files: []
|
data/MIT-LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright Mikkel Malmberg
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|