Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add gem configuration, with base component customization #160

Conversation

joelzwarrington
Copy link
Contributor

@joelzwarrington joelzwarrington commented Apr 5, 2024

What

  • Adds a configuration object singleton to ViewComponent::Form
  • Adds configuration option parent_component which all ViewComponent::Form components inherit from, and defaults to ViewComponent::Base

Why

So that one can define shared logic without having to use concerns or building their own components that don't inherit from their ViewComponent::Form component counterpart.

As an example, let's say I'd like to use the heroicon gem to add icons to my fields, I can do that easily by defining my own ApplicationFormComponent

class ApplicationFormComponent < ViewComponent::Base
  include Heroicon::Engine.helpers
end

or, if I'm using Tailwind, I could use tailwind_merge to merge HTML classes to avoid conflicts, etc.

Copy link
Collaborator

@Spone Spone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a stab at this!

@@ -1,10 +1,20 @@
# frozen_string_literal: true

require "view_component"
require_relative "form/configuration"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this line? Can Zeitwerk autoload the constant without it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the test suite without it in d1e420c and it seems to be loaded just fine!

I'll do another test in my production Rails application.

README.md Outdated Show resolved Hide resolved
Co-authored-by: Hans Lemuet <Spone@users.noreply.github.com>
@joelzwarrington joelzwarrington requested a review from Spone April 5, 2024 16:22
@joelzwarrington joelzwarrington marked this pull request as ready for review April 5, 2024 16:22
@Spone Spone requested a review from nicolas-brousse April 5, 2024 16:23
@Spone
Copy link
Collaborator

Spone commented Apr 5, 2024

@joelzwarrington mind adding a note to the CHANGELOG?

@joelzwarrington
Copy link
Contributor Author

Yep, I'll add a note to the change log 😄

@Spone Spone merged commit c617ee4 into pantographe:main Apr 8, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

It'd be nice to have the ability to customize the base class so that it can inherit our own class
3 participants