Skip to content

Commit

Permalink
[PBNTR-576] Tooltip for Truncated Form Pills (#3856)
Browse files Browse the repository at this point in the history
**What does this PR do?** A clear and concise description with your
runway ticket url.
[PBNTR-576](https://runway.powerhrg.com/backlog_items/PBNTR-576) follows
up [PBNTR-550](https://runway.powerhrg.com/backlog_items/PBNTR-550) by
adding a Tooltip containing text or tag content in full of a truncated
Form Pill.

This PR does the following:

- Adds a Tooltip to the text, tag, or avatar name component of a
truncated Form Pill. The Tooltip contains the entirety of the text
content (does not include avatar image or icon)
- Expands upon PBNTR-550 by adding the truncate prop to Rails Form Pills
as well - all Rails Typeaheads With Pills are react-rendered-rails, so
this expands the behavior so React/Rails are consistent. (**Note**:
there are no solo rails form pills in use in
[Nitro](https://github.com/search?q=repo%3Apowerhome%2Fnitro-web+pb_rails%28%22form_pill&type=code)).
For Rails Tooltips, an id must be included; if not included, the Form
Pill will be truncated but no Tooltip will appear (this is not necessary
for React, nor for react-rendered-rails Typeahead).
- Updates the Truncated Text Rails and React doc examples to include
several form pill variations (an avatar, an icon+text tag, and a text
tag only) within a Card of a small width to demonstrate the
truncation/tooltip in a non-Typeahead environment. Locally I tested many
variations (including truncation on a small Form Pill, or one with
customized color).

**Screenshots:** Screenshots to visualize your addition/change
React Truncated Text doc example screenshots showing Tooltip
<img width="1497" alt="react doc ex typeahead"
src="https://github.com/user-attachments/assets/89aa1fc6-0ebd-43af-b108-9b85c77b11b5">
<img width="1491" alt="react doc ex formpill"
src="https://github.com/user-attachments/assets/920ec0c5-107d-447d-9604-76664a99d3eb">

Rails Truncated Text doc example screenshots showing Tooltip
<img width="1388" alt="for PR rails updated typeahead doc ex"
src="https://github.com/user-attachments/assets/cc40eca6-068b-4023-8760-1e4c45f09b0d">
<img width="1395" alt="for PR rails updated formpill doc ex"
src="https://github.com/user-attachments/assets/2a9a3837-70e5-4f18-8f7a-a7dc5886f193">



**How to test?** Steps to confirm the desired behavior:
1. Go to the truncated text doc example
([rails](https://pr3856.playbook.beta.px.powerapp.cloud/kits/form_pill/rails#truncated-text)/[react](https://pr3856.playbook.beta.px.powerapp.cloud/kits/form_pill/react#truncated-text)).
2. Go to the Typeahead in the "Truncation Within Typeahead" section and
select a name. Hover over the Form Pill that appears with their
truncated name and observe the Tooltip in action displaying their full
name.
3. Hover over one/all of the truncated Form Pills in the "Form Pill
Truncation" section. Observe the Tooltip in action. For the last Form
Pill in the Rails doc ex, note that no Tooltip will appear because it
does not have an id.


#### Checklist:
- [x] **LABELS** Add a label: `enhancement`, `bug`, `improvement`, `new
kit`, `deprecated`, or `breaking`. See [Changelog &
Labels](https://github.com/powerhome/playbook/wiki/Changelog-&-Labels)
for details.
- [x] **DEPLOY** I have added the `milano` label to show I'm ready for a
review.
~~- [ ] **TESTS** I have added test coverage to my code.~~
  • Loading branch information
ElisaShapiro authored Nov 5, 2024
1 parent 3b17776 commit 50fc9f6
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 40 deletions.
8 changes: 6 additions & 2 deletions playbook/app/pb_kits/playbook/pb_form_pill/_form_pill.scss
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ $form_pill_colors: map-merge($status_color_text, map-merge($data_colors, $produc
height: 12px !important;
width: 12px !important;
padding-right: $space_xs;
+ .pb_form_pill_text, + .pb_form_pill_tag {
+ .pb_form_pill_text, + .pb_form_pill_tag,
+ .pb_tooltip_kit .pb_form_pill_text, + .pb_tooltip_kit .pb_form_pill_tag,
+ div .pb_form_pill_text, + div .pb_form_pill_tag {
padding-left: 0;
}
}
Expand All @@ -169,7 +171,9 @@ $form_pill_colors: map-merge($status_color_text, map-merge($data_colors, $produc
}
.pb_form_pill_icon {
padding-right: $space_xxs;
+ .pb_form_pill_text, + .pb_form_pill_tag {
+ .pb_form_pill_text, + .pb_form_pill_tag,
+ .pb_tooltip_kit .pb_form_pill_text, + .pb_tooltip_kit .pb_form_pill_tag,
+ div .pb_form_pill_text, + div .pb_form_pill_tag {
padding-left: 0;
}
}
Expand Down
56 changes: 30 additions & 26 deletions playbook/app/pb_kits/playbook/pb_form_pill/_form_pill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import classnames from 'classnames'
import Title from '../pb_title/_title'
import Icon from '../pb_icon/_icon'
import Avatar from '../pb_avatar/_avatar'
import Tooltip from '../pb_tooltip/_tooltip'
import { globalProps, GlobalProps } from '../utilities/globalProps'
import { buildDataProps, buildHtmlProps } from '../utilities/props'

Expand Down Expand Up @@ -62,6 +63,30 @@ const FormPill = (props: FormPillProps): React.ReactElement => {
const dataProps = buildDataProps(data)
const htmlProps = buildHtmlProps(htmlOptions)

const renderTitle = (content: string, className: string) => {
const titleComponent = (
<Title
className={className}
size={4}
text={content}
truncate={props.truncate}
/>
)
if (props.truncate) {
return (
<Tooltip
interaction
placement="top"
position="fixed"
text={content}
>
{titleComponent}
</Tooltip>
)
}
return titleComponent
}

return (
<div className={css}
id={id}
Expand All @@ -77,12 +102,7 @@ const FormPill = (props: FormPillProps): React.ReactElement => {
size="xxs"
status={null}
/>
<Title
className="pb_form_pill_text"
size={4}
text={name}
truncate={props.truncate}
/>
{renderTitle(name, "pb_form_pill_text")}
</>
)}
{((name && icon && !text) || (name && icon && text)) && (
Expand All @@ -93,12 +113,7 @@ const FormPill = (props: FormPillProps): React.ReactElement => {
size="xxs"
status={null}
/>
<Title
className="pb_form_pill_text"
size={4}
text={name}
truncate={props.truncate}
/>
{renderTitle(name, "pb_form_pill_text")}
<Icon
className="pb_form_pill_icon"
color={color}
Expand All @@ -113,22 +128,10 @@ const FormPill = (props: FormPillProps): React.ReactElement => {
color={color}
icon={icon}
/>
<Title
className="pb_form_pill_tag"
size={4}
text={text}
truncate={props.truncate}
/>
{renderTitle(text, "pb_form_pill_tag")}
</>
)}
{(!name && !icon && text) && (
<Title
className="pb_form_pill_tag"
size={4}
text={text}
truncate={props.truncate}
/>
)}
{(!name && !icon && text) && renderTitle(text, "pb_form_pill_tag")}
<div
className="pb_form_pill_close"
onClick={onClick}
Expand All @@ -143,4 +146,5 @@ const FormPill = (props: FormPillProps): React.ReactElement => {
</div>
)
}

export default FormPill
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,30 @@
id: "typeahead-form-pill",
is_multi: true,
options: names,
label: "Names",
label: "Truncation Within Typeahead",
pills: true,
truncate: 1,
}) %>

<%= pb_rails("caption", props: { text: "Form Pill Truncation" }) %>
<%= pb_rails("card", props: { max_width: "xs" }) do %>
<%= pb_rails("form_pill", props: {
name: "Princess Amelia Mignonette Grimaldi Thermopolis Renaldo",
avatar_url: "https://randomuser.me/api/portraits/women/44.jpg",
tabindex: 0,
truncate: 1,
id: "truncation-1"
}) %>
<%= pb_rails("form_pill", props: {
icon: "badge-check",
text: "icon and a very long tag to show truncation",
tabindex: 0,
truncate: 1,
id: "truncation-2"
}) %>
<%= pb_rails("form_pill", props: {
text: "form pill long tag no tooltip show truncation",
tabindex: 0,
truncate: 1,
}) %>
<% end %>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import Typeahead from '../../pb_typeahead/_typeahead'
import { Card, Caption, FormPill, Typeahead } from 'playbook-ui'

const names = [
{ label: 'Alexander Nathaniel Montgomery', value: 'Alexander Nathaniel Montgomery' },
Expand All @@ -15,11 +15,34 @@ const FormPillTruncatedText = (props) => {
<Typeahead
htmlOptions={{ style: { maxWidth: "240px" }}}
isMulti
label="Names"
label="Truncation Within Typeahead"
options={names}
truncate={1}
{...props}
/>
<Caption text="Form Pill Truncation"/>
<Card maxWidth="xs">
<FormPill
avatarUrl="https://randomuser.me/api/portraits/women/44.jpg"
name="Princess Amelia Mignonette Grimaldi Thermopolis Renaldo"
onClick={() => alert('Click!')}
tabIndex={0}
truncate={1}
/>
<FormPill
icon="badge-check"
onClick={() => {alert('Click!')}}
tabIndex={0}
text="icon and a very long tag to show truncation"
truncate={1}
/>
<FormPill
onClick={() => {alert('Click!')}}
tabIndex={0}
text="form pill with a very long tag to show truncation"
truncate={1}
/>
</Card>
</>
)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
For Form Pills with longer text, the truncate global prop can be used to truncate the label within each Form Pill. See [here](https://playbook.powerapp.cloud/visual_guidelines/truncate) for more information on the truncate global prop.

__NOTE__: For Rails Form Pills (not ones embedded within a React-rendered Typeahead or MultiLevelSelect), a unique `id` is required to enable the Tooltip functionality displaying the text or tag section of the Form Pill.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
For Form Pills with longer text, the `truncate` global prop can be used to truncate the label within each Form Pill. Hover over the truncated Form Pill and a Tooltip containing the text or tag section of the Form Pill will appear. See [here](https://playbook.powerapp.cloud/visual_guidelines/truncate) for more information on the truncate global prop.
54 changes: 46 additions & 8 deletions playbook/app/pb_kits/playbook/pb_form_pill/form_pill.html.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,57 @@
<%= content_tag(:div, id: object.id, data: object.data, class: object.classname + object.size_class, tabindex: object.tabindex, **combined_html_options) do %>
<% if object.name.present? %>
<%= pb_rails("avatar", props: { name: object.name, image_url: object.avatar_url, size: "xxs" }) %>
<%= pb_rails("title", props: { text: object.name, size: 4, classname: "pb_form_pill_text" }) %>
<% if object.truncate %>
<div>
<%= pb_rails("title", props: {
classname: "pb_form_pill_text truncate_#{object.truncate}",
id: object.id,
size: 4,
text: object.name,
}) %>
<% if object.id.present? %>
<%= pb_rails("tooltip", props: {
position: "top",
tooltip_id: "tooltip-#{object.id}",
trigger_element_selector: "##{object.id}"
}) do %>
<%= object.name %>
<% end %>
<% end %>
</div>
<% else %>
<%= pb_rails("title", props: { classname: "pb_form_pill_text", id: object.id, size: 4, text: object.name }) %>
<% end %>
<% if object.icon.present? %>
<%= pb_rails("icon", props: { classname: "pb_form_pill_icon", color: object.color, icon: object.icon }) %>
<% end %>
<% elsif object.text.present? %>
<% if object.icon.present? %>
<%= pb_rails("icon", props: { classname: "pb_form_pill_icon", color: object.color, icon: object.icon }) %>
<% end %>
<% if object.text.present? %>
<%= pb_rails("title", props: { text: object.text, size: 4, classname: "pb_form_pill_tag" }) %>
<% end %>
<% if object.icon.present? %>
<%= pb_rails("icon", props: { classname: "pb_form_pill_icon", color: object.color, icon: object.icon }) %>
<% end %>
<% if object.truncate %>
<div>
<%= pb_rails("title", props: {
classname: "pb_form_pill_tag truncate_#{object.truncate}",
id: object.id,
size: 4,
text: object.text,
}) %>
<% if object.id.present? %>
<%= pb_rails("tooltip", props: {
position: "top",
tooltip_id: "tooltip-#{object.id}",
trigger_element_selector: "##{object.id}"
}) do %>
<%= object.text %>
<% end %>
<% end %>
</div>
<% else %>
<%= pb_rails("title", props: { classname: "pb_form_pill_tag", id: object.id, size: 4, text: object.text, }) %>
<% end %>
<% end %>
<%= pb_rails("body", props: { classname: "pb_form_pill_close" }) do %>
<%= pb_rails("icon", props: { icon: 'times', fixed_width: true, size: object.close_icon_size }) %>
<% end %>
<% end %>
<% end %>

0 comments on commit 50fc9f6

Please sign in to comment.