Skip to content

Commit

Permalink
[CL-569] Optionally allow item content to wrap
Browse files Browse the repository at this point in the history
  • Loading branch information
vleague2 committed Jan 31, 2025
1 parent 3b8b9c9 commit e52f074
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 3 deletions.
16 changes: 14 additions & 2 deletions libs/components/src/item/item-content.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,26 @@
bitTypography="body2"
class="tw-text-main tw-truncate tw-inline-flex tw-items-center tw-gap-1.5 tw-w-full"
>
<div class="tw-truncate">
<div
[ngClass]="{
'tw-truncate': truncate,
'tw-text-wrap tw-overflow-auto tw-break-words': !truncate,
}"
>
<ng-content></ng-content>
</div>
<div class="tw-flex-grow">
<ng-content select="[slot=default-trailing]"></ng-content>
</div>
</div>
<div bitTypography="helper" class="tw-text-muted tw-w-full tw-truncate">
<div
bitTypography="helper"
class="tw-text-muted tw-w-full"
[ngClass]="{
'tw-truncate': truncate,
'tw-text-wrap tw-overflow-auto tw-break-words': !truncate,
}"
>
<ng-content select="[slot=secondary]"></ng-content>
</div>
</div>
Expand Down
8 changes: 8 additions & 0 deletions libs/components/src/item/item-content.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ChangeDetectionStrategy,
Component,
ElementRef,
Input,
signal,
ViewChild,
} from "@angular/core";
Expand All @@ -32,6 +33,13 @@ export class ItemContentComponent implements AfterContentChecked {

protected endSlotHasChildren = signal(false);

/**
* Determines whether text will truncate or wrap.
*
* Default behavior is truncation.
*/
@Input() truncate = true;

Check warning on line 41 in libs/components/src/item/item-content.component.ts

View check run for this annotation

Codecov / codecov/patch

libs/components/src/item/item-content.component.ts#L41

Added line #L41 was not covered by tests

ngAfterContentChecked(): void {
this.endSlotHasChildren.set(this.endSlot?.nativeElement.childElementCount > 0);
}
Expand Down
24 changes: 24 additions & 0 deletions libs/components/src/item/item.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,30 @@ Actions are commonly icon buttons or badge buttons.
</bit-item>
```

## Text Overflow Behavior

The default behavior for long text is to truncate it. However, you have the option of changing it to
wrap instead if that is what the design calls for.

This can be changed by passing `[truncate]="false"` to the `bit-item-content`.

```html
<bit-item>
<bit-item-content [truncate]="false">
Long text goes here!
<ng-container slot="secondary">This could also be very long text</ng-container>
</bit-item-content>
</bit-item>
```

### Truncation (Default)

<Story of={stories.TextOverflowTruncate} />

### Wrap

<Story of={stories.TextOverflowWrap} />

## Item Groups

Groups of items can be associated by wrapping them in the `<bit-item-group>`.
Expand Down
25 changes: 24 additions & 1 deletion libs/components/src/item/item.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const ContentTypes: Story = {
}),
};

export const TextOverflow: Story = {
export const TextOverflowTruncate: Story = {

Check warning on line 138 in libs/components/src/item/item.stories.ts

View check run for this annotation

Codecov / codecov/patch

libs/components/src/item/item.stories.ts#L138

Added line #L138 was not covered by tests
render: (args) => ({
props: args,
template: /*html*/ `
Expand All @@ -158,6 +158,29 @@ export const TextOverflow: Story = {
}),
};

export const TextOverflowWrap: Story = {
render: (args) => ({

Check warning on line 162 in libs/components/src/item/item.stories.ts

View check run for this annotation

Codecov / codecov/patch

libs/components/src/item/item.stories.ts#L161-L162

Added lines #L161 - L162 were not covered by tests
props: args,
template: /*html*/ `
<bit-item>
<bit-item-content [truncate]="false">
<i slot="start" class="bwi bwi-globe tw-text-2xl tw-text-muted" aria-hidden="true"></i>
Helloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo!
<ng-container slot="secondary">Worlddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd!</ng-container>
</bit-item-content>
<ng-container slot="end">
<bit-item-action>
<button type="button" bitIconButton="bwi-clone" size="small"></button>
</bit-item-action>
<bit-item-action>
<button type="button" bitIconButton="bwi-ellipsis-v" size="small"></button>
</bit-item-action>
</ng-container>
</bit-item>
`,
}),
};

const multipleActionListTemplate = /*html*/ `
<bit-item-group aria-label="Multiple Action List">
<bit-item>
Expand Down

0 comments on commit e52f074

Please sign in to comment.