Skip to content

Commit f383f50

Browse files
committed
chore: add tailwindcss for website
1 parent a6514b1 commit f383f50

8 files changed

Lines changed: 222 additions & 72 deletions

File tree

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
"eslint-plugin-react": "^7.31.8",
2929
"eslint-plugin-react-hooks": "^4.6.0",
3030
"jest": "^29.0.3",
31-
"prettier": "^2.7.1",
32-
"prettier-plugin-tailwindcss": "^0.1.13",
3331
"typescript": "^4.8.3"
3432
},
3533
"config": {

pnpm-lock.yaml

Lines changed: 8 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/contents/docs/react-typist-component.mdx

Lines changed: 191 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,194 @@ title: react-typist-component
44

55
# React Typist Component
66

7-
Ullamco et nostrud magna commodo nostrud occaecat quis pariatur id ipsum. Ipsum
8-
consequat enim id excepteur consequat nostrud esse esse fugiat dolore.
9-
Reprehenderit occaecat exercitation non cupidatat in eiusmod laborum ex eu
10-
fugiat aute culpa pariatur. Irure elit proident consequat veniam minim ipsum ex
11-
pariatur.
12-
13-
Mollit nisi cillum exercitation minim officia velit laborum non Lorem
14-
adipisicing dolore. Labore commodo consectetur commodo velit adipisicing irure
15-
dolore dolor reprehenderit aliquip. Reprehenderit cillum mollit eiusmod
16-
excepteur elit ipsum aute pariatur in. Cupidatat ex culpa velit culpa ad non
17-
labore exercitation irure laborum.
7+
Create typewriter effect by setting up a component's children directly.
8+
9+
## Install
10+
11+
```bash
12+
npm install react-typist-component
13+
# or
14+
yarn add react-typist-component
15+
```
16+
17+
## Example
18+
19+
```jsx
20+
import Typist from 'react-typist-component';
21+
22+
const MyComponent = () => {
23+
return (
24+
<Typist typingDelay={100} cursor={<span className='cursor'>|</span>}>
25+
This is a typo
26+
<br />
27+
<Typist.Backspace count={5} />
28+
<Typist.Delay ms={1500} />
29+
react component
30+
<Typist.Paste>
31+
<div>
32+
use
33+
<div>deeper div</div>
34+
</div>
35+
</Typist.Paste>
36+
</Typist>
37+
);
38+
};
39+
```
40+
41+
## API reference
42+
43+
### `Typist`
44+
45+
```ts
46+
export type Delay = number | (() => number);
47+
export type Splitter = (str: string) => string[];
48+
export type TypistProps = {
49+
children: React.ReactNode;
50+
typingDelay?: Delay;
51+
backspaceDelay?: Delay;
52+
loop?: boolean;
53+
pause?: boolean;
54+
startDelay?: number;
55+
finishDelay?: number;
56+
onTypingDone?: () => void;
57+
splitter?: Splitter;
58+
cursor?: string | React.ReactElement;
59+
disabled?: boolean;
60+
restartKey?: any;
61+
};
62+
```
63+
64+
#### `children`
65+
66+
The contents that will be rendered with typewriter effect. It accepts nested elements, so you can easily style your contents.
67+
68+
Note that `Typist` treats the element whose children is `null` or `undefined` as a single token. For example:
69+
70+
```jsx
71+
const Foo = () => {
72+
return <div>Foo</div>;
73+
};
74+
75+
// The text "Foo" will be displayed after "123" immediately instead of displayed seperately
76+
const App = () => {
77+
return (
78+
<Typist>
79+
123
80+
<Foo />
81+
</Typist>
82+
);
83+
};
84+
```
85+
86+
#### `typingDelay`
87+
88+
**Default**: `75`
89+
90+
The delay after typing a token. If you pass in a function, `Typist` will call the function after typing a token and use the return value as the delay.
91+
92+
#### `backspaceDelay`
93+
94+
**Default**: `typingDelay`
95+
96+
The delay after backspacing a token. If you pass in a function, `Typist` will call the function after backspacing a token and use the return value as the delay.
97+
98+
#### `loop`
99+
100+
**Default**: `false`
101+
102+
`Typist` will automatically restart the typing animation if this value is `true`.
103+
104+
#### `pause`
105+
106+
**Default**: `false`
107+
108+
Set to `true` if you want to pause the typing animation.
109+
110+
#### `startDelay`
111+
112+
**Default**: `0`
113+
114+
`Typist` will wait for this delay before starting the typing animation.
115+
116+
#### `finishDelay`
117+
118+
**Default**: `0`
119+
120+
`Typist` will wait for this delay after finishing the typing animation.
121+
122+
#### `onTypingDone`
123+
124+
This function will be called when the typing animation finishes. It will be called before waiting for the timeout with `finishDelay`.
125+
126+
#### `splitter`
127+
128+
**Default**: `(str: string) => str.split('')`
129+
130+
`Typist` will use this function to get tokens from strings. It may be useful when you want to split your string in different way. For example, you can use [grapheme-splitter](https://github.com/orling/grapheme-splitter) to split string if your string contains emoji.
131+
132+
```tsx
133+
import GraphemeSplitter from 'grapheme-splitter';
134+
135+
const splitter = (str: string) => {
136+
return new GraphemeSplitter().splitGraphemes(str);
137+
};
138+
139+
const App = () => {
140+
return (
141+
<Typist splitter={splitter}>
142+
😎🗑🥵⚠😀👍✌👨‍👨‍👧‍👦📏💡🚀🎂😓🎈💕😘
143+
<Typist.Backspace count={16} />
144+
</Typist>
145+
);
146+
};
147+
```
148+
149+
#### `cursor`
150+
151+
Will be inserted after the last typed token.
152+
153+
#### `disabled`
154+
155+
**Default**: `false`
156+
157+
If this value is `true`, the result will be displayed immediately without typing animation. It can be useful when you want to display the final result if a user has visited the typing animation.
158+
159+
#### `restartKey`
160+
161+
`Typist` will restart the typing animation whenever `restartKey` changes.
162+
163+
### `Typist.Backspace`
164+
165+
```ts
166+
type Props = {
167+
count: number;
168+
};
169+
```
170+
171+
#### `count`
172+
173+
The number of tokens that will be backspaced.
174+
175+
### `Typist.Delay`
176+
177+
```ts
178+
type Props = {
179+
ms: number;
180+
};
181+
```
182+
183+
#### `ms`
184+
185+
The duration of the delay in milliseconds.
186+
187+
### `Typist.Paste`
188+
189+
```ts
190+
type Props = {
191+
children: React.ReactNode;
192+
};
193+
```
194+
195+
#### `children`
196+
197+
Children inside this component will be pasted without typewriter effect. Do not wrap another `Paste` inside this component, otherwise `Typist` will produce weird behavior.

website/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@
1313
"next": "12.3.1",
1414
"next-contentlayer": "^0.2.8",
1515
"react": "^18.2.0",
16-
"react-dom": "^18.2.0"
16+
"react-dom": "^18.2.0",
17+
"react-typist-component": "workspace:*"
1718
},
1819
"devDependencies": {
1920
"@types/node": "18.7.18",
2021
"@types/react": "^18.0.20",
2122
"@types/react-dom": "^18.0.6",
23+
"autoprefixer": "^10.4.11",
2224
"eslint": "^8.23.1",
2325
"eslint-config-next": "12.3.0",
26+
"postcss": "^8.4.16",
27+
"tailwindcss": "^3.1.8",
2428
"typescript": "^4.8.3"
2529
}
2630
}

website/pages/index.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,9 @@ import Head from 'next/head';
22
import Image from 'next/image';
33
import styles from '../styles/Home.module.css';
44

5-
import type { Doc } from 'contentlayer/generated';
6-
import { allDocs } from 'contentlayer/generated';
7-
8-
import { useMDXComponent } from 'next-contentlayer/hooks';
9-
10-
export async function getStaticProps() {
11-
return { props: { docs: allDocs } };
12-
}
13-
14-
const Home = ({ docs }: { docs: Doc[] }) => {
15-
const MDXComponent = useMDXComponent(docs[0].body.code);
16-
5+
const Home = () => {
176
return (
187
<div className={styles.container}>
19-
<MDXComponent />
208
<Head>
219
<title>Create Next App</title>
2210
<meta name='description' content='Generated by create next app' />

website/postcss.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
plugins: {
3+
tailwindcss: {},
4+
autoprefixer: {},
5+
},
6+
}

website/styles/globals.css

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,3 @@
1-
html,
2-
body {
3-
padding: 0;
4-
margin: 0;
5-
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
6-
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
7-
}
8-
9-
a {
10-
color: inherit;
11-
text-decoration: none;
12-
}
13-
14-
* {
15-
box-sizing: border-box;
16-
}
17-
18-
@media (prefers-color-scheme: dark) {
19-
html {
20-
color-scheme: dark;
21-
}
22-
body {
23-
color: white;
24-
background: black;
25-
}
26-
}
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;

website/tailwind.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** @type {import('tailwindcss').Config} */
2+
module.exports = {
3+
content: ['./pages/**/*.tsx', './modules/**/*.tsx'],
4+
theme: {
5+
extend: {},
6+
},
7+
plugins: [],
8+
};

0 commit comments

Comments
 (0)