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

Move Primer::TimelineItemComponent to Primer::Beta::TimelineItem #1727

Merged
merged 7 commits into from
Dec 21, 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
5 changes: 5 additions & 0 deletions .changeset/unlucky-pugs-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

Move Primer::TimelineItemComponent to Primer::Beta::TimelineItem
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.
88 changes: 88 additions & 0 deletions app/components/primer/beta/timeline_item.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# frozen_string_literal: true

module Primer
module Beta
# Use `TimelineItem` to display items on a vertical timeline, connected by badge elements.
class TimelineItem < Primer::Component
status :beta

# Avatar to be rendered to the left of the Badge.
#
# @param kwargs [Hash] The same arguments as <%= link_to_component(Primer::Beta::Avatar) %>.
renders_one :avatar, lambda { |src:, size: 40, shape: :square, **system_arguments|
system_arguments[:classes] = class_names(
"TimelineItem-avatar",
system_arguments[:classes]
)

Primer::Beta::Avatar.new(src: src, size: size, shape: shape, **system_arguments)
}

# Badge that will be connected to other TimelineItems.
#
# @param icon [String] Name of <%= link_to_octicons %> to use.
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
renders_one :badge, "BadgeComponent"

# Body to be rendered to the left of the Badge.
#
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
renders_one :body, lambda { |**system_arguments|
deny_tag_argument(**system_arguments)
system_arguments[:tag] = :div
system_arguments[:classes] = class_names(
"TimelineItem-body",
system_arguments[:classes]
)

Primer::BaseComponent.new(**system_arguments)
}

# @example Default
# <div style="padding-left: 60px">
# <%= render(Primer::Beta::TimelineItem.new) do |component| %>
# <% component.with_avatar(src: Primer::ExampleImage::BASE64_SRC, alt: "github") %>
# <% component.with_badge(bg: :success_emphasis, color: :on_emphasis, icon: :check) %>
# <% component.with_body { "Success!" } %>
# <% end %>
# </div>
#
# @param condensed [Boolean] Reduce the vertical padding and remove the background from the badge item. Most commonly used in commits.
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(condensed: false, **system_arguments)
@system_arguments = deny_tag_argument(**system_arguments)
@system_arguments[:tag] = :div
@system_arguments[:classes] = class_names(
"TimelineItem",
condensed ? "TimelineItem--condensed" : "",
system_arguments[:classes]
)
end

def render?
avatar? || badge? || body?
end

# This component is part of `Primer::Beta::TimelineItem` and should not be
# used as a standalone component.
class BadgeComponent < Primer::Component
def initialize(icon: nil, **system_arguments)
@icon = icon

@system_arguments = deny_tag_argument(**system_arguments)
@system_arguments[:tag] = :div
@system_arguments[:classes] = class_names(
"TimelineItem-badge",
system_arguments[:classes]
)
end

def call
render(Primer::BaseComponent.new(**@system_arguments)) do
render(Primer::Beta::Octicon.new(@icon))
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion app/components/primer/primer.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
@import "./beta/truncate.pcss";

/* to be renamed */
@import "./timeline_item_component.pcss";
@import "./beta/timeline_item.pcss";
@import "./truncate.pcss";
83 changes: 2 additions & 81 deletions app/components/primer/timeline_item_component.rb
Original file line number Diff line number Diff line change
@@ -1,86 +1,7 @@
# frozen_string_literal: true

module Primer
# Use `TimelineItem` to display items on a vertical timeline, connected by badge elements.
class TimelineItemComponent < Primer::Component
status :beta

# Avatar to be rendered to the left of the Badge.
#
# @param kwargs [Hash] The same arguments as <%= link_to_component(Primer::Beta::Avatar) %>.
renders_one :avatar, lambda { |src:, size: 40, shape: :square, **system_arguments|
system_arguments[:classes] = class_names(
"TimelineItem-avatar",
system_arguments[:classes]
)

Primer::Beta::Avatar.new(src: src, size: size, shape: shape, **system_arguments)
}

# Badge that will be connected to other TimelineItems.
#
# @param icon [String] Name of <%= link_to_octicons %> to use.
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
renders_one :badge, "BadgeComponent"

# Body to be rendered to the left of the Badge.
#
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
renders_one :body, lambda { |**system_arguments|
deny_tag_argument(**system_arguments)
system_arguments[:tag] = :div
system_arguments[:classes] = class_names(
"TimelineItem-body",
system_arguments[:classes]
)

Primer::BaseComponent.new(**system_arguments)
}

# @example Default
# <div style="padding-left: 60px">
# <%= render(Primer::TimelineItemComponent.new) do |component| %>
# <% component.with_avatar(src: Primer::ExampleImage::BASE64_SRC, alt: "github") %>
# <% component.with_badge(bg: :success_emphasis, color: :on_emphasis, icon: :check) %>
# <% component.with_body { "Success!" } %>
# <% end %>
# </div>
#
# @param condensed [Boolean] Reduce the vertical padding and remove the background from the badge item. Most commonly used in commits.
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(condensed: false, **system_arguments)
@system_arguments = deny_tag_argument(**system_arguments)
@system_arguments[:tag] = :div
@system_arguments[:classes] = class_names(
"TimelineItem",
condensed ? "TimelineItem--condensed" : "",
system_arguments[:classes]
)
end

def render?
avatar? || badge? || body?
end

# This component is part of `Primer::TimelineItemComponent` and should not be
# used as a standalone component.
class BadgeComponent < Primer::Component
def initialize(icon: nil, **system_arguments)
@icon = icon

@system_arguments = deny_tag_argument(**system_arguments)
@system_arguments[:tag] = :div
@system_arguments[:classes] = class_names(
"TimelineItem-badge",
system_arguments[:classes]
)
end

def call
render(Primer::BaseComponent.new(**@system_arguments)) do
render(Primer::Beta::Octicon.new(@icon))
end
end
end
class TimelineItemComponent < Primer::Beta::TimelineItem
status :deprecated
end
end
2 changes: 1 addition & 1 deletion docs/src/@primer/gatsby-theme-doctocat/nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
- title: TextField
url: "/components/alpha/textfield"
- title: TimelineItem
url: "/components/timelineitem"
url: "/components/beta/timelineitem"
- title: ToggleSwitch
url: "/components/alpha/toggleswitch"
- title: Tooltip
Expand Down
4 changes: 4 additions & 0 deletions lib/primer/deprecations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ deprecations:
replacement: "Primer::Beta::RelativeTime"
guide: "https://primer.style/view-components/guides/primer_time_ago"

- component: "Primer::TimelineItemComponent"
autocorrect: true
replacement: "Primer::Beta::TimelineItem"

- component: "Primer::Tooltip"
autocorrect: true
replacement: "Primer::Alpha::Tooltip"
2 changes: 1 addition & 1 deletion lib/tasks/docs.rake
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace :docs do
Primer::Beta::Text,
Primer::Alpha::TextField,
Primer::TimeAgoComponent,
Primer::TimelineItemComponent,
Primer::Beta::TimelineItem,
Primer::Tooltip,
Primer::Truncate,
Primer::Beta::Truncate,
Expand Down
30 changes: 30 additions & 0 deletions previews/primer/beta/timeline_item_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

module Primer
module Beta
# @label TimelineItem
class TimelineItemPreview < ViewComponent::Preview
# @label Playground
#
# @param condensed [Boolean]
def playground(condensed: false)
render(Primer::Beta::TimelineItem.new(condensed: condensed)) do |component|
component.with_avatar(src: Primer::ExampleImage::BASE64_SRC, alt: "octocat")
component.with_badge(bg: :success_emphasis, color: :on_emphasis, icon: :check)
component.with_body { "Success!" }
end
end

# @label Default
#
# @param condensed [Boolean]
def default(condensed: false)
render(Primer::Beta::TimelineItem.new(condensed: condensed)) do |component|
component.with_avatar(src: Primer::ExampleImage::BASE64_SRC, alt: "octocat")
component.with_badge(bg: :success_emphasis, color: :on_emphasis, icon: :check)
component.with_body { "Success!" }
end
end
end
end
end
28 changes: 0 additions & 28 deletions previews/primer/timeline_item_component_preview.rb

This file was deleted.

40 changes: 20 additions & 20 deletions static/arguments.json
Original file line number Diff line number Diff line change
Expand Up @@ -2115,6 +2115,26 @@
}
]
},
{
"component": "TimelineItem",
"status": "beta",
"source": "https://github.com/primer/view_components/tree/main/app/components/primer/beta/timeline_item.rb",
"lookbook": "https://primer.style/view-components/lookbook/inspect/primer/beta/timeline_item_preview/default/",
"parameters": [
{
"name": "condensed",
"type": "Boolean",
"default": "`false`",
"description": "Reduce the vertical padding and remove the background from the badge item. Most commonly used in commits."
},
{
"name": "system_arguments",
"type": "Hash",
"default": "N/A",
"description": "[System arguments](/system-arguments)"
}
]
},
{
"component": "Truncate",
"status": "beta",
Expand Down Expand Up @@ -2481,26 +2501,6 @@
}
]
},
{
"component": "TimelineItem",
"status": "beta",
"source": "https://github.com/primer/view_components/tree/main/app/components/primer/timeline_item_component.rb",
"lookbook": "https://primer.style/view-components/lookbook/inspect/primer/timeline_item_preview/default/",
"parameters": [
{
"name": "condensed",
"type": "Boolean",
"default": "`false`",
"description": "Reduce the vertical padding and remove the background from the badge item. Most commonly used in commits."
},
{
"name": "system_arguments",
"type": "Hash",
"default": "N/A",
"description": "[System arguments](/system-arguments)"
}
]
},
{
"component": "Tooltip",
"status": "deprecated",
Expand Down
3 changes: 2 additions & 1 deletion static/audited_at.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
"Primer::Beta::State": "",
"Primer::Beta::Subhead": "",
"Primer::Beta::Text": "",
"Primer::Beta::TimelineItem": "",
"Primer::Beta::TimelineItem::BadgeComponent": "",
"Primer::Beta::Truncate": "",
"Primer::Beta::Truncate::TruncateText": "",
"Primer::BlankslateComponent": "",
Expand Down Expand Up @@ -98,7 +100,6 @@
"Primer::TabContainerComponent": "",
"Primer::TimeAgoComponent": "",
"Primer::TimelineItemComponent": "",
"Primer::TimelineItemComponent::BadgeComponent": "",
"Primer::Tooltip": "",
"Primer::Truncate": ""
}
8 changes: 5 additions & 3 deletions static/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,11 @@
"Primer::Beta::Text": {
"DEFAULT_TAG": "span"
},
"Primer::Beta::TimelineItem": {
"BadgeComponent": "Primer::Beta::TimelineItem::BadgeComponent"
},
"Primer::Beta::TimelineItem::BadgeComponent": {
},
"Primer::Beta::Truncate": {
"TruncateText": "Primer::Beta::Truncate::TruncateText"
},
Expand Down Expand Up @@ -1126,9 +1131,6 @@
"Primer::TimeAgoComponent": {
},
"Primer::TimelineItemComponent": {
"BadgeComponent": "Primer::TimelineItemComponent::BadgeComponent"
},
"Primer::TimelineItemComponent::BadgeComponent": {
},
"Primer::Tooltip": {
"ALIGN_DEFAULT": "default",
Expand Down
5 changes: 3 additions & 2 deletions static/statuses.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
"Primer::Beta::State": "beta",
"Primer::Beta::Subhead": "beta",
"Primer::Beta::Text": "beta",
"Primer::Beta::TimelineItem": "beta",
"Primer::Beta::TimelineItem::BadgeComponent": "alpha",
"Primer::Beta::Truncate": "beta",
"Primer::Beta::Truncate::TruncateText": "alpha",
"Primer::BlankslateComponent": "deprecated",
Expand Down Expand Up @@ -97,8 +99,7 @@
"Primer::SubheadComponent": "deprecated",
"Primer::TabContainerComponent": "deprecated",
"Primer::TimeAgoComponent": "deprecated",
"Primer::TimelineItemComponent": "beta",
"Primer::TimelineItemComponent::BadgeComponent": "alpha",
"Primer::TimelineItemComponent": "deprecated",
"Primer::Tooltip": "deprecated",
"Primer::Truncate": "beta"
}
Loading