File size: 3,591 Bytes
ef987bb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Floating Prompt Area</title>
<style>
* { box-sizing: border-box; }
body { font-family: system-ui, sans-serif; margin: 0; background: #f5f6f8; color: #1a1a1a;
min-height: 140vh; padding-bottom: 140px; }
header { padding: 16px 24px; background: #fff; border-bottom: 1px solid #e3e6ea; }
.chat-history { max-width: 760px; margin: 24px auto; padding: 0 16px; display: flex;
flex-direction: column; gap: 12px; }
.chat-message { padding: 10px 14px; border-radius: 12px; max-width: 70%; }
.chat-message.user { align-self: flex-end; background: #d7e9ff; }
.chat-message.bot { align-self: flex-start; background: #fff; border: 1px solid #e3e6ea; }
/*
floating-prompt-area refactor:
previously this area displayed messages that were already sent (history).
It now hosts a REUSABLE input in a pending (waiting-to-send) state.
The floating behavior (fixed at the bottom) and the rounded-corner
logic are preserved.
*/
.floating-prompt-area {
position: fixed;
left: 50%;
bottom: 80px;
transform: translateX(-50%);
width: min(720px, calc(100vw - 32px));
background: #fff;
border: 1px solid #ccd2da;
box-shadow: 0 8px 24px rgba(0,0,0,0.12);
padding: 10px 12px;
display: flex;
gap: 8px;
align-items: center;
}
/* rounded / corner logic kept on the floating area */
.floating-prompt-area.rounded { border-radius: 18px; }
.prompt-input {
flex: 1;
border: none;
outline: none;
font-size: 15px;
padding: 12px 8px;
background: transparent;
}
.send-btn { border: none; background: #2563eb; color: #fff; border-radius: 12px;
padding: 10px 18px; cursor: pointer; font-size: 15px; }
</style>
</head>
<body>
<header><strong>Conversation</strong></header>
<div class="chat-history" id="history">
<div class="chat-message bot">Hello! How can I help?</div>
<div class="chat-message user">Please refactor the floating input area.</div>
<div class="chat-message bot">Done. The input area is now ready for a new message.</div>
</div>
<!-- floating prompt area now contains the reusable pending input, not sent messages -->
<div class="floating-prompt-area rounded" data-testid="floating-prompt-area" data-state="pending">
<input class="prompt-input" data-testid="reusable-prompt-input"
placeholder="Type a message..." aria-label="prompt input">
<button class="send-btn" id="send" data-testid="send-button">Send</button>
</div>
<script>
window.__setComposerCorners=mode=>document.querySelector('[data-testid=floating-prompt-area]').classList.toggle('rounded',mode==='rounded');
const input = document.querySelector('[data-testid="reusable-prompt-input"]');
const history = document.getElementById('history');
function send() {
const text = input.value.trim();
if (!text) return; // empty input never appends
const msg = document.createElement('div');
msg.className = 'chat-message user';
msg.setAttribute('data-testid', 'chat-message-user');
msg.textContent = text;
history.appendChild(msg); // append the new user bubble
input.value = ''; // clear the reusable pending input
}
document.getElementById('send').addEventListener('click', send);
input.addEventListener('keydown', (e) => {
if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); send(); }
});
</script>
</body>
</html>
|