2
0
mirror of https://github.com/tenrok/maska.git synced 2026-06-05 16:42:28 +03:00
Files
maska/docs/v3/svelte.md
T
Alexander Shabunevich 488a52f760 feat: simple mode for mask directive
Allow string passing to set a mask without data-maska attribute
2024-06-12 17:52:55 +03:00

47 lines
1.1 KiB
Markdown

# Usage with Svelte
Maska provides simple Svelte action for use with input:
```html
<input use:maska={value}>
```
- `value` could be one of:
- `string` for the mask value (should be enclosed in additional quotation marks: `{'#-#'}`)
- `object` with a default options
## Minimal example
Apply `maska` action to the input:
```svelte
<script>
import { maska } from "maska/svelte"
</script>
<input use:maska={'#-#'}>
```
?> Please note that the mask value is enclosed in additional quotation marks: `"'#-#'"`.
## Set mask options
To set default [options](/options) for the mask, pass options via **directive value**:
```svelte
<script lang="ts">
import { maska } from "maska/svelte"
import type { MaskInputOptions } from "maska"
const options: MaskInputOptions = {
mask: "#-#",
eager: true
}
</script>
<input use:maska={options} data-maska-reversed>
```
You can override default options with `data-maska-` attributes on the input. In the example above we set **eager** mode using options and **reversed** mode using `data-maska-reversed` attribute.