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 beta layouts #937

Closed
wants to merge 118 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
78e67e7
Add SplitLayout skeleton
jklina Dec 7, 2021
67d0f62
Add SplitLayout
jklina Dec 7, 2021
a3719ce
Add PageLayout skeleton
jklina Dec 7, 2021
e1b3b25
Add wrapper sizes, header, and footer to layout
jklina Dec 7, 2021
deadbb9
Add outer spacing and gaps
jklina Dec 7, 2021
a3b4b5d
add responsive_variant option to layout
jklina Dec 7, 2021
97ea4c2
update documentation
jklina Dec 7, 2021
4c3505f
Add pane options
jklina Dec 7, 2021
684b6f6
update docs, stories for layouts
jklina Dec 7, 2021
5887991
docs: build docs
actions-user Dec 7, 2021
0fdb1c6
sync possible values, test default config
jklina Dec 8, 2021
9aa4a58
Merge branch 'add-beta-layouts' of https://github.com/primer/view_com…
jklina Dec 8, 2021
190c6f5
sync documentation with name changes
jklina Dec 8, 2021
32b5637
further sync documentation to args
jklina Dec 8, 2021
b844378
generate new docs to keep in sync w api
jklina Dec 8, 2021
8151329
docs: build docs
actions-user Dec 8, 2021
3d2ff3f
remove replaced base_layout template
jklina Dec 8, 2021
b972d28
Merge branch 'add-beta-layouts' of https://github.com/primer/view_com…
jklina Dec 8, 2021
26f3f86
remove duplicate test
jklina Dec 8, 2021
1094b7f
test header and footer
jklina Dec 8, 2021
64345e6
remove unused mappings
jklina Dec 8, 2021
3b3331e
test different pane tags
jklina Dec 8, 2021
d195b96
docs: build docs
actions-user Dec 8, 2021
d4d5aa7
remove duplicate tag options
jklina Dec 8, 2021
e44cb9d
Merge branch 'add-beta-layouts' of https://github.com/primer/view_com…
jklina Dec 8, 2021
5fdc2ed
docs: build docs
actions-user Dec 8, 2021
3dfbca5
add space between sections
jklina Dec 8, 2021
60b99a8
test pane tag options on SplitLayout
jklina Dec 8, 2021
42de455
add arg documentation to SplitLayout
jklina Dec 8, 2021
ae24424
Merge branch 'add-beta-layouts' of https://github.com/primer/view_com…
jklina Dec 8, 2021
14675ab
docs: build docs
actions-user Dec 8, 2021
ccb84a0
set status for sub components
jklina Dec 8, 2021
5b9372a
set proper requirements for component testing
jklina Dec 8, 2021
a6d331b
docs: build docs
actions-user Dec 8, 2021
df442e0
add test for main tags
jklina Dec 8, 2021
90c88ac
Merge branch 'add-beta-layouts' of https://github.com/primer/view_com…
jklina Dec 8, 2021
7a8f1ca
fix linting errors
jklina Dec 8, 2021
dd82910
fix erblinter errors
jklina Dec 8, 2021
1f6384a
move pane consts in Pane
jklina Dec 10, 2021
cb132ca
docs: build docs
actions-user Dec 10, 2021
4d741ef
use updated css class name
jklina Dec 10, 2021
609e732
Merge branch 'add-beta-layouts' of https://github.com/primer/view_com…
jklina Dec 10, 2021
e79a67b
use latest CSS classes
jklina Dec 10, 2021
976bb89
update pane positioning to new spec
jklina Dec 10, 2021
dbef809
update header and footer classes
jklina Dec 10, 2021
8205ff2
continue updating class names to new spec
jklina Dec 10, 2021
b595f79
docs: build docs
actions-user Dec 10, 2021
947129f
remove Bookend sub component
jklina Dec 10, 2021
7c2ee7c
Merge branch 'add-beta-layouts' of https://github.com/primer/view_com…
jklina Dec 10, 2021
d644743
docs: build docs
actions-user Dec 10, 2021
ab54155
update css classes for splitlayout
jklina Dec 13, 2021
fe777ec
Merge branch 'add-beta-layouts' of https://github.com/primer/view_com…
jklina Dec 13, 2021
1f2458b
docs: build docs
actions-user Dec 13, 2021
d8e9907
use correct class name
jklina Dec 13, 2021
13f998f
remove unused class name
jklina Dec 13, 2021
3d323ea
docs: build docs
actions-user Dec 13, 2021
e300bcb
update description with latest version
jklina Dec 13, 2021
f9fcabe
Merge branch 'add-beta-layouts' of https://github.com/primer/view_com…
jklina Dec 13, 2021
efa9f7c
docs: build docs
actions-user Dec 13, 2021
c10777a
Merge branch 'main' into add-beta-layouts
jklina Dec 13, 2021
b9dbe7e
appease linter
jklina Dec 13, 2021
c8dd211
remove reference to removed component
jklina Dec 13, 2021
ac7a440
sidebar renamed pane
jklina Dec 13, 2021
a6dfc8f
rename split_layout to split_page_layout
jklina Dec 13, 2021
98e60cc
remove more Sidebar references
jklina Dec 13, 2021
091b29b
docs: build docs
actions-user Dec 13, 2021
e815af4
add additional info about keyboard selection order
jklina Dec 13, 2021
5f2577c
Merge branch 'add-beta-layouts' of https://github.com/primer/view_com…
jklina Dec 13, 2021
87d685a
docs: build docs
actions-user Dec 13, 2021
aa6c7d3
Namespace PageLayout slots
jklina Dec 14, 2021
56c7484
Merge branch 'add-beta-layouts' of https://github.com/primer/view_com…
jklina Dec 14, 2021
7b20e20
Namespace SplitPageLayout slots
jklina Dec 14, 2021
bea0d06
docs: build docs
actions-user Dec 14, 2021
338ae1a
Update stories to use new API
jklina Dec 14, 2021
a7b0480
Use updated API
jklina Dec 14, 2021
1c86a65
Use new slots API
jklina Dec 14, 2021
e52640e
Merge branch 'add-beta-layouts' of https://github.com/primer/view_com…
jklina Dec 14, 2021
f339dd0
Cleaning up documentation for clarity.
jklina Dec 14, 2021
4cf253a
docs: build docs
actions-user Dec 14, 2021
43d5446
Docs cleanup
jklina Dec 14, 2021
89f2fff
Merge branch 'add-beta-layouts' of https://github.com/primer/view_com…
jklina Dec 14, 2021
c131953
docs: build docs
actions-user Dec 14, 2021
2268fa5
cleanup
jklina Dec 14, 2021
a7ef52d
Merge branch 'add-beta-layouts' of https://github.com/primer/view_com…
jklina Dec 14, 2021
96356e4
add argument docs to Pane initializer
jklina Dec 14, 2021
d7262a5
Documentation cleanup
jklina Dec 14, 2021
c88c7da
docs: build docs
actions-user Dec 14, 2021
ebef84d
Convert variant css ref to responsive
jklina Dec 21, 2021
9fe9cc5
Rename `responsive_primary` -> `primary`
jklina Dec 21, 2021
e346e92
`responsive_position` -> `position_narrow`
jklina Dec 21, 2021
3356fc3
`hasDivider` -> `dividerNarrow`
jklina Dec 21, 2021
331ce16
Remove regions reference
jklina Dec 21, 2021
dd505a7
Pane responsive_divider -> divider_narrow
jklina Dec 22, 2021
662b37b
Header responsive_divider -> divider_narrow
jklina Dec 22, 2021
54b9fe2
Footer responsive_divider -> divider_narrow
jklina Dec 22, 2021
633b0cf
Add inherit argument to divider options
jklina Dec 22, 2021
9e67d9a
Cleanup positioning of constants
jklina Dec 22, 2021
f107154
Ensure pane divider classes depend on position
jklina Dec 22, 2021
b63a015
Update pane, header dividers to new spec
jklina Dec 22, 2021
6bba667
Update footer to new spec
jklina Dec 22, 2021
f8669bb
Merge branch 'add-beta-layouts' of https://github.com/primer/view_com…
jklina Dec 22, 2021
37a9e63
docs: build docs
actions-user Dec 22, 2021
d8a8591
Update stories to use new Layout API
jklina Dec 22, 2021
425f26f
Merge branch 'main' into add-beta-layouts
jklina Dec 22, 2021
accb6f1
Use primer css with PageLayout classes
jklina Dec 22, 2021
c2dda83
Appease rubocop
jklina Dec 23, 2021
bc957b8
Fix accidental double backtick
jklina Dec 23, 2021
ac949f7
docs: build docs
actions-user Dec 23, 2021
0b524d8
Remove double backtick
jklina Dec 23, 2021
6d8c2e3
Merge branch 'add-beta-layouts' of https://github.com/primer/view_com…
jklina Dec 23, 2021
d809392
Sync story with API change
jklina Dec 23, 2021
004e1bf
Update CSS classes
jklina Dec 23, 2021
12b012b
docs: build docs
actions-user Dec 23, 2021
966682d
Merge branch 'main' into add-beta-layouts
jonrohan Jan 19, 2022
3503f3f
Merge branch 'main' into add-beta-layouts
jklina Jan 21, 2022
4a6d8f6
Bump primer/css
jklina Jan 21, 2022
0ab7e9e
Merge branch 'add-beta-layouts' of https://github.com/primer/view_com…
jklina Jan 21, 2022
a96404f
Update yarn.lock
jklina Jan 21, 2022
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
15 changes: 15 additions & 0 deletions app/components/primer/beta/page_layout.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<%= render Primer::BaseComponent.new(**@system_arguments) do %>
<%= render(Primer::BaseComponent.new(tag: :div, classes: "PageLayout-wrapper #{@wrapper_sizing_class}")) do %>
<%= header_region %>
<%= render(Primer::BaseComponent.new(tag: :div, classes: "PageLayout-columns")) do %>
<% if pane_region.render_first? %>
<%= pane_region %>
<%= content_region %>
<% else %>
<%= content_region %>
<%= pane_region %>
<% end %>
<% end %>
<%= footer_region %>
<% end %>
<% end %>
504 changes: 504 additions & 0 deletions app/components/primer/beta/page_layout.rb

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions app/components/primer/beta/split_page_layout.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<%= render Primer::BaseComponent.new(**@system_arguments) do %>
<%= render(Primer::BaseComponent.new(tag: :div, classes: "PageLayout-wrapper")) do %>
<%= render(Primer::BaseComponent.new(tag: :div, classes: "PageLayout-columns")) do %>
<%= pane_region %>
<%= content_region %>
<% end %>
<% end %>
<% end %>
210 changes: 210 additions & 0 deletions app/components/primer/beta/split_page_layout.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
# frozen_string_literal: true

module Primer
module Beta
# In the `SplitPageLayout`, changes in the Pane region are reflected in the `Content` region. This is also known as a "List/Detail" or "Master/Detail" pattern.
#
# On larger screens, the user sees both regions side by side, with the `Pane` region appearing flushed to the left.
#
# On smaller screens, the user only sees one of `Pane` or `Content` regions at a time.
# Pages may decide if it's more important to show the `Pane` region or the `Content` region first by the `:primary_region` property.
#
# @accessibility
# Keyboard navigation follows the markup order. In the case of the `SplitPageLayout`, the `Pane` region is the first region, and the `Content` region is the second.
class SplitPageLayout < Primer::Component
status :beta

PANE_TAG_DEFAULT = :div
PANE_TAG_OPTIONS = [PANE_TAG_DEFAULT, :aside, :nav, :section].freeze

PANE_WIDTH_DEFAULT = :default
PANE_WIDTH_MAPPINGS = {
PANE_WIDTH_DEFAULT => "",
:narrow => "PageLayout--paneWidth-narrow",
:wide => "PageLayout--paneWidth-wide"
}.freeze
PANE_WIDTH_OPTIONS = PANE_WIDTH_MAPPINGS.keys.freeze

INNER_SPACING_DEFAULT = :normal
INNER_SPACING_MAPPINGS = {
normal: "PageLayout--innerSpacing-normal",
condensed: "PageLayout--innerSpacing-condensed"
}.freeze
INNER_SPACING_OPTIONS = INNER_SPACING_MAPPINGS.keys.freeze

PRIMARY_REGION_DEFAULT = :content
PRIMARY_REGION_MAPPINGS = {
PRIMARY_REGION_DEFAULT => "PageLayout--responsive-primary-content",
:pane => "PageLayout--responsive-primary-pane"
}.freeze
PRIMARY_REGION_OPTIONS = PRIMARY_REGION_MAPPINGS.keys.freeze

# The layout's content.
#
# @param width [Symbol] <%= one_of(Primer::Beta::SplitPageLayout::Content::WIDTH_OPTIONS) %>
# @param tag [Symbol] <%= one_of(Primer::Beta::SplitPageLayout::Content::TAG_OPTIONS) %>
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
renders_one :content_region, "Primer::Beta::SplitPageLayout::Content"

# The layout's pane.
#
# @param width [Symbol] <%= one_of(Primer::Beta::SplitPageLayout::PANE_WIDTH_OPTIONS) %>
# @param tag [Symbol] <%= one_of(Primer::Beta::SplitPageLayout::PANE_TAG_OPTIONS) %>
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
renders_one :pane_region, lambda { |width: PANE_WIDTH_DEFAULT, tag: PANE_TAG_DEFAULT, **system_arguments|
@pane_system_arguments = system_arguments
@pane_system_arguments[:tag] = fetch_or_fallback(PANE_TAG_OPTIONS, tag, PANE_TAG_DEFAULT)
@pane_system_arguments[:classes] = class_names(
@pane_system_arguments[:classes],
"PageLayout-region",
"PageLayout-pane"
)

# These classes have to be set in the parent element, so we modify its system arguments.
@system_arguments[:classes] = class_names(
@system_arguments[:classes],
PANE_WIDTH_MAPPINGS[fetch_or_fallback(PANE_WIDTH_OPTIONS, width, PANE_WIDTH_DEFAULT)]
)

Primer::BaseComponent.new(**@pane_system_arguments)
}

# @example Default
#
# <%= render(Primer::Beta::SplitPageLayout.new) do |c| %>
# <% c.content_region(border: true) { "Content" } %>
# <% c.pane_region(border: true) { "Pane" } %>
# <% end %>
#
# @example Inner spacing
#
# @description
# Sets padding to regions individually.
#
# - `:condensed` keeps the margin at 16px.
# - `:normal` sets the margin to 16px, and to 24px on lg breakpoints and above.
#
# @code
# <%= render(Primer::Beta::PageLayout.new(inner_spacing: :condensed)) do |c| %>
# <% c.content_region(border: true) { "Content" } %>
# <% c.pane_region(border: true) { "Pane" } %>
# <% end %>
# <%= render(Primer::Beta::PageLayout.new(inner_spacing: :normal)) do |c| %>
# <% c.content_region(border: true) { "Content" } %>
# <% c.pane_region(border: true) { "Pane" } %>
# <% end %>
#
# @example Responsive primary region
#
# @description
# When `responsive_variant` is set to `:separate_regions`, defines which region appears first on small viewports. `:content` is default.
#
# - `:content`
# - `:pane`
#
# @code
# <%= render(Primer::Beta::PageLayout.new(resposive_primary_region: :content)) do |c| %>
# <% c.content_region(border: true) { "Content" } %>
# <% c.pane_region(border: true) { "Pane" } %>
# <% end %>
# <%= render(Primer::Beta::PageLayout.new(primary_region: :pane)) do |c| %>
# <% c.content_region(border: true) { "Content" } %>
# <% c.pane_region(border: true) { "Pane" } %>
# <% end %>
#
# @example Pane widths
#
# @description
# Sets the pane width. The width is predetermined according to the breakpoint instead of it being percentage-based.
#
# - `default`:
# - `narrow`:
# - `wide`:
#
# When flowing as a row, `Pane` takes the full width.
#
# @code
# <%= render(Primer::Beta::SplitPageLayout.new) do |c| %>
# <% c.content_region(border: true) { "Content" } %>
# <% c.pane_region(width: :default, border: true) { "Pane" } %>
# <% end %>
# <%= render(Primer::Beta::SplitPageLayout.new(mt: 5)) do |c| %>
# <% c.content_region(border: true) { "Content" } %>
# <% c.pane_region(width: :narrow, border: true) { "Pane" } %>
# <% end %>
# <%= render(Primer::Beta::SplitPageLayout.new(mt: 5)) do |c| %>
# <% c.content_region(border: true) { "Content" } %>
# <% c.pane_region(width: :wide, border: true) { "Pane" } %>
# <% end %>
#
#
# @param inner_spacing [Symbol] Sets padding to regions individually. <%= one_of(Primer::Beta::SplitPageLayout::INNER_SPACING_OPTIONS) %>
# @param primary_region [Symbol] When `responsive_variant` is set to `:separate_regions`, defines which region appears first on small viewports. `:content` is default. <%= one_of(Primer::Beta::SplitPageLayout::PRIMARY_REGION_OPTIONS) %>
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(
inner_spacing: INNER_SPACING_DEFAULT,
primary_region: PRIMARY_REGION_DEFAULT,
**system_arguments
)

@system_arguments = system_arguments
@system_arguments[:tag] = :div
@system_arguments[:classes] = class_names(
"PageLayout",
INNER_SPACING_MAPPINGS[fetch_or_fallback(INNER_SPACING_OPTIONS, inner_spacing, INNER_SPACING_DEFAULT)],
PRIMARY_REGION_MAPPINGS[fetch_or_fallback(PRIMARY_REGION_OPTIONS, primary_region, PRIMARY_REGION_DEFAULT)],
"PageLayout--responsive-separateRegions",
"PageLayout--columnGap-none",
"PageLayout--rowGap-none",
"PageLayout--panePos-start",
"PageLayout--hasPaneDivider",
system_arguments[:classes]
)
end

def render?
content_region.present? && pane_region.present?
end

# The layout's content.
class Content < Primer::Component
status :beta

WIDTH_DEFAULT = :fluid
WIDTH_OPTIONS = [WIDTH_DEFAULT, :md, :lg, :xl].freeze

TAG_DEFAULT = :div
TAG_OPTIONS = [TAG_DEFAULT, :main].freeze

# @param width [Symbol] <%= one_of(Primer::Beta::SplitPageLayout::Content::WIDTH_OPTIONS) %>
# @param tag [Symbol] <%= one_of(Primer::Beta::SplitPageLayout::Content::TAG_OPTIONS) %>
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(tag: TAG_DEFAULT, width: WIDTH_DEFAULT, **system_arguments)
@width = fetch_or_fallback(WIDTH_OPTIONS, width, WIDTH_DEFAULT)

@system_arguments = system_arguments
@system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, TAG_DEFAULT)
@system_arguments[:classes] = class_names(
"PageLayout-region",
"PageLayout-content",
system_arguments[:classes]
)
end

def call
render(Primer::BaseComponent.new(**@system_arguments)) do
if @width == :fluid
content
else
render(Primer::BaseComponent.new(tag: :div, classes: "PageLayout-content-centered-#{@width}")) do
render(Primer::BaseComponent.new(tag: :div, container: @width)) do
content
end
end
end
end
end
end
end
end
end
Loading