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

Add BorderGrid component #32

Merged
merged 2 commits into from
Sep 20, 2023
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
7 changes: 7 additions & 0 deletions .changeset/lucky-rules-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@openproject/primer-view-components': minor
---

Add BorderGrid Component

<!-- Changed components: Primer::OpenProject::BorderGrid -->
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions app/components/primer/open_project/border_grid.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<%= render Primer::BaseComponent.new(**@system_arguments) do %>
<% rows.each do |row| %>
<%= render Primer::BaseComponent.new(tag: :div, classes: "BorderGrid-row") do %>
<%= row %>
<% end %>
<% end %>
<% end %>
35 changes: 35 additions & 0 deletions app/components/primer/open_project/border_grid.pcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* CSS for BorderGrid */

.BorderGrid {
display: table;
width: 100%;
margin-top: -16px;
margin-bottom: -16px;
table-layout: fixed;
border-collapse: collapse;
border-style: hidden
}

.BorderGrid .BorderGrid-cell {
padding-top: 16px;
padding-bottom: 16px
}

.BorderGrid--spacious {
margin-top: -24px;
margin-bottom: -24px
}

.BorderGrid--spacious .BorderGrid-cell {
padding-top: 24px;
padding-bottom: 24px
}

.BorderGrid-row {
display: table-row
}

.BorderGrid-cell {
display: table-cell;
border: 1px solid var(--borderColor-muted)
}
36 changes: 36 additions & 0 deletions app/components/primer/open_project/border_grid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

module Primer
module OpenProject
# A set of blocks that are shown below each other with separator lines in between
class BorderGrid < Primer::Component
status :open_project

# Use to render a block inside the grid
#
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
renders_many :rows, lambda { |**system_arguments|
Primer::OpenProject::BorderGrid::Cell.new(**system_arguments)
}

# @param spacious [Boolean] Whether to add margin to the bottom of the component.
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(spacious: false, **system_arguments)
@system_arguments = system_arguments
@system_arguments[:tag] = "div"
@spacious = spacious

@system_arguments[:classes] =
class_names(
@system_arguments[:classes],
"BorderGrid",
"BorderGrid--spacious" => @spacious
)
end

def render?
rows.any?
end
end
end
end
3 changes: 3 additions & 0 deletions app/components/primer/open_project/border_grid/cell.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= render Primer::BaseComponent.new(**@system_arguments) do %>
<%= content %>
<% end %>
25 changes: 25 additions & 0 deletions app/components/primer/open_project/border_grid/cell.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module Primer
module OpenProject
class BorderGrid
# A single cell inside the BorderGrid
# A cell can contain for example an action list or a status badge
class Cell < Primer::Component
status :open_project

# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(**system_arguments)
@system_arguments = system_arguments
@system_arguments[:tag] = "div"

@system_arguments[:classes] =
class_names(
@system_arguments[:classes],
"BorderGrid-cell"
)
end
end
end
end
end
1 change: 1 addition & 0 deletions app/components/primer/primer.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@
/* OP specifics */
@import "./open_project/page_header.pcss";
@import "./open_project/drag_handle.pcss";
@import "./open_project/border_grid.pcss";
42 changes: 42 additions & 0 deletions previews/primer/open_project/border_grid_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# frozen_string_literal: true

# Setup Playground to use all available component props
# Setup Features to use individual component props and combinations

module Primer
module OpenProject
# @label BorderGrid
class BorderGridPreview < ViewComponent::Preview

# @label Playground
# @param spacious [Boolean] toggle
def playground(spacious: false)
render(Primer::OpenProject::BorderGrid.new(spacious: spacious)) do |grid|
grid.with_row { "Block 1" }
grid.with_row { "Block 2" }
grid.with_row { "Block 3" }
end
end

# @label Default Options
#
# @snapshot
def default()
render(Primer::OpenProject::BorderGrid.new) do |grid|
grid.with_row { "Block 1" }
grid.with_row { "Block 2" }
grid.with_row { "Block 3" }
end
end

# @label Spacious
def spacious()
render(Primer::OpenProject::BorderGrid.new(spacious: true)) do |grid|
grid.with_row { "Block 1" }
grid.with_row { "Block 2" }
grid.with_row { "Block 3" }
end
end
end
end
end
12 changes: 12 additions & 0 deletions static/classes.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@
"Banner": [
"Primer::Alpha::Banner"
],
"BorderGrid": [
"Primer::OpenProject::BorderGrid"
],
"BorderGrid--spacious": [
"Primer::OpenProject::BorderGrid"
],
"BorderGrid-cell": [
"Primer::OpenProject::BorderGrid"
],
"BorderGrid-row": [
"Primer::OpenProject::BorderGrid"
],
"Box": [
"Primer::Beta::BorderBox"
],
Expand Down
6 changes: 5 additions & 1 deletion test/components/component_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class PrimerComponentTest < Minitest::Test
# Components with any arguments necessary to make them render
COMPONENTS_WITH_ARGS = [
[Primer::OpenProject::DragHandle, {}],
[Primer::OpenProject::BorderGrid, {}, proc { |component|
component.with_row { "Foo" }
}],
[Primer::OpenProject::PageHeader, {}, proc { |component|
component.with_title { "Foo" }
}],
Expand Down Expand Up @@ -149,7 +152,8 @@ def test_registered_components
"Primer::Alpha::OcticonSymbols",
"Primer::Component",
"Primer::Content",
"Primer::Navigation::TabComponent"
"Primer::Navigation::TabComponent",
"Primer::OpenProject::BorderGrid::Cell"
]

primer_component_files_count = Dir["app/components/**/*.rb"].count { |p| p.exclude?("/experimental/") }
Expand Down
13 changes: 13 additions & 0 deletions test/components/primer/open_project/border_grid/cell_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

require "components/test_helper"

class PrimerOpenProjectBorderGridCellTest < Minitest::Test
include Primer::ComponentTestHelpers

def test_renders
render_inline(Primer::OpenProject::BorderGrid::Cell.new)

assert_selector(".BorderGrid-cell")
end
end
29 changes: 29 additions & 0 deletions test/components/primer/open_project/border_grid_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require "components/test_helper"

class PrimerOpenProjectBorderGridTest < Minitest::Test
include Primer::ComponentTestHelpers

def test_renders
render_inline(Primer::OpenProject::BorderGrid.new) do |grid|
grid.with_row { "Block 1" }
grid.with_row { "Block 2" }
grid.with_row { "Block 3" }
end

assert_selector(".BorderGrid")
assert_selector(".BorderGrid-row", count: 3)
assert_selector(".BorderGrid-row .BorderGrid-cell", text: "Block 1")
end

def test_renders_spacious
render_inline(Primer::OpenProject::BorderGrid.new(spacious: true)) do |grid|
grid.with_row { "Block 1" }
grid.with_row { "Block 2" }
grid.with_row { "Block 3" }
end

assert_selector(".BorderGrid.BorderGrid--spacious")
end
end
11 changes: 11 additions & 0 deletions test/system/open_project/border_grid_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require "system/test_case"

class IntegrationOpenProjectBorderGridTest < System::TestCase
def test_renders_component
visit_preview(:default)

assert_selector(".BorderGrid")
end
end