refactor(ui): one chip primitive for all four pickers; DateField reuses lib/dates
This commit is contained in:
@@ -1,63 +1,43 @@
|
||||
import { Pressable, StyleSheet, Text, View } from "react-native";
|
||||
import { StyleSheet, View } from "react-native";
|
||||
import { haptic } from "../lib/haptics";
|
||||
import { PRIORITIES, PRIORITY_COLOR, PRIORITY_LABEL, PRIORITY_TINT } from "../lib/priority";
|
||||
import { C, radius, space, type } from "../lib/theme";
|
||||
import { C, space } from "../lib/theme";
|
||||
import type { Task } from "../lib/types";
|
||||
import { SectionHeader } from "./ui";
|
||||
import { ChipRow, OptionChip, SectionHeader } from "./ui";
|
||||
|
||||
/** Omit `label` when the surrounding panel already titles the group. */
|
||||
export default function PriorityChips({
|
||||
value,
|
||||
onChange,
|
||||
label,
|
||||
}: {
|
||||
value: Task["priority"] | null;
|
||||
onChange: (p: Task["priority"]) => void;
|
||||
label?: string;
|
||||
}) {
|
||||
return (
|
||||
<View style={s.wrap}>
|
||||
<SectionHeader>Priority</SectionHeader>
|
||||
<View style={s.rowWrap}>
|
||||
{PRIORITIES.map((p) => {
|
||||
const active = value === p;
|
||||
const color = PRIORITY_COLOR[p];
|
||||
return (
|
||||
<Pressable
|
||||
key={p}
|
||||
style={({ pressed }) => [
|
||||
s.chip,
|
||||
active && { borderColor: color, backgroundColor: PRIORITY_TINT[p] },
|
||||
pressed && !active && { backgroundColor: C.surface2 },
|
||||
]}
|
||||
onPress={() => {
|
||||
haptic.select();
|
||||
onChange(p);
|
||||
}}
|
||||
>
|
||||
<View style={[s.flag, { backgroundColor: color }]} />
|
||||
<Text style={[s.text, active && { color, fontWeight: "600" }]}>
|
||||
{PRIORITY_LABEL[p]}
|
||||
</Text>
|
||||
</Pressable>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
<View style={label ? { marginBottom: space.lg } : undefined}>
|
||||
{!!label && <SectionHeader>{label}</SectionHeader>}
|
||||
<ChipRow>
|
||||
{PRIORITIES.map((p) => (
|
||||
<OptionChip
|
||||
key={p}
|
||||
label={PRIORITY_LABEL[p]}
|
||||
active={value === p}
|
||||
tone={PRIORITY_COLOR[p]}
|
||||
tint={PRIORITY_TINT[p]}
|
||||
leading={<View style={[s.flag, { backgroundColor: PRIORITY_COLOR[p] }]} />}
|
||||
onPress={() => {
|
||||
haptic.select();
|
||||
onChange(p);
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</ChipRow>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const s = StyleSheet.create({
|
||||
wrap: { marginBottom: space.lg },
|
||||
rowWrap: { flexDirection: "row", flexWrap: "wrap", gap: space.sm },
|
||||
chip: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: 7,
|
||||
paddingVertical: 9,
|
||||
paddingHorizontal: 14,
|
||||
borderRadius: radius.pill,
|
||||
backgroundColor: C.surface,
|
||||
borderWidth: 1,
|
||||
borderColor: C.border,
|
||||
},
|
||||
flag: { width: 9, height: 9, borderRadius: 999 },
|
||||
text: { ...type.chip, color: C.textSecondary },
|
||||
flag: { width: 9, height: 9, borderRadius: 999, backgroundColor: C.muted },
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user