(props: { item: TodoItem; index: () => number })
| 138 | } |
| 139 | |
| 140 | function TodoItem(props: { item: TodoItem; index: () => number }) { |
| 141 | const colorScheme = useColorScheme(); |
| 142 | let textField: HTMLTextFieldElement | null = null; |
| 143 | const [editable, setEditable] = createSignal(false); |
| 144 | |
| 145 | return ( |
| 146 | <view |
| 147 | style={{ |
| 148 | flexDirection: "row", |
| 149 | alignItems: "center", |
| 150 | justifyContent: "space-between", |
| 151 | backgroundColor: props.index() % 2 === 0 |
| 152 | ? colorScheme === "dark" ? "rgba(0,0,0,0.1)" : "#f7f7f7" |
| 153 | : undefined, |
| 154 | paddingHorizontal: 10, |
| 155 | width: "100%", |
| 156 | }} |
| 157 | > |
| 158 | <view |
| 159 | style={{ |
| 160 | flexDirection: "row", |
| 161 | alignItems: "center", |
| 162 | gap: 10, |
| 163 | }} |
| 164 | > |
| 165 | <checkbox |
| 166 | checked={props.item.completed} |
| 167 | onClick={(event) => { |
| 168 | const checkbox = event.target as HTMLCheckboxElement; |
| 169 | setTodos((prev) => { |
| 170 | const next = [...prev]; |
| 171 | next[props.index()] = { |
| 172 | ...next[props.index()], |
| 173 | completed: !checkbox.checked, |
| 174 | }; |
| 175 | return next; |
| 176 | }); |
| 177 | }} |
| 178 | style={{ |
| 179 | width: 15, |
| 180 | height: 15, |
| 181 | }} |
| 182 | /> |
| 183 | <text-field |
| 184 | ref={(el: HTMLTextFieldElement) => (textField = el)} |
| 185 | style={{ |
| 186 | color: props.item.completed ? "gray" : undefined, |
| 187 | fontSize: 14, |
| 188 | }} |
| 189 | value={props.item.title} |
| 190 | editable={editable()} |
| 191 | onSubmit={(event) => { |
| 192 | setTodos((prev) => { |
| 193 | const next = [...prev]; |
| 194 | next[props.index()] = { |
| 195 | ...next[props.index()], |
| 196 | title: event.value, |
| 197 | }; |
nothing calls this directly
no test coverage detected