Skip to content

Segmented 分段选择器 ​

一行互斥选项。stacked 渲染带比例示意图的高项,适合宽高比选择。

示例 ​

行模式 ​

moonbit
@sumi.segmented(
  items=[
    @sumi.SegmentedItem::new("2k", "2K", numeric=true),
    @sumi.SegmentedItem::new("4k", "4K", numeric=true, trailing=sparkle),
    @sumi.SegmentedItem::new("8k", "8K", numeric=true, trailing=sparkle),
  ],
  selected=current,
  on_select=set_res.map(v => _ => v),
)

堆叠比例选择 ​

moonbit
@sumi.segmented(
  stacked=true,
  items=[
    @sumi.SegmentedItem::new("16:9", "16:9", numeric=true,
      icon=@sumi.icon_ratio(width=16, height=9)),
    @sumi.SegmentedItem::new("1:1", "1:1", numeric=true,
      icon=@sumi.icon_ratio(width=1, height=1)),
  ],
  selected=current,
  on_select=set_ratio.map(v => _ => v),
)

API ​

segmented ​

名称类型默认值说明
items *Array[SegmentedItem]—选项列表
selected *String—选中项的值(受控)
stackedBoolfalse图标在上、标签在下的高布局
on_selectEmit[String]—选中某项时以其值调用
idString—元素 id
classString—附加 class 名
attrsAttrs—附加 HTML 属性
styleArray[String][]附加内联样式

SegmentedItem::new ​

一个选项。

名称类型默认值说明
valueString—
labelString—
iconHtml—前置图形(堆叠模式)
trailingHtml—尾部标记(如高级能力标识)
numericBoolfalse使用数字字体渲染
disabledBoolfalse禁用交互并降低不透明度

* 必填(标签)参数——其余均为可选。