🔥 遇见我们的新项目 t0ggles - 你终极的项目管理工具! 🔥

无线电 Svelte 组件

无线电组件

包括以下组件

  • 单选按钮

无线电属性

名称类型默认值描述
checked布尔值false

定义单选按钮输入是否被选中

颜色对象

包含 Tailwind CSS 颜色类别的对象

colors.bgCheckedIos字符串'bg-primary'
colors.bgCheckedMaterial字符串'bg-md-light-primary dark:bg-md-dark-primary'
colors.borderCheckedIos字符串'border-primary'
colors.borderCheckedMaterial字符串'border-md-light-primary dark:border-md-dark-primary'
colors.borderIos字符串'border-black border-opacity-30 dark:border-white dark:border-opacity-30'
colors.borderMaterial字符串'border-md-light-outline dark:border-md-dark-outline'
组件字符串'标签'

组件的 HTML 元素

disabled布尔值false

定义单选按钮输入是否被禁用

name字符串

单选按钮输入名称

readonly布尔值false

定义单选按钮输入是否只读

touchRipple布尔值true

在 Material 主题中启用触控涟漪效果

value任何

单选按钮输入值

onChange函数(e)

当单选按钮状态更改时将触发事件

无线电列表

无线电列表不是一个单独的组件,而只是使用 ListListItem 组件的一种特殊情况。

<List>
  <!-- Additional "label" prop on ListItem -->
  <ListItem label title="Books">
    <!-- Pass Radio to list item media -->
    <Radio slot="media" component="div" name="my-checkbox" />
  </ListItem>
  <ListItem label title="Movies">
    <!-- Pass Radio to list item media -->
    <Radio slot="media" component="div" name="my-checkbox" />
  </ListItem>
</List>

示例

Radio.svelte
<script>
import {
Page,
Navbar,
NavbarBackLink,
Radio,
BlockTitle,
Block,
List,
ListItem,
} from 'konsta/svelte';
let inlineValue = 'inline-1';
let groupValue = 'Books';
let mediaValue = 'Item 1';
</script>
<Page>
<Navbar title="Radio" />
<BlockTitle>Inline</BlockTitle>
<Block strongIos outlineIos>
<p>
Lorem{' '}
<Radio
name="demo-radio-inline"
value="inline-1"
checked={inlineValue === 'inline-1'}
onChange={() => (inlineValue = 'inline-1')}
/>{' '}
ipsum dolor sit amet, consectetur adipisicing elit. Alias beatae illo nihil
aut eius commodi sint eveniet aliquid eligendi{' '}
<Radio
name="demo-radio-inline"
value="inline-2"
checked={inlineValue === 'inline-2'}
onChange={() => (inlineValue = 'inline-2')}
/>{' '}
ad delectus impedit tempore nemo, enim vel praesentium consequatur nulla mollitia!
</p>
</Block>
<BlockTitle>Radio Group</BlockTitle>
<List strongIos outlineIos>
<ListItem label title="Books">
<Radio
slot="media"
component="div"
value="Books"
checked={groupValue === 'Books'}
onChange={() => (groupValue = 'Books')}
/>
</ListItem>
<ListItem label title="Movies">
<Radio
slot="media"
component="div"
value="Movies"
checked={groupValue === 'Movies'}
onChange={() => (groupValue = 'Movies')}
/>
</ListItem>
<ListItem label title="Food">
<Radio
slot="media"
component="div"
value="Food"
checked={groupValue === 'Food'}
onChange={() => (groupValue = 'Food')}
/>
</ListItem>
<ListItem label title="Drinks">
<Radio
slot="media"
component="div"
value="Drinks"
checked={groupValue === 'Drinks'}
onChange={() => (groupValue = 'Drinks')}
/>
</ListItem>
</List>
<List strongIos outlineIos>
<ListItem label title="Books">
<Radio
slot="after"
component="div"
value="Books"
checked={groupValue === 'Books'}
onChange={() => (groupValue = 'Books')}
/>
</ListItem>
<ListItem label title="Movies">
<Radio
slot="after"
component="div"
value="Movies"
checked={groupValue === 'Movies'}
onChange={() => (groupValue = 'Movies')}
/>
</ListItem>
<ListItem label title="Food">
<Radio
slot="after"
component="div"
value="Food"
checked={groupValue === 'Food'}
onChange={() => (groupValue = 'Food')}
/>
</ListItem>
<ListItem label title="Drinks">
<Radio
slot="after"
component="div"
value="Drinks"
checked={groupValue === 'Drinks'}
onChange={() => (groupValue = 'Drinks')}
/>
</ListItem>
</List>
<BlockTitle>With Media Lists</BlockTitle>
<List strongIos outlineIos>
<ListItem
label
title="Facebook"
after="17:14"
subtitle="New messages from John Doe"
text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sagittis tellus ut turpis condimentum, ut dignissim lacus tincidunt. Cras dolor metus, ultrices condimentum sodales sit amet, pharetra sodales eros. Phasellus vel felis tellus. Mauris rutrum ligula nec dapibus feugiat. In vel dui laoreet, commodo augue id, pulvinar lacus."
>
<Radio
slot="media"
component="div"
checked={mediaValue === 'Item 1'}
onChange={() => (mediaValue = 'Item 1')}
/>
</ListItem>
<ListItem
label
title="John Doe (via Twitter)"
after="17:11"
subtitle="John Doe (@_johndoe) mentioned you on Twitter!"
text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sagittis tellus ut turpis condimentum, ut dignissim lacus tincidunt. Cras dolor metus, ultrices condimentum sodales sit amet, pharetra sodales eros. Phasellus vel felis tellus. Mauris rutrum ligula nec dapibus feugiat. In vel dui laoreet, commodo augue id, pulvinar lacus."
>
<Radio
slot="media"
component="div"
checked={mediaValue === 'Item 2'}
onChange={() => (mediaValue = 'Item 2')}
/>
</ListItem>
</List>
</Page>
代码许可证 MIT.
2022 © Konsta UI 由 nolimits4web.