Merge pull request #54 from djwesty/vutukuri15/53

Fixed text input box for white chips # 53
This commit is contained in:
Vutukuri15 2025-03-08 12:16:06 -08:00 committed by GitHub
commit 31e0a7a995
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -29,12 +29,12 @@ const ChipInputModal = ({
const color: ColorValue = useMemo(() => showModal[1], [showModal]); const color: ColorValue = useMemo(() => showModal[1], [showModal]);
const colorIdx = useMemo(() => colors.indexOf(color), [color]); const colorIdx = useMemo(() => colors.indexOf(color), [color]);
const [value, setValue] = useState<number | undefined>(); // value may be undefined initially const [value, setValue] = useState<number | undefined>();
// Reset the color value when the specific color this modal is for, changes. The same modal is shared/reused in all cases. // Reset the color value when the specific color this modal is for changes
useEffect(() => { useEffect(() => {
setValue(totalChipsCount[colorIdx]); setValue(totalChipsCount[colorIdx]);
}, [colorIdx]); }, [colorIdx, totalChipsCount]);
const shadow = useMemo(() => color === "white", [color]); const shadow = useMemo(() => color === "white", [color]);
@ -126,8 +126,9 @@ const ChipsSelector = ({
false, false,
colors[0], colors[0],
]); ]);
const colorsUsed = useMemo( const colorsUsed = useMemo(
() => colors.filter((v, i) => i < numberOfChips), () => colors.slice(0, numberOfChips), // Only show as many colors as the `numberOfChips`
[numberOfChips] [numberOfChips]
); );
@ -139,14 +140,13 @@ const ChipsSelector = ({
newTotalChipsCount[colorIndex] = count; newTotalChipsCount[colorIndex] = count;
setTotalChipsCount(newTotalChipsCount); setTotalChipsCount(newTotalChipsCount);
}, },
[numberOfChips, totalChipsCount, setTotalChipsCount] [totalChipsCount, setTotalChipsCount]
); );
// When the number of chips changes (dec or inc), update the array being careful to add in sensible default values where they belong // Handling number of chips to make sure the array updates accordingly
useEffect(() => { useEffect(() => {
if (numberOfChips !== totalChipsCount.length) { if (numberOfChips !== totalChipsCount.length) {
let newTotalChipsCount = totalChipsCount.slice(); let newTotalChipsCount = totalChipsCount.slice();
if (numberOfChips < totalChipsCount.length) { if (numberOfChips < totalChipsCount.length) {
newTotalChipsCount = newTotalChipsCount.slice(0, numberOfChips); newTotalChipsCount = newTotalChipsCount.slice(0, numberOfChips);
} else if (numberOfChips > totalChipsCount.length) { } else if (numberOfChips > totalChipsCount.length) {
@ -171,14 +171,17 @@ const ChipsSelector = ({
disabled={numberOfChips == 1} disabled={numberOfChips == 1}
/> />
<View style={[styles.container, { flexDirection: "row" }]}> <View style={[styles.container, { flexDirection: "row" }]}>
{colorsUsed.map((color) => ( {colorsUsed.map((color) => {
<Chip const chipCount = totalChipsCount[colors.indexOf(color)] ?? 0;
key={color.toString()} return (
color={color} <Chip
count={totalChipsCount[colors.indexOf(color)] ?? 0} key={color.toString()}
setShowModal={setShowModal} color={color}
/> count={chipCount}
))} setShowModal={setShowModal}
/>
);
})}
</View> </View>
<Button <Button
title="+" title="+"