Skip to content

Commit

Permalink
[CL-458] Exclude badges from truncation and vertically center content (
Browse files Browse the repository at this point in the history
  • Loading branch information
vleague2 authored Sep 30, 2024
1 parent a6b9088 commit b149db9
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<bit-item>
<button bit-item-content type="button" (click)="openAttachments()">
<p class="tw-m-0">
{{ "attachments" | i18n }}
<span *ngIf="!canAccessAttachments" bitBadge variant="success" class="tw-ml-2">
{{ "premium" | i18n }}
</span>
</p>
{{ "attachments" | i18n }}
<span *ngIf="!canAccessAttachments" bitBadge variant="success" slot="default-trailing">
{{ "premium" | i18n }}
</span>
<ng-container slot="end">
<i class="bwi bwi-popout" aria-hidden="true" *ngIf="openAttachmentsInPopout"></i>
<i class="bwi bwi-angle-right" aria-hidden="true" *ngIf="!openAttachmentsInPopout"></i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
>
<bit-item slot="attachment-button">
<button bit-item-content type="button" (click)="openAttachmentsDialog()">
<p class="tw-m-0">
{{ "attachments" | i18n }}
<span *ngIf="!canAccessAttachments" bitBadge variant="success" class="tw-ml-2">
{{ "premium" | i18n }}
</span>
</p>
{{ "attachments" | i18n }}
<span *ngIf="!canAccessAttachments" bitBadge variant="success" slot="default-trailing">
{{ "premium" | i18n }}
</span>
<i slot="end" class="bwi bwi-angle-right" aria-hidden="true"></i>
</button>
</bit-item>
Expand Down
12 changes: 10 additions & 2 deletions libs/components/src/item/item-content.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@
<ng-content select="[slot=start]"></ng-content>

<div class="tw-flex tw-flex-col tw-items-start tw-text-start tw-w-full tw-truncate [&_p]:tw-mb-0">
<div class="tw-text-main tw-text-base tw-w-full tw-truncate">
<ng-content></ng-content>
<div
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">
<ng-content></ng-content>
</div>
<div class="tw-flex-grow">
<ng-content select="[slot=default-trailing]"></ng-content>
</div>
</div>
<div class="tw-text-muted tw-text-sm tw-w-full tw-truncate">
<ng-content select="[slot=secondary]"></ng-content>
Expand Down
14 changes: 8 additions & 6 deletions libs/components/src/item/item.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ The content can be a button, anchor, or static container.

`bit-item-content` contains the following slots to help position the content:

| Slot | Description |
| ------------------ | --------------------------------------------------- |
| default | primary text or arbitrary content; fan favorite |
| `slot="secondary"` | supporting text; under the default slot |
| `slot="start"` | commonly an icon or avatar; before the default slot |
| `slot="end"` | commonly an icon; after the default slot |
| Slot | Description |
| ------------------------- | --------------------------------------------------------------------------------------------------------- |
| default | primary text or arbitrary content; fan favorite |
| `slot="secondary"` | supporting text; under the default slot |
| `slot="start"` | commonly an icon or avatar; before the default slot |
| `slot="default-trailing"` | commonly a badge; default content that should not be truncated and is placed right after the default slot |
| `slot="end"` | commonly an icon; placed at the far end after the default slot |

- Note: There is also an `end` slot within `bit-item` itself. Place
[interactive secondary actions](#secondary-actions) there, and place non-interactive content (such
Expand All @@ -71,6 +72,7 @@ The content can be a button, anchor, or static container.
<button bit-item-content type="button">
<bit-avatar slot="start" text="Foo"></bit-avatar>
[email protected]
<span bitBadge variant="primary" slot="default-trailing">Auto-fill</span>
<ng-container slot="secondary">
<div>Bitwarden.com</div>
<div><em>locked</em></div>
Expand Down
26 changes: 25 additions & 1 deletion libs/components/src/item/item.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,38 @@ export const SingleActionList: Story = {
}),
};

export const SingleActionWithBadge: Story = {
render: (args) => ({
props: args,
template: /*html*/ `
<bit-item-group aria-label="Single Action With Badge">
<bit-item>
<a bit-item-content href="#">
Foobar
<span bitBadge variant="primary" slot="default-trailing">Auto-fill</span>
<i slot="end" class="bwi bwi-angle-right" aria-hidden="true"></i>
</a>
</bit-item>
<bit-item>
<a bit-item-content href="#">
Helloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo!
<span bitBadge variant="primary" slot="default-trailing">Auto-fill</span>
<i slot="end" class="bwi bwi-angle-right" aria-hidden="true"></i>
</a>
</bit-item>
</bit-item-group>
`,
}),
};

export const VirtualScrolling: Story = {
render: (_args) => ({
props: {
data: Array.from(Array(100000).keys()),
},
template: /*html*/ `
<cdk-virtual-scroll-viewport [itemSize]="46" class="tw-h-[500px]">
<bit-item-group aria-label="Single Action List">
<bit-item-group aria-label="Virtual Scrolling">
<bit-item *cdkVirtualFor="let item of data">
<button bit-item-content>
<i slot="start" class="bwi bwi-globe tw-text-3xl tw-text-muted" aria-hidden="true"></i>
Expand Down

0 comments on commit b149db9

Please sign in to comment.