-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Page Title): add new
bq-page-title
component (#1085)
- Loading branch information
Showing
9 changed files
with
445 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
packages/beeq/src/components/page-title/__tests__/bq-page-title.e2e.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { newE2EPage } from '@stencil/core/testing'; | ||
|
||
describe('bq-page-title', () => { | ||
it('should render', async () => { | ||
const page = await newE2EPage({ | ||
html: '<bq-page-title>Title</bq-page-title>', | ||
}); | ||
const element = await page.find('bq-page-title'); | ||
|
||
expect(element).toHaveClass('hydrated'); | ||
}); | ||
|
||
it('should have shadow root', async () => { | ||
const page = await newE2EPage({ | ||
html: '<bq-page-title>Title</bq-page-title>', | ||
}); | ||
const element = await page.find('bq-page-title'); | ||
|
||
expect(element.shadowRoot).not.toBeNull(); | ||
}); | ||
|
||
it('should render title + back navigation button', async () => { | ||
const page = await newE2EPage({ | ||
html: '<bq-page-title haveBackNavigation="true">Title</bq-page-title>', | ||
}); | ||
const backIcon = await page.find('bq-page-title >>> slot[name="back"]'); | ||
expect(backIcon).not.toBeNull(); | ||
}); | ||
|
||
it('should render title + action icons - suffix', async () => { | ||
const page = await newE2EPage({ | ||
html: ` | ||
<bq-page-title> | ||
Title | ||
<div slot="suffix"> | ||
<bq-icon name="start"></bq-icon> | ||
</div> | ||
</bq-page-title>`, | ||
}); | ||
const suffixSlot = await page.find('bq-page-title >>> slot[name="suffix"]'); | ||
expect(suffixSlot).not.toBeNull(); | ||
}); | ||
|
||
it('should render title + sub-title + divider', async () => { | ||
const page = await newE2EPage({ | ||
html: ` | ||
<bq-page-title> | ||
Title | ||
<div slot="sub-title"> | ||
Sub-title | ||
</div> | ||
<div slot="divider"> | ||
<bq-divider /> | ||
</div> | ||
</bq-page-title>`, | ||
}); | ||
const subTitleSlot = await page.find('bq-page-title >>> slot[name="sub-title"]'); | ||
expect(subTitleSlot).not.toBeNull(); | ||
|
||
const dividerSlot = await page.find('bq-page-title >>> slot[name="divider"]'); | ||
expect(dividerSlot).not.toBeNull(); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
packages/beeq/src/components/page-title/_storybook/bq-page-title.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ArgTypes, Title, Subtitle } from '@storybook/addon-docs'; | ||
|
||
<div className="bq-doc__wrapper" data-theme="light"> | ||
<div className="bq-doc__container"> | ||
<Title>Page title</Title> | ||
|
||
The Page Title component is a versatile and essential element used to display the main title of a page or section | ||
within an application. It often includes optional icons for actions like navigation or editing, and can be paired | ||
with a subtitle for additional context. | ||
|
||
<Subtitle>Usage</Subtitle> | ||
|
||
- Use the Page Title component to clearly indicate the primary title of a page or section within your application. | ||
- Use the Page Title component to provide contextual information by including a subtitle or additional icons. | ||
- Use the Page Title component to enhance navigation with an optional back icon for returning to the previous page. | ||
|
||
<Subtitle>👍 When to use</Subtitle> | ||
|
||
- When you need to display the main title of a page, such as a dashboard or a settings page. | ||
- When you want to provide clear and immediate understanding of the current page or section to the users. | ||
- When you need to enhance navigation by allowing users to go back to the previous page. | ||
- When you want to include actions that are relevant to the content, such as editing or downloading a document. | ||
|
||
<Title>Properties</Title> | ||
|
||
<ArgTypes of="bq-page-title" /> | ||
</div> | ||
</div> |
132 changes: 132 additions & 0 deletions
132
packages/beeq/src/components/page-title/_storybook/bq-page-title.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import type { Args, Meta, StoryObj } from '@storybook/web-components'; | ||
import { html, nothing } from 'lit-html'; | ||
|
||
import mdx from './bq-page-title.mdx'; | ||
|
||
const meta: Meta = { | ||
title: 'Components/Page title', | ||
component: 'bq-page-title', | ||
parameters: { | ||
docs: { | ||
page: mdx, | ||
}, | ||
}, | ||
argTypes: { | ||
// Not part of the component's API, so we don't want to expose it in the controls panel | ||
'have-back-navigation': { control: 'boolean', table: { disable: true } }, | ||
customDivider: { control: 'boolean', table: { disable: true } }, | ||
title: { control: 'text', table: { disable: true } }, | ||
'sub-title': { control: 'text', table: { disable: true } }, | ||
actions: { control: 'text', table: { disable: true } }, | ||
'custom-style': { control: 'boolean', table: { disable: true } }, | ||
}, | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj; | ||
|
||
const Template = (args: Args) => { | ||
const customDivider = args.customDivider | ||
? html`<bq-divider | ||
slot="divider" | ||
class="mb-m block" | ||
stroke-color="stroke--secondary" | ||
stroke-thickness="1" | ||
dashed | ||
/>` | ||
: nothing; | ||
|
||
const actionsSlotClass = args['custom-style'] ? 'flex flex-grow justify-end' : 'flex'; | ||
|
||
return html` | ||
<bq-page-title> | ||
${args['have-back-navigation'] | ||
? html` | ||
<bq-button appearance="link" slot="back"> | ||
<bq-icon | ||
color="text--primary" | ||
name="arrow-left" | ||
weight="bold" | ||
role="img" | ||
title="Navigate back to the previous page" | ||
></bq-icon> | ||
</bq-button> | ||
` | ||
: nothing} | ||
${args.title} ${args['sub-title'] ? html`<div slot="sub-title">${args['sub-title']}</div>` : nothing} | ||
${args.actions ? html`<div class="${actionsSlotClass}" slot="suffix">${args.actions}</div>` : nothing} | ||
${customDivider} | ||
</bq-page-title> | ||
`; | ||
}; | ||
|
||
export const Default: Story = { | ||
render: Template, | ||
args: { | ||
title: 'Title', | ||
}, | ||
}; | ||
|
||
export const TitleBack: Story = { | ||
name: 'Title + Back', | ||
render: Template, | ||
args: { | ||
'have-back-navigation': true, | ||
title: 'Title', | ||
}, | ||
}; | ||
|
||
export const TitleBackSubtitle: Story = { | ||
name: 'Title + Back + Subtitle', | ||
render: Template, | ||
args: { | ||
'have-back-navigation': true, | ||
title: 'Title', | ||
'sub-title': 'Sub-title', | ||
}, | ||
}; | ||
|
||
export const TitleBackActions: Story = { | ||
name: 'Custom - Title + Back + Subtitle + Actions', | ||
render: Template, | ||
args: { | ||
'have-back-navigation': true, | ||
title: 'Title', | ||
'sub-title': 'Sub-title', | ||
actions: html` | ||
<bq-icon class="p-xs2" color="text--brand" name="pencil-simple" weight="bold"></bq-icon> | ||
<bq-icon class="p-xs2" color="text--brand" name="download-simple" weight="bold"></bq-icon> | ||
`, | ||
'custom-style': true, | ||
}, | ||
}; | ||
|
||
export const TitleBackActionsCustomDefault: Story = { | ||
name: 'Default - Title + Back + Subtitle + Actions + Divider', | ||
render: Template, | ||
args: { | ||
'have-back-navigation': true, | ||
title: 'Title', | ||
'sub-title': 'Sub-title', | ||
actions: html` | ||
<bq-icon class="p-xs2" color="text--brand" name="pencil-simple" weight="bold"></bq-icon> | ||
<bq-icon class="p-xs2" color="text--brand" name="download-simple" weight="bold"></bq-icon> | ||
`, | ||
}, | ||
}; | ||
|
||
export const TitleBackActionsCustom: Story = { | ||
name: 'Custom - Title + Back + Subtitle + Actions + Divider', | ||
render: Template, | ||
args: { | ||
customDivider: true, | ||
'have-back-navigation': true, | ||
title: 'Title', | ||
'sub-title': 'Sub-title', | ||
actions: html` | ||
<bq-icon class="p-xs2" color="text--brand" name="pencil-simple" weight="bold"></bq-icon> | ||
<bq-icon class="p-xs2" color="text--brand" name="download-simple" weight="bold"></bq-icon> | ||
`, | ||
'custom-style': true, | ||
}, | ||
}; |
Oops, something went wrong.