Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

ControlConfig#component_params does not take into consideration keyword arguments #19

Closed
manuelpuyol opened this issue Jan 29, 2021 · 0 comments · Fixed by #20
Closed

Comments

@manuelpuyol
Copy link
Contributor

👋 Hello there!

In primer_view_components we use kwargs for most of our components, so we can easily modify some simpler css (like margins, background colors...). An example:

module Primer
  class BoxComponent < Primer::Component
    def initialize(**system_arguments)

When I'm writing a story, I wanted to show examples with different margins. This would be something like

class Primer::BoxComponentStories < ViewComponent::Storybook::Stories
  layout "storybook_preview"

  story(:box) do
    controls do
      select(:m, [1,2,3], 1)
    end

    content do
      "This is a div"
    end
  end
end

which would be the same as calling Primer::BoxComponent.new(m: 1)

But, this is raising an error due the component_params validation, since m is not directly defined as a parameter name from initialize

https://github.com/jonspalmer/view_component_storybook/blob/1631e9cfcbaa9936f86f8b9d5f2bda44ede48f1a/lib/view_component/storybook/controls/control_config.rb#L33-L35

a fix would be to check if there is a :keyrest type parameter, which indicates that the method receives a **kwarg parameter and in that case any control name should be accepted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant