rails_accordion 0.1.12.pre.beta → 0.2.1.pre.beta

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.
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class AccordionComponent < ViewComponent::Base
4
+
4
5
  def initialize(**args)
5
6
  super
6
7
  @args = args.presence || {}
7
- set_controller
8
+ set_data_params
8
9
  end
9
10
 
10
11
  def call
@@ -13,8 +14,10 @@ class AccordionComponent < ViewComponent::Base
13
14
 
14
15
  private
15
16
 
16
- def set_controller
17
+ def set_data_params
17
18
  @args[:data] ||= {}
18
19
  @args[:data][:controller] = [@args[:data][:controller], "accordion"].compact.join(" ")
20
+ @args[:data][:multiple_open] = @args.delete(:multiple_open) || RailsAccordion.configuration.multiple_open
21
+ @args[:data][:default_state] = @args.delete(:default_state) || RailsAccordion.configuration.default_state
19
22
  end
20
23
  end
@@ -3,6 +3,24 @@ import { Controller } from "@hotwired/stimulus";
3
3
  export default class extends Controller {
4
4
  connect() {
5
5
  this.initAccordion();
6
+
7
+ this.initDefaultState()
8
+ }
9
+
10
+ initDefaultState() {
11
+ const items = this.element.querySelectorAll('.accordion_item');
12
+
13
+ switch($(this.element).data('default-state')) {
14
+ case 'all_closed':
15
+ this.hideAll(items);
16
+ break;
17
+ case 'all_opened':
18
+ this.showAll(items);
19
+ break;
20
+ case 'first_opened':
21
+ this.hideAll(items)
22
+ this.open(items[0].querySelector('.accordion_content'))
23
+ }
6
24
  }
7
25
 
8
26
  initAccordion() {
@@ -16,7 +34,9 @@ export default class extends Controller {
16
34
  if (content.classList.contains('accordion_active')) {
17
35
  this.hide(content);
18
36
  } else {
19
- this.hideAll(items);
37
+ if ($(this.element).data('multiple-open') != true) {
38
+ this.hideAll(items);
39
+ }
20
40
  this.open(content);
21
41
  }
22
42
  });
@@ -27,6 +47,10 @@ export default class extends Controller {
27
47
  items.forEach((item) => this.hide(item.querySelector('.accordion_content')));
28
48
  }
29
49
 
50
+ showAll(items) {
51
+ items.forEach((item) => this.open(item.querySelector('.accordion_content')));
52
+ }
53
+
30
54
  hide(item) {
31
55
  item.classList.remove("accordion_active")
32
56
  item.style.height = 0;
@@ -1,4 +1,5 @@
1
1
  RailsAccordion.configure do |config|
2
2
  config.default_state = :all_closed # :all_closed, :all_opened, :first_opened
3
3
  config.animation_duration = 300 # in ms
4
+ config.multiple_open = false
4
5
  end
@@ -1,10 +1,11 @@
1
1
  module RailsAccordion
2
2
  class Configuration
3
- attr_accessor :default_state, :animation_duration
3
+ attr_accessor :default_state, :animation_duration, :multiple_open
4
4
 
5
5
  def initialize
6
- @default_state = :closed
6
+ @default_state = :all_closed
7
7
  @animation_duration = 300
8
+ @multiple_open = false
8
9
  end
9
10
  end
10
11
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsAccordion
4
- VERSION = "0.1.12-beta"
4
+ VERSION = "0.2.0-beta"
5
5
  end
@@ -4,7 +4,7 @@ require_relative "lib/rails_accordion/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "rails_accordion"
7
- spec.version = RailsAccordion::VERSION
7
+ spec.version = ENV['GEM_VERSION'] || RailsAccordion::VERSION
8
8
  spec.authors = ["Ahmadshoh Nasrullozoda"]
9
9
  spec.email = ["tajbrains@gmail.com"]
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_accordion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12.pre.beta
4
+ version: 0.2.1.pre.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ahmadshoh Nasrullozoda
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-21 00:00:00.000000000 Z
11
+ date: 2023-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stimulus-rails
@@ -91,7 +91,7 @@ metadata:
91
91
  homepage_uri: https://tajbrains.com
92
92
  source_code_uri: https://github.com/Tajbrains/rails_accordion
93
93
  changelog_uri: https://github.com/Tajbrains/rails_accordion/blob/master/CHANGELOG.md
94
- post_install_message:
94
+ post_install_message:
95
95
  rdoc_options: []
96
96
  require_paths:
97
97
  - lib
@@ -106,8 +106,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  - !ruby/object:Gem::Version
107
107
  version: 1.3.1
108
108
  requirements: []
109
- rubygems_version: 3.0.1
110
- signing_key:
109
+ rubygems_version: 3.3.20
110
+ signing_key:
111
111
  specification_version: 4
112
112
  summary: rails_accordion is in development.
113
113
  test_files: []