Mobilens English

控件 · 选择

分段选择

所有状态

何时出现
行为规则

    用法

    import { useState } from 'react';
    import { SegmentedControl } from '@/components/mobilens/SegmentedControl';
    
    type Plan = 'monthly' | 'yearly';
    
    export function BillingPeriod({ onChange }: { onChange: (plan: Plan) => void }) {
      const [plan, setPlan] = useState<Plan>('yearly');
      return (
        <SegmentedControl
          accessibilityLabel="Billing period"
          options={[
            { value: 'monthly', label: 'Monthly' },
            { value: 'yearly', label: 'Yearly' },
          ]}
          value={plan}
          onChange={(next) => {
            setPlan(next);
            onChange(next);
          }}
        />
      );
    }
    

    API

    参数类型默认值说明
    options Segment<T>[] – Two to five options. Keep each label to one short word.
    value T – The selected option's value.
    onChange (value: T) => void – Called with the new value when another option is tapped.
    disabled? boolean false Grey and cannot be changed.
    accessibilityLabel? string – What screen readers call the whole control, such as "Time range".

    用在这些流程里