[![license](https://img.shields.io/badge/License-MIT-purple.svg)](LICENSE) [![Gem Version](https://img.shields.io/gem/v/amber_component.svg?style=flat)](https://rubygems.org/gems/amber_component) [![Maintainability](https://api.codeclimate.com/v1/badges/ad84af499e9791933a87/maintainability)](https://codeclimate.com/github/amber-ruby/amber_component/maintainability) [![CI badge](https://github.com/amber-ruby/amber_component/actions/workflows/ci_ruby.yml/badge.svg)](https://github.com/amber-ruby/amber_component/actions/workflows/ci_ruby.yml) [![Coverage Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/Verseth/6a095c79278b074d79feaa4f8ceeb2a8/raw/amber_component__heads_main.json)](https://github.com/amber-ruby/amber_component/actions/workflows/ci_ruby.yml) [![Downloads](https://ruby-gem-downloads-badge.herokuapp.com/amber_component)]((https://rubygems.org/gems/amber_component)) # AmberComponent AmberComponent is a simple component library which seamlessly hooks into your Rails project and allows you to create simple backend components. They work like mini controllers which are bound with their view and stylesheet. Created by [Garbus Beach](https://github.com/garbusbeach) and [Mateusz Drewniak](https://github.com/Verseth). ## Getting started You can read a lot more about AmberComponent in its [official docs](https://ambercomponent.com). ## Installation Install the gem and add to the application's Gemfile by executing: $ bundle add amber_component If bundler is not being used to manage dependencies, install the gem by executing: $ gem install amber_component If you're using a Rails application there's an installation generator that you should run: ```sh $ bin/rails generate amber_component:install ``` ## Usage ## Components Components are located under `app/components`. Every component consists of: - a Ruby file which defines its properties, encapsulates logic and may implement helper methods (like a controller) - a view/template file (html.erb, haml, slim etc.) - a style file (css, scss, sass etc.) An individual component which implements a button may look like this. ```ruby # app/components/button_component.rb class ButtonComponent < AmberComponent::Base prop :label, required: true end ``` ```html
``` ```scss // app/components/button_component/style.scss .button_component { background-color: indigo; border-radius: 1rem; transition-duration: 500ms; &:hover { background-color: blue; } } ``` You can render this component in other components or in a Rails view. ```html