Fixed text input box for white chips
This commit is contained in:
parent
5265730c0c
commit
c41db0db8b
@ -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) => {
|
||||||
|
const chipCount = totalChipsCount[colors.indexOf(color)] ?? 0;
|
||||||
|
return (
|
||||||
<Chip
|
<Chip
|
||||||
key={color.toString()}
|
key={color.toString()}
|
||||||
color={color}
|
color={color}
|
||||||
count={totalChipsCount[colors.indexOf(color)] ?? 0}
|
count={chipCount}
|
||||||
setShowModal={setShowModal}
|
setShowModal={setShowModal}
|
||||||
/>
|
/>
|
||||||
))}
|
);
|
||||||
|
})}
|
||||||
</View>
|
</View>
|
||||||
<Button
|
<Button
|
||||||
title="+"
|
title="+"
|
||||||
|
Loading…
Reference in New Issue
Block a user