Skip to content

Commit bc485a0

Browse files
Merge pull request #93 from linked-planet/dev
fixed nowbar moving with slot selection
2 parents 9314b4c + 4f96f61 commit bc485a0

File tree

5 files changed

+61
-158
lines changed

5 files changed

+61
-158
lines changed

library/src/components/timetable/TimeTable.tsx

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -625,50 +625,23 @@ function moveNowBar(
625625

626626
const startSlot = startAndEndSlot.startSlot
627627

628-
// the first row in the body is used for the time slot bars
629-
let childIdx = 0
630-
let tbodyFirstRow = tableBody.children[childIdx] as
631-
| HTMLTableRowElement
632-
| undefined
633-
// now get the current time slot index element (not -1 because the first empty element for the groups)
634-
635-
// find the first rendered row
636-
while (tbodyFirstRow && tbodyFirstRow.children.length === 0) {
637-
childIdx++
638-
tbodyFirstRow = tableBody.children[childIdx] as
639-
| HTMLTableRowElement
640-
| undefined
641-
}
642-
643-
if (!tbodyFirstRow) {
644-
console.warn(
645-
"LPTimeTable - unable to find time slot row for the now bar",
646-
)
647-
return
648-
}
649-
650-
const slotBar = tbodyFirstRow?.children[startSlot + 1] as
651-
| HTMLDivElement
652-
| undefined
653-
if (!slotBar) {
654-
console.warn(
655-
"LPTimeTable - unable to find time slot column for the now bar: ",
656-
startSlot,
657-
)
628+
// add orange border
629+
const nowTimeSlotCell = headerTimeSlotCells[startSlot + 1]
630+
if (!nowTimeSlotCell) {
631+
console.error("unable to find header for time slot of the current time")
658632
return
659633
}
660634

661-
// adjust the nowbar div to the right parent, or create it if it doesn't exist
662635
if (nowBar) {
663-
if (nowBar.parentElement !== slotBar) {
664-
slotBar.appendChild(nowBar)
636+
if (nowBar.parentElement !== nowTimeSlotCell) {
637+
nowTimeSlotCell.appendChild(nowBar)
665638
}
666639
} else {
667640
nowBar = document.createElement("div")
668641
//nowBar.className = styles.nowBar
669642
nowBar.className =
670643
"absolute opacity-60 bg-orange-bold top-0 bottom-0 z-[2] w-[2px]"
671-
slotBar.appendChild(nowBar)
644+
//slotBar.appendChild(nowBar)
672645
nowBarRef.current = nowBar
673646
}
674647

@@ -682,14 +655,8 @@ function moveNowBar(
682655

683656
const diffPerc = diffNow / timeSlotMinutes
684657
nowBar.style.left = `${diffPerc * 100}%`
685-
nowBar.style.height = `${tableBody.getBoundingClientRect().bottom - slotBar.getBoundingClientRect().top}px`
686-
687-
// add orange border
688-
const nowTimeSlotCell = headerTimeSlotCells[startSlot + 1]
689-
if (!nowTimeSlotCell) {
690-
console.error("unable to find header for time slot of the current time")
691-
return
692-
}
658+
nowBar.style.top = "100%"
659+
nowBar.style.height = `${tableBody.getBoundingClientRect().bottom - nowTimeSlotCell.getBoundingClientRect().top}px`
693660

694661
nowTimeSlotCell.classList.remove(
695662
"border-b-border-bold",

library/src/components/timetable/TimeTableHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export const LPTimeTableHeader = function TimeTableHeader<
203203
)
204204
})}
205205
</colgroup>
206-
<thead ref={tableHeaderRef} className="sticky top-0 z-[5]">
206+
<thead ref={tableHeaderRef} className="sticky top-0 z-[4]">
207207
<tr>
208208
<th
209209
style={{

package-lock.json

Lines changed: 18 additions & 113 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@
7676
]
7777
},
7878
"dependencies": {
79-
"@atlaskit/empty-state": "^7.12.3",
80-
"@atlaskit/icon": "^22.28.0",
79+
"@atlaskit/empty-state": "^8.0.1",
80+
"@atlaskit/icon": "^23.1.0",
8181
"@emotion/css": "^11.13.5",
8282
"@hello-pangea/dnd": "^17.0.0",
8383
"@radix-ui/react-accordion": "^1.2.1",

showcase/public/showcase-sources.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2214,6 +2214,32 @@ export default CodeBlockShowcase
22142214
import { Collapsible } from "@linked-planet/ui-kit-ts/components/Collapsible"
22152215
import type { ShowcaseProps } from "../../ShowCaseWrapperItem/ShowcaseWrapperItem"
22162216
import ShowcaseWrapperItem from "../../ShowCaseWrapperItem/ShowcaseWrapperItem"
2217+
import { useState } from "react"
2218+
import { Button } from "@linked-planet/ui-kit-ts"
2219+
2220+
//#region collapsible-controlled
2221+
function CollapsibleControlled() {
2222+
const [open, setOpen] = useState(false)
2223+
return (
2224+
<>
2225+
<Button
2226+
onClick={() => setOpen(!open)}
2227+
className="btn btn-primary"
2228+
type="button"
2229+
>
2230+
{open ? "Close" : "Open"}
2231+
</Button>
2232+
<Collapsible
2233+
header={<h4>Collapsible Title</h4>}
2234+
open={open}
2235+
onChanged={setOpen}
2236+
>
2237+
<div className="p-4">collapsible content</div>
2238+
</Collapsible>
2239+
</>
2240+
)
2241+
}
2242+
//#endregion collapsible-controlled
22172243

22182244
export default function CollapsibleShowcase(props: ShowcaseProps) {
22192245
//#region collapsible
@@ -2264,6 +2290,11 @@ export default function CollapsibleShowcase(props: ShowcaseProps) {
22642290
example: example1,
22652291
sourceCodeExampleId: "collapsible1",
22662292
},
2293+
{
2294+
title: "Controlled",
2295+
example: <CollapsibleControlled />,
2296+
sourceCodeExampleId: "collapsible-controlled",
2297+
},
22672298
]}
22682299
/>
22692300
)

0 commit comments

Comments
 (0)