헤더 타이머 추가

This commit is contained in:
ming 2025-04-17 04:51:57 +09:00
parent f90962c54f
commit 578f41c212
4 changed files with 29 additions and 3 deletions

View File

@ -86,7 +86,7 @@
@layer utilities {
.header {
@apply p-4 text-lg font-bold h-16 flex justify-between;
@apply p-4 text-lg font-bold h-16 flex justify-between items-center;
}
.side-bar {

View File

@ -6,3 +6,6 @@ import { application } from "./application"
import HelloController from "./hello_controller"
application.register("hello", HelloController)
import TimerController from "./timer_controller"
application.register("timer", TimerController)

View File

@ -0,0 +1,22 @@
import { Controller } from "@hotwired/stimulus"
// Connects to data-controller="timer"
export default class extends Controller {
static targets = ["output"]
connect() {
this.updateTime()
this.interval = setInterval(() => this.updateTime(), 1000)
}
disconnect() {
clearInterval(this.interval)
}
updateTime() {
const now = new Date()
const formatted = `${now.getFullYear()}${String(now.getMonth() + 1).padStart(2, '0')}${String(now.getDate()).padStart(2, '0')}` +
`${String(now.getHours()).padStart(2, '0')}${String(now.getMinutes()).padStart(2, '0')}${String(now.getSeconds()).padStart(2, '0')}`
this.outputTarget.textContent = formatted
}
}

View File

@ -1,8 +1,9 @@
<header class="flex header">
<div class="flex flex-row">
<header class="flex header" data-controller="timer">
<div class="flex flex-row h-full">
<%= image_tag "svg/svg_logo.svg", class: "w-16 h-auto" %>
<div class="flex h-full items-center tracking-[0.5rem]">FARMITRY</div>
</div>
<div data-timer-target="output" class="text-gray-600"></div>
<div class="flex flex-row items-center gap-x-4">
<i class="fa-solid fa-circle-user text-4xl text-default-slate-dark"></i>
<%= link_to "로그아웃", '', class: "btn" %>