import type { Meta, StoryObj } from '@storybook/nextjs-vite';
import { PhoneInput } from '../components/ui/phone-input';
import { useState } from 'react';
import type { CountryCode } from 'libphonenumber-js';
const meta = {
title: 'UI/PhoneInput',
component: PhoneInput,
parameters: {
layout: 'padded',
},
decorators: [
(Story) => (
),
],
} satisfies Meta;
export default meta;
type Story = StoryObj;
function PhoneInputControlled(props: Partial>) {
const [phone, setPhone] = useState(props.value ?? '');
const [country, setCountry] = useState(props.countryCode ?? 'US');
const [isInvalid, setIsInvalid] = useState(false);
return (
{isInvalid && (
Invalid phone number
)}
);
}
/**
* Default phone input with US country code.
*/
export const Default: Story = {
args: {
value: '',
countryCode: 'US',
onPhoneChange: () => {},
onCountryChange: () => {},
},
render: () => ,
};
/**
* Phone input with UK country code.
*/
export const UnitedKingdom: Story = {
args: {
value: '',
countryCode: 'GB',
onPhoneChange: () => {},
onCountryChange: () => {},
},
render: () => ,
};
/**
* Phone input with a pre-filled value.
*/
export const WithValue: Story = {
args: {
value: '(555) 123-4567',
countryCode: 'US',
onPhoneChange: () => {},
onCountryChange: () => {},
},
render: () => ,
};
/**
* Disabled state.
*/
export const Disabled: Story = {
args: {
value: '(555) 123-4567',
countryCode: 'US',
disabled: true,
onPhoneChange: () => {},
onCountryChange: () => {},
},
render: () => ,
};
/**
* Custom placeholder text.
*/
export const CustomPlaceholder: Story = {
args: {
value: '',
countryCode: 'US',
placeholder: 'Enter phone...',
onPhoneChange: () => {},
onCountryChange: () => {},
},
render: () => ,
};
/**
* In a narrow container (300px) to test overflow handling.
*/
export const NarrowContainer: Story = {
args: {
value: '',
countryCode: 'US',
onPhoneChange: () => {},
onCountryChange: () => {},
},
decorators: [
(Story) => (
),
],
render: () => ,
};
/**
* German country code pre-selected.
*/
export const Germany: Story = {
args: {
value: '',
countryCode: 'DE',
onPhoneChange: () => {},
onCountryChange: () => {},
},
render: () => ,
};