Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c99efc9
init
brianchristopherbrady May 30, 2024
21fc694
adds drawer exports
brianchristopherbrady May 30, 2024
3656271
yarn change
brianchristopherbrady May 30, 2024
601d3d0
refactors drawer animation to css only solution
brianchristopherbrady May 31, 2024
5cda5a3
adds drawer body
brianchristopherbrady May 31, 2024
9271838
updates drawer animation styles
brianchristopherbrady Jun 4, 2024
29a33d7
fixes attributes
brianchristopherbrady Jun 4, 2024
e58d3f0
adds drawer body to package json exports
brianchristopherbrady Jun 4, 2024
6917431
addresses PR feedback
brianchristopherbrady Jun 4, 2024
ff81c60
drawer: addresses feedback
brianchristopherbrady Jun 4, 2024
baee2f6
Update packages/web-components/src/drawer/drawer.spec.ts
brianchristopherbrady Jun 4, 2024
b36b6e0
updates readme
brianchristopherbrady Jun 4, 2024
a17bb47
updates tests
brianchristopherbrady Jun 5, 2024
3093bb3
drawer: updates tests
brianchristopherbrady Jun 5, 2024
f0cc64e
removes dead code
brianchristopherbrady Jun 5, 2024
bc2ae3e
merge
brianchristopherbrady Jun 11, 2024
0e04bc1
drawer: addresses feedback
brianchristopherbrady Jun 11, 2024
6ac2483
updates role attr
brianchristopherbrady Jun 11, 2024
e3e9694
sets nonModal drawer to open via dialog.show
brianchristopherbrady Jun 11, 2024
72fd346
drawer: style fix
brianchristopherbrady Jun 11, 2024
2f343f9
drawer: cleans up storybook, adjusts styles
brianchristopherbrady Jun 11, 2024
69694eb
Merge branch 'master' into user/brianbrady/addDrawerWebComponent
brianchristopherbrady Jun 12, 2024
0cacc13
Update packages/web-components/src/drawer-body/drawer-body.styles.ts
brianchristopherbrady Jun 13, 2024
6ab95a5
Merge branch 'master' into user/brianbrady/addDrawerWebComponent
brianchristopherbrady Jun 13, 2024
e14e09e
Merge branch 'master' into user/brianbrady/addDrawerWebComponent
brianchristopherbrady Jun 14, 2024
8bb7ced
Merge branch 'master' into user/brianbrady/addDrawerWebComponent
brianchristopherbrady Jun 17, 2024
f14dbe3
Merge branch 'master' into user/brianbrady/addDrawerWebComponent
brianchristopherbrady Jun 18, 2024
7644c4b
Merge branch 'master' into user/brianbrady/addDrawerWebComponent
brianchristopherbrady Jun 19, 2024
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
@@ -0,0 +1,7 @@
{
Comment thread
brianchristopherbrady marked this conversation as resolved.
"type": "prerelease",
"comment": "feat(drawer): add drawer web component",
"packageName": "@fluentui/web-components",
"email": "email not defined",
"dependentChangeType": "patch"
}
8 changes: 8 additions & 0 deletions packages/web-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@
"types": "./dist/dts/divider/define.d.ts",
"default": "./dist/esm/divider/define.js"
},
"./drawer.js": {
"types": "./dist/dts/drawer/define.d.ts",
"default": "./dist/esm/drawer/define.js"
},
"./drawer-body.js": {
"types": "./dist/dts/drawer-body/define.d.ts",
"default": "./dist/esm/drawer-body/define.js"
},
"./image.js": {
"types": "./dist/dts/image/define.d.ts",
"default": "./dist/esm/image/define.js"
Expand Down
49 changes: 49 additions & 0 deletions packages/web-components/src/drawer-body/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# DrawerBody

## Overview

The `DrawerBody` component is a part of the Fluent UI library and is intended to be used with the `fluent-drawer` component. It provides consumers with a structured template for the drawer's content, including areas for a header, content, and footer.

## Attributes

This component does not have specific attributes beyond standard HTML attributes.

## Methods

The `DrawerBody` component does not define custom methods beyond those inherited from `FASTElement`.

## Events

The `DrawerBody` component does not emit custom events beyond those standard to HTML elements.

### **Slots**

| Name | Description |
| -------- | ------------------------------------- |
| `title` | The slot for title |
| `close` | The slot for the close button |
| | The default slot for the main content |
| `footer` | The slot for the footer |

## CSS Parts

| Name | Description |
| --------- | ---------------------------------------------- |
| `header` | Styles the header section of the drawer. |
| `content` | Styles the main content section of the drawer. |
| `footer` | Styles the footer section of the drawer. |

## Usage Examples

### Basic Usage

```html
<fluent-drawer>
<fluent-drawer-body>
<div slot="title">Drawer Title</div>
<button slot="close">Close</button>
<div>Content goes here...</div>
<div slot="footer">Footer content</div>
</fluent-drawer-body>
</fluent-drawer>
```
4 changes: 4 additions & 0 deletions packages/web-components/src/drawer-body/define.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { FluentDesignSystem } from '../fluent-design-system.js';
import { definition } from './drawer-body.definition.js';

definition.define(FluentDesignSystem.registry);
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { FluentDesignSystem } from '../fluent-design-system.js';
import { DrawerBody } from './drawer-body.js';
import { styles } from './drawer-body.styles.js';
import { template } from './drawer-body.template.js';

/**
*
* @public
* @remarks
* HTML Element: <fluent-drawer>
*/

export const definition = DrawerBody.compose({
name: `${FluentDesignSystem.prefix}-drawer-body`,
template,
styles,
});
31 changes: 31 additions & 0 deletions packages/web-components/src/drawer-body/drawer-body.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { css } from '@microsoft/fast-element';
import { display } from '../utils/index.js';
import { spacingHorizontalM, spacingHorizontalXL } from '../theme/design-tokens.js';
import { typographySubtitle1Styles } from '../styles/partials/typography.partials.js';

/** Drawer styles
* @public
*/
export const styles = css`
${display('grid')}
:host {
box-sizing: border-box;
grid-template-rows: min-content auto min-content;
position: relative;
height: 100%;
padding: ${spacingHorizontalXL};
max-height: 100svh;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
${typographySubtitle1Styles}
}

.footer {
display: flex;
justify-content: flex-start;
gap: ${spacingHorizontalM};
}
`;
23 changes: 23 additions & 0 deletions packages/web-components/src/drawer-body/drawer-body.template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ElementViewTemplate, html } from '@microsoft/fast-element';
import type { DrawerBody } from './drawer-body.js';

/**
* The template for the Drawer component.
* @public
*/
export function drawerBodyTemplate<T extends DrawerBody>(): ElementViewTemplate<T> {
return html<T>`
<div class="header" part="header">
<slot name="title"></slot>
<slot name="close"></slot>
</div>
<div class="content" part="content">
<slot></slot>
</div>
<div class="footer" part="footer">
<slot name="footer"></slot>
</div>
`;
}

export const template: ElementViewTemplate<DrawerBody> = drawerBodyTemplate();
3 changes: 3 additions & 0 deletions packages/web-components/src/drawer-body/drawer-body.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { FASTElement } from '@microsoft/fast-element';

export class DrawerBody extends FASTElement {}
4 changes: 4 additions & 0 deletions packages/web-components/src/drawer-body/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './drawer-body.js';
export { definition as DrawerBodyDefinition } from './drawer-body.definition.js';
export { styles as DrawerBodyStyles } from './drawer-body.styles.js';
export { template as DrawerBodyTemplate } from './drawer-body.template.js';
111 changes: 111 additions & 0 deletions packages/web-components/src/drawer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Drawer

The `Drawer` component represents a drawer that can be opened and closed, typically used for navigation or additional content.

## Design Spec

Link to Drawer Design Spec in Figma: [Link](<https://www.figma.com/file/V2sDk36xZfp8tFhb53DfsT/Drawer-(Overlay-%26-Inline)?type=design&viewport=2606%2C1404%2C0.23&t=iNWjZIpDljA1EshA-0>)

## Engineering Spec

The Fluent WC3 Drawer extends `FASTElement`

### Class `Drawer`

### Template

```ts
export function drawerTemplate<T extends Drawer>(): ElementViewTemplate<T> {
return html<T>`
<dialog
class="dialog"
part="dialog"
role="${x => (x.type === 'modal' ? 'dialog' : void 0)}"
aria-modal="${x => (x.type === 'modal' ? 'true' : void 0)}"
aria-describedby="${x => x.ariaDescribedby}"
aria-labelledby="${x => x.ariaLabelledby}"
aria-label="${x => x.ariaLabel}"
size="${x => x.size}"
position="${x => x.position}"
type="${x => x.type}"
@click="${(x, c) => x.clickHandler(c.event as MouseEvent)}"
@cancel="${(x, c) => x.hide()}"
${ref('dialog')}
>
<slot></slot>
</dialog>
`;
}
```

### **Variables**

| Name | Type | Description |
| ---------------- | ------------------------------- | ---------------------- |
| `DrawerPosition` | `start` `end` | Positions for Drawer |
| `DrawerSize` | `small` `medium` `large` `full` | Sizes for Drawer |
| `DrawerType` | `modal` `non-modal` `inline` | Modal types for Drawer |

### **Attributes**

| Name | Privacy | Type | Description |
| ----------------- | ------- | -------------- | ----------------------------------------------------------------------------------------- |
| `type` | public | DrawerType | Determines whether the drawer should be displayed as a modal, non-modal or inline drawer. |
| `position` | public | DrawerPosition | Sets the position of the drawer (start/end). |
| `size` | public | DrawerSize | Sets the size of the drawer (small/medium/large). |
| `ariaDescribedby` | public | string | The ID of the element that describes the drawer. |
| `ariaLabelledby` | public | string | The ID of the element that labels the drawer. |

### **Events**

| Name | Type | Description |
| -------------- | ------------- | -------------------------------------------- |
| `toggle` | `CustomEvent` | Fires after the dialog's open state changes |
| `beforetoggle` | `CustomEvent` | Fires before the dialog's open state changes |

### **Methods**

| Name | Privacy | Description |
| ------------------ | ------- | --------------------------------------------------------------- |
| `show` | public | Shows the drawer. |
| `hide` | public | Hides the drawer. |
| `emitToggle` | public | Method to emit an event after the dialog's open state changes. |
| `emitBeforeToggle` | public | Method to emit an event before the dialog's open state changes. |
| `clickHandler` | public | Handles click events on the drawer. |
| `keydownHandler` | public | Handles keydown events on the drawer. |

### **Slots**

| Name | Description |
| ---- | ------------------------------------- |
| | The default slot for the main content |

### **CSS Variables**

| Name | Description |
| ---------------- | ----------------------------------- |
| `--drawer-width` | Used to set the width of the drawer |

## **Accessiblity**

### **WAI-ARIA Roles, States, and Properties**

| Name | Privacy | Type | Description |
| ------------------ | ------- | ------------------- | ---------------------------------------------------------------------------- |
| `role` | public | string | Sets the role of the dialog element to dialog when modal dialog is rendered. |
| `aria-modal` | public | string or undefined | Indicates if the drawer is modal. |
| `aria-describedby` | public | string | The ID of the element that describes the drawer. |
| `aria-labelledby` | public | string | The ID of the element that labels the drawer. |
| `aria-label` | public | string | Provides an accessible name for the drawer when aria-labelledby is not used. |

### **Fluent Web Component v3 v.s Fluent React 9**

<br />

**Component and Slot Mapping**

| Fluent UI React 9 | Fluent Web Components 3 |
| ----------------- | ----------------------- |
| `<DrawerOverlay>` | `type="modal"` |
| `<DrawerInline>` | `type="inline"` |
| `<DrawerBody> ` | `<drawer-body>` |
4 changes: 4 additions & 0 deletions packages/web-components/src/drawer/define.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { FluentDesignSystem } from '../fluent-design-system.js';
import { definition } from './drawer.definition.js';

definition.define(FluentDesignSystem.registry);
17 changes: 17 additions & 0 deletions packages/web-components/src/drawer/drawer.definition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { FluentDesignSystem } from '../fluent-design-system.js';
import { Drawer } from './drawer.js';
import { styles } from './drawer.styles.js';
import { template } from './drawer.template.js';

/**
*
* @public
* @remarks
* HTML Element: <fluent-drawer>
*/

export const definition = Drawer.compose({
name: `${FluentDesignSystem.prefix}-drawer`,
template,
styles,
});
46 changes: 46 additions & 0 deletions packages/web-components/src/drawer/drawer.options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { ValuesOf } from '../utils/index.js';

/**
* A drawer can be positioned on the left or right side of the viewport.
*/
export const DrawerPosition = {
start: 'start',
end: 'end',
} as const;

/**
* The position of the drawer.
* @public
*/
export type DrawerPosition = ValuesOf<typeof DrawerPosition>;

/**
* A drawer can be different sizes
*/
export const DrawerSize = {
small: 'small',
medium: 'medium',
large: 'large',
full: 'full',
} as const;

/**
* The size of the drawer.
* @public
*/
export type DrawerSize = ValuesOf<typeof DrawerSize>;

/**
* A drawer can be different sizes
*/
export const DrawerType = {
nonModal: 'non-modal',
modal: 'modal',
inline: 'inline',
} as const;

/**
* The size of the drawer.
* @public
*/
export type DrawerType = ValuesOf<typeof DrawerType>;
Loading