nitro_kit 0.7.0 → 0.9.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/assets/tailwind/application.css +49 -0
- data/app/components/nitro_kit/accordion.rb +3 -3
- data/app/components/nitro_kit/alert.rb +1 -1
- data/app/components/nitro_kit/avatar.rb +2 -2
- data/app/components/nitro_kit/avatar_stack.rb +1 -1
- data/app/components/nitro_kit/card.rb +1 -1
- data/app/components/nitro_kit/checkbox.rb +2 -2
- data/app/components/nitro_kit/combobox.rb +5 -5
- data/app/components/nitro_kit/component.rb +2 -2
- data/app/components/nitro_kit/datepicker.rb +1 -1
- data/app/components/nitro_kit/dialog.rb +3 -3
- data/app/components/nitro_kit/dropdown.rb +10 -6
- data/app/components/nitro_kit/field.rb +18 -7
- data/app/components/nitro_kit/field_group.rb +1 -1
- data/app/components/nitro_kit/fieldset.rb +1 -1
- data/app/components/nitro_kit/form_builder.rb +13 -0
- data/app/components/nitro_kit/label.rb +1 -1
- data/app/components/nitro_kit/pagination.rb +5 -5
- data/app/components/nitro_kit/select.rb +30 -8
- data/app/components/nitro_kit/switch.rb +4 -4
- data/app/components/nitro_kit/table.rb +15 -10
- data/app/components/nitro_kit/tabs.rb +1 -1
- data/app/components/nitro_kit/toast.rb +10 -14
- data/app/helpers/nitro_kit/checkbox_helper.rb +1 -1
- data/app/helpers/nitro_kit/pagination_helper.rb +12 -8
- data/app/helpers/nitro_kit/select_helper.rb +1 -1
- data/app/javascript/controllers/nk/toast_controller.js +4 -2
- data/lib/generators/nitro_kit/component_generator.rb +2 -2
- data/lib/nitro_kit/schema_builder.rb +16 -8
- data/lib/nitro_kit/version.rb +1 -1
- data/lib/nitro_kit.rb +18 -18
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 06ec36dc808b0223864423889cf64d62465c925e111a49d334110aadfa0859a3
|
|
4
|
+
data.tar.gz: 9a1f9f81419b52fcfb8c5a956e134f424419a4c5b922ecc68d820f3bfb135a9d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dd3df11e3987edb2be111e580442b9ccac3d3e1f414bdb7933469f1ab7d1c29cf0e3b17648eb01793301ea64b8880a776d545428b34e76aabf779c9161e7c889
|
|
7
|
+
data.tar.gz: b5ef21b4509537b8e373278ea1fa52e08d154e5a46869c942ad39f2fe69888ba2cb215a85e00e1e34f196a94afbace25e2a6b1ed744ef18116724462b2a22676
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
@import "tailwindcss";
|
|
2
|
+
|
|
3
|
+
@theme {
|
|
4
|
+
--color-foreground: var(--color-zinc-900);
|
|
5
|
+
--color-background: var(--color-white);
|
|
6
|
+
|
|
7
|
+
--color-border: var(--color-zinc-200);
|
|
8
|
+
--color-ring: var(--color-blue-600);
|
|
9
|
+
--color-muted: var(--color-zinc-100);
|
|
10
|
+
--color-muted-content: var(--color-zinc-500);
|
|
11
|
+
--color-primary: var(--color-zinc-800);
|
|
12
|
+
--color-primary-content: var(--zinc-800);
|
|
13
|
+
--color-primary-foreground: var(--color-zinc-100);
|
|
14
|
+
--color-destructive: var(--color-red-500);
|
|
15
|
+
--color-destructive-content: var(--color-red-800);
|
|
16
|
+
--color-destructive-foreground: var(--color-white);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@layer base {
|
|
20
|
+
[data-theme="dark"] {
|
|
21
|
+
--color-foreground: var(--color-zinc-100);
|
|
22
|
+
--color-background: var(--color-zinc-950);
|
|
23
|
+
|
|
24
|
+
--color-border: var(--color-zinc-700);
|
|
25
|
+
--color-ring: var(--color-blue-700);
|
|
26
|
+
--color-muted: var(--color-zinc-800);
|
|
27
|
+
--color-muted-content: var(--color-zinc-400);
|
|
28
|
+
--color-primary: var(--color-zinc-50);
|
|
29
|
+
--color-primary-content: var(--color-zinc-50);
|
|
30
|
+
--color-primary-foreground: var(--color-zinc-900);
|
|
31
|
+
--color-destructive: var(--color-red-900);
|
|
32
|
+
--color-destructive-content: var(--color-red-600);
|
|
33
|
+
--color-destructive-foreground: var(--color-white);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@variant dark (&:where([data-theme="dark"], [data-theme="dark"] *));
|
|
38
|
+
|
|
39
|
+
@layer base {
|
|
40
|
+
* {
|
|
41
|
+
@apply border-border ring-ring min-w-0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
body {
|
|
45
|
+
/* Nitro Kit looks great in Inter as well */
|
|
46
|
+
/* https://rsms.me/inter */
|
|
47
|
+
@apply bg-background text-foreground font-sans;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -6,7 +6,7 @@ module NitroKit
|
|
|
6
6
|
super(
|
|
7
7
|
attrs,
|
|
8
8
|
class: item_class,
|
|
9
|
-
data: {controller: "nk--accordion"}
|
|
9
|
+
data: { controller: "nk--accordion" }
|
|
10
10
|
)
|
|
11
11
|
end
|
|
12
12
|
|
|
@@ -35,7 +35,7 @@ module NitroKit
|
|
|
35
35
|
action: "nk--accordion#toggle",
|
|
36
36
|
nk__accordion_target: "trigger"
|
|
37
37
|
},
|
|
38
|
-
aria: {expanded: "false"}
|
|
38
|
+
aria: { expanded: "false" }
|
|
39
39
|
)
|
|
40
40
|
) do
|
|
41
41
|
block_given? ? yield : plain(text)
|
|
@@ -53,7 +53,7 @@ module NitroKit
|
|
|
53
53
|
data: {
|
|
54
54
|
nk__accordion_target: "content"
|
|
55
55
|
},
|
|
56
|
-
aria: {hidden: "true"}
|
|
56
|
+
aria: { hidden: "true" }
|
|
57
57
|
)
|
|
58
58
|
) do
|
|
59
59
|
div(class: "pb-4") { yield }
|
|
@@ -10,7 +10,7 @@ module NitroKit
|
|
|
10
10
|
|
|
11
11
|
super(
|
|
12
12
|
attrs,
|
|
13
|
-
class: [container_class, size_classes]
|
|
13
|
+
class: [ container_class, size_classes ]
|
|
14
14
|
)
|
|
15
15
|
end
|
|
16
16
|
|
|
@@ -22,7 +22,7 @@ module NitroKit
|
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
def image
|
|
26
26
|
image_tag(src, class: image_class)
|
|
27
27
|
end
|
|
28
28
|
|
|
@@ -48,7 +48,7 @@ module NitroKit
|
|
|
48
48
|
stroke_linecap: "round",
|
|
49
49
|
stroke_linejoin: "round",
|
|
50
50
|
stroke_width: 3,
|
|
51
|
-
data: {check: ""}
|
|
51
|
+
data: { check: "" }
|
|
52
52
|
) do |svg|
|
|
53
53
|
svg.path(d: "M 3 8 L 6 12 L 13 5")
|
|
54
54
|
end
|
|
@@ -62,7 +62,7 @@ module NitroKit
|
|
|
62
62
|
stroke: "currentColor",
|
|
63
63
|
stroke_linecap: "round",
|
|
64
64
|
stroke_width: 3,
|
|
65
|
-
data: {indeterminate: ""}
|
|
65
|
+
data: { indeterminate: "" }
|
|
66
66
|
) do |svg|
|
|
67
67
|
svg.line(x1: "3", y1: "8", x2: "13", y2: "8")
|
|
68
68
|
end
|
|
@@ -9,7 +9,7 @@ module NitroKit
|
|
|
9
9
|
placement: "bottom",
|
|
10
10
|
tab_inserts_suggestions: true,
|
|
11
11
|
first_option_selection_mode: "selected",
|
|
12
|
-
scroll_into_view_options: {block: "nearest", inline: "nearest"},
|
|
12
|
+
scroll_into_view_options: { block: "nearest", inline: "nearest" },
|
|
13
13
|
|
|
14
14
|
**attrs
|
|
15
15
|
)
|
|
@@ -56,8 +56,8 @@ module NitroKit
|
|
|
56
56
|
|
|
57
57
|
def view_template
|
|
58
58
|
div(
|
|
59
|
+
class: "isolate",
|
|
59
60
|
data: {
|
|
60
|
-
class: "isolate",
|
|
61
61
|
slot: "control",
|
|
62
62
|
controller: "nk--combobox",
|
|
63
63
|
nk__combobox_placement_value: placement,
|
|
@@ -77,19 +77,19 @@ module NitroKit
|
|
|
77
77
|
type: "hidden",
|
|
78
78
|
value: attrs[:value],
|
|
79
79
|
name: attrs[:name],
|
|
80
|
-
data: {nk__combobox_target: "hiddenField"}
|
|
80
|
+
data: { nk__combobox_target: "hiddenField" }
|
|
81
81
|
)
|
|
82
82
|
|
|
83
83
|
ul(
|
|
84
84
|
role: "listbox",
|
|
85
85
|
id: id(:listbox),
|
|
86
86
|
class: list_class,
|
|
87
|
-
data: {nk__combobox_target: "list", state: "closed"}
|
|
87
|
+
data: { nk__combobox_target: "list", state: "closed" }
|
|
88
88
|
) do
|
|
89
89
|
options.each do |(key, value)|
|
|
90
90
|
li(
|
|
91
91
|
role: "option",
|
|
92
|
-
data: {value:},
|
|
92
|
+
data: { value: },
|
|
93
93
|
class: merge_class(option_class)
|
|
94
94
|
) { key }
|
|
95
95
|
end
|
|
@@ -13,7 +13,7 @@ module NitroKit
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def builder(&block)
|
|
16
|
-
@_nk_from_template ? capture(&block) : yield
|
|
16
|
+
@_nk_from_template && !self.is_a?(NitroKit::Component) ? capture(&block) : yield
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
private
|
|
@@ -62,7 +62,7 @@ module NitroKit
|
|
|
62
62
|
# Concat Stimulus actions
|
|
63
63
|
case key
|
|
64
64
|
when :action, :controller
|
|
65
|
-
[new_val, old_val].compact.join(" ")
|
|
65
|
+
[ new_val, old_val ].compact.join(" ")
|
|
66
66
|
else
|
|
67
67
|
new_val
|
|
68
68
|
end
|
|
@@ -7,7 +7,7 @@ module NitroKit
|
|
|
7
7
|
|
|
8
8
|
super(
|
|
9
9
|
attrs,
|
|
10
|
-
data: {controller: "nk--dialog", action: "click->nk--dialog#clickOutside"}
|
|
10
|
+
data: { controller: "nk--dialog", action: "click->nk--dialog#clickOutside" }
|
|
11
11
|
)
|
|
12
12
|
end
|
|
13
13
|
|
|
@@ -50,7 +50,7 @@ module NitroKit
|
|
|
50
50
|
**mattr(
|
|
51
51
|
attrs,
|
|
52
52
|
class: dialog_class,
|
|
53
|
-
data: {nk__dialog_target: "dialog"},
|
|
53
|
+
data: { nk__dialog_target: "dialog" },
|
|
54
54
|
aria: {
|
|
55
55
|
labelledby: id(:title),
|
|
56
56
|
describedby: id(:description)
|
|
@@ -71,7 +71,7 @@ module NitroKit
|
|
|
71
71
|
variant: :ghost,
|
|
72
72
|
size: :sm,
|
|
73
73
|
class: "absolute top-2 right-2",
|
|
74
|
-
data: {action: "nk--dialog#close"}
|
|
74
|
+
data: { action: "nk--dialog#close" }
|
|
75
75
|
)
|
|
76
76
|
)
|
|
77
77
|
) do
|
|
@@ -30,8 +30,8 @@ module NitroKit
|
|
|
30
30
|
builder do
|
|
31
31
|
trigger_attrs = mattr(
|
|
32
32
|
attrs,
|
|
33
|
-
aria: {haspopup: "true", expanded: "false"},
|
|
34
|
-
data: {nk__dropdown_target: "trigger", action: "click->nk--dropdown#toggle"}
|
|
33
|
+
aria: { haspopup: "true", expanded: "false" },
|
|
34
|
+
data: { nk__dropdown_target: "trigger", action: "click->nk--dropdown#toggle" }
|
|
35
35
|
)
|
|
36
36
|
|
|
37
37
|
case as
|
|
@@ -53,9 +53,9 @@ module NitroKit
|
|
|
53
53
|
**mattr(
|
|
54
54
|
attrs,
|
|
55
55
|
role: "menu",
|
|
56
|
-
aria: {hidden: "true"},
|
|
56
|
+
aria: { hidden: "true" },
|
|
57
57
|
class: content_class,
|
|
58
|
-
data: {nk__dropdown_target: "content"},
|
|
58
|
+
data: { nk__dropdown_target: "content" },
|
|
59
59
|
popover: true
|
|
60
60
|
)
|
|
61
61
|
) do
|
|
@@ -78,7 +78,7 @@ module NitroKit
|
|
|
78
78
|
attrs,
|
|
79
79
|
role: "menuitem",
|
|
80
80
|
tabindex: "-1",
|
|
81
|
-
class: [item_class, item_variant_class(variant)]
|
|
81
|
+
class: [ item_class, item_variant_class(variant) ]
|
|
82
82
|
)
|
|
83
83
|
|
|
84
84
|
if href
|
|
@@ -117,7 +117,11 @@ module NitroKit
|
|
|
117
117
|
|
|
118
118
|
def destructive_item_to(text_or_block, href = nil, **attrs, &block)
|
|
119
119
|
builder do
|
|
120
|
-
|
|
120
|
+
if block_given?
|
|
121
|
+
href = text_or_block
|
|
122
|
+
text_or_block = nil
|
|
123
|
+
end
|
|
124
|
+
|
|
121
125
|
destructive_item(text_or_block, href: href, **attrs, &block)
|
|
122
126
|
end
|
|
123
127
|
end
|
|
@@ -11,6 +11,8 @@ module NitroKit
|
|
|
11
11
|
errors: nil,
|
|
12
12
|
wrapper: {},
|
|
13
13
|
options: nil,
|
|
14
|
+
include_blank: nil,
|
|
15
|
+
prompt: nil,
|
|
14
16
|
**attrs
|
|
15
17
|
)
|
|
16
18
|
@form = form
|
|
@@ -22,6 +24,8 @@ module NitroKit
|
|
|
22
24
|
|
|
23
25
|
# select, radio group
|
|
24
26
|
@options = options
|
|
27
|
+
@include_blank = include_blank
|
|
28
|
+
@prompt = prompt
|
|
25
29
|
|
|
26
30
|
@field_attrs = attrs
|
|
27
31
|
@field_label = label.nil? ? field_name.to_s.humanize : label
|
|
@@ -32,7 +36,7 @@ module NitroKit
|
|
|
32
36
|
|
|
33
37
|
super(
|
|
34
38
|
wrapper,
|
|
35
|
-
data: {as: @as.to_s},
|
|
39
|
+
data: { as: @as.to_s },
|
|
36
40
|
class: base_class
|
|
37
41
|
)
|
|
38
42
|
end
|
|
@@ -66,7 +70,7 @@ module NitroKit
|
|
|
66
70
|
|
|
67
71
|
return unless text
|
|
68
72
|
|
|
69
|
-
render(Label.new(**mattr(attrs, for: id, data: {slot: "label"}))) do
|
|
73
|
+
render(Label.new(**mattr(attrs, for: id, data: { slot: "label" }))) do
|
|
70
74
|
text
|
|
71
75
|
end
|
|
72
76
|
end
|
|
@@ -78,7 +82,7 @@ module NitroKit
|
|
|
78
82
|
|
|
79
83
|
return unless text || block_given?
|
|
80
84
|
|
|
81
|
-
div(**mattr(attrs, data: {slot: "description"}, class: description_class)) do
|
|
85
|
+
div(**mattr(attrs, data: { slot: "description" }, class: description_class)) do
|
|
82
86
|
text_or_block(text, &block)
|
|
83
87
|
end
|
|
84
88
|
end
|
|
@@ -90,7 +94,7 @@ module NitroKit
|
|
|
90
94
|
|
|
91
95
|
return unless error_messages&.any?
|
|
92
96
|
|
|
93
|
-
ul(**mattr(attrs, data: {slot: "error"}, class: error_class)) do |msg|
|
|
97
|
+
ul(**mattr(attrs, data: { slot: "error" }, class: error_class)) do |msg|
|
|
94
98
|
error_messages.each do |msg|
|
|
95
99
|
li { msg }
|
|
96
100
|
end
|
|
@@ -166,7 +170,7 @@ module NitroKit
|
|
|
166
170
|
name:,
|
|
167
171
|
id:,
|
|
168
172
|
value: value_before_typecast,
|
|
169
|
-
data: {slot: "control"}
|
|
173
|
+
data: { slot: "control" }
|
|
170
174
|
)
|
|
171
175
|
end
|
|
172
176
|
|
|
@@ -185,10 +189,17 @@ module NitroKit
|
|
|
185
189
|
|
|
186
190
|
alias :html_select :select
|
|
187
191
|
|
|
188
|
-
def select(options: nil, **attrs)
|
|
192
|
+
def select(options: nil, include_blank: nil, prompt: nil, **attrs)
|
|
193
|
+
collection = options || @options || []
|
|
194
|
+
blank_option = include_blank || @include_blank
|
|
195
|
+
prompt_text = prompt || @prompt
|
|
196
|
+
|
|
189
197
|
render(
|
|
190
198
|
Select.new(
|
|
191
|
-
|
|
199
|
+
collection,
|
|
200
|
+
value: value,
|
|
201
|
+
include_empty: blank_option,
|
|
202
|
+
prompt: prompt_text,
|
|
192
203
|
**control_attrs(
|
|
193
204
|
**field_attrs,
|
|
194
205
|
**attrs
|
|
@@ -32,7 +32,7 @@ module NitroKit
|
|
|
32
32
|
|
|
33
33
|
def description(text = nil, **attrs, &block)
|
|
34
34
|
builder do
|
|
35
|
-
div(**mattr(attrs, class: description_class, data: {slot: "text"})) do
|
|
35
|
+
div(**mattr(attrs, class: description_class, data: { slot: "text" })) do
|
|
36
36
|
text_or_block(text, &block)
|
|
37
37
|
end
|
|
38
38
|
end
|
|
@@ -86,5 +86,18 @@ module NitroKit
|
|
|
86
86
|
|
|
87
87
|
@template.render(NitroKit::Button.new(value, **attrs), &block)
|
|
88
88
|
end
|
|
89
|
+
|
|
90
|
+
def select(method, choices = nil, options = {}, html_options = {}, &block)
|
|
91
|
+
field_options = {
|
|
92
|
+
as: :select,
|
|
93
|
+
options: choices,
|
|
94
|
+
include_blank: options[:include_blank],
|
|
95
|
+
prompt: options[:prompt]
|
|
96
|
+
}.compact
|
|
97
|
+
|
|
98
|
+
field_attributes = options.except(:include_blank, :prompt, :selected)
|
|
99
|
+
|
|
100
|
+
field(method, **field_options, **field_attributes, **html_options, &block)
|
|
101
|
+
end
|
|
89
102
|
end
|
|
90
103
|
end
|
|
@@ -6,7 +6,7 @@ module NitroKit
|
|
|
6
6
|
super(
|
|
7
7
|
attrs,
|
|
8
8
|
class: merge_class(nav_class, attrs[:class]),
|
|
9
|
-
aria: {label: "Pagination"}
|
|
9
|
+
aria: { label: "Pagination" }
|
|
10
10
|
)
|
|
11
11
|
end
|
|
12
12
|
|
|
@@ -18,7 +18,7 @@ module NitroKit
|
|
|
18
18
|
|
|
19
19
|
def prev(text = nil, **attrs, &block)
|
|
20
20
|
builder do
|
|
21
|
-
page_link(**mattr(attrs, aria: {label: "Previous page"})) do
|
|
21
|
+
page_link(**mattr(attrs, aria: { label: "Previous page" })) do
|
|
22
22
|
if text || block_given?
|
|
23
23
|
text_or_block(text, &block)
|
|
24
24
|
else
|
|
@@ -31,7 +31,7 @@ module NitroKit
|
|
|
31
31
|
|
|
32
32
|
def next(text = nil, **attrs, &block)
|
|
33
33
|
builder do
|
|
34
|
-
page_link(**mattr(attrs, aria: {label: "Next page"})) do
|
|
34
|
+
page_link(**mattr(attrs, aria: { label: "Next page" })) do
|
|
35
35
|
if text || block_given?
|
|
36
36
|
text_or_block(text, &block)
|
|
37
37
|
else
|
|
@@ -51,7 +51,7 @@ module NitroKit
|
|
|
51
51
|
current: current ? "page" : nil
|
|
52
52
|
},
|
|
53
53
|
disabled: current,
|
|
54
|
-
class: [page_class, current && "bg-zinc-200/50 dark:bg-zinc-800/50"]
|
|
54
|
+
class: [ page_class, current && "bg-zinc-200/50 dark:bg-zinc-800/50" ]
|
|
55
55
|
)
|
|
56
56
|
) do
|
|
57
57
|
text_or_block(text, &block)
|
|
@@ -83,7 +83,7 @@ module NitroKit
|
|
|
83
83
|
**mattr(
|
|
84
84
|
attrs,
|
|
85
85
|
role: "link",
|
|
86
|
-
aria: {disabled: disabled.to_s},
|
|
86
|
+
aria: { disabled: disabled.to_s },
|
|
87
87
|
class: link_class
|
|
88
88
|
)
|
|
89
89
|
) do
|
|
@@ -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
|
|
@@ -15,13 +15,35 @@ module NitroKit
|
|
|
15
15
|
)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
attr_reader :value, :options, :include_empty, :
|
|
18
|
+
attr_reader :value, :options, :include_empty, :prompt, :index
|
|
19
19
|
|
|
20
20
|
def view_template
|
|
21
|
-
span(class: wrapper_class, data: {slot: "control"}) do
|
|
21
|
+
span(class: wrapper_class, data: { slot: "control" }) do
|
|
22
22
|
select(**attrs, class: select_class) do
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
if include_empty
|
|
24
|
+
blank_text = if include_empty.is_a?(String)
|
|
25
|
+
include_empty
|
|
26
|
+
elsif @prompt
|
|
27
|
+
@prompt
|
|
28
|
+
else
|
|
29
|
+
""
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
html_option(value: "", selected: @value == "") { blank_text }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
if options
|
|
36
|
+
options.each do |opt|
|
|
37
|
+
if opt.is_a?(Array) && opt.length >= 2
|
|
38
|
+
html_option(value: opt[1], selected: @value == opt[1].to_s) { opt[0] }
|
|
39
|
+
else
|
|
40
|
+
# Handle simple strings - use as both label and value
|
|
41
|
+
html_option(value: opt.to_s, selected: @value == opt.to_s) { opt.to_s }
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
else
|
|
45
|
+
yield if block_given?
|
|
46
|
+
end
|
|
25
47
|
end
|
|
26
48
|
|
|
27
49
|
chevron_icon
|
|
@@ -30,15 +52,15 @@ module NitroKit
|
|
|
30
52
|
|
|
31
53
|
alias :html_option :option
|
|
32
54
|
|
|
33
|
-
def option(
|
|
55
|
+
def option(text = nil, value = nil, **attrs, &block)
|
|
34
56
|
builder do
|
|
35
|
-
value ||=
|
|
57
|
+
value ||= text
|
|
36
58
|
|
|
37
59
|
html_option(value:, selected: @value == value.to_s, **attrs) do
|
|
38
60
|
if block_given?
|
|
39
61
|
yield
|
|
40
62
|
else
|
|
41
|
-
|
|
63
|
+
text
|
|
42
64
|
end
|
|
43
65
|
end
|
|
44
66
|
end
|
|
@@ -22,10 +22,10 @@ module NitroKit
|
|
|
22
22
|
**mattr(
|
|
23
23
|
**attrs,
|
|
24
24
|
type: "button",
|
|
25
|
-
class: [base_class, size_class],
|
|
26
|
-
data: {controller: "nk--switch", action: "nk--switch#toggle"},
|
|
25
|
+
class: [ base_class, size_class ],
|
|
26
|
+
data: { controller: "nk--switch", action: "nk--switch#toggle" },
|
|
27
27
|
role: "switch",
|
|
28
|
-
aria: {checked: checked.to_s}
|
|
28
|
+
aria: { checked: checked.to_s }
|
|
29
29
|
)
|
|
30
30
|
) do
|
|
31
31
|
span(class: "sr-only") { description }
|
|
@@ -36,7 +36,7 @@ module NitroKit
|
|
|
36
36
|
private
|
|
37
37
|
|
|
38
38
|
def handle
|
|
39
|
-
span(aria: {hidden: true}, class: handle_class, data: {slot: "handle"})
|
|
39
|
+
span(aria: { hidden: true }, class: handle_class, data: { slot: "handle" })
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
def base_class
|
|
@@ -2,16 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
module NitroKit
|
|
4
4
|
class Table < Component
|
|
5
|
-
def initialize(**attrs)
|
|
6
|
-
super(
|
|
7
|
-
|
|
8
|
-
class: "w-full caption-bottom text-sm divide-y"
|
|
9
|
-
)
|
|
5
|
+
def initialize(wrapper: {}, **attrs)
|
|
6
|
+
super(attrs)
|
|
7
|
+
@wrapper = wrapper
|
|
10
8
|
end
|
|
11
9
|
|
|
10
|
+
attr_reader :wrapper
|
|
11
|
+
|
|
12
12
|
def view_template
|
|
13
|
-
div(class: "w-full overflow-x-scroll") do
|
|
14
|
-
table(
|
|
13
|
+
div(**mattr(wrapper, class: "w-full overflow-x-scroll")) do
|
|
14
|
+
table(
|
|
15
|
+
**mattr(
|
|
16
|
+
attrs,
|
|
17
|
+
class: "w-full caption-bottom text-sm divide-y"
|
|
18
|
+
)
|
|
19
|
+
) do
|
|
15
20
|
yield
|
|
16
21
|
end
|
|
17
22
|
end
|
|
@@ -43,7 +48,7 @@ module NitroKit
|
|
|
43
48
|
|
|
44
49
|
def th(text = nil, align: :left, **attrs, &block)
|
|
45
50
|
builder do
|
|
46
|
-
html_th(**mattr(attrs, class: [header_cell_classes, cell_classes, align_classes(align), "font-medium"])) do
|
|
51
|
+
html_th(**mattr(attrs, class: [ header_cell_classes, cell_classes, align_classes(align), "font-medium" ])) do
|
|
47
52
|
text_or_block(text, &block)
|
|
48
53
|
end
|
|
49
54
|
end
|
|
@@ -51,7 +56,7 @@ module NitroKit
|
|
|
51
56
|
|
|
52
57
|
def td(text = nil, align: nil, **attrs, &block)
|
|
53
58
|
builder do
|
|
54
|
-
html_td(**mattr(attrs, class: [cell_classes, align_classes(align)])) do
|
|
59
|
+
html_td(**mattr(attrs, class: [ cell_classes, align_classes(align) ])) do
|
|
55
60
|
text_or_block(text, &block)
|
|
56
61
|
end
|
|
57
62
|
end
|
|
@@ -64,7 +69,7 @@ module NitroKit
|
|
|
64
69
|
end
|
|
65
70
|
|
|
66
71
|
def cell_classes
|
|
67
|
-
"
|
|
72
|
+
"py-2 min-h-10 px-2"
|
|
68
73
|
end
|
|
69
74
|
|
|
70
75
|
def align_classes(align = nil)
|
|
@@ -37,9 +37,9 @@ module NitroKit
|
|
|
37
37
|
variant_class
|
|
38
38
|
],
|
|
39
39
|
role: "status",
|
|
40
|
-
aria: {live: "off", atomic: "true"},
|
|
40
|
+
aria: { live: "off", atomic: "true" },
|
|
41
41
|
tabindex: "0",
|
|
42
|
-
data: {state: "closed"}
|
|
42
|
+
data: { state: "closed" }
|
|
43
43
|
)
|
|
44
44
|
)
|
|
45
45
|
end
|
|
@@ -49,11 +49,11 @@ module NitroKit
|
|
|
49
49
|
def view_template(&block)
|
|
50
50
|
li(**attrs) do
|
|
51
51
|
div(class: "grid gap-1") do
|
|
52
|
-
div(class: "text-sm font-semibold", data: {slot: "title"}) do
|
|
52
|
+
div(class: "text-sm font-semibold", data: { slot: "title" }) do
|
|
53
53
|
title && plain(title)
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
-
div(class: "text-sm opacity-90", data: {slot: "description"}) do
|
|
56
|
+
div(class: "text-sm opacity-90", data: { slot: "description" }) do
|
|
57
57
|
text_or_block(description, &block)
|
|
58
58
|
end
|
|
59
59
|
end
|
|
@@ -87,34 +87,30 @@ module NitroKit
|
|
|
87
87
|
attrs,
|
|
88
88
|
role: "region",
|
|
89
89
|
tabindex: "-1",
|
|
90
|
-
aria: {label: "Notifications"},
|
|
90
|
+
aria: { label: "Notifications" },
|
|
91
91
|
class: "pointer-events-none"
|
|
92
92
|
)
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
def view_template
|
|
96
96
|
div(**attrs) do
|
|
97
|
-
ol(class: list_class, data: {nk__toast_target: "list"})
|
|
97
|
+
ol(class: list_class, data: { nk__toast_target: "list" })
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
flash_sink
|
|
101
101
|
|
|
102
|
-
template(data: {nk__toast_target: "template"}) do
|
|
102
|
+
template(data: { nk__toast_target: "template" }) do
|
|
103
103
|
item
|
|
104
104
|
end
|
|
105
105
|
end
|
|
106
106
|
|
|
107
107
|
def item(title: nil, description: nil, **attrs, &block)
|
|
108
|
-
|
|
109
|
-
render(Item.new(title:, description:, **attrs), &block)
|
|
110
|
-
end
|
|
108
|
+
render(Item.new(title:, description:, **attrs), &block)
|
|
111
109
|
end
|
|
112
110
|
|
|
113
111
|
def flash_sink
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
render(FlashMessages.new(view_context.flash))
|
|
117
|
-
end
|
|
112
|
+
div(id: "nk--toast-sink", data: { nk__toast_target: "sink" }, hidden: true) do
|
|
113
|
+
render(FlashMessages.new(view_context.flash))
|
|
118
114
|
end
|
|
119
115
|
end
|
|
120
116
|
|
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
begin
|
|
4
|
+
require "pagy/toolbox/helpers/support/series"
|
|
5
|
+
rescue LoadError
|
|
6
|
+
# Pagy isn't around
|
|
7
|
+
end
|
|
8
|
+
|
|
3
9
|
module NitroKit
|
|
4
10
|
module PaginationHelper
|
|
5
|
-
include Pagy::UrlHelpers if defined?(Pagy)
|
|
6
|
-
|
|
7
11
|
def nk_pagination(**attrs, &block)
|
|
8
12
|
render(Pagination.from_template(**attrs), &block)
|
|
9
13
|
end
|
|
10
14
|
|
|
11
15
|
def nk_pagy_nav(pagy, id: nil, aria_label: nil, **attrs)
|
|
12
|
-
attrs[:aria] ||= {label: aria_label}
|
|
16
|
+
attrs[:aria] ||= { label: aria_label }
|
|
13
17
|
|
|
14
18
|
nk_pagination(id:, **attrs) do |p|
|
|
15
|
-
if prev_page = pagy.
|
|
16
|
-
p.prev(href:
|
|
19
|
+
if prev_page = pagy.previous
|
|
20
|
+
p.prev(href: pagy.page_url(prev_page))
|
|
17
21
|
else
|
|
18
22
|
p.prev(disabled: true)
|
|
19
23
|
end
|
|
20
24
|
|
|
21
|
-
pagy.series.each do |item|
|
|
25
|
+
pagy.send(:series).each do |item|
|
|
22
26
|
case item
|
|
23
27
|
when Integer
|
|
24
|
-
p.page(item.to_s, href:
|
|
28
|
+
p.page(item.to_s, href: pagy.page_url(item))
|
|
25
29
|
when String
|
|
26
30
|
p.page(item, current: true)
|
|
27
31
|
when :gap
|
|
@@ -32,7 +36,7 @@ module NitroKit
|
|
|
32
36
|
end
|
|
33
37
|
|
|
34
38
|
if next_page = pagy.next
|
|
35
|
-
p.next(href:
|
|
39
|
+
p.next(href: pagy.page_url(next_page))
|
|
36
40
|
else
|
|
37
41
|
p.next(disabled: true)
|
|
38
42
|
end
|
|
@@ -18,7 +18,7 @@ module NitroKit
|
|
|
18
18
|
|
|
19
19
|
# TODO: support index
|
|
20
20
|
|
|
21
|
-
render(Select.from_template(options, value:, include_blank:, prompt:, **compat_options, **attrs), &block)
|
|
21
|
+
render(Select.from_template(options, value:, include_blank:, prompt:, name:, **compat_options, **attrs), &block)
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
end
|
|
@@ -7,8 +7,6 @@ export default class extends Controller {
|
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
connect() {
|
|
10
|
-
this.#flushSink();
|
|
11
|
-
|
|
12
10
|
if (this.hasSinkTarget) {
|
|
13
11
|
this.mutationObserver = new MutationObserver(([event]) => {
|
|
14
12
|
if (event.addedNodes.length === 0) return;
|
|
@@ -16,6 +14,8 @@ export default class extends Controller {
|
|
|
16
14
|
});
|
|
17
15
|
this.mutationObserver.observe(this.sinkTarget, { childList: true });
|
|
18
16
|
}
|
|
17
|
+
|
|
18
|
+
this.#flushSink();
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
disconnect() {
|
|
@@ -60,6 +60,8 @@ export default class extends Controller {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
#flushSink() {
|
|
63
|
+
if (!this.hasSinkTarget) return;
|
|
64
|
+
|
|
63
65
|
for (const li of this.sinkTarget.children) {
|
|
64
66
|
this.show(li.cloneNode(true));
|
|
65
67
|
li.remove();
|
|
@@ -50,7 +50,7 @@ module NitroKit
|
|
|
50
50
|
def components
|
|
51
51
|
return @components if @components
|
|
52
52
|
|
|
53
|
-
if component_names == ["all"]
|
|
53
|
+
if component_names == [ "all" ]
|
|
54
54
|
return @components = SCHEMA.all
|
|
55
55
|
end
|
|
56
56
|
|
|
@@ -58,7 +58,7 @@ module NitroKit
|
|
|
58
58
|
@components = component_names
|
|
59
59
|
.flat_map do |name|
|
|
60
60
|
component = SCHEMA.find(name)
|
|
61
|
-
[component] + component.dependencies
|
|
61
|
+
[ component ] + component.dependencies
|
|
62
62
|
end
|
|
63
63
|
end
|
|
64
64
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require "set"
|
|
2
|
+
|
|
1
3
|
module NitroKit
|
|
2
4
|
module SchemaBuilder
|
|
3
5
|
class Component
|
|
@@ -21,12 +23,18 @@ module NitroKit
|
|
|
21
23
|
def resolve!
|
|
22
24
|
raise "Component already resolved" if resolved?
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
dependencies = Set.new
|
|
27
|
+
stack = @unresolved_dependencies.dup
|
|
28
|
+
|
|
29
|
+
until stack.empty?
|
|
30
|
+
name = stack.pop
|
|
31
|
+
next if dependencies.include?(name)
|
|
32
|
+
|
|
33
|
+
dependencies.add(name)
|
|
34
|
+
stack.concat(@schema.find(name).unresolved_dependencies)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
@dependencies = dependencies.map { |name| @schema.find(name) }
|
|
30
38
|
|
|
31
39
|
@resolved = true
|
|
32
40
|
end
|
|
@@ -71,8 +79,8 @@ module NitroKit
|
|
|
71
79
|
gems: []
|
|
72
80
|
)
|
|
73
81
|
# Default is one component, one helper with same name
|
|
74
|
-
components ||= [name]
|
|
75
|
-
helpers ||= [name]
|
|
82
|
+
components ||= [ name ]
|
|
83
|
+
helpers ||= [ name ]
|
|
76
84
|
|
|
77
85
|
files = [
|
|
78
86
|
components.map { |c| "app/components/nitro_kit/#{c}.rb" },
|
data/lib/nitro_kit/version.rb
CHANGED
data/lib/nitro_kit.rb
CHANGED
|
@@ -10,37 +10,37 @@ module NitroKit
|
|
|
10
10
|
extend SchemaBuilder
|
|
11
11
|
|
|
12
12
|
SCHEMA = build_schema do |s|
|
|
13
|
-
s.add(:accordion, js: [:accordion])
|
|
13
|
+
s.add(:accordion, js: [ :accordion ])
|
|
14
14
|
s.add(:alert)
|
|
15
15
|
s.add(:avatar)
|
|
16
16
|
s.add(:badge)
|
|
17
|
-
s.add(:button, [:icon], components: [:button, :button_group], helpers: [:button, :button_group])
|
|
17
|
+
s.add(:button, [ :icon ], components: [ :button, :button_group ], helpers: [ :button, :button_group ])
|
|
18
18
|
s.add(:card)
|
|
19
|
-
s.add(:checkbox, [:label], components: [:checkbox, :checkbox_group])
|
|
19
|
+
s.add(:checkbox, [ :label ], components: [ :checkbox, :checkbox_group ])
|
|
20
20
|
s.add(
|
|
21
21
|
:combobox,
|
|
22
|
-
[:input],
|
|
23
|
-
js: [:combobox],
|
|
24
|
-
modules: ["@floating-ui/core", "@floating-ui/dom", "@github/combobox-nav"]
|
|
22
|
+
[ :input ],
|
|
23
|
+
js: [ :combobox ],
|
|
24
|
+
modules: [ "@floating-ui/core", "@floating-ui/dom", "@github/combobox-nav" ]
|
|
25
25
|
)
|
|
26
26
|
s.add(:datepicker)
|
|
27
|
-
s.add(:dialog, [:button, :icon], js: [:dialog])
|
|
28
|
-
s.add(:dropdown, [:button], js: [:dropdown], modules: ["@floating-ui/core", "@floating-ui/dom"])
|
|
29
|
-
s.add(:field, [:label, :checkbox, :combobox, :label, :radio_button, :select, :switch, :textarea])
|
|
27
|
+
s.add(:dialog, [ :button, :icon ], js: [ :dialog ])
|
|
28
|
+
s.add(:dropdown, [ :button ], js: [ :dropdown ], modules: [ "@floating-ui/core", "@floating-ui/dom" ])
|
|
29
|
+
s.add(:field, [ :label, :checkbox, :combobox, :label, :radio_button, :select, :switch, :textarea ])
|
|
30
30
|
s.add(:field_group)
|
|
31
|
-
s.add(:fieldset, [:field_group])
|
|
32
|
-
s.add(:form_builder, [:field], helpers: [:form])
|
|
33
|
-
s.add(:icon, gems: ["lucide-rails"])
|
|
31
|
+
s.add(:fieldset, [ :field_group ])
|
|
32
|
+
s.add(:form_builder, [ :field ], helpers: [ :form ])
|
|
33
|
+
s.add(:icon, gems: [ "lucide-rails" ])
|
|
34
34
|
s.add(:input)
|
|
35
35
|
s.add(:label)
|
|
36
|
-
s.add(:pagination, [:icon, :button])
|
|
37
|
-
s.add(:radio_button, [:label], components: [:radio_button, :radio_button_group])
|
|
36
|
+
s.add(:pagination, [ :icon, :button ])
|
|
37
|
+
s.add(:radio_button, [ :label ], components: [ :radio_button, :radio_button_group ])
|
|
38
38
|
s.add(:select)
|
|
39
|
-
s.add(:switch, js: [:switch])
|
|
39
|
+
s.add(:switch, js: [ :switch ])
|
|
40
40
|
s.add(:table)
|
|
41
|
-
s.add(:tabs, js: [:tabs])
|
|
41
|
+
s.add(:tabs, js: [ :tabs ])
|
|
42
42
|
s.add(:textarea)
|
|
43
|
-
s.add(:toast, js: [:toast])
|
|
44
|
-
s.add(:tooltip, js: [:tooltip], modules: ["@floating-ui/core", "@floating-ui/dom"])
|
|
43
|
+
s.add(:toast, js: [ :toast ])
|
|
44
|
+
s.add(:tooltip, js: [ :tooltip ], modules: [ "@floating-ui/core", "@floating-ui/dom" ])
|
|
45
45
|
end
|
|
46
46
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: nitro_kit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mikkel Malmberg
|
|
@@ -60,6 +60,7 @@ extra_rdoc_files: []
|
|
|
60
60
|
files:
|
|
61
61
|
- README.md
|
|
62
62
|
- Rakefile
|
|
63
|
+
- app/assets/tailwind/application.css
|
|
63
64
|
- app/components/nitro_kit/accordion.rb
|
|
64
65
|
- app/components/nitro_kit/alert.rb
|
|
65
66
|
- app/components/nitro_kit/avatar.rb
|
|
@@ -157,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
157
158
|
- !ruby/object:Gem::Version
|
|
158
159
|
version: '0'
|
|
159
160
|
requirements: []
|
|
160
|
-
rubygems_version:
|
|
161
|
+
rubygems_version: 4.0.3
|
|
161
162
|
specification_version: 4
|
|
162
163
|
summary: WIP, not usable yet
|
|
163
164
|
test_files: []
|