0.1.3 • Published 4 years ago

@loscrackitos/svelte-typed-js v0.1.3

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

svelte-typed-js

npm npm

Svelte Typed.js component

Typed.js is a library that types. Enter in any string, and watch it type at the speed you've set, backspace what it's typed, and begin a new sentence for however many strings you've set.

Checkout the official project here.

Table of contents

Installation

npm i -D @loscrackitos/svelte-typed-js

Default import

Import the component:

import TypedJs from '@loscrackitos/svelte-typed-js';

Usage

Import the TypedJs component inside your Svelte template and set the sentences that needs to be typed inside the strings props.

Simplest usage:

<TypedJs strings="['Hello John', 'Hello Martin']">
  <h1 class="typing"></h1>
</TypedJs>

typing class also allows you to just animate certain parts of a string:

<TypedJs strings="['John', 'Martin']">
  <h1>👋 <span class="typing"></span></h1>
</TypedJs>

Props

PropertyTypeDescriptionUsage
stringsArraystrings to be typedstrings="{['Text 1', 'Text 2']}"
stringsElementStringID of element containing string childrenstringsElement="myId"
typeSpeedNumbertype speed in millisecondstypeSpeed={50}
startDelayNumbertime before typing starts in millisecondsstartDelay={1000}
backSpeedNumberbackspacing speed in millisecondsbackSpeed={10}
smartBackspaceBooleanonly backspace what doesn't match the previous stringsmartBackspace={true}
shuffleBooleanshuffle the stringsshuffle={true}
backDelayNumbertime before backspacing in millisecondsbackDelay={100}
fadeOutBooleanFade out instead of backspacefadeOut={true}
fadeOutClassStringcss class for fade animationfadeOutClass="fadeOutClass"
fadeOutDelayNumberfade out delay in millisecondsfadeOutDelay={500}
loopBooleanloop stringsloop={true}
loopCountNumberamount of loopsloopCount={3}
showCursorBooleanshow cursorshowCursor={true}
cursorCharStringcharacter for cursorcursorChar="_"
autoInsertCssBooleaninsert CSS for cursor and fadeOut into HTMLautoInsertCss={true}
attrStringattribute for typing Ex: input placeholder, value, or just HTML textattr="placeholder"
bindInputFocusEventsBooleanbind to focus and blur if el is text inputbindInputFocusEvents={true}
contentTypeString'html' or 'null' for plaintextcontentType="html"

Events

Available events:

EventDescriptionUsage
onCompleteAll typing is completeon:complete={handler}
preStringTypedBefore each string is typedon:preStringTyped={handler}
onStringTypedAfter each string is typedon:stringTyped={handler}
onLastStringBackspacedDuring looping, after last string is typedon:lastStringBackspaced={handler}
onTypingPausedTyping has been stoppedon:typingPaused={handler}
onTypingResumedTyping has been started after being stoppedon:typingResumed={handler}
onResetAfter reseton:reset={handler}
onStopAfter stopon:stop={handler}
onStartAfter starton:start={handler}
onDestroyAfter destroyon:destroy={handler}

Features

Find every features documentation on the main library page.

Examples

Here are several examples:

<!-- infinite loop -->
<TypedJs
  strings="{['awesome', 'brilliant']}"
  loop="{true}"
  on:complete="{handle}"
>
  <p>We are a <span class="typing"></span> company!</p>
</TypedJs>

<!-- type with some pause -->
<TypedJs
  strings="{['This is text ^1000 which gets paused for 1 second', 'wow, interesting']}"
>
  <p class="typing"></p>
</TypedJs>

<!-- render html from strings -->
<TypedJs
  strings="{['<p>Paragraph</p>', '<span>Span</span>']}"
  contentType="html"
>
  <p class="typing"></p>
</TypedJs>
0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago