# swipe-bottom-sheet

> [Demo](https://joeflateau.github.io/typescript-bottom-sheet/)

Latest version **0.2.14** (published 2022-02-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install swipe-bottom-sheet
pnpm add swipe-bottom-sheet
yarn add swipe-bottom-sheet
bun add swipe-bottom-sheet
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.14 |
| Published | 2022-02-26 |
| First published | 2019-06-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 61.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Maintainers | joeflateau |

## Links

- npm: https://www.npmjs.com/package/swipe-bottom-sheet
- Repository: https://github.com/joeflateau/typescript-bottom-sheet
- Homepage: https://github.com/joeflateau/typescript-bottom-sheet#readme
- Issues: https://github.com/joeflateau/typescript-bottom-sheet/issues
- npm.io page: https://npm.io/package/swipe-bottom-sheet

## Recent versions

- 0.2.14 (latest) — 2022-02-26
- 0.2.13 — 2022-01-14
- 0.2.12 — 2022-01-14
- 0.2.11 — 2022-01-14
- 0.2.10 — 2022-01-13
- 0.2.9 — 2022-01-13
- 0.2.8 — 2022-01-13
- 0.2.7 — 2022-01-13
- 0.2.6 — 2022-01-13
- 0.2.5 — 2021-09-28
- 0.2.4 — 2021-09-06
- 0.2.3 — 2021-08-04
- 0.2.2 — 2021-08-04
- 0.2.1 — 2021-08-04
- 0.2.0 — 2021-08-04
- … 35 more at https://npm.io/package/swipe-bottom-sheet/versions

## README

# swipe-bottom-sheet

[Demo](https://joeflateau.github.io/typescript-bottom-sheet/)
[Stackblitz](https://stackblitz.com/edit/angular-swipe-bottom-sheet)

## Usage in Angular

### TLDR:

- Install from npm
- Inject the module into app module
- Import the scss
- Set the root view container ref to the app component's view container
- Open sheets


### Install from npm

```
npm i swipe-bottom-sheet
```

### Import the `BottomSheetModule` into your app module

```typescript
import { BottomSheetModule } from "swipe-bottom-sheet/angular";

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, BottomSheetModule],
  providers: [],
  bootstrap: [AppComponent],
  entryComponents: []
})
export class AppModule {}
```

### Import the module's scss

```scss
@import "~swipe-bottom-sheet/style.scss";
```

### Inject the `BrowserSheetProvider` into your app component and set the bottomSheet's `rootVcRef` property

```typescript
import { BottomSheetProvider } from "swipe-bottom-sheet/angular";

@Component({
  selector: "app-root",
  templateUrl: "app.html"
})
export class AppComponent {
  constructor(
    private bottomSheet: BottomSheetProvider,
    vcRef: ViewContainerRef
  ) {
    // only set this once and do so in the app component's constructor
    bottomSheet.rootVcRef = vcRef;
  }
}
```

### Open a bottom sheet using a TemplateRef

```typescript
import { BottomSheetProvider } from "swipe-bottom-sheet/angular";

@Component({
  selector: "app-component",
  templateUrl: "component.html"
})
export class MyComponent {
  constructor(private bottomSheet: BottomSheetProvider) {}

  async openSheet<T>(content: TemplateRef<T>) {
    const value = await this.bottomSheet.show(content, {
      title: "Sheet Title",
      stops: [270]
    });
    console.log({ value });
  }
}
```

```html
<button type="button" (click)="openSheet(sheetTemplate)">
  Open Template
</button>

<ng-template #sheetTemplate let-context>
  <ul class="sheet-list">
    <li class="sheet-list-item" (click)="context.dismiss('value')">
      Dismiss with value
    </li>
  </ul>
</ng-template>
```

### Open a bottom sheet using a Component

#### Write the Component

Have `BottomSheetContext` injected and use that to control the sheet

```typescript
import { BottomSheetContext } from "swipe-bottom-sheet/angular";

@Component({
  selector: "app-example-component",
  template: `
    <ul class="sheet-list">
      <li
        class="sheet-list-item"
        (click)="context.dismiss('dismissed with value from component')"
      >
        Dismiss with value
      </li>
    </ul>
  `
})
export class ExampleComponent {
  constructor(public context: BottomSheetContext) {}
}
```

#### Open the sheet with a reference to your component

```html
<button type="button" (click)="openSheet()">
  Open Component
</button>
```

```typescript
import { BottomSheetProvider } from "swipe-bottom-sheet/angular";
import { ExampleComponent } from "./example-sheet-component";

@Component({
  selector: "app-component",
  templateUrl: "component.html",
  styles: []
})
export class MyComponent {
  constructor(private bottomSheet: BottomSheetProvider) {}

  async openSheet<T>() {
    const value = await this.bottomSheet.show(ExampleComponent, {
      title: "Sheet Title",
      stops: [270]
    });
    console.log({ value });
  }
}
```

---
_Source: https://npm.io/package/swipe-bottom-sheet · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
