widgets/README.md

62 lines
1.4 KiB
Markdown
Raw Normal View History

2024-01-12 04:54:53 +08:00
# widgets
2024-01-12 01:04:22 +08:00
2024-01-12 04:54:53 +08:00
像 flutter 风格用纯粹 js 构建页面
2024-05-14 14:57:46 +08:00
{ createElement List ListItem Span Button Img Input TextArea Avatar Dialog }
2024-01-12 05:34:37 +08:00
```bash
npm i @laniakeasupercluster/widgets
```
```javascript
import { createElement, Button, Span } from '@laniakeasupercluster/widgets'
document.body.appendChild(createElement({
style: { width: 320, height: 320, padding: 64 },
children: [
Span({ textContent: 'hello world!' })
Button({
textContent: 'click',
onclick: event => {
const randomNumber = Math.floor(Math.random() * 100)
event.traget.textContent = 'click' + randomNumber
}
})
]
}))
```
### dev
```
git clone git@git.satori.love:LaniakeaSupercluster/widgets.git
npm i
npm run dev
```
2024-05-15 22:38:07 +08:00
### HTML 基本概念
对于UI书写划分为两类, 一是外观样式, 一是结构关系
一个元素的基本构成就是其外观样式, 因此它书写在声明它的同一列
```javascript
div.w(128).h(64)
```
嵌套关系则应该换行并缩进, 保持与 HTML 一致的风格
```javascript
document.body.appendChild(div.w(128).h(64).children([
div.text('Hello world!'),
div.text('Hello world!'),
div.text('Hello world!')
]))
```
有时期望复用样式
```javascript
const option = { style: { width: '128px', height: '64px' } }
div(option).children([
div.text('Hello world!'),
div.text('Hello world!'),
div.text('Hello world!')
])
```