自定义组件

Oct 03, 2024
13 min read
2923

See source code to learn the custom markdown rules.

Code

Playground

tsx

Code Playground
App.jsx
Test.css
Test.tsx
Test2.tsx
App.css
import Test from './Test'
import './App.css'

function App() {
  return (
    <div onClick={() => console.log('App')}>
      <h1 className="app">App - {Math.random()}</h1>
      <Test text="Test1" />
    </div>
  )
}
export default App
Preview
Console

static

Code Playground
index.html
color.css
font-weight.css
<div class="test" onclick="console.log(111)">hello</div>

meta

Code Playground
import { useRef, useEffect } from 'react'
import * as THREE from 'three'
import { buildCamera, buildRenderer } from './utils'

function ThreeLearnPrimitivesBox() {
  const containerRef = useRef<HTMLDivElement>(null)

  useEffect(() => {
    const renderer = buildRenderer(containerRef)

    const scene = new THREE.Scene()
    const camera = buildCamera(10, 10, 10)

    const box = new THREE.BoxGeometry(4, 4, 4)
    const material = new THREE.MeshBasicMaterial({ color: 0x3451b2 })
    const mesh = new THREE.Mesh(box, material)

    // 获取 box 的边界
    const edges = new THREE.EdgesGeometry(box)
    const edgesMaterial = new THREE.LineBasicMaterial({
      color: 0x00ffff,
    })
    const line = new THREE.LineSegments(edges, edgesMaterial)
    mesh.add(line)

    scene.add(mesh)
    function render() {
      renderer.render(scene, camera)
    }

    function animate() {
      requestAnimationFrame(animate)
      mesh.rotation.x += 0.01
      mesh.rotation.y += 0.01
      mesh.rotation.z += 0.01
      render()
    }
    const cancelRaf = animate()

    return cancelRaf
  }, [])

  return <div ref={containerRef} />
}

export default ThreeLearnPrimitivesBox

Runner

simple

Code Runner
function log(n: any) {
  console.log(n)
}

log(1)
log('ch')
log({ obj: 1 })
log([1, 2, 3])
log(function t() {})
log(() => {
  console.log(1)
})
log(Symbol('foo'))
log(undefined)
log(null)
log(true)
log(/foo/)
log(new Date(Date.now()))
Running...

long time

Code Runner
const start = Date.now()
console.log('start')
while (Date.now() - start < 3000) {}
console.log('end')
Running...

Switcher

npm
yarn
pnpm
npm install @plumbiu/react-store

Block

Diff

console.log('hewwo')
console.log('hello')
console.log('goodbye')

Notation:

console.log('hewwo')
console.log('hello')
console.log('goodbye')

Highlight

Line

console.log('hewwo')
console.log('hello')
console.log('goodbye')

Notation:

console.log('hewwo')
console.log('hello')
console.log('goodbye')

Word

console.log('hewwo')
console.log('hello')
console.log('goodbye')

Notation:

console.log('hewwo')
console.log('hello')
console.log('goodbye')

Show line

console.log('hewwo')
console.log('hello')
console.log('goodbye')

Path

Local

function Iframe(props: any) {
  return <iframe {...props} />
}

export default Iframe

Remote

const s = 'Wow, this is from remote'
console.log(s)

Custom Component

Tip

Normal Tip

This is some description. This is some description.This is some description.

console.log('info')

This is Info

This is some description. This is some description. This is some description.

console.log('info')

This is Warn

This is some description. This is some description. This is some description.

console.log('warn')

This is Danger

This is some description. This is some description. This is some description.

console.log('danger')

This is some description. This is some description. This is some description.

console.log('info')

This is some description. This is some description. This is some description.

console.log('warn')

This is some description. This is some description. This is some description.

console.log('danger')

Details

Detail 测试

Hello World console.log('details')

Image gallery

Injection and Table

Variable

ExpressionTextCodeBlodLink
${foo}TestTestTestTest
${bar.test.a}TestTestTestTest
${bar['test'].a}TestTestTestTest

Object:

ExpressionTextCodeBlod
${bar.test}{"a":"Test"}{"a":"Test"}{"a":"Test"}
${bar['test']}{"a":"Test"}{"a":"Test"}{"a":"Test"}

Emoji

ExpressionTextCodeBlod
:smile:😄😄😄
:hugs:🤗🤗🤗

Video

Bilibili

Youtube

CC BY-NC-SA 4.0 2024 © Plumbiu