Skip to content

Commit

Permalink
feat: object details in page header can be styled (#261)
Browse files Browse the repository at this point in the history
* feat: object details for page header can be styled

* feat: object detail styles test
  • Loading branch information
markuczy authored May 28, 2024
1 parent 6d6b9c6 commit ae72fc7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
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

0 comments on commit ae72fc7

Please sign in to comment.