windjammer-ui 0.3.6

Cross-platform UI framework for Windjammer (Web, Desktop, Mobile)
Documentation
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Windjammer Form Validation</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }

        .container {
            background: white;
            border-radius: 12px;
            box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
            max-width: 500px;
            width: 100%;
            padding: 40px;
        }

        h1 {
            color: #333;
            margin-bottom: 30px;
            font-size: 28px;
            text-align: center;
        }

        .form-group {
            margin-bottom: 20px;
        }

        label {
            display: block;
            margin-bottom: 8px;
            color: #555;
            font-weight: 600;
            font-size: 14px;
        }

        input, textarea {
            width: 100%;
            padding: 12px 16px;
            border: 2px solid #e0e0e0;
            border-radius: 8px;
            font-size: 16px;
            font-family: inherit;
            transition: border-color 0.3s;
        }

        input:focus, textarea:focus {
            outline: none;
            border-color: #667eea;
        }

        input.error, textarea.error {
            border-color: #dc3545;
        }

        input.valid, textarea.valid {
            border-color: #28a745;
        }

        .error-message {
            color: #dc3545;
            font-size: 13px;
            margin-top: 6px;
            display: none;
        }

        .error-message.show {
            display: block;
        }

        .success-message {
            color: #28a745;
            font-size: 13px;
            margin-top: 6px;
            display: none;
        }

        .success-message.show {
            display: block;
        }

        button {
            width: 100%;
            padding: 14px;
            background: #667eea;
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: background 0.3s;
            margin-top: 10px;
        }

        button:hover:not(:disabled) {
            background: #5568d3;
        }

        button:disabled {
            background: #ccc;
            cursor: not-allowed;
        }

        .success-banner {
            background: #d4edda;
            border: 2px solid #28a745;
            color: #155724;
            padding: 16px;
            border-radius: 8px;
            margin-bottom: 20px;
            display: none;
            text-align: center;
            font-weight: 600;
        }

        .success-banner.show {
            display: block;
        }

        .char-count {
            font-size: 12px;
            color: #999;
            text-align: right;
            margin-top: 4px;
        }

        .char-count.warning {
            color: #ff9800;
        }

        .char-count.error {
            color: #dc3545;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>📋 Registration Form</h1>
        
        <div class="success-banner" id="success-banner">
            ✅ Form submitted successfully!
        </div>

        <form id="registration-form">
            <div class="form-group">
                <label for="username">Username *</label>
                <input type="text" id="username" placeholder="Choose a username" />
                <div class="error-message" id="username-error"></div>
                <div class="success-message" id="username-success">✓ Username available</div>
            </div>

            <div class="form-group">
                <label for="email">Email *</label>
                <input type="email" id="email" placeholder="your@email.com" />
                <div class="error-message" id="email-error"></div>
                <div class="success-message" id="email-success">✓ Valid email</div>
            </div>

            <div class="form-group">
                <label for="password">Password *</label>
                <input type="password" id="password" placeholder="At least 8 characters" />
                <div class="error-message" id="password-error"></div>
                <div class="success-message" id="password-success">✓ Strong password</div>
            </div>

            <div class="form-group">
                <label for="confirm-password">Confirm Password *</label>
                <input type="password" id="confirm-password" placeholder="Re-enter password" />
                <div class="error-message" id="confirm-password-error"></div>
                <div class="success-message" id="confirm-password-success">✓ Passwords match</div>
            </div>

            <div class="form-group">
                <label for="bio">Bio (optional)</label>
                <textarea id="bio" rows="4" placeholder="Tell us about yourself..." maxlength="200"></textarea>
                <div class="char-count" id="char-count">0 / 200</div>
            </div>

            <button type="submit" id="submit-btn" disabled>Submit</button>
        </form>
    </div>

    <script>
        // Form validation logic (demonstrates what we'll build in Windjammer)
        const form = document.getElementById('registration-form');
        const username = document.getElementById('username');
        const email = document.getElementById('email');
        const password = document.getElementById('password');
        const confirmPassword = document.getElementById('confirm-password');
        const bio = document.getElementById('bio');
        const submitBtn = document.getElementById('submit-btn');
        const successBanner = document.getElementById('success-banner');
        const charCount = document.getElementById('char-count');

        const validators = {
            username: (value) => {
                if (!value) return 'Username is required';
                if (value.length < 3) return 'Username must be at least 3 characters';
                if (!/^[a-zA-Z0-9_]+$/.test(value)) return 'Username can only contain letters, numbers, and underscores';
                return null;
            },
            email: (value) => {
                if (!value) return 'Email is required';
                if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) return 'Invalid email format';
                return null;
            },
            password: (value) => {
                if (!value) return 'Password is required';
                if (value.length < 8) return 'Password must be at least 8 characters';
                if (!/[A-Z]/.test(value)) return 'Password must contain an uppercase letter';
                if (!/[a-z]/.test(value)) return 'Password must contain a lowercase letter';
                if (!/[0-9]/.test(value)) return 'Password must contain a number';
                return null;
            },
            confirmPassword: (value) => {
                if (!value) return 'Please confirm your password';
                if (value !== password.value) return 'Passwords do not match';
                return null;
            }
        };

        function validateField(field, validatorKey) {
            const value = field.value;
            const error = validators[validatorKey](value);
            const errorEl = document.getElementById(`${field.id}-error`);
            const successEl = document.getElementById(`${field.id}-success`);

            if (error) {
                field.classList.add('error');
                field.classList.remove('valid');
                errorEl.textContent = error;
                errorEl.classList.add('show');
                successEl.classList.remove('show');
                return false;
            } else {
                field.classList.remove('error');
                field.classList.add('valid');
                errorEl.classList.remove('show');
                if (value) successEl.classList.add('show');
                return true;
            }
        }

        function checkFormValidity() {
            const isValid = 
                validateField(username, 'username') &&
                validateField(email, 'email') &&
                validateField(password, 'password') &&
                validateField(confirmPassword, 'confirmPassword');
            
            submitBtn.disabled = !isValid;
        }

        username.addEventListener('input', () => {
            validateField(username, 'username');
            checkFormValidity();
        });

        email.addEventListener('input', () => {
            validateField(email, 'email');
            checkFormValidity();
        });

        password.addEventListener('input', () => {
            validateField(password, 'password');
            if (confirmPassword.value) {
                validateField(confirmPassword, 'confirmPassword');
            }
            checkFormValidity();
        });

        confirmPassword.addEventListener('input', () => {
            validateField(confirmPassword, 'confirmPassword');
            checkFormValidity();
        });

        bio.addEventListener('input', () => {
            const length = bio.value.length;
            charCount.textContent = `${length} / 200`;
            
            if (length > 180) {
                charCount.classList.add('error');
                charCount.classList.remove('warning');
            } else if (length > 150) {
                charCount.classList.add('warning');
                charCount.classList.remove('error');
            } else {
                charCount.classList.remove('warning', 'error');
            }
        });

        form.addEventListener('submit', (e) => {
            e.preventDefault();
            
            successBanner.classList.add('show');
            form.reset();
            submitBtn.disabled = true;
            
            // Clear all validation states
            [username, email, password, confirmPassword].forEach(field => {
                field.classList.remove('valid', 'error');
                document.getElementById(`${field.id}-error`).classList.remove('show');
                document.getElementById(`${field.id}-success`).classList.remove('show');
            });

            charCount.textContent = '0 / 200';
            charCount.classList.remove('warning', 'error');

            setTimeout(() => {
                successBanner.classList.remove('show');
            }, 3000);
        });
    </script>
</body>
</html>