File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313 "preinstall" : " npx only-allow pnpm" ,
1414 "commit" : " cz" ,
1515 "test" : " pnpm -r --filter ./packages/* run test" ,
16- "dev:website" : " pnpm --filter ./website dev" ,
17- "build:website" : " pnpm --filter ./website run build" ,
16+ "dev:website" : " pnpm build:packages && pnpm --filter ./website dev" ,
17+ "build:website" : " pnpm build:packages && pnpm --filter ./website run build" ,
1818 "build:packages" : " pnpm -r --filter ./packages/* run build:package" ,
1919 "prepublishOnly" : " pnpm build:lib"
2020 },
4747 "@vitejs/plugin-react" : " ^2.1.0" ,
4848 "typescript" : " ^4.8.3"
4949 }
50+ },
51+ "dependencies" : {
52+ "next" : " 12.3.1"
5053 }
5154}
Original file line number Diff line number Diff line change @@ -6,6 +6,12 @@ export const Doc = defineDocumentType(() => ({
66 filePathPattern : 'docs/**/*.mdx' ,
77 contentType : 'mdx' ,
88 fields : {
9+ name : {
10+ type : 'enum' ,
11+ options : [ 'react-typist-component' ] ,
12+ description : `The package's name` ,
13+ required : true ,
14+ } ,
915 title : {
1016 type : 'string' ,
1117 description : 'The title of the document' ,
Original file line number Diff line number Diff line change 11---
2- title : react-typist-component
2+ name : react-typist-component
3+ title : React Typist Component
34intro : A react component for creating typewritter effect by setting up its children directy.
45---
56
6- # React Typist Component
7-
8- Create typewriter effect by setting up a component's children directly.
9-
107## Install
118
129``` bash
@@ -15,7 +12,17 @@ npm install react-typist-component
1512yarn add react-typist-component
1613```
1714
18- ## Example
15+ ## Features
16+
17+ ### Support Looping
18+
19+ <Loop />
20+
21+ ### Support Pausing
22+
23+ <Pause />
24+
25+ ## Examples
1926
2027``` jsx
2128import Typist from ' react-typist-component' ;
Original file line number Diff line number Diff line change 1+ import type { ReactNode } from 'react' ;
2+
3+ interface Props {
4+ children : ReactNode ;
5+ }
6+
7+ export default function NotProse ( { children } : Props ) {
8+ return < div className = 'not-prose' > { children } </ div > ;
9+ }
Original file line number Diff line number Diff line change 1+ import { useState } from 'react' ;
2+ import Typist from 'react-typist-component' ;
3+
4+ import NotProse from '~/modules/common/components/NotProse' ;
5+
6+ export function Loop ( ) {
7+ return (
8+ < NotProse >
9+ < Typist loop = { true } cursor = '|' >
10+ The typing animation can be looped infinitely.
11+ </ Typist >
12+ </ NotProse >
13+ ) ;
14+ }
15+
16+ export function Pause ( ) {
17+ const [ pause , setPause ] = useState ( false ) ;
18+
19+ return (
20+ < NotProse >
21+ < div className = 'flex gap-2' >
22+ < input
23+ type = 'checkbox'
24+ checked = { pause }
25+ onChange = { e => setPause ( e . target . checked ) }
26+ />
27+ Pause
28+ </ div >
29+ < Typist pause = { pause } loop = { true } cursor = '_' >
30+ You can pause the typing animation whenever you want.
31+ </ Typist >
32+ </ NotProse >
33+ ) ;
34+ }
35+
36+ const TypistExamples = {
37+ Loop,
38+ Pause,
39+ } ;
40+
41+ export default TypistExamples ;
Original file line number Diff line number Diff line change 1+ import type { ComponentName , ExamplesType } from '../types' ;
2+ import TypistExamples from './TypistExamples' ;
3+
4+ const components : Record < ComponentName , ExamplesType > = {
5+ 'react-typist-component' : TypistExamples ,
6+ } ;
7+
8+ export default components ;
Original file line number Diff line number Diff line change 1+ import type { ReactNode } from 'react' ;
2+
3+ export type ComponentName = 'react-typist-component' ;
4+ export type ExamplesType = Record < string , ( ) => ReactNode > ;
Original file line number Diff line number Diff line change @@ -6,17 +6,15 @@ interface Props {
66}
77
88export default function Aside ( { docs } : Props ) {
9- const titles = docs ?. map ( doc => doc . title ) || [ ] ;
10-
119 return (
1210 < aside
1311 style = { { height : 'calc(100vh - 5rem)' } }
1412 className = 'sticky top-20 flex-shrink-0 border-r border-r-black py-5 pr-5' >
1513 < ul >
16- { titles . map ( title => {
14+ { docs ? .map ( doc => {
1715 return (
18- < li key = { title } className = 'text-lg text-primary hover:underline' >
19- < Link href = { `/${ title } ` } > { title } </ Link >
16+ < li key = { doc . _id } className = 'text-lg text-primary hover:underline' >
17+ < Link href = { `/${ doc . name } ` } > { doc . title } </ Link >
2018 </ li >
2119 ) ;
2220 } ) }
Original file line number Diff line number Diff line change 11import { allDocs , Doc } from 'contentlayer/generated' ;
22import type { GetStaticPaths , GetStaticProps } from 'next' ;
33import { useMDXComponent } from 'next-contentlayer/hooks' ;
4+ import Head from 'next/head' ;
45import { useRouter } from 'next/router' ;
56
7+ import components from '~/modules/docs/components' ;
8+
69interface Props {
710 docs : Doc [ ] ;
811}
912
1013export default function Component ( { docs } : Props ) {
1114 const { query } = useRouter ( ) ;
12- const doc = docs . find ( d => d . title === query . component ) ;
15+ const doc = docs . find ( d => d . name === query . component ) ;
16+
1317 const MDXComponent = useMDXComponent ( doc ?. body . code || '' ) ;
1418
1519 if ( ! doc ) return null ;
1620
1721 return (
1822 < div className = 'p-10' >
23+ < Head >
24+ < title > { doc . title } </ title >
25+ < meta name = 'description' content = { doc . intro } />
26+ </ Head >
1927 < article className = 'prose max-w-none' >
20- < MDXComponent />
28+ < h1 > { doc . title } </ h1 >
29+ < p > { doc . intro } </ p >
30+ < MDXComponent components = { components [ doc . name ] } />
2131 </ article >
2232 </ div >
2333 ) ;
@@ -34,7 +44,7 @@ export const getStaticProps: GetStaticProps<
3444
3545export const getStaticPaths : GetStaticPaths = ( ) => {
3646 const paths = allDocs . map ( doc => ( {
37- params : { component : doc . title } ,
47+ params : { component : doc . name } ,
3848 } ) ) ;
3949
4050 return {
You can’t perform that action at this time.
0 commit comments