Skip to content

Commit 015e0ef

Browse files
committed
feat: add pause example
1 parent a738c16 commit 015e0ef

3 files changed

Lines changed: 54 additions & 1 deletion

File tree

dev/App.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,22 @@ import React, { useState } from 'react';
22
import './App.css';
33
import Typist from '../src';
44
import Header from './components/Header';
5+
import Section from './components/Section';
6+
import PauseExample from './components/PauseExample';
57

68
function App() {
79
const [count, setCount] = useState(0);
810
const [key, setKey] = useState(1);
911

1012
return (
11-
<div className='bg-slate-600 px-12 py-10 text-white '>
13+
<div className='min-h-screen bg-slate-600 px-12 py-10 text-white'>
1214
<Header />
15+
<Section title='Support Looping'>
16+
<Typist loop>
17+
The typing animation will be restarted automatically...
18+
</Typist>
19+
</Section>
20+
<PauseExample />
1321
<button onClick={() => setKey(key + 1)}>key</button>
1422
<button onClick={() => setCount(count + 1)}>{count}</button>
1523
<br />

dev/components/PauseExample.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React, { useState } from 'react';
2+
3+
import Typist from '../../src';
4+
import Section from './Section';
5+
6+
export default function PauseExample() {
7+
const [isPause, setIsPause] = useState(false);
8+
9+
console.log(isPause);
10+
11+
return (
12+
<Section title='Support Pausing'>
13+
<div className='mb-2 flex'>
14+
<label htmlFor='pause' className='mr-2'>
15+
pause
16+
</label>
17+
<input
18+
id='pause'
19+
type='checkbox'
20+
checked={isPause}
21+
onChange={(e) => setIsPause(e.currentTarget.checked)}
22+
/>
23+
</div>
24+
<Typist loop pause={isPause}>
25+
The typing animation will be paused if you check the input.
26+
</Typist>
27+
</Section>
28+
);
29+
}

dev/components/Section.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { ReactNode } from 'react';
2+
import React from 'react';
3+
4+
interface Props {
5+
title: string;
6+
children: ReactNode;
7+
}
8+
9+
export default function Section({ title, children }: Props) {
10+
return (
11+
<section className='py-8 px-4'>
12+
<h1 className='mb-4 text-2xl text-rose-400'>{title}</h1>
13+
{children}
14+
</section>
15+
);
16+
}

0 commit comments

Comments
 (0)