Bangladesh
Phone input
+880 mobile numbers typed any way, Bangla digits too; names the operator and gives back +8801XXXXXXXXX.
+880Grameenphone
Type it any way: 017…, +880 17…, or in Bangla digits.
+880
Try 012: no operator uses it.
phone-input.tsx
"use client";
import { type BdPhone, FormField, PhoneInput } from "@waveinno/ui";
import * as React from "react";
export default function PhoneDemo() {
const [phone, setPhone] = React.useState<BdPhone | null>(null);
return (
<div className="grid gap-6 md:grid-cols-2">
<FormField label="Mobile number" hint={phone?.valid ? `Saved as ${phone.e164}` : "Type it any way: 017…, +880 17…, or in Bangla digits."}>
<PhoneInput defaultValue="01712345678" onValueChange={(_, p) => setPhone(p)} />
</FormField>
<FormField label="Empty, with a wrong prefix as you type" hint="Try 012: no operator uses it.">
<PhoneInput />
</FormField>
</div>
);
}Import#
Everything comes from the package root. The example above uses:
your-component.tsx
import { type BdPhone, FormField, PhoneInput } from "@waveinno/ui";Props#
Read from the source of this version, so they match the code exactly.
<PhoneInput>
src/components/ui/phone-input.tsx| Prop | Type | Default | Description |
|---|---|---|---|
value | string | — | Any form of the number; "+8801712345678" is what you get back. |
defaultValue | string | "" | |
onValueChange | (e164: string, phone: BdPhone) => void | — | |
showOperator | boolean | true | Show the operator on the right as you type. Default true. |
state | InputState | "default" | |
labels | { invalidPrefix?: string } | — |
Also takes Omit<React.InputHTMLAttributes<HTMLInputElement>, "value" | "defaultValue" | "onChange" | "type">.
<FormField>
src/components/ui/form-field.tsx| Prop | Type | Default | Description |
|---|---|---|---|
label | React.ReactNode | — | |
htmlFor | string | — | The control's id, so clicking the label focuses it. |
required | boolean | — | |
hint | React.ReactNode | — | |
error | React.ReactNode | — | |
warning | React.ReactNode | — | |
success | React.ReactNode | — | |
count | { value: number; max: number } | — | Character counter, e.g. { value: note.length, max: 240 }. |
className | string | — | |
childrenrequired | React.ReactNode | — |
Install#
If the project does not have the package yet, add it, then follow the setup for Next.js or Vite once.
$ npm install @waveinno/ui