rails_accordion 0.1.9.pre.beta → 0.1.11.pre.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +13 -0
- data/Gemfile.lock +126 -0
- data/README.md +57 -0
- data/Rakefile +12 -0
- data/app/assets/builds/rails_accordion.css +527 -0
- data/app/assets/builds/rails_accordion.js +19707 -0
- data/app/assets/builds/rails_accordion.js.map +7 -0
- data/app/assets/stylesheets/rails_accordion.css +11 -0
- data/app/components/accordion_component.rb +20 -0
- data/app/components/item_component.rb +38 -0
- data/app/javascript/controllers/accordion_controller.js +43 -0
- data/app/javascript/rails_accordion.js +11 -0
- data/bin/console +15 -0
- data/bin/rails +13 -0
- data/bin/setup +8 -0
- data/lib/generators/rails_accordion/install_generator.rb +17 -0
- data/lib/generators/rails_accordion/templates/accordion_controller.js.tt +38 -0
- data/lib/rails_accordion/version.rb +5 -0
- data/lib/rails_accordion.rb +37 -0
- data/lib/tasks/rails_accordion_tasks.rake +4 -0
- data/rails_accordion.gemspec +26 -0
- data/vendor/assets/javascripts/rails_accordion.js +19707 -0
- data/vendor/assets/javascripts/rails_accordion.js.map +7 -0
- data/vendor/assets/stylesheets/rails_accordion.css +527 -0
- metadata +27 -3
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class AccordionComponent < ViewComponent::Base
|
4
|
+
def initialize(**args)
|
5
|
+
super
|
6
|
+
@args = args.presence || {}
|
7
|
+
set_controller
|
8
|
+
end
|
9
|
+
|
10
|
+
def call
|
11
|
+
content_tag(:div, content, **@args)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def set_controller
|
17
|
+
@args[:data] ||= {}
|
18
|
+
@args[:data][:controller] = [@args[:data][:controller], "accordion"].compact.join(" ")
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ItemComponent < ViewComponent::Base
|
4
|
+
renders_one :body
|
5
|
+
renders_one :header
|
6
|
+
|
7
|
+
def initialize(**args)
|
8
|
+
super
|
9
|
+
@args = args.presence || {}
|
10
|
+
set_classes
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
content_tag :div, **@args do
|
15
|
+
header_component + body_component
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def header_component
|
22
|
+
content_tag :div, header, class: "accordion_toggle"
|
23
|
+
end
|
24
|
+
|
25
|
+
def body_component
|
26
|
+
if body?
|
27
|
+
content_tag :div, class: "accordion_content" do
|
28
|
+
content_tag :div, body, class: "accordion_content-container p-2"
|
29
|
+
end
|
30
|
+
else
|
31
|
+
content_tag(:div, nil, class: "hidden")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def set_classes
|
36
|
+
@args[:class] = [@args[:class], "accordion_item"].compact.join(" ")
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { Controller } from "@hotwired/stimulus";
|
2
|
+
|
3
|
+
export default class extends Controller {
|
4
|
+
connect() {
|
5
|
+
this.initAccordion();
|
6
|
+
}
|
7
|
+
|
8
|
+
initAccordion() {
|
9
|
+
const items = this.element.querySelectorAll('.accordion_item');
|
10
|
+
|
11
|
+
items.forEach((item) => {
|
12
|
+
const toggle = item.querySelector('.accordion_toggle');
|
13
|
+
|
14
|
+
toggle.addEventListener('click', (e) => {
|
15
|
+
if (item.classList.contains('active')) {
|
16
|
+
this.hide(item);
|
17
|
+
} else {
|
18
|
+
this.hideAll(items);
|
19
|
+
this.open(item);
|
20
|
+
}
|
21
|
+
});
|
22
|
+
});
|
23
|
+
}
|
24
|
+
|
25
|
+
hideAll(items) {
|
26
|
+
items.forEach((item) => this.hide(item));
|
27
|
+
}
|
28
|
+
|
29
|
+
hide(item) {
|
30
|
+
item.classList.remove("active")
|
31
|
+
const content = item.querySelector('.accordion_content');
|
32
|
+
content.style.height = '0px';
|
33
|
+
}
|
34
|
+
|
35
|
+
open(item) {
|
36
|
+
item.classList.add("active")
|
37
|
+
const content = item.querySelector('.accordion_content');
|
38
|
+
content.style.height = 'auto';
|
39
|
+
const contentHeight = content.style.height
|
40
|
+
// content.style.height = '0px';
|
41
|
+
content.animate({ height: contentHeight + 'px' }, 50);
|
42
|
+
}
|
43
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import 'mapkick/bundle'
|
2
|
+
import AccordionController from './controllers/accordion_controller'
|
3
|
+
import { Application } from '@hotwired/stimulus'
|
4
|
+
|
5
|
+
const application = Application.start()
|
6
|
+
|
7
|
+
window.Stimulus = application
|
8
|
+
|
9
|
+
application.register('accordion', AccordionController)
|
10
|
+
|
11
|
+
export { application }
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "rails_accordion"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/rails
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
3
|
+
# installed from the root of your application.
|
4
|
+
|
5
|
+
ENGINE_ROOT = File.expand_path('..', __dir__)
|
6
|
+
# ENGINE_PATH = File.expand_path('../lib/rails_table/engine', __dir__)
|
7
|
+
|
8
|
+
# Set up gems listed in the Gemfile.
|
9
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
10
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
11
|
+
|
12
|
+
require 'rails/all'
|
13
|
+
require 'rails/engine/commands'
|
data/bin/setup
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "rails/generators"
|
3
|
+
|
4
|
+
module RailsAccordion
|
5
|
+
module Generators
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
source_root File.expand_path("templates", __dir__)
|
8
|
+
|
9
|
+
namespace "rails_accordion:install"
|
10
|
+
desc "Copies all necessary files"
|
11
|
+
|
12
|
+
def copy_build_files
|
13
|
+
# directory File.join(__dir__, "../", "../", "../", "app", "assets", "builds"), "app/assets/builds"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
2
|
+
|
3
|
+
export default class extends Controller {
|
4
|
+
connect() {
|
5
|
+
this.initAccordion();
|
6
|
+
}
|
7
|
+
|
8
|
+
initAccordion() {
|
9
|
+
const $toggles = $(this.element).find('.accordion_toggle');
|
10
|
+
|
11
|
+
const removeAllActiveClass = () => {
|
12
|
+
$toggles.each((el) => {
|
13
|
+
const $parent = $(el).parent();
|
14
|
+
$parent.removeClass('active');
|
15
|
+
$parent.find('.accordion_content').height(0);
|
16
|
+
});
|
17
|
+
};
|
18
|
+
|
19
|
+
$toggles.on('touch click', (e) => {
|
20
|
+
const $toggle = $(e.currentTarget);
|
21
|
+
const $parent = $toggle.parent();
|
22
|
+
const $content = $parent.find('.accordion_content');
|
23
|
+
|
24
|
+
if (!$parent.hasClass('active')) {
|
25
|
+
removeAllActiveClass();
|
26
|
+
$parent.addClass('active');
|
27
|
+
$content.height('100%');
|
28
|
+
} else {
|
29
|
+
$parent.removeClass('active');
|
30
|
+
$content.css({ height: '0px' });
|
31
|
+
}
|
32
|
+
});
|
33
|
+
}
|
34
|
+
|
35
|
+
afterReflex() {
|
36
|
+
this.initAccordion();
|
37
|
+
}
|
38
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "zeitwerk"
|
4
|
+
|
5
|
+
loader = Zeitwerk::Loader.for_gem
|
6
|
+
loader.ignore("#{__dir__}/generators")
|
7
|
+
loader.setup
|
8
|
+
|
9
|
+
module RailsAccordion
|
10
|
+
|
11
|
+
class Error < StandardError; end
|
12
|
+
|
13
|
+
class Engine < ::Rails::Engine
|
14
|
+
initializer "rails_accordion.importmap" do |app|
|
15
|
+
if defined?(Importmap)
|
16
|
+
app.config.assets.precompile << "rails_accordion.js"
|
17
|
+
app.config.assets.precompile << "rails_accordion.css"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Railtie < Rails::Railtie
|
23
|
+
ActiveSupport.on_load :action_view do
|
24
|
+
include RailsAccordion
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def accordion(**args, &block)
|
29
|
+
render AccordionComponent.new(**args), &block
|
30
|
+
end
|
31
|
+
|
32
|
+
def accordion_item(**args, &block)
|
33
|
+
render ItemComponent.new(**args), &block
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
loader.eager_load
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/rails_accordion/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "rails_accordion"
|
7
|
+
spec.version = RailsAccordion::VERSION
|
8
|
+
spec.authors = ["Ahmadshoh Nasrullozoda"]
|
9
|
+
spec.email = ["tajbrains@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "rails_accordion is in development."
|
12
|
+
spec.description = "rails_accordion is in development."
|
13
|
+
spec.homepage = "https://tajbrains.com"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/Tajbrains/rails_accordion"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/Tajbrains/rails_accordion/blob/master/CHANGELOG.md"
|
20
|
+
|
21
|
+
spec.files = Dir["{bin,app,lib,vendor}/**/*", "MIT-LICENSE", "Rakefile", "README.md", "rails_accordion.gemspec", "Gemfile", "Gemfile.lock"]
|
22
|
+
|
23
|
+
spec.add_dependency "stimulus-rails", "~> 1.2"
|
24
|
+
spec.add_dependency "view_component", "~> 2.52"
|
25
|
+
spec.add_dependency "zeitwerk", "~> 2.6"
|
26
|
+
end
|