phone-input-lib
Version:
A lightweight, developer-friendly npm library that provides a phone number input component with flags, country codes, and Tailwind support.
199 lines (174 loc) • 4.4 kB
CSS
/* Phone Input Library Styles - Native Tailwind-like CSS */
.phone-input-lib {
--color-gray-50: #f9fafb;
--color-gray-100: #f3f4f6;
--color-gray-200: #e5e7eb;
--color-gray-300: #d1d5db;
--color-gray-400: #9ca3af;
--color-gray-500: #6b7280;
--color-gray-600: #4b5563;
--color-gray-700: #374151;
--color-gray-800: #1f2937;
--color-gray-900: #111827;
--color-blue-500: #3b82f6;
--color-blue-600: #2563eb;
--color-white: #ffffff;
--color-red-500: #ef4444;
--shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
--shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
--border-radius: 0.5rem;
--transition: all 0.15s ease-in-out;
}
/* Phone Input Container */
.phone-input-container {
display: flex;
align-items: center;
gap: 0.5rem;
width: 100%;
}
/* Phone Input Field */
.phone-input-field {
flex: 1;
padding: 0.5rem 0.75rem;
font-size: 0.875rem;
line-height: 1.25rem;
color: var(--color-gray-700);
background-color: var(--color-white);
border: 1px solid var(--color-gray-300);
border-radius: var(--border-radius);
transition: var(--transition);
outline: none;
}
.phone-input-field:focus {
border-color: var(--color-blue-500);
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}
.phone-input-field:disabled {
background-color: var(--color-gray-50);
color: var(--color-gray-400);
cursor: not-allowed;
}
.phone-input-field.error {
border-color: var(--color-red-500);
box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}
/* Country Select Styles */
.country-select-container {
position: relative;
display: inline-block;
min-width: 8rem;
}
.country-select-trigger {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
padding: 0.5rem 0.75rem;
font-size: 0.875rem;
line-height: 1.25rem;
color: var(--color-gray-700);
background-color: var(--color-white);
border: 1px solid var(--color-gray-300);
border-radius: var(--border-radius);
cursor: pointer;
transition: var(--transition);
outline: none;
}
.country-select-trigger:hover {
border-color: var(--color-gray-400);
}
.country-select-trigger:focus {
border-color: var(--color-blue-500);
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}
.country-select-trigger:disabled {
background-color: var(--color-gray-50);
color: var(--color-gray-400);
cursor: not-allowed;
}
.country-select-content {
display: flex;
align-items: center;
gap: 0.5rem;
}
.country-select-chevron {
width: 1rem;
height: 1rem;
transition: transform 0.2s ease-in-out;
fill: currentColor;
}
.country-select-chevron.open {
transform: rotate(180deg);
}
.country-select-dropdown {
position: absolute;
top: 100%;
left: 0;
right: 0;
margin-top: 0.25rem;
background-color: var(--color-white);
border: 1px solid var(--color-gray-300);
border-radius: var(--border-radius);
box-shadow: var(--shadow-lg);
z-index: 50;
max-height: 12rem;
overflow-y: auto;
}
.country-select-option {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 0.5rem 0.75rem;
font-size: 0.875rem;
color: var(--color-gray-700);
cursor: pointer;
transition: background-color 0.15s ease-in-out;
}
.country-select-option:hover {
background-color: var(--color-gray-100);
}
.country-select-option.selected {
background-color: var(--color-blue-500);
color: var(--color-white);
}
.country-select-option-text {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/* Flag Icon Styles */
.flag-icon {
width: 1.25rem;
height: auto;
border-radius: 0.125rem;
flex-shrink: 0;
}
/* Utility Classes */
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
.truncate {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* Responsive Design */
@media (max-width: 640px) {
.phone-input-container {
flex-direction: column;
align-items: stretch;
}
.country-select-container {
min-width: unset;
width: 100%;
}
}