Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: object details in page header can be styled #261

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ <h2 id='page-subheader' *ngIf="!!subheader">{{ subheader }}</h2>
<span
*ngIf="item.icon || item.value"
class="flex text-900 mt-2"
[ngClass]="item.icon ? 'gap-1 align-items-center' : null"
[ngClass]="generateItemStyle(item)"
[title]="item.tooltip || ''"
name="object-detail-value"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,25 @@ describe('PageHeaderComponent', () => {
expect(await fourthDetail?.getIcon()).toBeUndefined()
})

it('should use styles to render objectDetails in the page header', async () => {
const objectDetailsWithIcons: ObjectDetailItem[] = [
{
label: 'Venue',
value: 'AIE Munich',
valueCssClass: 'bg-green-400 text-white',
},
]
expect((await pageHeaderHarness.getObjectInfos()).length).toEqual(0)

component.objectDetails = objectDetailsWithIcons

expect((await pageHeaderHarness.getObjectInfos()).length).toEqual(1)
const firstDetail = await pageHeaderHarness.getObjectInfoByLabel('Venue')
const firstDetailStyles = await firstDetail?.getValueStyles()
expect(firstDetailStyles?.includes('bg-green-400')).toBeTruthy()
expect(firstDetailStyles?.includes('text-white')).toBeTruthy()
})

it('should show overflow actions when menu overflow button clicked', async () => {
component.actions = mockActions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ const objectDetailsWithIcons: ObjectDetailItem[] = [
{
label: 'I have no value',
},
{
label: 'Status with style',
value: 'Completed',
icon: PrimeIcons.CHECK_SQUARE,
valueCssClass: 'bg-green-400 text-white border-round-sm p-1',
},
]

export const WithObjectDetailsAndIcons = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface ObjectDetailItem {
labelPipe?: Type<any>
valuePipe?: Type<any>
valuePipeArgs?: string
valueCssClass?: string
}

export interface HomeItem {
Expand Down Expand Up @@ -172,6 +173,13 @@ export class PageHeaderComponent implements OnInit, OnChanges {
}
}

public generateItemStyle(item: ObjectDetailItem): string {
let style = ''
if (item.icon) style = style.concat(style, ' ', 'gap-1 align-items-center')
if (item.valueCssClass) style = style.concat(style, ' ', item.valueCssClass)
return style
}

/**
* Generates a list of actions that should be rendered in an overflow menu
*/
Expand Down
4 changes: 4 additions & 0 deletions libs/angular-accelerator/testing/page-header.harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ class ObjectDetailItemHarness extends ComponentHarness {
return (await this.getValueElement())?.text()
}

async getValueStyles() {
return (await this.getValueElement())?.getAttribute('class')
}

async getIcon() {
return (await this.getIconElement())?.getAttribute('class')
}
Expand Down
Loading