Skip to content

WIP composable primer styles#39

Closed
BlakeWilliams wants to merge 1 commit intomainfrom
bmw/composable-primer
Closed

WIP composable primer styles#39
BlakeWilliams wants to merge 1 commit intomainfrom
bmw/composable-primer

Conversation

@BlakeWilliams
Copy link
Copy Markdown
Contributor

This introduces a new module, Primer::Styleable which adds methods to a
component that generate primer based class names.

Comment on lines +87 to +92
assert_equal "d-block", EmptyComponent.new.block.primer_classes
assert_equal "d-none", EmptyComponent.new.none.primer_classes
assert_equal "d-inline", EmptyComponent.new.inline.primer_classes
assert_equal "d-inline-block", EmptyComponent.new.inline_block.primer_classes
assert_equal "d-table", EmptyComponent.new.table.primer_classes
assert_equal "d-table-cell", EmptyComponent.new.table_cell.primer_classes
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should probably prefix these methods with d_?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Or, could we do d(:table_cell)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Or, could we do d(:table_cell)?

We totally could. I went with methods for this first attempt at an implementation instead of arguments since it will immediately raise an error instead of requiring us to validate the arguments. Thoughts?

end

def float(direction)
primer_class_list << "float-#{direction}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we have VALID_DIRECTIONS?

@nuthinking
Copy link
Copy Markdown
Contributor

nuthinking commented Aug 12, 2020

Personally I think that View Components should treat Primer classes as second class citizens (in the future these perhaps shouldn't be allowed?). Hence I'm actually more in favour of using them (for now) explicitly (i.e.: classes: "d-inline-block etc...") or maybe even primer_classes: "...". Finding new ways to express them could make it hard to get rid off them.

@BlakeWilliams
Copy link
Copy Markdown
Contributor Author

Personally I think that View Components should treat Primer classes as second class citizens (in the future these perhaps shouldn't be allowed?). Hence I'm actually more in favour of using them (for now) explicitly (i.e.: classes: "d-inline-block etc...") or maybe even primer_classes: "...". Finding new ways to express them could make it hard to get rid off them.

I think that's an interesting thought, and brings up a really good point, how much do we want to couple these components to Primer through methods? Additionally, how coupled do we want to allow people to opt-in to components being coupled to primer?

The original goal of this approach is to help remove the need to use **kwargs in so many components. The thought behind this approach was to build a module that you can include that gives you explicit methods that generate primer classes. I think one advantage here is that the DSL could be replaced/updated to support any CSS framework's classes. So if we update primer classes upstream we could easily update these methods to support the new version's CSS classes.

I'd also be 👍 on removing **kwargs in favor of something like:

def initialize(tag_name:, primer_classes:)

Assuming that would be a 1-to-1 replacement.

@nuthinking
Copy link
Copy Markdown
Contributor

So if we update primer classes upstream we could easily update these methods to support the new version's CSS classes.

Is this really a realistic scenario?

@BlakeWilliams
Copy link
Copy Markdown
Contributor Author

Is this really a realistic scenario?

I believe so, it looks like one of the last times we had a breaking CSS name change was in December 2019 here, primer/css#966 so there is some precedent.

@BlakeWilliams
Copy link
Copy Markdown
Contributor Author

Closing for now, since we want to stick with a more React-like API

@joelhawksley joelhawksley deleted the bmw/composable-primer branch October 12, 2020 21:55
camertron pushed a commit to camertron/view_components that referenced this pull request Apr 23, 2025
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 this pull request may close these issues.

4 participants