ui_bibz 4.0.0.beta15 → 4.0.0.beta17

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.
@@ -0,0 +1,158 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UiBibz::Ui::Core::Forms::Dropdowns::Components
4
+ # Create DropdownDropdown
5
+ #
6
+ # This element is an extend of UiBibz::Ui::Core::Forms::Dropdowns::Dropdown.
7
+ #
8
+ # ==== Attributes
9
+ #
10
+ # * +content+ - Content of element
11
+ # * +options+ - Options of element
12
+ # * +html_options+ - Html Options of element
13
+ #
14
+ # ==== Options
15
+ #
16
+ # You can add HTML attributes using the +html_options+.
17
+ # You can pass arguments in options attribute:
18
+ # * +state+ - status of element with symbol value:
19
+ # (+:active+)
20
+ # * +url+ - String
21
+ # * +glyph+ - Add glyph with name or hash options
22
+ # * +name+ - String
23
+ # * +size+ - Integer
24
+ # * +type+ - Symbol
25
+ # * +link_html_options+ - Hash
26
+ #
27
+ # ==== Signatures
28
+ #
29
+ # UiBibz::Ui::Core::Forms::DropdownDropdown.new(content, options = nil, html_options = nil)
30
+ #
31
+ # UiBibz::Ui::Core::Forms::DropdownDropdown.new(options = nil, html_options = nil) do
32
+ # content
33
+ # end
34
+ #
35
+ # ==== Examples
36
+ #
37
+ # UiBibz::Ui::Core::Forms::DropdownDropdown.new('Home', { glyph: 'home', state: :active, url: '#home', link_html_options: { class: 'link1' }},{ class: 'test' }).render
38
+ #
39
+ # UiBibz::Ui::Core::Forms::DropdownDropdown.new({ glyph: { name: 'eye', size: 3 }, url: '#home' }, { class: 'test' }) do
40
+ # 'Home'
41
+ # end.render
42
+ #
43
+ class DropdownDropdown < UiBibz::Ui::Core::Component
44
+ include UiBibz::Ui::Concerns::HtmlConcern
45
+
46
+ def initialize(...)
47
+ super
48
+ @items = []
49
+ @status = @options.delete(:status)
50
+ end
51
+
52
+ # Render html tag
53
+ def pre_render
54
+ content_tag :div, html_options do
55
+ concat button_html
56
+ concat ul_html
57
+ end
58
+ end
59
+
60
+ # Add dropdown header
61
+ # See UiBibz::Ui::Core::Forms::Dropdowns::Components::DropdownHeader
62
+ def header(content = nil, options = nil, html_options = nil, &)
63
+ @items << UiBibz::Ui::Core::Forms::Dropdowns::Components::DropdownHeader.new(content, options, html_options, &).render
64
+ end
65
+
66
+ # Add dropdown Separator
67
+ # See UiBibz::Ui::Core::Forms::Dropdowns::Components::DropdownDivider
68
+ def divider
69
+ @items << UiBibz::Ui::Core::Forms::Dropdowns::Components::DropdownDivider.new.render
70
+ end
71
+
72
+ # Add dropdown link in list
73
+ # See UiBibz::Ui::Core::Forms::Dropdowns::Components::DropdownLink
74
+ def link(content = nil, options = nil, html_options = nil, &)
75
+ @items << UiBibz::Ui::Core::Forms::Dropdowns::Components::DropdownLink.new(content, options, html_options, &).render
76
+ end
77
+
78
+ def dropdown(content = nil, options = nil, html_options = nil, &)
79
+ @items << new(content, options, html_options, &).render
80
+ end
81
+
82
+ def id
83
+ @id ||= html_options[:id] || generate_id('dropdown')
84
+ end
85
+
86
+ protected
87
+
88
+ def component_html_classes
89
+ ['dropdown-item', hover, position, open, inline, without_caret, keep_open]
90
+ end
91
+
92
+ def button_content
93
+ glyph_and_content_html(@content)
94
+ end
95
+
96
+ def button_html
97
+ content_tag :a, button_content, { class: join_classes(state, 'dropdown-toggle'), role: 'button', 'data-bs-toggle' => 'dropdown', 'aria-expanded' => false, 'id' => id }
98
+ end
99
+
100
+ def ul_html
101
+ content_tag :div, @items.join.html_safe, class: join_classes('dropdown-menu', theme, alignment, open), 'arial-labelledby' => id
102
+ end
103
+
104
+ def alignment
105
+ return nil if @options[:alignment].nil?
106
+
107
+ if @options[:alignment].is_a? Hash
108
+ ['dropdown-menu', @options[:alignment][:size], match_direction[@options[:alignment][:direction]]].join('-')
109
+ else
110
+ "dropdown-menu-#{match_direction[@options[:alignment]]}"
111
+ end
112
+ end
113
+
114
+ def position
115
+ "drop#{match_direction[@options[:position] || :right]}"
116
+ end
117
+
118
+ def open
119
+ 'show' if @options[:open]
120
+ end
121
+
122
+ def keep_open
123
+ 'keep-open' if @options[:keep_open]
124
+ end
125
+
126
+ def inline
127
+ 'btn-group' if @options[:inline] || @options[:alignment]
128
+ end
129
+
130
+ def without_caret
131
+ 'without-caret' if @options[:caret] == false
132
+ end
133
+
134
+ def outline
135
+ 'outline' if @options[:outline]
136
+ end
137
+
138
+ def hover
139
+ 'dropdown-hover' if @options[:hover]
140
+ end
141
+
142
+ def theme
143
+ 'dropdown-menu-dark' if @options[:theme]
144
+ end
145
+
146
+ # Match end and start directions
147
+ def match_direction
148
+ {
149
+ up: 'up',
150
+ right: 'end',
151
+ down: 'down',
152
+ left: 'start',
153
+ start: 'start',
154
+ end: 'end'
155
+ }.with_indifferent_access
156
+ end
157
+ end
158
+ end
@@ -3,6 +3,7 @@
3
3
  require 'ui_bibz/ui/core/forms/dropdowns/components/dropdown_header'
4
4
  require 'ui_bibz/ui/core/forms/dropdowns/components/dropdown_divider'
5
5
  require 'ui_bibz/ui/core/forms/dropdowns/components/dropdown_link'
6
+ require 'ui_bibz/ui/core/forms/dropdowns/components/dropdown_dropdown'
6
7
  module UiBibz::Ui::Core::Forms::Dropdowns
7
8
  # Create a dropdown
8
9
  #
@@ -102,6 +103,10 @@ module UiBibz::Ui::Core::Forms::Dropdowns
102
103
  @items << UiBibz::Ui::Core::Forms::Dropdowns::Components::DropdownLink.new(content, options, html_options, &).render
103
104
  end
104
105
 
106
+ def dropdown(name = nil, options = nil, html_options = nil, &)
107
+ @items << UiBibz::Ui::Core::Forms::Dropdowns::Components::DropdownDropdown.new(name, options, html_options).tap(&).render
108
+ end
109
+
105
110
  def id
106
111
  @id ||= html_options[:id] || generate_id('dropdown')
107
112
  end
@@ -67,7 +67,7 @@ module UiBibz::Ui::Core::Navigations
67
67
  end
68
68
 
69
69
  def text
70
- @options[:text].nil? ? true : @options[:text]
70
+ @options[:text].nil? || @options[:text]
71
71
  end
72
72
  end
73
73
  end
@@ -16,45 +16,25 @@ module UiBibz::Ui::Ux::Tables
16
16
  @model = store.model
17
17
  end
18
18
 
19
- def total_pages
20
- @records.total_pages
21
- end
19
+ delegate :total_pages, to: :@records
22
20
 
23
- def per_page
24
- @records.per_page
25
- end
21
+ delegate :per_page, to: :@records
26
22
 
27
- def total_entries
28
- @records.total_entries
29
- end
23
+ delegate :total_entries, to: :@records
30
24
 
31
- def id
32
- @store.id
33
- end
25
+ delegate :id, to: :@store
34
26
 
35
- def sort
36
- @store.sort
37
- end
27
+ delegate :sort, to: :@store
38
28
 
39
- def column_id
40
- @store.column_id
41
- end
29
+ delegate :column_id, to: :@store
42
30
 
43
- def direction
44
- @store.direction
45
- end
31
+ delegate :direction, to: :@store
46
32
 
47
- def searchable_attributes
48
- @store.searchable_attributes
49
- end
33
+ delegate :searchable_attributes, to: :@store
50
34
 
51
- def current_page
52
- @records.current_page
53
- end
35
+ delegate :current_page, to: :@records
54
36
 
55
- def limit_value
56
- @records.limit_value
57
- end
37
+ delegate :limit_value, to: :@records
58
38
 
59
39
  def columns
60
40
  @columns ||= Columns.new(model.attribute_names.map { |attribute_name| Column.new(attribute_name, { name: attribute_name.humanize }) })
@@ -62,17 +42,11 @@ module UiBibz::Ui::Ux::Tables
62
42
 
63
43
  attr_reader :model
64
44
 
65
- def search
66
- @store.search
67
- end
45
+ delegate :search, to: :@store
68
46
 
69
- def controller
70
- @store.controller
71
- end
47
+ delegate :controller, to: :@store
72
48
 
73
- def actions_controller
74
- @store.actions_controller
75
- end
49
+ delegate :actions_controller, to: :@store
76
50
 
77
51
  def params
78
52
  @store.params || {}
@@ -82,16 +56,10 @@ module UiBibz::Ui::Ux::Tables
82
56
  @store.params.to_h
83
57
  end
84
58
 
85
- def action
86
- @store.action
87
- end
59
+ delegate :action, to: :@store
88
60
 
89
- def param_id
90
- @store.param_id
91
- end
61
+ delegate :param_id, to: :@store
92
62
 
93
- def id_key
94
- @store.id_key
95
- end
63
+ delegate :id_key, to: :@store
96
64
  end
97
65
  end
@@ -9,7 +9,7 @@ module UiBibz::Ui::Ux::Tables
9
9
  end
10
10
 
11
11
  def actionable?
12
- @options[:actionable].nil? ? true : @options[:actionable]
12
+ @options[:actionable].nil? || @options[:actionable]
13
13
  end
14
14
 
15
15
  def header(ths)
@@ -25,7 +25,7 @@ module UiBibz::Ui::Ux::Tables
25
25
  private
26
26
 
27
27
  def default_actions?
28
- @options[:default_actions].nil? ? true : @options[:default_actions]
28
+ @options[:default_actions].nil? || @options[:default_actions]
29
29
  end
30
30
 
31
31
  def dropdown_action(record)
@@ -19,7 +19,7 @@ module UiBibz::Ui::Ux::Tables
19
19
  end
20
20
 
21
21
  def paginable?
22
- @options[:paginable].nil? ? true : @options[:paginable]
22
+ @options[:paginable].nil? || @options[:paginable]
23
23
  end
24
24
 
25
25
  private
@@ -18,7 +18,7 @@ module UiBibz::Ui::Ux::Tables
18
18
  end
19
19
 
20
20
  def searchable?
21
- @options[:searchable].nil? ? true : @options[:searchable]
21
+ @options[:searchable].nil? || @options[:searchable]
22
22
  end
23
23
 
24
24
  private
@@ -140,9 +140,7 @@ module UiBibz::Ui::Ux::Tables
140
140
  end
141
141
 
142
142
  # for test
143
- def actions_list
144
- @table.actions_list
145
- end
143
+ delegate :actions_list, to: :@table
146
144
 
147
145
  private
148
146
 
@@ -26,7 +26,7 @@ class TableTest < ActionView::TestCase
26
26
 
27
27
  test 'table search field' do
28
28
  actual = UiBibz::Ui::Ux::Tables::TableSearchField.new({ store: @users }).render
29
- expected = "<form class=\"form-table-search-field\" action=\"/users?direction=asc&amp;page=1&amp;per_page=2&amp;search=Name+fr&amp;sort=users.name_fr\" accept-charset=\"UTF-8\" method=\"get\"><div class=\"input-group input-group-sm table-search-field\"><span class=\"input-group-text\"><i class=\"glyph fa-solid fa-search\"></i></span><input type=\"hidden\" name=\"sort\" value=\"users.name_fr\" /><input type=\"hidden\" name=\"direction\" value=\"asc\" /><input type=\"hidden\" name=\"per_page\" value=\"2\" /><input type=\"hidden\" name=\"page\" value=\"1\" /><input type=\"hidden\" name=\"only_path\" value=\"true\" /><input type=\"hidden\" name=\"store_id\" value=\"users\" /><input type=\"hidden\" name=\"link_type\" value=\"search\" /><input type=\"search\" value=\"Name fr\" name=\"search\" class=\"form-control\" placeholder=\"Search by Name fr and Name en...\" /><button type=\"button\" class=\"btn btn-secondary input-group-btn clear-search-btn\"><i class=\"glyph fa-solid fa-times-circle\"></i> <span class=\"visually-hidden\">Clear Search</span></button></div></form>"
29
+ expected = "<form class=\"form-table-search-field\" action=\"/users?direction=asc&amp;page=1&amp;per_page=2&amp;search=Name+fr&amp;sort=users.name_fr\" accept-charset=\"UTF-8\" method=\"get\"><div class=\"input-group input-group-sm table-search-field\"><span class=\"input-group-text\"><i class=\"glyph fa-solid fa-search\"></i></span><input type=\"hidden\" name=\"sort\" value=\"users.name_fr\" /><input type=\"hidden\" name=\"direction\" value=\"asc\" /><input type=\"hidden\" name=\"per_page\" value=\"2\" /><input type=\"hidden\" name=\"page\" value=\"1\" /><input type=\"hidden\" name=\"only_path\" value=\"true\" /><input type=\"hidden\" name=\"store_id\" value=\"users\" /><input type=\"hidden\" name=\"link_type\" value=\"search\" /><input type=\"search\" value=\"Name fr\" name=\"search\" class=\"form-control\" placeholder=\"Search by Name fr and Name en...\" /><button type=\"button\" class=\"clear-search-btn input-group-btn btn-secondary btn\" data-bs-toggle=\"tooltip\" data-bs-title=\"Clear Search\"><i class=\"glyph fa-solid fa-times-circle\"></i> <span class=\"visually-hidden\">Clear Search</span></button></div></form>"
30
30
 
31
31
  assert_equal expected, actual
32
32
  end
@@ -97,7 +97,7 @@ class TableTest < ActionView::TestCase
97
97
  test 'table searchable' do
98
98
  options = { searchable: true }
99
99
  actual = UiBibz::Ui::Ux::Tables::Searchable.new(@store, options).render
100
- expected = "<div><div class=\"title\">Users list</div><form class=\"form-table-search-field\" action=\"/users?direction=asc&amp;page=1&amp;per_page=2&amp;search=Name+fr&amp;sort=users.name_fr\" accept-charset=\"UTF-8\" method=\"get\"><div class=\"input-group input-group-sm table-search-field\"><span class=\"input-group-text\"><i class=\"glyph fa-solid fa-search\"></i></span><input type=\"hidden\" name=\"sort\" value=\"users.name_fr\" /><input type=\"hidden\" name=\"direction\" value=\"asc\" /><input type=\"hidden\" name=\"per_page\" value=\"2\" /><input type=\"hidden\" name=\"page\" value=\"1\" /><input type=\"hidden\" name=\"only_path\" value=\"true\" /><input type=\"hidden\" name=\"store_id\" value=\"users\" /><input type=\"hidden\" name=\"link_type\" value=\"search\" /><input type=\"search\" value=\"Name fr\" name=\"search\" class=\"form-control\" placeholder=\"Search by Name fr and Name en...\" /><button type=\"button\" class=\"btn btn-secondary input-group-btn clear-search-btn\"><i class=\"glyph fa-solid fa-times-circle\"></i> <span class=\"visually-hidden\">Clear Search</span></button></div></form><br class=\"ui-bibz-clear\" /></div>"
100
+ expected = "<div><div class=\"title\">Users list</div><form class=\"form-table-search-field\" action=\"/users?direction=asc&amp;page=1&amp;per_page=2&amp;search=Name+fr&amp;sort=users.name_fr\" accept-charset=\"UTF-8\" method=\"get\"><div class=\"input-group input-group-sm table-search-field\"><span class=\"input-group-text\"><i class=\"glyph fa-solid fa-search\"></i></span><input type=\"hidden\" name=\"sort\" value=\"users.name_fr\" /><input type=\"hidden\" name=\"direction\" value=\"asc\" /><input type=\"hidden\" name=\"per_page\" value=\"2\" /><input type=\"hidden\" name=\"page\" value=\"1\" /><input type=\"hidden\" name=\"only_path\" value=\"true\" /><input type=\"hidden\" name=\"store_id\" value=\"users\" /><input type=\"hidden\" name=\"link_type\" value=\"search\" /><input type=\"search\" value=\"Name fr\" name=\"search\" class=\"form-control\" placeholder=\"Search by Name fr and Name en...\" /><button type=\"button\" class=\"clear-search-btn input-group-btn btn-secondary btn\" data-bs-toggle=\"tooltip\" data-bs-title=\"Clear Search\"><i class=\"glyph fa-solid fa-times-circle\"></i> <span class=\"visually-hidden\">Clear Search</span></button></div></form><br class=\"ui-bibz-clear\" /></div>"
101
101
 
102
102
  assert_equal expected, actual
103
103
  end
data/ui_bibz.gemspec CHANGED
@@ -26,10 +26,9 @@ Gem::Specification.new do |s|
26
26
  s.require_paths = %w[lib vendor]
27
27
 
28
28
  # Rails gems
29
- s.add_dependency 'rails', '>= 7.1.0'
30
- # Switch to bootstrap 5.3.3 as soon as possible
31
- s.add_dependency 'bootstrap-propshaft', '~> 5.3.2.2'
29
+ s.add_dependency 'bootstrap', '~> 5.3.3'
32
30
  s.add_dependency 'dartsass-rails'
31
+ s.add_dependency 'rails', '>= 7.1.0'
33
32
  s.add_dependency 'will_paginate'
34
33
  # Don't move factory_bot_rails to Gemfile else it will be loaded in test/dummy
35
34
  s.add_development_dependency 'factory_bot_rails', '~> 4.0' # rubocop:disable Gemspec/DevelopmentDependencies
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ui_bibz
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.beta15
4
+ version: 4.0.0.beta17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thooams [Thomas HUMMEL]
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-02 00:00:00.000000000 Z
11
+ date: 2025-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: bootstrap
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 7.1.0
19
+ version: 5.3.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 7.1.0
26
+ version: 5.3.3
27
27
  - !ruby/object:Gem::Dependency
28
- name: bootstrap-propshaft
28
+ name: dartsass-rails
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 5.3.2.2
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 5.3.2.2
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: dartsass-rails
42
+ name: rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 7.1.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 7.1.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: will_paginate
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,7 @@ files:
108
108
  - app/assets/javascripts/forms/formula.js
109
109
  - app/assets/javascripts/forms/input-connected.js
110
110
  - app/assets/javascripts/forms/jquery.multi-select-extend.js
111
+ - app/assets/javascripts/forms/nested-dropdown.js
111
112
  - app/assets/javascripts/interfaces.js
112
113
  - app/assets/javascripts/tables.js
113
114
  - app/assets/javascripts/ui_bibz_js.js
@@ -239,6 +240,7 @@ files:
239
240
  - lib/ui_bibz/ui/core/forms/choices/switch_field.rb
240
241
  - lib/ui_bibz/ui/core/forms/dates/date_picker_field.rb
241
242
  - lib/ui_bibz/ui/core/forms/dropdowns/components/dropdown_divider.rb
243
+ - lib/ui_bibz/ui/core/forms/dropdowns/components/dropdown_dropdown.rb
242
244
  - lib/ui_bibz/ui/core/forms/dropdowns/components/dropdown_header.rb
243
245
  - lib/ui_bibz/ui/core/forms/dropdowns/components/dropdown_link.rb
244
246
  - lib/ui_bibz/ui/core/forms/dropdowns/dropdown.rb