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

[SAGE-780] SageGrid column class fix #1566

Merged
merged 2 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/lib/sage_rails/app/helpers/sage_grid_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module SageGridHelper
def grid_column_classes(col)
column_classes = ""

if col.breakpoint.present? && col.size.present?
# if both breakpoint and sizing are provided
column_classes << "sage-col--#{col.breakpoint}-#{col.size} "
elsif !col.breakpoint.present? && col.size.present?
# or if only a size is provided, without a breakpoint
column_classes << "sage-col-#{col.size} "
elsif !col.breakpoint.present? && !col.size.present? && grid_col_legacy(col)
# or if a legacy individual breakpoint is provided
grid_col_breakpoint_individual(col, column_classes)
else
Copy link
Member Author

Choose a reason for hiding this comment

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

Providing a breakpoint value without a size constraint will output the plain sage-col since a size is required for these columns to be useful.

# otherwise we display a default unsized column
column_classes << "sage-col "
end

column_classes << col.generated_css_classes
end

private

def grid_col_legacy(col)
col.xlarge.present? || col.large.present? || col.medium.present? || col.small.present?
end

def grid_col_breakpoint_individual(col, column_classes)
column_classes << "sage-col--xl-#{col.xlarge} " if col.xlarge.present?
column_classes << "sage-col--lg-#{col.large} " if col.large.present?
column_classes << "sage-col--md-#{col.medium} " if col.medium.present?
column_classes << "sage-col--sm-#{col.small} " if col.small.present?
end
end
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
<% has_infix = component.breakpoint || component.size || component.small || component.medium || component.large %>

<div class="
<%= "sage-col" if !has_infix -%>
<%= "sage-col-#{component.size}" if component.size -%>
<%= "sage-col--#{component.breakpoint}-#{component.size}" if component.breakpoint && component.size -%>
<%= "sage-col--sm-#{component.small}" if component.small%>
<%= "sage-col--md-#{component.medium}" if component.medium%>
<%= "sage-col--lg-#{component.large}" if component.large%>
<%= "sage-col--xl-#{component.xlarge}" if component.xlarge%>
<%= component.generated_css_classes %>
" <%= component.generated_html_attributes.html_safe %>>
<div class="<%= grid_column_classes(component) %>" <%= component.generated_html_attributes.html_safe %>>
<%= component.content %>
</div>