mirror of
https://github.com/lainbo/component-party.git
synced 2026-04-05 04:59:02 +08:00
add create-section script
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
import { useState, useMemo } from "react"
|
||||
|
||||
const TRAFFIC_LIGHTS = ["red", 'orange', "green"]
|
||||
|
||||
export default function TrafficLight(){
|
||||
const [trafficLights] = useState(["red", 'orange', "green"])
|
||||
|
||||
const [lightIndex, setLightIndex] = useState(0)
|
||||
|
||||
const light = useMemo(() =>
|
||||
|
||||
trafficLights[lightIndex]
|
||||
, [lightIndex, trafficLights]);
|
||||
TRAFFIC_LIGHTS[lightIndex]
|
||||
, [lightIndex]);
|
||||
|
||||
function nextLight(){
|
||||
if(lightIndex + 1 > trafficLights.length - 1){
|
||||
if(lightIndex + 1 > TRAFFIC_LIGHTS.length - 1){
|
||||
setLightIndex(0)
|
||||
} else {
|
||||
setLightIndex(lightIndex + 1)
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
} else {
|
||||
lightIndex.value++
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
17
components/4-component/1-props/App.jsx
Normal file
17
components/4-component/1-props/App.jsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import { useState } from "react"
|
||||
import Hello from "./Hello.jsx"
|
||||
|
||||
export default function App(){
|
||||
const [username, setUsername] = useState("John");
|
||||
|
||||
function handleChange(event){
|
||||
setUsername(event.target.value)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<input value={username} onChange={handleChange} />
|
||||
<Hello name={username} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
8
components/4-component/1-props/App.svelte
Normal file
8
components/4-component/1-props/App.svelte
Normal file
@@ -0,0 +1,8 @@
|
||||
<script>
|
||||
import Hello from "./Hello.svelte"
|
||||
let username = "John"
|
||||
</script>
|
||||
|
||||
<input bind:value={username} />
|
||||
|
||||
<Hello name={username} />
|
||||
10
components/4-component/1-props/App.vue
Normal file
10
components/4-component/1-props/App.vue
Normal file
@@ -0,0 +1,10 @@
|
||||
<script setup>
|
||||
import { ref } from "vue"
|
||||
import Hello from "./Hello.vue"
|
||||
|
||||
const username = ref("John")
|
||||
</script>
|
||||
|
||||
<input v-model="username" />
|
||||
|
||||
<Hello :name="username" />
|
||||
3
components/4-component/1-props/Hello.jsx
Normal file
3
components/4-component/1-props/Hello.jsx
Normal file
@@ -0,0 +1,3 @@
|
||||
export default function Hello(props){
|
||||
return <p>Hello {props.name} !</p>
|
||||
}
|
||||
5
components/4-component/1-props/Hello.svelte
Normal file
5
components/4-component/1-props/Hello.svelte
Normal file
@@ -0,0 +1,5 @@
|
||||
<script>
|
||||
let name;
|
||||
</script>
|
||||
|
||||
<p>Hello {name} !</p>
|
||||
7
components/4-component/1-props/Hello.vue
Normal file
7
components/4-component/1-props/Hello.vue
Normal file
@@ -0,0 +1,7 @@
|
||||
<script setup>
|
||||
const props = defineProps({
|
||||
name: String
|
||||
})
|
||||
</script>
|
||||
|
||||
<p>Hello {props.name} !</p>
|
||||
0
new-section/react/Component.jsx
Normal file
0
new-section/react/Component.jsx
Normal file
0
new-section/svelte/Component.svelte
Normal file
0
new-section/svelte/Component.svelte
Normal file
0
new-section/vue3/Component.vue
Normal file
0
new-section/vue3/Component.vue
Normal file
@@ -2,9 +2,10 @@
|
||||
"name": "component-party",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"type": "module",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"create-section": "node scripts/createSection.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
41
scripts/createSection.js
Normal file
41
scripts/createSection.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import fs from "fs"
|
||||
|
||||
function getArgs(){
|
||||
const [componentName] = process.argv.slice(2);
|
||||
return {
|
||||
componentName
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
const args = getArgs()
|
||||
|
||||
async function main(){
|
||||
fs.mkdirSync("new-section")
|
||||
|
||||
const frameworks = [
|
||||
{
|
||||
name: "svelte",
|
||||
ext: "svelte"
|
||||
},
|
||||
{
|
||||
name: "react",
|
||||
ext: "jsx"
|
||||
},
|
||||
{
|
||||
name: "vue3",
|
||||
ext: "vue"
|
||||
}
|
||||
]
|
||||
|
||||
const componentName = args.componentName || "Component"
|
||||
|
||||
for(const {name, ext} of frameworks){
|
||||
const dir = `new-section/${name}`
|
||||
fs.mkdirSync(dir)
|
||||
fs.writeFileSync(`${dir}/${componentName}.${ext}`, "")
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(console.error)
|
||||
Reference in New Issue
Block a user