Skip to content

Commit 8ba222f

Browse files
authored
Merge pull request #4 from onion108/main
feat: `<radio>` component
1 parent 546a4e6 commit 8ba222f

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

packages/model/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export { default as button } from './button'
22
export { default as checkbox } from './checkbox'
33
export { default as input } from './input'
4+
export { default as radio } from './radio'
45
export { default as slider } from './slider'

packages/model/src/radio.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+
group: 'string',
11+
value: 'string',
12+
})
13+
14+
export default defineComponent<'radio', typeof T.infer, Context>((attrs, context) => {
15+
const input = document.createElement('input')
16+
input.type = 'radio'
17+
if (attrs.model) {
18+
input.addEventListener('input', (e) => {
19+
const target = e.target as HTMLInputElement
20+
if (target.checked) {
21+
(context[attrs.model!.value!] as Ref<string>).value = target.value
22+
}
23+
})
24+
}
25+
return {
26+
name: 'radio',
27+
attrs: T,
28+
setup: () => {
29+
input.name = toValue(attrs.group)
30+
input.value = toValue(attrs.value)
31+
return input
32+
},
33+
}
34+
})

packages/model/src/ratio.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)