Skip to content

Commit

Permalink
[PBNTR-550] Truncating the Typeahead FormPill text (#3738)
Browse files Browse the repository at this point in the history
**What does this PR do?**
Making Typeahead truncate global prop being applied to the FormPill
text.


#### 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.

---------

Co-authored-by: Nida Ghuman <[email protected]>
  • Loading branch information
carloslimasd and nidaqg authored Oct 3, 2024
1 parent bb1461f commit 4cf8451
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 4 deletions.
10 changes: 9 additions & 1 deletion playbook/app/pb_kits/playbook/pb_form_pill/_form_pill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ const FormPill = (props: FormPillProps): React.ReactElement => {

const iconClass = icon ? "_icon" : ""
const closeIconSize = size === "small" ? "xs" : "sm"

const filteredProps: FormPillProps = {...props}
delete filteredProps.truncate

const css = classnames(
`pb_form_pill_kit_${color}${iconClass}`,
globalProps(props),
globalProps(filteredProps),
className,
size === 'small' ? 'small' : null,
textTransform,
Expand Down Expand Up @@ -77,6 +81,7 @@ const FormPill = (props: FormPillProps): React.ReactElement => {
className="pb_form_pill_text"
size={4}
text={name}
truncate={props.truncate}
/>
</>
)}
Expand All @@ -92,6 +97,7 @@ const FormPill = (props: FormPillProps): React.ReactElement => {
className="pb_form_pill_text"
size={4}
text={name}
truncate={props.truncate}
/>
<Icon
className="pb_form_pill_icon"
Expand All @@ -111,6 +117,7 @@ const FormPill = (props: FormPillProps): React.ReactElement => {
className="pb_form_pill_tag"
size={4}
text={text}
truncate={props.truncate}
/>
</>
)}
Expand All @@ -119,6 +126,7 @@ const FormPill = (props: FormPillProps): React.ReactElement => {
className="pb_form_pill_tag"
size={4}
text={text}
truncate={props.truncate}
/>
)}
<div
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<%
names = [
{ label: 'Alexander Nathaniel Montgomery', value: 'Alexander Nathaniel Montgomery' },
{ label: 'Isabella Anastasia Wellington', value: 'Isabella Anastasia Wellington' },
{ label: 'Christopher Maximilian Harrington', value: 'Christopher Maximilian Harrington' },
{ label: 'Elizabeth Seraphina Kensington', value: 'Elizabeth Seraphina Kensington' },
{ label: 'Theodore Jonathan Abernathy', value: 'Theodore Jonathan Abernathy' },
]
%>
<%= pb_rails("typeahead", props: {
html_options: { style: { maxWidth: "240px" }},
id: "typeahead-form-pill",
is_multi: true,
options: names,
label: "Names",
pills: true,
truncate: 1,
}) %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react'
import Typeahead from '../../pb_typeahead/_typeahead'

const names = [
{ label: 'Alexander Nathaniel Montgomery', value: 'Alexander Nathaniel Montgomery' },
{ label: 'Isabella Anastasia Wellington', value: 'Isabella Anastasia Wellington' },
{ label: 'Christopher Maximilian Harrington', value: 'Christopher Maximilian Harrington' },
{ label: 'Elizabeth Seraphina Kensington', value: 'Elizabeth Seraphina Kensington' },
{ label: 'Theodore Jonathan Abernathy', value: 'Theodore Jonathan Abernathy' },
]

const FormPillTruncatedText = (props) => {
return (
<>
<Typeahead
htmlOptions={{ style: { maxWidth: "240px" }}}
isMulti
label="Names"
options={names}
truncate={1}
{...props}
/>
</>
)
}

export default FormPillTruncatedText
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
For 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.
2 changes: 2 additions & 0 deletions playbook/app/pb_kits/playbook/pb_form_pill/docs/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ examples:
rails:
- form_pill_user: Form Pill User
- form_pill_size: Form Pill Size
- form_pill_truncated_text: Truncated Text
- form_pill_tag: Form Pill Tag
- form_pill_example: Example
- form_pill_icon: Form Pill Icon
Expand All @@ -11,6 +12,7 @@ examples:
react:
- form_pill_user: Form Pill User
- form_pill_size: Form Pill Size
- form_pill_truncated_text: Truncated Text
- form_pill_tag: Form Pill Tag
- form_pill_example: Example
- form_pill_icon: Form Pill Icon
Expand Down
1 change: 1 addition & 0 deletions playbook/app/pb_kits/playbook/pb_form_pill/docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export { default as FormPillTag } from './_form_pill_tag.jsx'
export { default as FormPillExample } from './_form_pill_example.jsx'
export { default as FormPillIcon } from './_form_pill_icon.jsx'
export { default as FormPillColors } from './_form_pill_colors.jsx'
export { default as FormPillTruncatedText } from './_form_pill_truncated_text.jsx'
5 changes: 4 additions & 1 deletion playbook/app/pb_kits/playbook/pb_typeahead/_typeahead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,15 @@ const Typeahead = ({
}
}

const filteredProps: TypeaheadProps = {...props}
delete filteredProps.truncate

const dataProps = buildDataProps(data)
const htmlProps = buildHtmlProps(htmlOptions)
const classes = classnames(
'pb_typeahead_kit react-select',
`mb_${marginBottom}`,
globalProps(props),
globalProps(filteredProps),
className
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Props = {
const MultiValue = (props: Props) => {
const { removeProps } = props
const { imageUrl, label } = props.data
const { dark, multiKit, pillColor } = props.selectProps
const { dark, multiKit, pillColor, truncate } = props.selectProps

const formPillProps = {
marginRight: 'xs',
Expand Down Expand Up @@ -51,6 +51,7 @@ const MultiValue = (props: Props) => {
name={label}
size={multiKit === 'smallPill' ? 'small' : ''}
text=''
truncate={truncate}
{...props}
/>
}
Expand All @@ -64,6 +65,7 @@ const MultiValue = (props: Props) => {
name=''
size={multiKit === 'smallPill' ? 'small' : ''}
text={label}
truncate={truncate}
{...props}
/>
}
Expand Down
4 changes: 3 additions & 1 deletion playbook/app/pb_kits/playbook/pb_typeahead/typeahead.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ def is_react?
def typeahead_react_options
base_options = {
className: classname,
pillColor: pill_color,
dark: dark,
defaultValue: default_options,
error: error,
htmlOptions: html_options,
id: id,
inline: inline,
isMulti: is_multi,
Expand All @@ -77,8 +77,10 @@ def typeahead_react_options
multiKit: multi_kit,
name: name,
options: options,
pillColor: pill_color,
placeholder: placeholder,
plusIcon: plus_icon,
truncate: truncate,
}

base_options[:getOptionLabel] = get_option_label if get_option_label.present?
Expand Down

0 comments on commit 4cf8451

Please sign in to comment.