@appcorp/fusion-storybook 0.5.31 → 0.5.34

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.
@@ -1,16 +1,22 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useMemo, useState } from "react";
4
+ import { useTranslations } from "next-intl";
4
5
  import { Check, ChevronsUpDown } from "lucide-react";
5
6
  import { dialCodes } from "@react-pakistan/util-functions/constants/dial-codes";
6
- import { EnhancedInput } from "@appcorp/shadcn/components/enhanced-input";
7
- import { EnhancedLabel } from "@appcorp/shadcn/components/enhanced-label";
8
7
  import { Button } from "@appcorp/shadcn/components/ui/button";
8
+ import { Input } from "@appcorp/shadcn/components/ui/input";
9
+ import { EnhancedLabel } from "@appcorp/shadcn/components/enhanced-label";
9
10
  import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "@appcorp/shadcn/components/ui/command";
10
11
  import { Popover, PopoverContent, PopoverTrigger, } from "@appcorp/shadcn/components/ui/popover";
11
12
  import { cn } from "@appcorp/shadcn/lib/utils";
12
13
  import { countryNameFor, dialCodeFor, flagForCountry, formatNationalNumber, isDialCodeCompatible, joinPhoneValue, splitPhoneValue, toIsoCountry, } from "../utils/phone";
13
- export function PhoneInput({ id, label, info, error, required = false, disabled = false, value, onChange, defaultCountry, placeholder, className, countryAriaLabel = "Country code", countrySearchPlaceholder = "Search country...", countryEmptyText = "No country found.", testId, }) {
14
+ export function PhoneInput({ id, label, info, error, required = false, disabled = false, value, onChange, defaultCountry, placeholder, className, countryAriaLabel, countrySearchPlaceholder, countryEmptyText, testId, }) {
15
+ const t = useTranslations();
16
+ const translate = (key, fallback) => t.has(key) ? t(key) : fallback;
17
+ const resolvedCountryAriaLabel = countryAriaLabel !== null && countryAriaLabel !== void 0 ? countryAriaLabel : translate("phoneInput.countryAriaLabel", "Country code");
18
+ const resolvedCountrySearchPlaceholder = countrySearchPlaceholder !== null && countrySearchPlaceholder !== void 0 ? countrySearchPlaceholder : translate("phoneInput.countrySearchPlaceholder", "Search country...");
19
+ const resolvedCountryEmptyText = countryEmptyText !== null && countryEmptyText !== void 0 ? countryEmptyText : translate("phoneInput.countryEmptyText", "No country found.");
14
20
  const fallback = toIsoCountry(defaultCountry);
15
21
  const parsed = splitPhoneValue(value, fallback);
16
22
  const [selectedCountry, setSelectedCountry] = useState(parsed.country);
@@ -40,5 +46,6 @@ export function PhoneInput({ id, label, info, error, required = false, disabled
40
46
  setSelectedCountry(country);
41
47
  onChange(joinPhoneValue(country, digits));
42
48
  };
43
- return (_jsxs("div", { className: cn("space-y-2", className), children: [label && (_jsx(EnhancedLabel, { htmlFor: id, required: required, children: label })), _jsxs("div", { className: "flex items-start gap-2", children: [_jsxs(Popover, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs(Button, { type: "button", variant: "outline", role: "combobox", "aria-expanded": open, "aria-label": countryAriaLabel, disabled: disabled, className: cn("h-9 w-[112px] shrink-0 justify-between px-2 font-normal", error && "border-destructive"), children: [_jsxs("span", { className: "truncate", children: [flagForCountry(country), " ", selectedDial] }), _jsx(ChevronsUpDown, { className: "ml-1 h-4 w-4 shrink-0 opacity-50" })] }) }), _jsx(PopoverContent, { className: "w-[320px] max-w-[calc(100vw-2rem)] p-0", align: "start", children: _jsxs(Command, { children: [_jsx(CommandInput, { placeholder: countrySearchPlaceholder }), _jsxs(CommandList, { children: [_jsx(CommandEmpty, { children: countryEmptyText }), _jsx(CommandGroup, { children: countries.map((entry) => (_jsxs(CommandItem, { value: `${entry.displayName} ${entry.code} ${entry.dial_code}`, onSelect: () => handleCountryChange(entry.code), children: [_jsx("span", { className: "mr-2", children: entry.flag }), _jsx("span", { className: "flex-1 truncate", children: entry.displayName }), _jsx("span", { className: "text-muted-foreground ml-2", children: entry.dial_code }), _jsx(Check, { className: cn("ml-2 h-4 w-4", country === entry.code ? "opacity-100" : "opacity-0") })] }, entry.code))) })] })] }) })] }), _jsx("div", { className: "min-w-0 flex-1", children: _jsx(EnhancedInput, { id: id, type: "tel", inputMode: "tel", autoComplete: "tel-national", value: displayValue, onChange: (event) => handleNationalChange(event.target.value), error: error, info: info, placeholder: placeholder, disabled: disabled, required: required, testIdWrapper: testId, testIdInput: testId ? `${testId}-input` : undefined }) })] })] }));
49
+ return (_jsxs("div", { className: cn("space-y-2", className), children: [label && (_jsx(EnhancedLabel, { htmlFor: id, required: required, children: label })), _jsxs("div", { className: "flex items-start gap-2", children: [_jsxs(Popover, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs(Button, { type: "button", variant: "outline", role: "combobox", "aria-expanded": open, "aria-label": resolvedCountryAriaLabel, disabled: disabled, className: cn("h-9 w-28 shrink-0 justify-between px-2 font-normal", error && "border-destructive"), children: [_jsxs("span", { className: "truncate", children: [flagForCountry(country), " ", selectedDial] }), _jsx(ChevronsUpDown, { className: "ml-1 h-4 w-4 shrink-0 opacity-50" })] }) }), _jsx(PopoverContent, { className: "w-[320px] max-w-[calc(100vw-2rem)] p-0", align: "start", children: _jsxs(Command, { children: [_jsx(CommandInput, { placeholder: resolvedCountrySearchPlaceholder }), _jsxs(CommandList, { children: [_jsx(CommandEmpty, { children: resolvedCountryEmptyText }), _jsx(CommandGroup, { children: countries.map((entry) => (_jsxs(CommandItem, { value: `${entry.displayName} ${entry.code} ${entry.dial_code}`, onSelect: () => handleCountryChange(entry.code), children: [_jsx("span", { className: "mr-2", children: entry.flag }), _jsx("span", { className: "flex-1 truncate", children: entry.displayName }), _jsx("span", { className: "text-muted-foreground ml-2", children: entry.dial_code }), _jsx(Check, { className: cn("ml-2 h-4 w-4", country === entry.code ? "opacity-100" : "opacity-0") })] }, entry.code))) })] })] }) })] }), _jsxs("div", { className: "min-w-0 flex-1 space-y-2", "data-testid": testId, children: [_jsx(Input, { id: id, type: "tel", inputMode: "tel", autoComplete: "tel-national", value: displayValue, onChange: (event) => handleNationalChange(event.target.value), placeholder: placeholder, disabled: disabled, required: required, "aria-invalid": Boolean(error), "data-testid": testId ? `${testId}-input` : undefined, className: cn(error &&
50
+ "border-destructive focus-visible:border-destructive focus-visible:ring-destructive/20") }), (error || info) && (_jsx("div", { children: error ? (_jsx("p", { className: "text-xs text-destructive", children: error })) : (_jsx("p", { className: "text-xs text-blue-600 dark:text-blue-400", children: info })) }))] })] })] }));
44
51
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/fusion-storybook",
3
- "version": "0.5.31",
3
+ "version": "0.5.34",
4
4
  "scripts": {
5
5
  "build-storybook": "storybook build",
6
6
  "build:next": "next build",