Skip to content

Commit

Permalink
feat(Page Title): add new bq-page-title component (#1085)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cata1989 authored Jun 7, 2024
1 parent 2b2b329 commit cd9d767
Show file tree
Hide file tree
Showing 9 changed files with 445 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/beeq/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,8 @@ export namespace Components {
*/
"ariaLabel": string;
}
interface BqPageTitle {
}
interface BqPanel {
/**
* Represents the distance (gutter or margin) between the panel and the trigger element.
Expand Down Expand Up @@ -1910,6 +1912,12 @@ declare global {
prototype: HTMLBqOptionListElement;
new (): HTMLBqOptionListElement;
};
interface HTMLBqPageTitleElement extends Components.BqPageTitle, HTMLStencilElement {
}
var HTMLBqPageTitleElement: {
prototype: HTMLBqPageTitleElement;
new (): HTMLBqPageTitleElement;
};
interface HTMLBqPanelElement extends Components.BqPanel, HTMLStencilElement {
}
var HTMLBqPanelElement: {
Expand Down Expand Up @@ -2222,6 +2230,7 @@ declare global {
"bq-option": HTMLBqOptionElement;
"bq-option-group": HTMLBqOptionGroupElement;
"bq-option-list": HTMLBqOptionListElement;
"bq-page-title": HTMLBqPageTitleElement;
"bq-panel": HTMLBqPanelElement;
"bq-progress": HTMLBqProgressElement;
"bq-radio": HTMLBqRadioElement;
Expand Down Expand Up @@ -3117,6 +3126,8 @@ declare namespace LocalJSX {
*/
"onBqSelect"?: (event: BqOptionListCustomEvent<{ value: string; item: HTMLBqOptionElement }>) => void;
}
interface BqPageTitle {
}
interface BqPanel {
/**
* Represents the distance (gutter or margin) between the panel and the trigger element.
Expand Down Expand Up @@ -3877,6 +3888,7 @@ declare namespace LocalJSX {
"bq-option": BqOption;
"bq-option-group": BqOptionGroup;
"bq-option-list": BqOptionList;
"bq-page-title": BqPageTitle;
"bq-panel": BqPanel;
"bq-progress": BqProgress;
"bq-radio": BqRadio;
Expand Down Expand Up @@ -3930,6 +3942,7 @@ declare module "@stencil/core" {
"bq-option": LocalJSX.BqOption & JSXBase.HTMLAttributes<HTMLBqOptionElement>;
"bq-option-group": LocalJSX.BqOptionGroup & JSXBase.HTMLAttributes<HTMLBqOptionGroupElement>;
"bq-option-list": LocalJSX.BqOptionList & JSXBase.HTMLAttributes<HTMLBqOptionListElement>;
"bq-page-title": LocalJSX.BqPageTitle & JSXBase.HTMLAttributes<HTMLBqPageTitleElement>;
"bq-panel": LocalJSX.BqPanel & JSXBase.HTMLAttributes<HTMLBqPanelElement>;
"bq-progress": LocalJSX.BqProgress & JSXBase.HTMLAttributes<HTMLBqProgressElement>;
"bq-radio": LocalJSX.BqRadio & JSXBase.HTMLAttributes<HTMLBqRadioElement>;
Expand Down
2 changes: 2 additions & 0 deletions packages/beeq/src/components/divider/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@
### Used by

- [bq-drawer](../drawer)
- [bq-page-title](../page-title)
- [bq-steps](../steps)

### Graph
```mermaid
graph TD;
bq-drawer --> bq-divider
bq-page-title --> bq-divider
bq-steps --> bq-divider
style bq-divider fill:#f9f,stroke:#333,stroke-width:4px
```
Expand Down
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();
});
});
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>
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,
},
};
Loading

0 comments on commit cd9d767

Please sign in to comment.