Skip to content

Commit

Permalink
Removed descriptionDisplay and labelDisplay props from `EuiSugges…
Browse files Browse the repository at this point in the history
…tItem`
  • Loading branch information
cee-chen committed May 4, 2022
1 parent f36693b commit b6c7e2a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 87 deletions.
45 changes: 9 additions & 36 deletions src/components/suggest/__snapshots__/suggest_item.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,14 @@ exports[`EuiSuggestItem is rendered 1`] = `
/>
</span>
<span
class="euiSuggestItem__label"
class="euiSuggestItem__label euiSuggestItem__label--width50"
title="Test label"
>
Test label
</span>
</span>
`;

exports[`props descriptionDisplay as wrap is rendered 1`] = `
<span
class="euiSuggestItem euiSuggestItem--truncate"
>
<span
class="euiSuggestItem__type euiSuggestItem__type--tint2"
>
<span
color="inherit"
data-euiicon-type="kqlValue"
/>
</span>
<span
class="euiSuggestItem__label euiSuggestItem__label--width50"
title="This is the description"
>
This is the description
</span>
<span
class="euiSuggestItem__description euiSuggestItem__description--wrap"
title="This is the description"
>
This is the description
</span>
</span>
`;

exports[`props item with no description has expanded label is rendered 1`] = `
<span
class="euiSuggestItem euiSuggestItem--truncate"
Expand All @@ -63,15 +36,15 @@ exports[`props item with no description has expanded label is rendered 1`] = `
/>
</span>
<span
class="euiSuggestItem__label"
class="euiSuggestItem__label euiSuggestItem__label--width50"
title="Charles de Gaulle International Airport"
>
Charles de Gaulle International Airport
</span>
</span>
`;

exports[`props labelDisplay as expand is rendered 1`] = `
exports[`props labelWidth is 30% is rendered 1`] = `
<span
class="euiSuggestItem euiSuggestItem--truncate"
>
Expand All @@ -84,7 +57,7 @@ exports[`props labelDisplay as expand is rendered 1`] = `
/>
</span>
<span
class="euiSuggestItem__label"
class="euiSuggestItem__label euiSuggestItem__label--width30"
title="This is the description"
>
This is the description
Expand All @@ -98,7 +71,7 @@ exports[`props labelDisplay as expand is rendered 1`] = `
</span>
`;

exports[`props labelWidth is 30% is rendered 1`] = `
exports[`props truncate is rendered 1`] = `
<span
class="euiSuggestItem euiSuggestItem--truncate"
>
Expand All @@ -111,7 +84,7 @@ exports[`props labelWidth is 30% is rendered 1`] = `
/>
</span>
<span
class="euiSuggestItem__label euiSuggestItem__label--width30"
class="euiSuggestItem__label euiSuggestItem__label--width50"
title="This is the description"
>
This is the description
Expand All @@ -125,9 +98,9 @@ exports[`props labelWidth is 30% is rendered 1`] = `
</span>
`;

exports[`props truncate is rendered 1`] = `
exports[`props truncate renders false 1`] = `
<span
class="euiSuggestItem euiSuggestItem--truncate"
class="euiSuggestItem"
>
<span
class="euiSuggestItem__type euiSuggestItem__type--tint2"
Expand All @@ -144,7 +117,7 @@ exports[`props truncate is rendered 1`] = `
This is the description
</span>
<span
class="euiSuggestItem__description"
class="euiSuggestItem__description euiSuggestItem__description--wrap"
title="This is the description"
>
This is the description
Expand Down
28 changes: 6 additions & 22 deletions src/components/suggest/suggest_item.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,56 +34,40 @@ describe('props', () => {
description: 'This is the description',
};

describe('labelDisplay as expand', () => {
test('is rendered', () => {
const component = render(
<EuiSuggestItem
type={sampleItem.type}
description={sampleItem.description}
label={sampleItem.description}
labelDisplay="expand"
/>
);
expect(component).toMatchSnapshot();
});
});

describe('descriptionDisplay as wrap', () => {
describe('labelWidth is 30%', () => {
test('is rendered', () => {
const component = render(
<EuiSuggestItem
type={sampleItem.type}
description={sampleItem.description}
label={sampleItem.description}
descriptionDisplay="wrap"
labelWidth="30"
/>
);
expect(component).toMatchSnapshot();
});
});

describe('labelWidth is 30%', () => {
describe('truncate', () => {
test('is rendered', () => {
const component = render(
<EuiSuggestItem
type={sampleItem.type}
description={sampleItem.description}
label={sampleItem.description}
labelWidth="30"
truncate
/>
);
expect(component).toMatchSnapshot();
});
});

describe('truncate', () => {
test('is rendered', () => {
test('renders false', () => {
const component = render(
<EuiSuggestItem
type={sampleItem.type}
description={sampleItem.description}
label={sampleItem.description}
truncate
truncate={false}
/>
);
expect(component).toMatchSnapshot();
Expand Down
34 changes: 5 additions & 29 deletions src/components/suggest/suggest_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,6 @@ export interface _EuiSuggestItemPropsBase {
* Truncates both label and description.
*/
truncate?: boolean;

/**
* **DEPRECATED** Use `truncate` instead to specify truncation for both label and description.
*
* _Set the way in which 'description' is displayed, defaults to 'truncate'._
*/
descriptionDisplay?: 'truncate' | 'wrap';

/**
* **DEPRECATED** Use `labelWidth` instead to specify a specific width.
*
* _Label display is 'fixed' by default. Label will increase its width beyond 50% if needed with 'expand'._
*/
labelDisplay?: keyof typeof labelDisplayToClassMap;
}

type PropsForSpan = Omit<HTMLAttributes<HTMLSpanElement>, 'onClick'>;
Expand Down Expand Up @@ -125,22 +111,13 @@ const colorToClassNameMap: ColorToClassMap = {

export const COLORS = keysOf(colorToClassNameMap);

const labelDisplayToClassMap = {
fixed: 'euiSuggestItem__labelDisplay--fixed',
expand: 'euiSuggestItem__labelDisplay--expand',
};

export const DISPLAYS = keysOf(labelDisplayToClassMap);

export const EuiSuggestItem: FunctionComponent<EuiSuggestItemProps> = ({
className,
label,
type,
labelDisplay: _labelDisplay = 'fixed',
labelWidth = '50',
description,
truncate = true,
descriptionDisplay = 'truncate',
onClick,
...rest
}) => {
Expand All @@ -152,14 +129,13 @@ export const EuiSuggestItem: FunctionComponent<EuiSuggestItemProps> = ({
className
);

const labelDisplay = !description ? 'expand' : _labelDisplay;

const labelClassNames = classNames('euiSuggestItem__label', {
[`euiSuggestItem__label--width${labelWidth}`]: labelDisplay === 'fixed',
});
const labelClassNames = classNames(
'euiSuggestItem__label',
`euiSuggestItem__label--width${labelWidth}`
);

const descriptionClassNames = classNames('euiSuggestItem__description', {
'euiSuggestItem__description--wrap': descriptionDisplay === 'wrap',
'euiSuggestItem__description--wrap': !truncate,
});

let typeColorClass = '';
Expand Down
1 change: 1 addition & 0 deletions upcoming_changelogs/5868.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
- Removed `isSelected` and `isComplete` props from `EuiHorizontalStep` - use `status` prop instead
- Removed `isHollow` prop from `EuiStep` - this visual appearance is no longer used in Amsterdam
- Removed condensed `display` prop from `EuiTabs` & `EuiTabbedContent` - this visual appearance is no longer used in Amsterdam
- Removed `descriptionDisplay` and `labelDisplay` props from `EuiSuggestItem` - use `truncate` and `labelWidth` instead, respectively

0 comments on commit b6c7e2a

Please sign in to comment.