@fairmint/ui 0.2.2 → 0.2.3
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/components/form/ZipField/ZipField.d.ts +25 -0
- package/dist/components/form/ZipField/ZipField.d.ts.map +1 -0
- package/dist/fairmint-ui.cjs +26 -0
- package/dist/fairmint-ui.cjs.map +1 -1
- package/dist/fairmint-ui.js +27 -1
- package/dist/fairmint-ui.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { TextInputProps } from '../../primitives/TextInput/TextInput';
|
|
3
|
+
export interface ZipSchemaOptions {
|
|
4
|
+
/** When true, accepts international postal codes (UK, Canada, Europe, etc.).
|
|
5
|
+
* Defaults to false — US ZIP codes only. */
|
|
6
|
+
international?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Creates a Zod schema for postal/ZIP code validation.
|
|
10
|
+
*
|
|
11
|
+
* Default (US): accepts `94105` and `94105-1234` only.
|
|
12
|
+
* International: accepts `K1A 0B1`, `SW1A 2AA`, `12345`, etc.
|
|
13
|
+
* Input is trimmed before validation in both modes.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createZipSchema(options?: ZipSchemaOptions): z.ZodString;
|
|
16
|
+
/** Zod schema for US ZIP codes (`94105`, `94105-1234`). Use `createZipSchema({ international: true })` for international. */
|
|
17
|
+
export declare const zipSchema: z.ZodString;
|
|
18
|
+
export interface ZipFieldProps extends Omit<TextInputProps, "type"> {
|
|
19
|
+
error?: string;
|
|
20
|
+
/** When true, adjusts placeholder for international postal codes. */
|
|
21
|
+
international?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/** Postal/ZIP code input. US ZIP only by default; pass `international` for global formats. */
|
|
24
|
+
export declare function ZipField({ error, international, ...rest }: ZipFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
25
|
+
//# sourceMappingURL=ZipField.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ZipField.d.ts","sourceRoot":"","sources":["../../../../src/components/form/ZipField/ZipField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AAa3E,MAAM,WAAW,gBAAgB;IAC/B;iDAC6C;IAC7C,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,gBAAgB,eAazD;AAED,6HAA6H;AAC7H,eAAO,MAAM,SAAS,aAAoB,CAAC;AAE3C,MAAM,WAAW,aAAc,SAAQ,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC;IACjE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,8FAA8F;AAC9F,wBAAgB,QAAQ,CAAC,EAAE,KAAK,EAAE,aAAqB,EAAE,GAAG,IAAI,EAAE,EAAE,aAAa,2CAYhF"}
|
package/dist/fairmint-ui.cjs
CHANGED
|
@@ -24840,6 +24840,29 @@ function PhoneField({ error: error2, ...rest }) {
|
|
|
24840
24840
|
}
|
|
24841
24841
|
);
|
|
24842
24842
|
}
|
|
24843
|
+
const US_ZIP_REGEX = /^\d{5}(-\d{4})?$/;
|
|
24844
|
+
const INTL_POSTAL_REGEX = /^[A-Z0-9]+(?:[ -][A-Z0-9]+)*$/i;
|
|
24845
|
+
function createZipSchema(options) {
|
|
24846
|
+
if (options?.international) {
|
|
24847
|
+
return stringType().trim().min(3, "Please enter a valid postal code").max(10, "Please enter a valid postal code").regex(INTL_POSTAL_REGEX, "Please enter a valid postal code");
|
|
24848
|
+
}
|
|
24849
|
+
return stringType().trim().regex(US_ZIP_REGEX, "Please enter a valid ZIP code (e.g. 94105 or 94105-1234)");
|
|
24850
|
+
}
|
|
24851
|
+
const zipSchema = createZipSchema();
|
|
24852
|
+
function ZipField({ error: error2, international = false, ...rest }) {
|
|
24853
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
24854
|
+
TextInput,
|
|
24855
|
+
{
|
|
24856
|
+
type: "text",
|
|
24857
|
+
label: rest.label ?? "ZIP / Postal Code",
|
|
24858
|
+
placeholder: rest.placeholder ?? (international ? "SW1A 2AA" : "94105"),
|
|
24859
|
+
autoComplete: "postal-code",
|
|
24860
|
+
inputMode: "text",
|
|
24861
|
+
error: error2,
|
|
24862
|
+
...rest
|
|
24863
|
+
}
|
|
24864
|
+
);
|
|
24865
|
+
}
|
|
24843
24866
|
const ANIMATION_MAP = {
|
|
24844
24867
|
up: "fadeUp",
|
|
24845
24868
|
down: "fadeDown",
|
|
@@ -25838,8 +25861,10 @@ exports.Tooltip = Tooltip;
|
|
|
25838
25861
|
exports.UserMenu = UserMenu;
|
|
25839
25862
|
exports.WalletList = WalletList;
|
|
25840
25863
|
exports.ZERO_ETHEREUM_ADDRESS = ZERO_ETHEREUM_ADDRESS;
|
|
25864
|
+
exports.ZipField = ZipField;
|
|
25841
25865
|
exports.brandColors = brandColors;
|
|
25842
25866
|
exports.colors = colors;
|
|
25867
|
+
exports.createZipSchema = createZipSchema;
|
|
25843
25868
|
exports.emailSchema = emailSchema;
|
|
25844
25869
|
exports.formatCurrency = formatCurrency;
|
|
25845
25870
|
exports.formatCurrencyPrecise = formatCurrencyPrecise;
|
|
@@ -25871,4 +25896,5 @@ exports.useScrollIntoView = useScrollIntoView;
|
|
|
25871
25896
|
exports.useViewportSize = useViewportSize;
|
|
25872
25897
|
exports.validateEthereumAddress = validateEthereumAddress;
|
|
25873
25898
|
exports.z = z;
|
|
25899
|
+
exports.zipSchema = zipSchema;
|
|
25874
25900
|
//# sourceMappingURL=fairmint-ui.cjs.map
|