Skip to content

Commit

Permalink
Deprecate Primer::Truncate in favor of Primer::Beta::Truncate (#1877
Browse files Browse the repository at this point in the history
)
  • Loading branch information
hrs authored Mar 13, 2023
1 parent 838ab59 commit 864fb98
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-phones-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

Deprecate Primer::Truncate in favor of Primer::Beta::Truncate, and adding a migration guide
2 changes: 1 addition & 1 deletion app/components/primer/truncate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Primer
# Use `Truncate` to shorten overflowing text with an ellipsis.
class Truncate < Primer::Component
status :beta
status :deprecated

DEFAULT_TAG = :div
TAG_OPTIONS = [DEFAULT_TAG, :span, :p, :strong].freeze
Expand Down
3 changes: 2 additions & 1 deletion docs/content/guides/primer_local_time.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ For example, if the `LocalTime` was set up in this way:
<%= Primer::LocalTime(datetime: Time.now, initial_text: Time.now.iso8601) %>
```
It can be migrated by removing `initial_text`c, setting an empty `prefix`, and adding `threshold: "PT0S"`.
It can be migrated by removing `initial_text`, setting an empty `prefix`, and
adding `threshold: "PT0S"`.
```rb
<%= Primer::Beta::RelativeTime(datetime: Time.now, prefix: "", threshold: "PT0S") %>
Expand Down
4 changes: 2 additions & 2 deletions docs/content/guides/primer_time_ago.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ noted, however.
| `micro` | `format: :micro` | Instead of a boolean flag, set the `format` argument to the value of `:micro` |
| n/a | `tense: :past` | Required for displaying how long ago the set time was. This argument tells `RelativeTime` to behave like `TimeAgo` did. |

The remaining arguments for `RelativeTime` can be found in the docu7mentation
for that component.
The remaining arguments for `RelativeTime` can be found in the documentation for
that component.

Please see the following for complete descriptions and examples.

Expand Down
67 changes: 67 additions & 0 deletions docs/content/guides/primer_truncate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
title: Moving Away From `Primer::Truncate`
---

This guide will show you how to upgrade from the now-deprecated
[`Primer::Truncate`](https://primer.style/view-components/components/truncate)
to the latest
[`Primer::Beta::Truncate`](https://primer.style/view-components/components/beta/truncate)
component.

The new `Truncate` component additionally now includes a text slot used for the
truncated text.

## Some Migration Examples

Migrating the most common use cases of the `Truncate` component simply requires
changing the name.

Previously we might have something like:

```ruby
<%= render(Primer::Truncate.new(tag: :p)) { "Some really, really verbose content" } %>
```
That's now:
```ruby
<%= render(Primer::Beta::Truncate.new(tag: :p)) { "Some really, really verbose content" } %>
```

The `tag` argument now defaults to `:span` instead of `:div`, so if we want to
continue wrapping content in `<div>` tags we'll need to explicitly set that. So,
if we'd been using:

```ruby
<%= render(Primer::Truncate.new) { "Some more very very long text" } %>
```
We can now equivalently write:
```ruby
<%= render(Primer::Beta::Truncate.new(tag: :div)) { "Some more very very long text" } %>
```

## Arguments

The following arguments for the component initializer have changed between the deprecated and newer versions
of the `Truncate` component.

| From `Primer::Truncate` | To `Primer::Beta::Truncate` | Notes |
|-------------------------|-----------------------------|--------------------------------------------------------------------------|
| `tag` | `tag` | Previously defaulted to `:div`, now `:span`. |
| `inline` | n/a | Removed in `Primer::Beta::Truncate`. |
| n/a | `priority` | If `true`, the text will be given priority (by increasing `flex-basis`). |

The remaining arguments for `Truncate` can be found in the documentation for
that component.

Please see the following for complete descriptions and examples.

* [Deprecated `Primer::Truncate`](https://primer.style/view-components/components/truncate)
* [`Primer::Beta::Truncate` component](https://primer.style/view-components/components/beta/truncate)
* [`Primer::Beta::Truncate` Lookbook examples](https://primer.style/view-components/lookbook/inspect/primer/beta/truncate/default)

<p>&nbsp;</p>

[&larr; Back to migration guides](https://primer.style/view-components/migration)
1 change: 1 addition & 0 deletions docs/content/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ components.
| [`Primer::ButtonComponent`](https://primer.style/view-components/components/button) | [`Primer::Beta::Button`](https://primer.style/view-components/components/beta/button) | [Upgrade to Primer::Beta::Button](https://primer.style/view-components/guides/primer_button_component) |
| [`Primer::LocalTime`](https://primer.style/view-components/components/localtime) | [`Primer::Beta::RelativeTime`](https://primer.style/view-components/components/beta/relativetime) | [Upgrade to Primer::Beta::RelativeTime](https://primer.style/view-components/guides/primer_local_time) |
| [`Primer::TimeAgoComponent`](https://primer.style/view-components/components/timeago) | [`Primer::Beta::RelativeTime`](https://primer.style/view-components/components/beta/relativetime) | [Upgrade to Primer::Beta::RelativeTime](https://primer.style/view-components/guides/primer_time_ago) |
| [`Primer::Truncate`](https://primer.style/view-components/components/truncate) | [`Primer::Beta::Truncate`](https://primer.style/view-components/components/beta/truncate) | [Upgrade to Primer::Beta::Truncate](https://primer.style/view-components/guides/primer_truncate) |
2 changes: 2 additions & 0 deletions docs/src/@primer/gatsby-theme-doctocat/nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@
url: "/components/iconbutton"
- title: Tooltip
url: "/components/tooltip"
- title: Truncate
url: "/components/truncate"
- title: Architecture decisions
children:
- title: Developing and publishing client-side behaviours
Expand Down
5 changes: 5 additions & 0 deletions lib/primer/deprecations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ deprecations:
- component: "Primer::Tooltip"
autocorrect: true
replacement: "Primer::Alpha::Tooltip"

- component: "Primer::Truncate"
autocorrect: false
replacement: "Primer::Beta::Truncate"
guide: "https://primer.style/view-components/guides/primer_truncate"
2 changes: 1 addition & 1 deletion static/arguments.json
Original file line number Diff line number Diff line change
Expand Up @@ -1805,7 +1805,7 @@
},
{
"component": "Truncate",
"status": "beta",
"status": "deprecated",
"source": "https://github.com/primer/view_components/tree/main/app/components/primer/truncate.rb",
"lookbook": "https://primer.style/view-components/lookbook/inspect/primer/truncate/default/",
"parameters": [
Expand Down
2 changes: 1 addition & 1 deletion static/statuses.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,5 @@
"Primer::LayoutComponent": "alpha",
"Primer::Navigation::TabComponent": "deprecated",
"Primer::Tooltip": "deprecated",
"Primer::Truncate": "beta"
"Primer::Truncate": "deprecated"
}

0 comments on commit 864fb98

Please sign in to comment.