Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
feat: sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
choisihun committed Aug 26, 2024
1 parent 76f0cb1 commit 03d3070
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 0 deletions.
Empty file added canbus-web/route/addRoute.js
Empty file.
7 changes: 7 additions & 0 deletions canbus-web/route/editRoute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
useEffect(() => {
document.body.style.overflow = "hidden";

return () => {
document.body.style.overflow = "unset";
};
}, []);
12 changes: 12 additions & 0 deletions canbus-web/route/editroute.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Example</title>
<style>
.gray-bar {
width: 35px;
height: 4px;
position: relative;
background: #DCDDDE;
border-radius: 8px;
margin-bottom: 16px;
align-self: center;
}

.input-container {
display: flex;
flex-direction: column;
width: 361px;
padding: 20px;
border-radius: 10px;
background-color: #ffffff;
align-self: center;
}

.input-wrapper {
Expand Down Expand Up @@ -78,6 +89,7 @@
</head>
<body>
<div class="input-container">
<div class="gray-bar"></div>
<div>
<div class="input-wrapper">
<input type="text" placeholder="출발 시간을 입력하세요">
Expand Down
153 changes: 153 additions & 0 deletions canbus-web/sheet/sheet.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Draggable Bottom Modal Sheet</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
height: 100vh;
background-color: #f0f0f0;
display: flex;
justify-content: center;
align-items: center;
}

button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}

.modal {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
display: flex;
justify-content: flex-end;
transition: height 0.3s ease;
}

.modal-bg {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
transition: background-color 0.3s ease;
pointer-events: none;
}

.modal.show .modal-bg {
pointer-events: auto;
}

.modal-content {
width: 100%;
background-color: white;
padding: 0px;
border-radius: 15px 15px 0 0;
position: relative;
transform: translateY(100%);
transition: transform 0.3s ease, height 0.3s ease;
min-height: 230px;
}

.modal.show .modal-content {
transform: translateY(0);
}

.white-bar {
width: 100%;
height: 30px;
display: flex;
justify-content: center; /* Align horizontally to center */
align-items: center; /* Align vertically to center */
cursor: grab; /* Add cursor style for dragging */
}

.gray-bar {
width: 35px;
height: 4px;
background: #DCDDDE;
border-radius: 8px;
margin-top: 12px;
margin-bottom: 16px;
}

.white-bar:active {
cursor: grabbing;
}
</style>
</head>
<body>
<button id="openModalBtn">Open Modal</button>

<div id="modal" class="modal">
<div class="modal-bg"></div>
<div class="modal-content">
<div class="white-bar">
<div class="gray-bar"></div>
</div>
<div>

</div>
</div>
</div>

<script>
document.addEventListener('DOMContentLoaded', function () {
const modal = document.getElementById('modal');
const modalBg = document.querySelector('.modal-bg');
const openModalBtn = document.getElementById('openModalBtn');
const modalContent = document.querySelector('.modal-content');
const whiteBar = document.querySelector('.white-bar');

let isDragging = false;
let startY = 0;
let startHeight = 0;
const MIN_HEIGHT = 230;
const MAX_HEIGHT = 700;

function onMouseMove(event) {
if (!isDragging) return;

// Calculate new height and ensure it is not below MIN_HEIGHT
const newHeight = Math.min(MAX_HEIGHT, Math.max(MIN_HEIGHT, startHeight - (event.clientY - startY)));

// Adjust the height and translateY
modalContent.style.height = newHeight + 'px';
modalContent.style.transform = `translateY(${Math.max(0, MIN_HEIGHT - newHeight)}px)`;
}

function onMouseUp() {
isDragging = false;
document.removeEventListener('mousemove', onMouseMove);
document.removeEventListener('mouseup', onMouseUp);
}

whiteBar.addEventListener('mousedown', function (event) {
isDragging = true;
startY = event.clientY;
startHeight = modalContent.offsetHeight;
document.addEventListener('mousemove', onMouseMove);
document.addEventListener('mouseup', onMouseUp);
});

openModalBtn.addEventListener('click', function () {
modal.classList.add('show');
modalContent.style.height = MAX_HEIGHT + 'px'; // Set to maximum height when opened
modalContent.style.transform = `translateY(0)`;
});

modalBg.addEventListener('click', function () {
closeModalBtn.click(); // Trigger close button functionality
});
});
</script>
</body>
</html>
19 changes: 19 additions & 0 deletions canbus-web/sheet/sheet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
document.addEventListener('DOMContentLoaded', function () {
const modal = document.getElementById('modal');
const openModalBtn = document.getElementById('openModalBtn');
const closeModalBtn = document.getElementById('closeModalBtn');

openModalBtn.addEventListener('click', function () {
modal.classList.add('show');
});

closeModalBtn.addEventListener('click', function () {
modal.classList.remove('show');
});

window.addEventListener('click', function (event) {
if (event.target === modal) {
modal.classList.remove('show');
}
});
});

0 comments on commit 03d3070

Please sign in to comment.