Replace status prop with checked in ToggleButton component

未关闭
#4,866 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
50/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
react-native, typescript
领域
frontend, mobile

调研方向

在 react-native-paper 代码库中找到 ToggleButton 的实现及其使用位置,然后检查当前 status prop 的类型定义和使用方式。当组件及其调用方都统一使用布尔值 checked,而不是 status 字符串值时,工作即完成。

由索引模型根据 Issue 内容生成。

描述

feature request

Is your feature request related to a problem? Please describe.
The ToggleButton component currently uses a status prop with string values checked | unchecked. This adds unnecessary complexity for a binary state.

Describe the solution you'd like
Replace the status prop with a boolean checked prop.

Before:

const ToggleButtonExample = () => {
  const [status, setStatus] = React.useState('checked');

  const onButtonToggle = () => {
    setStatus(status === 'checked' ? 'unchecked' : 'checked');
  };

  return (
    <ToggleButton
      icon="bluetooth"
      value="bluetooth"
      status={status}
      onPress={onButtonToggle}
    />
  );
};

After:

const ToggleButtonExample = () => {
  const [isChecked, setIsChecked] = React.useState(true);

  const onButtonToggle = () => {
    setIsChecked(s => !s);
  };

  return (
    <ToggleButton
      icon="bluetooth"
      value="bluetooth"
      checked={isChecked}
      onPress={onButtonToggle}
    />
  );
};

Additional context
A boolean checked prop is simpler, clearer, and more consistent with common React patterns than using string values like 'checked' and 'unchecked'.

主要语言
TypeScript
星标
14.5k
派生
2.3k
平均合并
8 天 7 小时
30 天内合并 PR
5

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

callstack/react-native-paper 的其他 Issue

查看 callstack/react-native-paper 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。