Skip to content

Commit

Permalink
Allow deleting link variant options
Browse files Browse the repository at this point in the history
  • Loading branch information
dani-mp committed Dec 16, 2024
1 parent b1a4ba9 commit 015cf3b
Showing 1 changed file with 34 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Box,
Button,
Icon,
IconButton,
Switch,
Text,
TextInput,
Expand Down Expand Up @@ -119,6 +120,8 @@ export function Variants({

const addButtonShown = (variants?.length ?? 0) < 5;

const deleteButtonShown = (variants?.length ?? 0) > 2;

return (
<Box overflow="hidden" flexDirection="column" border borderRadius={6}>
<Box
Expand Down Expand Up @@ -153,26 +156,37 @@ export function Variants({
)}
</Text>
{variants?.map((variant, position) => (
<Box
key={position}
backgroundColor="white"
padding={{ inline: 12, block: 8 }}
flexDirection="column"
gap={8}
border
borderRadius={4}
>
<TextInput
placeholder="Variant option (e.g. Primary)"
value={variant}
onValueChange={(newVariant) =>
onVariantsChange(
variants?.map((variant, index) =>
index === position ? newVariant : variant,
),
)
}
/>
<Box key={position} gap={4} alignItems="center">
<Box
flexGrow={1}
backgroundColor="white"
padding={{ inline: 12, block: 8 }}
flexDirection="column"
border
borderRadius={4}
>
<TextInput
placeholder="Variant option (e.g. Primary)"
value={variant}
onValueChange={(newVariant) =>
onVariantsChange(
variants?.map((variant, index) =>
index === position ? newVariant : variant,
),
)
}
/>
</Box>
{deleteButtonShown && (
<IconButton
icon="delete"
onClick={() =>
onVariantsChange(
variants?.filter((_, index) => index !== position),
)
}
/>
)}
</Box>
))}
{addButtonShown && (
Expand Down

0 comments on commit 015cf3b

Please sign in to comment.