# @matthewp/if-else

> A __716 byte__ custom element to conditionally render a template.

Latest version **1.0.1** (published 2019-01-26) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install @matthewp/if-else
pnpm add @matthewp/if-else
yarn add @matthewp/if-else
bun add @matthewp/if-else
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-01-26 |
| First published | 2019-01-26 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Author | Matthew Phillips |
| Maintainers | matthewp |

## Links

- npm: https://www.npmjs.com/package/@matthewp/if-else
- Repository: https://github.com/matthewp/if-else
- Issues: https://github.com/matthewp/if-else/issues
- npm.io page: https://npm.io/package/@matthewp/if-else

## Recent versions

- 1.0.1 (latest) — 2019-01-26
- 1.0.0 — 2019-01-26

## README

# &lt;if-else&gt;

A __716 byte__ custom element to conditionally render a template.

```html
<if-else>
  <template slot="if">
    <div>Woo hoo!</div>
  </template>
</if-else>

<script type="module">
  import "https://unpkg.com/@matthewp/if-else/index.js";

  document.querySelector('if-else').value = true;

  // Content is now shown!
</script>
```

## Install

Install with [npm](https://www.npmjs.com/package/@matthewp/if-else)

```shell
npm install @matthewp/if-else
```

Or [Yarn](https://yarnpkg.com/en/package/@matthewp/if-else)

```shell
yarn add @matthewp/if-else
```

## Usage

`<if-else>` is an element. It has an attribute `true` that when set, shows the slot named `if`. This works like so:

```html
<if-else true>
  <template slot="if">This will be shown</template>
</if-else>
```

The children of `if-else` must be template elements.

If you would like to show an `else` condition provide a slot for `else`:


```html
<if-else>
  <template slot="if">This is NOT shown</template>
  <template slot="else">This is shown because no true attribute</template>
</if-else>
```

*Also* there is a `value` property. It is set to `true` when the condition is true and set to `false` when the condition is false.

Just remember:

* __true__: Renders the `if` slot.
* __false__: Renders the `else` slot.

## License

BSD-2-Clause

---
_Source: https://npm.io/package/@matthewp/if-else · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
