Skip to content

Commit d935914

Browse files
authored
Merge branch 'main' into main
2 parents 58c6711 + 3546147 commit d935914

File tree

5 files changed

+72
-4
lines changed

5 files changed

+72
-4
lines changed

packages/model/src/checkbox.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { Ref } from '@vue/reactivity'
2+
import type { Context } from 'sciux-laplace'
3+
4+
import { toValue } from '@vue/reactivity'
5+
import { type } from 'arktype'
6+
import { defineComponent } from 'sciux-laplace'
7+
8+
const T = type({
9+
model: 'string',
10+
disabled: 'boolean',
11+
})
12+
13+
export default defineComponent<'checkbox', typeof T.infer, Context>((attrs, context) => {
14+
const input = document.createElement('input')
15+
input.type = 'checkbox'
16+
if (attrs.model) {
17+
input.addEventListener('input', (e) => {
18+
(context[attrs.model!.value!] as Ref<boolean>).value = (e.target as HTMLInputElement).checked
19+
})
20+
}
21+
return {
22+
name: 'checkbox',
23+
attrs: T,
24+
setup: () => {
25+
input.disabled = toValue(attrs.disabled)
26+
return input
27+
},
28+
}
29+
})

packages/model/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
export { default as button } from './button'
2+
export { default as checkbox } from './checkbox'
23
export { default as input } from './input'
4+
export { default as slider } from './slider'

packages/model/src/slider.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { Ref } from '@vue/reactivity'
2+
import type { Context } from 'sciux-laplace'
3+
4+
import { toValue } from '@vue/reactivity'
5+
import { type } from 'arktype'
6+
import { defineComponent } from 'sciux-laplace'
7+
8+
const T = type({
9+
model: 'string',
10+
defaultValue: 'number',
11+
disabled: 'boolean',
12+
})
13+
14+
export default defineComponent<'slider', typeof T.infer, Context>((attrs, context) => {
15+
const input = document.createElement('input')
16+
input.type = 'range'
17+
input.min = '0'
18+
input.max = '1'
19+
input.step = 'any'
20+
if (attrs.model) {
21+
input.addEventListener('input', (e) => {
22+
(context[attrs.model!.value!] as Ref<number>).value = Number.parseFloat((e.target as HTMLInputElement).value)
23+
})
24+
}
25+
return {
26+
name: 'slider',
27+
attrs: T,
28+
setup: () => {
29+
input.defaultValue = toValue(attrs.defaultValue).toString()
30+
input.disabled = toValue(attrs.disabled)
31+
return input
32+
},
33+
}
34+
})

packages/test/src/example.sciux

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
<!--
21
<columns>
32
<let :value="2" />
3+
<let :checked="false" />
44
<flexbox>1</flexbox>
55
<flexbox>{{ value }}</flexbox>
6+
<flexbox>{{ checked }}</flexbox>
67
<rows>
78
<flexbox>1</flexbox>
89
<flexbox>1</flexbox>
910
<flexbox>
1011
<input model="value"/>
12+
<checkbox model="checked"/>
1113
</flexbox>
1214
</rows>
1315
</columns>
14-
-->
16+
1517
<!-- 测试水平布局表格 -->
1618
<table caption="水平布局测试" align="horizon" columns="3">
1719
<block>1</block>

packages/test/src/main.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { align, block, columns, flexbox, grid, rows } from '@sciux/layout'
2-
// import { model } from "@sciux/model";
3-
import { button, input } from '@sciux/model'
42
import { table } from '@sciux/widget'
3+
import { button, checkbox, input, slider } from '@sciux/model'
54
import { components, render } from 'sciux-laplace'
65
import source from './example.sciux?raw'
76

@@ -14,5 +13,7 @@ components.set('align', align)
1413
components.set('button', button)
1514
components.set('input', input)
1615
components.set('table', table)
16+
components.set('checkbox', checkbox)
17+
components.set('slider', slider)
1718

1819
render(source, document.getElementById('app')!)

0 commit comments

Comments
 (0)