Skip to content

Commit

Permalink
fix: update readme (#10)
Browse files Browse the repository at this point in the history
* chore: update sample

* fix: update readme
  • Loading branch information
bobbyg603 authored Feb 18, 2023
1 parent 34b5da5 commit 5bc01a8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
47 changes: 34 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# NgxToggle
![cd](https://github.com/bobbyg603/ngx-toggle/actions/workflows/cd.yml/badge.svg)

A simple iOS style toggle switch for Angular projects.
A simple iOS style toggle switch for Angular projects.

## Installation
## 🏗️ Installation

Install `@bobbyg603/ngx-toggle`:

Expand All @@ -13,6 +14,7 @@ npm i @bobbyg603/ngx-toggle
Import the `NgxToggleModule` module in each module that uses `<ngx-toggle>`:

[app.module.ts](https://github.com/bobbyg603/ngx-toggle/blob/main/projects/ngx-toggle-example/src/app/app.module.ts)

```ts
import { NgxToggleModule } from '@bobbyg603/ngx-toggle';

Expand All @@ -30,23 +32,42 @@ import { NgxToggleModule } from '@bobbyg603/ngx-toggle';
export class AppModule { }
```

## Usage
## 🧑‍💻 Usage

Add `<ngx-toggle>` to your component's template:

[app.component.ts](https://github.com/bobbyg603/ngx-toggle/blob/139148ac2d6f18f69777835686fbfd44766d58d1/projects/ngx-toggle-example/src/app/app.component.html#L12)
```ts
[pricing.component.html](https://github.com/bobbyg603/ngx-toggle/blob/34b5da55ec9e5adf80bfa196cddb380c9d95314d/projects/ngx-toggle-example/src/app/pricing/pricing.component.html#L4-L6)

```html
<ngx-toggle
id="toggle-example"
[(checked)]="checked"
[disabled]="false"
(checkedChange)="onCheckedChanged($event)">
id="toggle-example"
[(checked)]="checked"
[disabled]="false"
(checkedChange)="onCheckedChange($event)">
</ngx-toggle>
```

Be sure to give each toggle a unique id. Failing to give each toggle a unique id will result in clicking one input toggling any inputs with a matching id.
Be sure to give each toggle a unique `id`. Failing to give each toggle a unique id will result in clicking one input toggling any inputs with a matching id.

You can also use `<ngx-toggle>` as a [FormControl](https://angular.io/api/forms/FormControl):

[checkout.component.html](https://github.com/bobbyg603/ngx-toggle/blob/1781fc109e1879c64c24bd82d249539911ec7587/projects/ngx-toggle-example/src/app/checkout/checkout.component.html#L71)

```html
<form [formGroup]="formGroup">
<ngx-toggle class="ms-auto" formControlName="saveForNextTime"></ngx-toggle>
</form>
```

[checkout.component.ts](https://github.com/bobbyg603/ngx-toggle/blob/1781fc109e1879c64c24bd82d249539911ec7587/projects/ngx-toggle-example/src/app/checkout/checkout.component.ts#L10-L19)
```ts
formGroup = new FormGroup({
saveForNextTime: new FormControl(false)
});
```


## API
## 🧩 API

### Inputs
| Property | Type | Description |
Expand All @@ -60,6 +81,6 @@ Be sure to give each toggle a unique id. Failing to give each toggle a unique id
|----------------|-------------------------|---------------------------------------------------------|
| checkedChange | EventEmitter\<boolean\> | Emits new `checked` value when control has been toggled |

## Attribution
## 🤝 Attribution

The `ngx-toggle-example` layout was inspired by Benjamin King's [Pricing Cards](https://codepen.io/bballinben/pen/wyLjvm) codepen.
The `ngx-toggle-example` layout was inspired by Benjamin King's [Pricing Cards](https://codepen.io/bballinben/pen/wyLjvm) codepen.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ <h4 class="mb-3">Billing address</h4>

<div class="col-12 d-flex">
<label class="form-check-label" for="save-info">Save this information for next time?</label>
<ngx-toggle class="ms-auto" formControlName="saveForNextTime"></ngx-toggle>
<ngx-toggle id="save-for-next-time" class="ms-auto" formControlName="saveForNextTime"></ngx-toggle>
</div>

<hr class="my-4">
Expand Down

0 comments on commit 5bc01a8

Please sign in to comment.