ui_bibz 2.1.6 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +19 -10
- data/app/assets/javascripts/interface.coffee +8 -0
- data/app/assets/javascripts/ui_bibz.coffee.erb +3 -0
- data/app/assets/stylesheets/fix_addon.sass +2 -2
- data/lib/ui_bibz.rb +8 -0
- data/lib/ui_bibz/helpers/ui/core/forms_helper.rb +35 -0
- data/lib/ui_bibz/infos.rb +2 -2
- data/lib/ui_bibz/inputs/ui_bibz_inputs/ui_box_switch_field_input.rb +18 -0
- data/lib/ui_bibz/inputs/ui_bibz_inputs/ui_file_field_input.rb +10 -0
- data/lib/ui_bibz/inputs/ui_bibz_inputs/ui_range_field_input.rb +10 -0
- data/lib/ui_bibz/inputs/ui_bibz_inputs/ui_switch_field_input.rb +5 -1
- data/lib/ui_bibz/ui/core/component.rb +4 -0
- data/lib/ui_bibz/ui/core/forms/choices/box_switch_field.rb +141 -0
- data/lib/ui_bibz/ui/core/forms/choices/checkbox_field.rb +18 -27
- data/lib/ui_bibz/ui/core/forms/choices/radio_field.rb +15 -40
- data/lib/ui_bibz/ui/core/forms/choices/switch_field.rb +11 -95
- data/lib/ui_bibz/ui/core/forms/dates/date_picker_field.rb +25 -0
- data/lib/ui_bibz/ui/core/forms/dropdowns/dropdown.rb +5 -1
- data/lib/ui_bibz/ui/core/forms/files/file_field.rb +72 -0
- data/lib/ui_bibz/ui/core/forms/numbers/number_field.rb +15 -0
- data/lib/ui_bibz/ui/core/forms/numbers/range_field.rb +66 -0
- data/lib/ui_bibz/ui/core/forms/selects/multi_select_field.rb +9 -1
- data/lib/ui_bibz/ui/core/forms/texts/text_field.rb +3 -0
- data/test/simple_form_test.rb +33 -3
- data/test/ui/core/forms/choices/{switch_field_test.rb → box_switch_field_test.rb} +21 -21
- data/test/ui/core/forms/choices/checkbox_field_test.rb +1 -1
- data/test/ui/core/forms/choices/radio_field_test.rb +1 -1
- data/test/ui/core/forms/files/text_field_test.rb +11 -0
- data/test/ui/core/forms/numbers/number_field_test.rb +18 -0
- data/test/ui/core/forms/numbers/range_field_test.rb +18 -0
- data/vendor/assets/javascripts/bs-custom-file-input.min.js +7 -0
- metadata +19 -6
@@ -14,10 +14,12 @@ module UiBibz::Ui::Core::Forms::Choices
|
|
14
14
|
#
|
15
15
|
# You can add HTML attributes using the +html_options+.
|
16
16
|
# You can pass arguments in options attribute:
|
17
|
-
# * +
|
18
|
-
#
|
19
|
-
#
|
20
|
-
# * +
|
17
|
+
# * +state+ - Symbol
|
18
|
+
# (+:active+, +:disabled+)
|
19
|
+
# * +inline+ - Boolean
|
20
|
+
# * +checked+ - Boolean
|
21
|
+
# * +action+ - String Stimulus Option
|
22
|
+
# * +label+ - String
|
21
23
|
#
|
22
24
|
# ==== Signatures
|
23
25
|
#
|
@@ -37,9 +39,9 @@ module UiBibz::Ui::Core::Forms::Choices
|
|
37
39
|
#
|
38
40
|
# ==== Helper
|
39
41
|
#
|
40
|
-
#
|
42
|
+
# ui_checkbox_field(content, options = {}, html_options = {})
|
41
43
|
#
|
42
|
-
#
|
44
|
+
# ui_checkbox_field(options = {}, html_options = {}) do
|
43
45
|
# content
|
44
46
|
# end
|
45
47
|
#
|
@@ -62,22 +64,23 @@ module UiBibz::Ui::Core::Forms::Choices
|
|
62
64
|
content_tag(:div, html_options.except(:id, "data-action")) do
|
63
65
|
concat hidden_field_tag content, '0', id: "#{ content }-hidden"
|
64
66
|
concat check_box_tag content, options[:value] || '1', options[:checked] || html_options[:checked], checkbox_html_options
|
65
|
-
concat label_tag label_name, label_content,
|
67
|
+
concat label_tag label_name, label_content, class: 'custom-control-label'
|
66
68
|
end
|
67
69
|
end
|
68
70
|
|
69
71
|
def checkbox_html_options
|
70
|
-
{
|
72
|
+
{
|
73
|
+
disabled: is_disabled?,
|
74
|
+
indeterminate: options[:indeterminate],
|
75
|
+
"data-action": options[:action],
|
76
|
+
class: 'custom-control-input'
|
77
|
+
}
|
71
78
|
end
|
72
79
|
|
73
80
|
def label_name
|
74
81
|
html_options[:id] || content
|
75
82
|
end
|
76
83
|
|
77
|
-
def label_html_options
|
78
|
-
{ class: join_classes("form-check-label", ("fix-label" if options[:label] == false)) }
|
79
|
-
end
|
80
|
-
|
81
84
|
def label_content
|
82
85
|
case options[:label]
|
83
86
|
when nil
|
@@ -89,24 +92,12 @@ module UiBibz::Ui::Core::Forms::Choices
|
|
89
92
|
end
|
90
93
|
end
|
91
94
|
|
92
|
-
def
|
93
|
-
"
|
94
|
-
end
|
95
|
-
|
96
|
-
def type
|
97
|
-
"abc-checkbox-circle" unless options[:type].nil?
|
98
|
-
end
|
99
|
-
|
100
|
-
def indeterminate
|
101
|
-
"indeterminate" unless options[:indeterminate].nil?
|
95
|
+
def component_html_classes
|
96
|
+
super << ["custom-control", "custom-checkbox", inline]
|
102
97
|
end
|
103
98
|
|
104
99
|
def inline
|
105
|
-
"
|
106
|
-
end
|
107
|
-
|
108
|
-
def component_html_classes
|
109
|
-
super << ["form-check", "abc-checkbox", type, indeterminate, inline]
|
100
|
+
"custom-control-inline" if options[:inline]
|
110
101
|
end
|
111
102
|
|
112
103
|
end
|
@@ -15,9 +15,11 @@ module UiBibz::Ui::Core::Forms::Choices
|
|
15
15
|
# You can add HTML attributes using the +html_options+.
|
16
16
|
# You can pass arguments in options attribute:
|
17
17
|
# * +value+ - String, Integer, Boolean [required]
|
18
|
-
# * +
|
19
|
-
# (+:
|
20
|
-
# * +
|
18
|
+
# * +state+ - Symbol
|
19
|
+
# (+:active+, +:disabled+)
|
20
|
+
# * +inline+ - Boolean
|
21
|
+
# * +action+ - String Stimulus Option
|
22
|
+
# * +label+ - String
|
21
23
|
#
|
22
24
|
# ==== Signatures
|
23
25
|
#
|
@@ -29,9 +31,9 @@ module UiBibz::Ui::Core::Forms::Choices
|
|
29
31
|
#
|
30
32
|
# ==== Examples
|
31
33
|
#
|
32
|
-
# UiBibz::Ui::Core::Forms::RadioField.new(content, {
|
34
|
+
# UiBibz::Ui::Core::Forms::RadioField.new(content, { inline: true },{ class: 'test' }).render
|
33
35
|
#
|
34
|
-
# UiBibz::Ui::Core::Forms::RadioField.new({
|
36
|
+
# UiBibz::Ui::Core::Forms::RadioField.new({ label: "My Radio" }, { class: 'test' }) do
|
35
37
|
# content
|
36
38
|
# end.render
|
37
39
|
#
|
@@ -43,7 +45,7 @@ module UiBibz::Ui::Core::Forms::Choices
|
|
43
45
|
# content
|
44
46
|
# end
|
45
47
|
#
|
46
|
-
class RadioField < UiBibz::Ui::Core::
|
48
|
+
class RadioField < UiBibz::Ui::Core::Forms::Choices::CheckboxField
|
47
49
|
|
48
50
|
# See UiBibz::Ui::Core::Component.initialize
|
49
51
|
def initialize content = nil, options = nil, html_options = nil, &block
|
@@ -60,51 +62,24 @@ module UiBibz::Ui::Core::Forms::Choices
|
|
60
62
|
def radio_field_html_tag
|
61
63
|
content_tag :div, html_options.except(:id) do
|
62
64
|
concat radio_button_tag content, options[:value], options[:checked] || false, checkbox_html_options
|
63
|
-
concat label_tag label_name, label_content,
|
65
|
+
concat label_tag label_name, label_content, class: 'custom-control-label'
|
64
66
|
end
|
65
67
|
end
|
66
68
|
|
67
69
|
def checkbox_html_options
|
68
|
-
{
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
{
|
71
|
+
disabled: options[:state] == :disabled,
|
72
|
+
"data-action": options[:action],
|
73
|
+
class: 'custom-control-input'
|
74
|
+
}
|
73
75
|
end
|
74
76
|
|
75
77
|
def label_name
|
76
78
|
"#{ content }_#{ options[:value] }"
|
77
79
|
end
|
78
80
|
|
79
|
-
def label_content
|
80
|
-
case options[:label]
|
81
|
-
when nil
|
82
|
-
content
|
83
|
-
when false
|
84
|
-
" "
|
85
|
-
else
|
86
|
-
options[:label]
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def status
|
91
|
-
"abc-#{ type }-#{ options[:status] || :default }"
|
92
|
-
end
|
93
|
-
|
94
|
-
def type
|
95
|
-
if !options[:type].nil? && options[:type] == :square
|
96
|
-
:checkbox
|
97
|
-
else
|
98
|
-
:radio
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def inline
|
103
|
-
"#{ type }-inline" unless options[:inline].nil?
|
104
|
-
end
|
105
|
-
|
106
81
|
def component_html_classes
|
107
|
-
[
|
82
|
+
["custom-control", "custom-radio", inline]
|
108
83
|
end
|
109
84
|
|
110
85
|
end
|
@@ -14,125 +14,41 @@ module UiBibz::Ui::Core::Forms::Choices
|
|
14
14
|
#
|
15
15
|
# You can add HTML attributes using the +html_options+.
|
16
16
|
# You can pass arguments in options attribute:
|
17
|
-
# * +state+ -
|
18
|
-
#
|
19
|
-
# * +
|
20
|
-
# * +off_color+ - String
|
21
|
-
# * +on_text+ - String
|
22
|
-
# * +off_text+ - String
|
23
|
-
# * +label_text+ - String
|
24
|
-
# * +readonly+ - Boolean
|
17
|
+
# * +state+ - Symbol
|
18
|
+
# (+:active+, +:disabled+)
|
19
|
+
# * +inline+ - Boolean
|
25
20
|
# * +checked+ - Boolean
|
21
|
+
# * +action+ - String Stimulus Option
|
22
|
+
# * +label+ - String
|
26
23
|
#
|
27
24
|
# ==== Signatures
|
28
25
|
#
|
29
|
-
# UiBibz::Ui::Core::Forms::
|
26
|
+
# UiBibz::Ui::Core::Forms::SwithField.new(content, options = {}, html_options = {}).render
|
30
27
|
#
|
31
|
-
# UiBibz::Ui::Core::Forms::
|
28
|
+
# UiBibz::Ui::Core::Forms::SwithField.new(options = {}, html_options = {}) do
|
32
29
|
# content
|
33
30
|
# end.render
|
34
31
|
#
|
35
32
|
# ==== Examples
|
36
33
|
#
|
37
|
-
#
|
34
|
+
# ui_switch_field 'name', checked: true
|
38
35
|
#
|
39
36
|
# ==== Helper
|
40
37
|
#
|
41
|
-
#
|
38
|
+
# ui_switch_field(options = {}, html_options = {}) do
|
42
39
|
# # content
|
43
40
|
# end
|
44
41
|
#
|
45
|
-
class SwitchField < UiBibz::Ui::Core::
|
42
|
+
class SwitchField < UiBibz::Ui::Core::Forms::Choices::CheckboxField
|
46
43
|
|
47
|
-
# See UiBibz::Ui::Core::Component.initialize
|
48
44
|
def initialize content = nil, options = nil, html_options = nil, &block
|
49
45
|
super
|
50
46
|
end
|
51
47
|
|
52
|
-
# Render html tag
|
53
|
-
def pre_render
|
54
|
-
switch_field_html_tag
|
55
|
-
end
|
56
|
-
|
57
48
|
private
|
58
49
|
|
59
|
-
def switch_field_html_tag
|
60
|
-
content_tag :div, class: component_wrapper_html_classes do
|
61
|
-
concat hidden_field_tag content, '0'
|
62
|
-
concat check_box_tag content, '1', html_options[:checked], html_options
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def value
|
67
|
-
options[:value]
|
68
|
-
end
|
69
|
-
|
70
|
-
def component_wrapper_html_classes
|
71
|
-
join_classes('switch-field-container', inline)
|
72
|
-
end
|
73
|
-
|
74
50
|
def component_html_classes
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
def component_html_data
|
79
|
-
super
|
80
|
-
size
|
81
|
-
state
|
82
|
-
animate
|
83
|
-
left_color
|
84
|
-
right_color
|
85
|
-
left_text
|
86
|
-
right_text
|
87
|
-
middle_text
|
88
|
-
end
|
89
|
-
|
90
|
-
# '', 'mini', 'small', 'normal', 'large'
|
91
|
-
def size
|
92
|
-
add_html_data('size', matching_size[options[:size]]) unless options[:size].nil?
|
93
|
-
end
|
94
|
-
|
95
|
-
def matching_size
|
96
|
-
{ sm: 'small', md: 'normal', lg: 'large' }
|
97
|
-
end
|
98
|
-
|
99
|
-
# true, false => default : true
|
100
|
-
def animate
|
101
|
-
add_html_data('animate', options.delete(:animate)) unless options[:animate].nil?
|
102
|
-
end
|
103
|
-
|
104
|
-
# active, disabled => default : active
|
105
|
-
def state
|
106
|
-
html_options[:disabled] = true if options[:state] == 'disabled'
|
107
|
-
end
|
108
|
-
|
109
|
-
# 'primary', 'info', 'success', 'warning', 'danger', 'default' => default : default
|
110
|
-
def left_color
|
111
|
-
add_html_data('on_color', options[:left_color]) unless options[:left_color].nil?
|
112
|
-
end
|
113
|
-
|
114
|
-
# 'primary', 'info', 'success', 'warning', 'danger', 'default' => default : default
|
115
|
-
def right_color
|
116
|
-
add_html_data('off_color', options[:right_color]) unless options[:right_color].nil?
|
117
|
-
end
|
118
|
-
|
119
|
-
# String => default : "ON"
|
120
|
-
def left_text
|
121
|
-
add_html_data('on_text', options[:left_text]) unless options[:left_text].nil?
|
122
|
-
end
|
123
|
-
|
124
|
-
# String => default : "OFF"
|
125
|
-
def right_text
|
126
|
-
add_html_data('off_text', options[:right_text]) unless options[:right_text].nil?
|
127
|
-
end
|
128
|
-
|
129
|
-
# String => default : ' '
|
130
|
-
def middle_text
|
131
|
-
add_html_data('label_text', options[:middle_text]) unless options[:middle_text].nil?
|
132
|
-
end
|
133
|
-
|
134
|
-
def inline
|
135
|
-
"btn-group" unless options[:inline].nil?
|
51
|
+
["custom-control", "custom-switch", inline]
|
136
52
|
end
|
137
53
|
|
138
54
|
end
|
@@ -84,6 +84,9 @@ module UiBibz::Ui::Core::Forms::Dates
|
|
84
84
|
days_of_week_disabled
|
85
85
|
days_of_week_highlighted
|
86
86
|
multiple
|
87
|
+
display_mode
|
88
|
+
display_mode_min
|
89
|
+
display_mode_max
|
87
90
|
end
|
88
91
|
|
89
92
|
def component_html_classes
|
@@ -134,6 +137,18 @@ module UiBibz::Ui::Core::Forms::Dates
|
|
134
137
|
add_html_data("date_toggle_active", true)
|
135
138
|
end
|
136
139
|
|
140
|
+
def display_mode
|
141
|
+
add_html_data("date_start_view", views[options[:display_mode]]) if options[:display_mode]
|
142
|
+
end
|
143
|
+
|
144
|
+
def display_mode_min
|
145
|
+
add_html_data("date_min_view_mode", views[options[:display_mode_min]]) if options[:display_mode_min]
|
146
|
+
end
|
147
|
+
|
148
|
+
def display_mode_max
|
149
|
+
add_html_data("date_max_view_mode", views[options[:display_mode_max]]) if options[:display_mode_max]
|
150
|
+
end
|
151
|
+
|
137
152
|
def days_of_week_disabled
|
138
153
|
add_html_data("date_days_of_week_disabled", [options[:days_of_week_disabled]].flatten) if options[:days_of_week_disabled]
|
139
154
|
end
|
@@ -155,5 +170,15 @@ module UiBibz::Ui::Core::Forms::Dates
|
|
155
170
|
"has-#{ options[:status] }" if options[:status]
|
156
171
|
end
|
157
172
|
|
173
|
+
def views
|
174
|
+
{
|
175
|
+
days: 0,
|
176
|
+
months: 1,
|
177
|
+
years: 2,
|
178
|
+
decades: 3,
|
179
|
+
centuries: 4
|
180
|
+
}
|
181
|
+
end
|
182
|
+
|
158
183
|
end
|
159
184
|
end
|
@@ -111,7 +111,7 @@ module UiBibz::Ui::Core::Forms::Dropdowns
|
|
111
111
|
protected
|
112
112
|
|
113
113
|
def component_html_classes
|
114
|
-
[type, open, inline, without_caret]
|
114
|
+
[type, open, inline, without_caret, keep_open]
|
115
115
|
end
|
116
116
|
|
117
117
|
def button_content
|
@@ -146,6 +146,10 @@ module UiBibz::Ui::Core::Forms::Dropdowns
|
|
146
146
|
"show" if @options[:open]
|
147
147
|
end
|
148
148
|
|
149
|
+
def keep_open
|
150
|
+
"keep-open" if @options[:keep_open]
|
151
|
+
end
|
152
|
+
|
149
153
|
def inline
|
150
154
|
"btn-group" if @options[:inline]
|
151
155
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module UiBibz::Ui::Core::Forms::Files
|
2
|
+
|
3
|
+
# Create a FileField
|
4
|
+
#
|
5
|
+
# This element is an extend of UiBibz::Ui::Core::Component.
|
6
|
+
#
|
7
|
+
# ==== Attributes
|
8
|
+
#
|
9
|
+
# * +content+ - Content of element
|
10
|
+
# * +options+ - Options of element
|
11
|
+
# * +html_options+ - Html Options of element
|
12
|
+
#
|
13
|
+
# ==== Options
|
14
|
+
#
|
15
|
+
# You can add HTML attributes using the +html_options+.
|
16
|
+
# You can pass arguments in options attribute:
|
17
|
+
# * +state+ - Symbol
|
18
|
+
# (+:active+, +:disabled+)
|
19
|
+
#
|
20
|
+
# ==== Signatures
|
21
|
+
#
|
22
|
+
# UiBibz::Ui::Core::Forms::Texts::FileField.new(content, options = {}, html_options = {}).render
|
23
|
+
#
|
24
|
+
# UiBibz::Ui::Core::Forms::Texts::FileField.new(options = {}, html_options = {}) do
|
25
|
+
# content
|
26
|
+
# end.render
|
27
|
+
#
|
28
|
+
# ==== Examples
|
29
|
+
#
|
30
|
+
# UiBibz::Ui::Core::Forms::Texts::FileField.new('upload', class: 'test')
|
31
|
+
#
|
32
|
+
# UiBibz::Ui::Core::Forms::Texts::FileField.new(class: 'test') do
|
33
|
+
# #content
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# ==== Helper
|
37
|
+
#
|
38
|
+
# ui_file_field(options = {}, html_options = {}) do
|
39
|
+
# # content
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
class FileField < UiBibz::Ui::Core::Component
|
43
|
+
|
44
|
+
# See UiBibz::Ui::Core::Component.initialize
|
45
|
+
def initialize content = nil, options = nil, html_options = nil, &block
|
46
|
+
super
|
47
|
+
end
|
48
|
+
|
49
|
+
# Render html tag
|
50
|
+
def pre_render
|
51
|
+
content_tag :div, html_options do
|
52
|
+
concat file_field_tag content, class: "custom-file-input" , multiple: options[:multiple], disabled: is_disabled?
|
53
|
+
concat label_tag label_name, label_content, class: 'custom-file-label'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def label_name
|
60
|
+
html_options[:id] || content
|
61
|
+
end
|
62
|
+
|
63
|
+
def label_content
|
64
|
+
options[:value] || ''
|
65
|
+
end
|
66
|
+
|
67
|
+
def component_html_classes
|
68
|
+
super << "custom-file"
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|