定制 mrshanebarron/phone-input 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mrshanebarron/phone-input

最新稳定版本:v1.0.4

Composer 安装命令:

composer require mrshanebarron/phone-input

包简介

Phone number input with country codes for Laravel - supports Livewire and Vue

README 文档

README

A phone number input with country code selector for Laravel applications. Flag dropdown with dial codes. Works with Livewire and Vue 3.

Installation

composer require mrshanebarron/phone-input

Livewire Usage

Basic Usage

<livewire:sb-phone-input wire:model="phone" />

With Default Country

<livewire:sb-phone-input
    wire:model="phone"
    default-country="GB"
/>

Livewire Props

Prop Type Default Description
wire:model string - Full phone number with country code
default-country string 'US' Default country code
placeholder string 'Phone number' Input placeholder

Vue 3 Usage

Setup

import { SbPhoneInput } from './vendor/sb-phone-input';
app.component('SbPhoneInput', SbPhoneInput);

Basic Usage

<template>
  <SbPhoneInput v-model="phone" />
  <p class="mt-2 text-sm text-gray-500">Full number: {{ phone }}</p>
</template>

<script setup>
import { ref } from 'vue';
const phone = ref('');
</script>

With Default Country

<template>
  <SbPhoneInput
    v-model="phone"
    default-country="GB"
    placeholder="Enter your mobile"
  />
</template>

Contact Form Example

<template>
  <form @submit.prevent="submit" class="space-y-4">
    <div>
      <label class="block text-sm font-medium mb-1">Name</label>
      <input v-model="form.name" class="w-full px-3 py-2 border rounded-lg" />
    </div>

    <div>
      <label class="block text-sm font-medium mb-1">Email</label>
      <input v-model="form.email" type="email" class="w-full px-3 py-2 border rounded-lg" />
    </div>

    <div>
      <label class="block text-sm font-medium mb-1">Phone</label>
      <SbPhoneInput v-model="form.phone" />
    </div>

    <button type="submit" class="w-full py-2 bg-blue-600 text-white rounded-lg">
      Submit
    </button>
  </form>
</template>

<script setup>
import { reactive } from 'vue';

const form = reactive({
  name: '',
  email: '',
  phone: ''
});

const submit = () => {
  console.log('Submitting:', form);
};
</script>

Vue Props

Prop Type Default Description
modelValue String '' Full phone number with dial code
defaultCountry String 'US' Default country code (ISO)
placeholder String 'Phone number' Input placeholder text

Events

Event Payload Description
update:modelValue string Phone number changed

Included Countries

Code Country Dial Code
US United States +1
GB United Kingdom +44
CA Canada +1
AU Australia +61
DE Germany +49
FR France +33
IT Italy +39
ES Spain +34
JP Japan +81
CN China +86
IN India +91
BR Brazil +55
MX Mexico +52

Features

  • Country Selector: Dropdown with flags and dial codes
  • Search Countries: Filter countries by name or code
  • Flag Display: Emoji flags for each country
  • Auto Format: Strips non-numeric characters
  • Combined Output: Returns full number with dial code
  • Click Outside: Closes dropdown on outside click

Styling

Uses Tailwind CSS:

  • Country button with flag
  • Dropdown with search
  • Hover highlights
  • Focus ring on input
  • Rounded input group

Requirements

  • PHP 8.1+
  • Laravel 10, 11, or 12
  • Tailwind CSS 3.x

License

MIT License

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: Vue

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-14