-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[DREAM-693] Unify and document ExpandableTextComponent
#23328
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4477b8c
[#75274] Unify truncation controllers
myabc 17dec9f
[#75274] Compose from AttributeComponent
myabc da299b9
[#75274] Add and document ExpandableText preview
myabc 7f03c9c
[#75274] Extract VerticalTruncateComponent
myabc b08309d
Privatise expandable-text controller; rename API
myabc 78e0b9e
Deep-dup expander_arguments to protect caller hashes
myabc ba70cd6
Add VerticalTruncateComponent Lookbook preview
myabc d06192e
Merge branch 'dev' into code-maintenance/75274-document-expandable-text
myabc 8a016f5
Own the dialog slot in ExpandableText
myabc ec5558b
[DREAM-693] Rework the ExpandableText docs
myabc 0f8f839
Merge branch 'dev' into code-maintenance/75274-document-expandable-text
myabc 6a89622
Expose dialog ARIA on the ExpandableText expander
myabc 7034c07
Disable preview cop for VerticalTruncateComponent
myabc 1a92b29
Use accessible selectors in ExpandableText spec
myabc 0915bc7
Increase height of vertical preview
myabc 09e58d3
Extract ExpandableText lines default to a constant
myabc 2bd9d11
Fix broken Lookbook preview link in ExpandableText docs
myabc 9b47949
Rename ExpandableText direction to truncate
myabc a957c67
Bump ExpandableText line clamp limit to 8
myabc 852b075
Floor multi_line truncation at 2 lines
myabc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 13 additions & 10 deletions
23
app/components/op_primer/expandable_text_component.html.erb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,18 @@ | ||
| <%= render(Primer::BaseComponent.new(**@system_arguments)) do %> | ||
| <%= render Primer::Beta::Truncate.new( | ||
| data: { truncation_target: "truncate" }, | ||
| flex: 1 | ||
| ) do %> | ||
| <%= render(@truncate_component) do %> | ||
| <%= content %> | ||
| <% end %> | ||
|
|
||
| <%= render Primer::Alpha::HiddenTextExpander.new( | ||
| hidden: true, | ||
| mt: 1, | ||
| aria: { label: t(:"js.label_expand_text") }, | ||
| data: { truncation_target: "expander" } | ||
| ) %> | ||
| <%= render Primer::Alpha::HiddenTextExpander.new(**@expander_arguments) %> | ||
| <% end %> | ||
|
|
||
| <% if @expansion.dialog? %> | ||
| <% unless dialog? %> | ||
| <% with_dialog(title: I18n.t("js.label_expand_text"), visually_hide_title: true) do |dialog| %> | ||
| <% dialog.with_header %> | ||
| <% dialog.with_body_content(content) %> | ||
| <% end %> | ||
| <% end %> | ||
|
|
||
| <%= dialog %> | ||
| <% end %> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| #-- copyright | ||
| # OpenProject is an open source project management software. | ||
| # Copyright (C) the OpenProject GmbH | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License version 3. | ||
| # | ||
| # OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
| # Copyright (C) 2006-2013 Jean-Philippe Lang | ||
| # Copyright (C) 2010-2013 the ChiliProject Team | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License | ||
| # as published by the Free Software Foundation; either version 2 | ||
| # of the License, or (at your option) any later version. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with this program; if not, write to the Free Software | ||
| # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| # | ||
| # See COPYRIGHT and LICENSE files for more details. | ||
| #++ | ||
|
|
||
| module OpPrimer | ||
| # Clamps block content to a fixed number of lines via CSS `-webkit-line-clamp`, | ||
| # styled through the `.op-vertical-truncate` class hierarchy. | ||
| # | ||
| # The vertical counterpart to `Primer::Beta::Truncate` (which clips a single | ||
| # line horizontally). Like `Truncate`, it wraps whatever block content it is | ||
| # given; callers pass system arguments (e.g. `flex:`, `data:`) through. | ||
| class VerticalTruncateComponent < Primer::Component # rubocop:disable OpenProject/AddPreviewForViewComponent | ||
| LINES_RANGE = (1..6) | ||
| LINES_DEFAULT = 3 | ||
|
|
||
| # @param lines [Integer] number of visible rows, clamped to `1..6`. | ||
| # @param tag [Symbol] wrapping element; defaults to `:div` (safe for block | ||
| # content). Overridable, mirroring `Primer::Beta::Truncate`. | ||
| # @param system_arguments [Hash] forwarded to the wrapping `Primer::BaseComponent`. | ||
| def initialize(lines: LINES_DEFAULT, **system_arguments) | ||
| super() | ||
|
|
||
| @system_arguments = system_arguments | ||
| @system_arguments[:tag] ||= :div | ||
|
|
||
| lines = lines.to_i.clamp(LINES_RANGE) | ||
| @system_arguments[:classes] = class_names( | ||
| @system_arguments[:classes], | ||
| "op-vertical-truncate", | ||
| "op-vertical-truncate--lines-#{lines}" | ||
| ) | ||
| end | ||
|
|
||
| def call | ||
| render(Primer::BaseComponent.new(**@system_arguments)) { content } | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Vertical (multi-line) truncation, the counterpart to Primer's `.Truncate`. | ||
| // `OpPrimer::VerticalTruncateComponent` clamps content to `--lines-N` rows; the | ||
| // `truncation` Stimulus controller toggles `--expanded` for inline expansion. | ||
| .op-vertical-truncate | ||
| min-width: 0 | ||
|
|
||
| @for $i from 1 through 6 | ||
| &--lines-#{$i} | ||
| @include line-clamp($i) | ||
|
|
||
| // Defined after the line-clamp modifiers so it wins on equal specificity. | ||
| &--expanded | ||
| display: block | ||
| overflow: visible | ||
| -webkit-line-clamp: unset |
76 changes: 22 additions & 54 deletions
76
app/components/open_project/common/attribute_component.html.erb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,54 +1,22 @@ | ||
| <div | ||
| data-controller="attribute" | ||
| data-attribute-background-reference-id-value="<%= background_reference_id %>" | ||
| class="op-long-text-attribute"> | ||
|
|
||
| <%= render( | ||
| Primer::Beta::Text.new( | ||
| tag: :div, | ||
| classes: ["op-long-text-attribute--text", PARAGRAPH_CSS_CLASS], | ||
| color: text_color, | ||
| style: "max-height: #{max_height};", | ||
| data: { | ||
| "attribute-target": "descriptionText" | ||
| } | ||
| ) | ||
| ) { short_text } %> | ||
|
|
||
| <%= render( | ||
| Primer::Beta::Text.new( | ||
| tag: :div, | ||
| display: display_expand_button_value, | ||
| classes: "op-long-text-attribute--text-hider", | ||
| data: { "attribute-target": "textHider" } | ||
| ) | ||
| ) %> | ||
|
|
||
| <%= render( | ||
| Primer::Alpha::HiddenTextExpander.new( | ||
| inline: false, | ||
| "aria-label": I18n.t("label_attribute_expand_text", attribute: name), | ||
| display: display_expand_button_value, | ||
| data: { | ||
| "attribute-target": "expandButton", | ||
| "test-selector": "expand-button" | ||
| }, | ||
| button_arguments: { "data-show-dialog-id": id }, | ||
| classes: "op-long-text-attribute--text-expander" | ||
| ) | ||
| ) %> | ||
|
|
||
| <%= render( | ||
| Primer::Alpha::Dialog.new( | ||
| id: id, | ||
| data: { | ||
| "test-selector": "attribute-dialog" | ||
| }, | ||
| title: name, | ||
| size: :large | ||
| ) | ||
| ) do |component| | ||
| component.with_body { full_text } | ||
| component.with_header(variant: :large) | ||
| end %> | ||
| </div> | ||
| <%= render( | ||
| OpPrimer::ExpandableTextComponent.new( | ||
| direction: truncation_direction, | ||
| lines:, | ||
| expansion: :dialog, | ||
| dialog_id: id, | ||
| expander_arguments: { | ||
| hidden: !show_expander?, | ||
| aria: { label: I18n.t("label_attribute_expand_text", attribute: name) }, | ||
| test_selector: "expand-button" | ||
| } | ||
| ) | ||
| ) do |component| | ||
| component.with_dialog(title: name, size: :large, test_selector: "attribute-dialog") do |dialog| | ||
| dialog.with_header(variant: :large) | ||
| dialog.with_body_content(full_text) | ||
| end | ||
| render( | ||
| Primer::Beta::Text.new(classes: PARAGRAPH_CSS_CLASS, color: text_color) | ||
| .with_content(short_text) | ||
| ) | ||
| end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 0 additions & 17 deletions
17
app/components/open_project/common/attribute_component.sass
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.