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(sheet): Add Sheet component #7561

Merged
merged 32 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f860608
feat(sheet): Add Sheet component. #6391
driskull Aug 11, 2023
73e3f08
WIP
driskull Aug 22, 2023
2478913
cleanup
driskull Aug 22, 2023
1c00f2a
cleanup
driskull Aug 22, 2023
cb90f65
docs, demos, cleanup
driskull Aug 22, 2023
de30b9e
cleanup
driskull Aug 22, 2023
c6239ef
WIP
driskull Aug 22, 2023
97af598
cleanup
driskull Aug 22, 2023
8df0829
cleanup
driskull Aug 22, 2023
37a20ba
cleanup
driskull Aug 22, 2023
c9c3545
cleanup
driskull Aug 22, 2023
0dea3a0
cleanup examples
driskull Aug 22, 2023
00e7d63
Merge branch 'main' into dris0000/sheet
driskull Aug 22, 2023
fb7f9e8
cleanup
driskull Aug 23, 2023
25fd3af
wip - Add animation and height / width
macandcheese Aug 23, 2023
fb9c311
Merge branch 'main' into dris0000/sheet
driskull Aug 23, 2023
adf1d77
Merge branch 'macandcheese/sheet-animation' into dris0000/sheet
macandcheese Aug 24, 2023
3db2b55
fix tests
driskull Aug 24, 2023
d1cf0cb
fix test
driskull Aug 24, 2023
7574ff5
cleanup + add CSS rtl util class
driskull Aug 24, 2023
f1baa65
test + bg color restore
driskull Aug 24, 2023
89b9210
cleanup
driskull Aug 24, 2023
6ac3516
cleanup beforeClose
driskull Aug 24, 2023
718a94f
test
driskull Aug 24, 2023
0f1f80b
fix test
driskull Aug 24, 2023
f36cea4
beforeClose fixes
driskull Aug 25, 2023
5c960cb
review fixes
driskull Aug 25, 2023
b886d0b
partial review fixes
driskull Aug 28, 2023
7895b45
review fixes
driskull Aug 28, 2023
c04e3e7
put back some host styles.
driskull Aug 28, 2023
aead538
fix border radius
driskull Aug 28, 2023
698638a
consistency
driskull Aug 28, 2023
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 @@
export type DisplayMode = "float" | "overlay";
142 changes: 142 additions & 0 deletions packages/calcite-components/src/components/sheet/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# calcite-sheet

<!-- Auto Generated Below -->

## Usage

### Basic

```html
<calcite-sheet open label="libero nunc" position="inline-start">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</calcite-sheet>
```

### Open

To open a sheet, add the `open` prop. Once the opening animation is complete, the `calciteSheetOpen` event will be fired.

To close the sheet, simply remove the attribute. This will run your before close method (if provided, see below) and fire the `calciteSheetClose` event after the animation and teardown is complete.

```html
<calcite-sheet open
>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
dolore</calcite-sheet
>
```

### Panel

```html
<calcite-sheet open label="libero nunc" position="inline-start">
<calcite-panel closable heading="Ultrices neque"
><p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<calcite-button slot="footer" width="half" appearance="outline">tincidunt lobortis</calcite-button>
<calcite-button slot="footer" width="half" appearance="outline">amet porttitor</calcite-button>
</calcite-panel>
<script>
document.addEventListener("calcitePanelClose", () => {
document.querySelector("calcite-sheet").open = false;
});
</script>
</calcite-sheet>
```

### Reacting-before-close

If you'd like to perform some actions prior to closing (ie. warning users they will lose their changes) you can pass a function to the `beforeClose` property. This method will be called prior to close and should return a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise):

```js
function beforeClose() {
return new Promise((resolve) => {
// do something async
resolve(); // this will trigger the close animation
});
}

const sheet = document.getElementById("my-sheet");
sheet.beforeClose = beforeClose;
```

## Properties

| Property | Attribute | Description | Type | Default |
| ---------------------- | ------------------------ | --------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- | ---------------- |
| `beforeClose` | -- | Passes a function to run before the component closes. | `(el: HTMLCalciteSheetElement) => Promise<void>` | `undefined` |
| `displayMode` | `display-mode` | Specifies the display mode - `"float"` (content is separated detached), or `"overlay"` (displays on top of center content). | `"float" \| "overlay"` | `"overlay"` |
| `escapeDisabled` | `escape-disabled` | When `true`, disables the default close on escape behavior. | `boolean` | `false` |
| `focusTrapDisabled` | `focus-trap-disabled` | When `true`, prevents focus trapping. | `boolean` | `false` |
| `heightScale` | `height-scale` | When `position` is `"block-start"` or `"block-end"`, specifies the height of the component. | `"l" \| "m" \| "s"` | `"m"` |
| `label` _(required)_ | `label` | Specifies the label of the component. | `string` | `undefined` |
| `open` | `open` | When `true`, displays and positions the component. | `boolean` | `false` |
| `outsideCloseDisabled` | `outside-close-disabled` | When `true`, disables the closing of the component when clicked outside. | `boolean` | `false` |
| `position` | `position` | When `true`, disables the closing of the component when clicked outside. | `"block-end" \| "block-start" \| "inline-end" \| "inline-start"` | `"inline-start"` |
| `widthScale` | `width-scale` | When `position` is `"inline-start"` or `"inline-end"`, specifies the width of the component. | `"l" \| "m" \| "s"` | `"m"` |

## Events

| Event | Description | Type |
| ------------------------- | -------------------------------------------------------------------------------------------------------- | ------------------- |
| `calciteSheetBeforeClose` | Fires when the component is requested to be closed and before the closing transition begins. | `CustomEvent<void>` |
| `calciteSheetBeforeOpen` | Fires when the component is added to the DOM but not rendered, and before the opening transition begins. | `CustomEvent<void>` |
| `calciteSheetClose` | Fires when the component is closed and animation is complete. | `CustomEvent<void>` |
| `calciteSheetOpen` | Fires when the component is open and animation is complete. | `CustomEvent<void>` |

## Methods

### `setFocus() => Promise<void>`

Sets focus on the component's "close" button (the first focusable item).

#### Returns

Type: `Promise<void>`

### `updateFocusTrapElements() => Promise<void>`

Updates the element(s) that are used within the focus-trap of the component.

#### Returns

Type: `Promise<void>`

## CSS Custom Properties

| Name | Description |
| ---------------------------------- | ---------------------------------------------------------------------------------------------------- |
| `--calcite-sheet-height` | When `position` is `"block-start"` or `"block-end"`, specifies the height of the component. |
| `--calcite-sheet-max-height` | When `position` is `"block-start"` or `"block-end"`, specifies the maximum height of the component. |
| `--calcite-sheet-max-width` | When `position` is `"inline-start"` or `"inline-end"`, specifies the maximum width of the component. |
| `--calcite-sheet-min-height` | When `position` is `"block-start"` or `"block-end"`, specifies the minimum height of the component. |
| `--calcite-sheet-min-width` | When `position` is `"inline-start"` or `"inline-end"`, specifies the minimum width of the component. |
| `--calcite-sheet-scrim-background` | Specifies the background color of the sheet scrim. |
| `--calcite-sheet-width` | When `position` is `"inline-start"` or `"inline-end"`, specifies the width of the component. |

## Dependencies

### Depends on

- [calcite-scrim](../scrim)

### Graph

```mermaid
graph TD;
calcite-sheet --> calcite-scrim
calcite-scrim --> calcite-loader
style calcite-sheet fill:#f9f,stroke:#333,stroke-width:4px
```

---

_Built with [StencilJS](https://stenciljs.com/)_
7 changes: 7 additions & 0 deletions packages/calcite-components/src/components/sheet/resources.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const CSS = {
scrim: "scrim",
container: "container",
containerOpen: "container--open",
content: "content",
containerSlottedInShell: "container--slotted-in-shell",
};
Loading