@william-callao/antonella-ui 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -1
- package/dist/index.js +25 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -570,12 +570,13 @@ type ProductCardProps = {
|
|
|
570
570
|
price?: string;
|
|
571
571
|
code?: string;
|
|
572
572
|
cart?: ProductCardCart;
|
|
573
|
+
maxQuantity?: number;
|
|
573
574
|
onQuantityChange?: (quantity: number) => void;
|
|
574
575
|
imageIcon?: IconName;
|
|
575
576
|
style?: ProductCardStyle;
|
|
576
577
|
containerStyle?: StyleProp<ViewStyle>;
|
|
577
578
|
};
|
|
578
|
-
declare function ProductCard({ name, price, code, cart, onQuantityChange, imageIcon, style, containerStyle, }: ProductCardProps): React__default.JSX.Element;
|
|
579
|
+
declare function ProductCard({ name, price, code, cart, maxQuantity, onQuantityChange, imageIcon, style, containerStyle, }: ProductCardProps): React__default.JSX.Element;
|
|
579
580
|
|
|
580
581
|
declare enum ElementCardStyle {
|
|
581
582
|
DEFAULT = "DEFAULT",
|
package/dist/index.js
CHANGED
|
@@ -4520,6 +4520,7 @@ function ProductCard({
|
|
|
4520
4520
|
price,
|
|
4521
4521
|
code,
|
|
4522
4522
|
cart,
|
|
4523
|
+
maxQuantity,
|
|
4523
4524
|
onQuantityChange,
|
|
4524
4525
|
imageIcon = "camera",
|
|
4525
4526
|
style = "DEFAULT" /* DEFAULT */,
|
|
@@ -4529,9 +4530,13 @@ function ProductCard({
|
|
|
4529
4530
|
const [quantity, setQuantity] = (0, import_react15.useState)(cart?.quantity ?? 0);
|
|
4530
4531
|
const [editing, setEditing] = (0, import_react15.useState)(false);
|
|
4531
4532
|
const [draft, setDraft] = (0, import_react15.useState)(String(cart?.quantity ?? 0));
|
|
4533
|
+
const hasMax = maxQuantity != null && Number.isFinite(maxQuantity);
|
|
4534
|
+
const max = hasMax ? Math.max(0, Math.floor(maxQuantity)) : 0;
|
|
4535
|
+
const atMax = hasMax && quantity >= max;
|
|
4532
4536
|
const commitQuantity = () => {
|
|
4533
4537
|
const parsed = Number.parseInt(draft, 10);
|
|
4534
|
-
const
|
|
4538
|
+
const raw = Number.isNaN(parsed) || parsed < 0 ? 0 : parsed;
|
|
4539
|
+
const next = hasMax ? Math.min(raw, max) : raw;
|
|
4535
4540
|
setQuantity(next);
|
|
4536
4541
|
setDraft(String(next));
|
|
4537
4542
|
setEditing(false);
|
|
@@ -4608,6 +4613,7 @@ function ProductCard({
|
|
|
4608
4613
|
import_react_native45.Pressable,
|
|
4609
4614
|
{
|
|
4610
4615
|
onPress: () => {
|
|
4616
|
+
if (atMax) return;
|
|
4611
4617
|
const q = quantity + 1;
|
|
4612
4618
|
setQuantity(q);
|
|
4613
4619
|
setDraft(String(q));
|
|
@@ -4616,10 +4622,12 @@ function ProductCard({
|
|
|
4616
4622
|
style: ({ pressed }) => [
|
|
4617
4623
|
styles41.stepperButton,
|
|
4618
4624
|
{ backgroundColor: ctx.bg.subtle },
|
|
4619
|
-
pressed && styles41.stepperButtonPressed
|
|
4625
|
+
pressed && styles41.stepperButtonPressed,
|
|
4626
|
+
atMax && styles41.stepperButtonDisabled
|
|
4620
4627
|
],
|
|
4621
4628
|
accessibilityRole: "button",
|
|
4622
4629
|
accessibilityLabel: "Aumentar cantidad",
|
|
4630
|
+
accessibilityState: { disabled: atMax },
|
|
4623
4631
|
children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(Icon, { name: "add", size: 16, color: import_antonella_theme42.cta1 })
|
|
4624
4632
|
}
|
|
4625
4633
|
)
|
|
@@ -4631,12 +4639,18 @@ function ProductCard({
|
|
|
4631
4639
|
setDraft("1");
|
|
4632
4640
|
onQuantityChange?.(1);
|
|
4633
4641
|
},
|
|
4634
|
-
|
|
4642
|
+
disabled: hasMax && max <= 0,
|
|
4643
|
+
style: ({ pressed }) => [
|
|
4644
|
+
styles41.addButton,
|
|
4645
|
+
{ backgroundColor: ctx.bg.default },
|
|
4646
|
+
hasMax && max <= 0 ? styles41.addButtonDisabled : pressed && styles41.stepperButtonPressed
|
|
4647
|
+
],
|
|
4635
4648
|
accessibilityRole: "button",
|
|
4636
4649
|
accessibilityLabel: "A\xF1adir al carrito",
|
|
4650
|
+
accessibilityState: { disabled: hasMax && max <= 0 },
|
|
4637
4651
|
children: [
|
|
4638
|
-
/* @__PURE__ */ (0, import_jsx_runtime44.jsx)(Icon, { name: "add", size: 16, color: import_antonella_theme42.cta1 }),
|
|
4639
|
-
/* @__PURE__ */ (0, import_jsx_runtime44.jsx)(Text, { variant: import_antonella_theme42.TextType.Caption, color: import_antonella_theme42.cta1, children: "A\xF1adir" })
|
|
4652
|
+
/* @__PURE__ */ (0, import_jsx_runtime44.jsx)(Icon, { name: "add", size: 16, color: hasMax && max <= 0 ? ctx.text.subtle : import_antonella_theme42.cta1 }),
|
|
4653
|
+
/* @__PURE__ */ (0, import_jsx_runtime44.jsx)(Text, { variant: import_antonella_theme42.TextType.Caption, color: hasMax && max <= 0 ? ctx.text.subtle : import_antonella_theme42.cta1, children: "A\xF1adir" })
|
|
4640
4654
|
]
|
|
4641
4655
|
}
|
|
4642
4656
|
) })
|
|
@@ -4720,6 +4734,9 @@ var styles41 = import_react_native45.StyleSheet.create({
|
|
|
4720
4734
|
stepperButtonPressed: {
|
|
4721
4735
|
opacity: 0.6
|
|
4722
4736
|
},
|
|
4737
|
+
stepperButtonDisabled: {
|
|
4738
|
+
opacity: 0.35
|
|
4739
|
+
},
|
|
4723
4740
|
addButton: {
|
|
4724
4741
|
flexDirection: "row",
|
|
4725
4742
|
alignItems: "center",
|
|
@@ -4728,6 +4745,9 @@ var styles41 = import_react_native45.StyleSheet.create({
|
|
|
4728
4745
|
paddingVertical: import_antonella_theme42.space.space2,
|
|
4729
4746
|
borderRadius: 999
|
|
4730
4747
|
},
|
|
4748
|
+
addButtonDisabled: {
|
|
4749
|
+
opacity: 0.5
|
|
4750
|
+
},
|
|
4731
4751
|
quantity: {
|
|
4732
4752
|
minWidth: 32,
|
|
4733
4753
|
textAlign: "center"
|