Skip to content

Commit

Permalink
Calendar: Popup from calendar widget to be resized #580
Browse files Browse the repository at this point in the history
Calendar: Improve event layout and positioning
  • Loading branch information
ivan-b committed Jan 31, 2025
1 parent 1dd1995 commit 2e66b44
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
34 changes: 30 additions & 4 deletions packages/oceanfront/src/components/Calendar/daycolumn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ export default defineComponent({
selectionStart: 0,
selectionEnd: 0,
selectionCategory: '',
dayEl: undefined as HTMLElement | undefined,
eventMaxWidth: 250,
allDayPopups: {
active: {},
closeTimerId: {},
Expand Down Expand Up @@ -203,6 +205,9 @@ export default defineComponent({
return [start, end]
}
},
mounted: function () {
this.$data.dayEl = this.$refs.dayEl as HTMLElement | undefined
},
methods: {
intervals() {
const [start, end] = this.hoursInterval
Expand Down Expand Up @@ -309,7 +314,8 @@ export default defineComponent({
style: {
'background-color': finalColor,
width: 'calc(' + (e.daysSpan || 1) * 100 + '% - 4px)',
top: '' + e.top * eventHeight + 'px'
top: '' + e.top * eventHeight + 'px',
'max-width': this.$data.eventMaxWidth + 'px'
},
tabindex: '0',
onClick: (event: any) => {
Expand Down Expand Up @@ -660,6 +666,24 @@ export default defineComponent({
this.$props.eventClass?.(e.event) ??
(e.event.class ? { [e.event.class]: true } : {})
const finalEvent = { ...e.event, color: finalColor }

const eventsGap = 3
const dayWidth =
this.$data.dayEl?.getBoundingClientRect().width ??
this.$data.eventMaxWidth
const columnsNum = 1 / e.width
const maxWidth = columnsNum * this.$data.eventMaxWidth < dayWidth
const left = maxWidth
? this.$data.eventMaxWidth * e.columnNum +
e.columnNum * eventsGap +
'px'
: this.$props.layout === 'stack'
? e.left * 100 + '%'
: 'calc(' + e.left * 100 + '% + ' + eventsGap + 'px)'
const width = maxWidth
? this.$data.eventMaxWidth - eventsGap + 'px'
: 'calc(' + (e.width * 100 + '% - ' + eventsGap) + 'px)'

return h(
'div',
{
Expand All @@ -670,10 +694,11 @@ export default defineComponent({
'two-lines': brk
},
style: {
'max-width': this.$data.eventMaxWidth + 'px',
'background-color': finalColor,
'z-index': e.zIndex,
left: e.left * 100 + '%',
width: 'calc(' + e.width * 100 + '% - 4px)',
left,
width,
top: 'calc(' + e.top + '% + 1px)',
height: 'calc(' + e.height + '% - 3px)',
'min-height': 'calc(' + e.height + '% - 3px)'
Expand Down Expand Up @@ -738,7 +763,8 @@ export default defineComponent({
'div',
{
class: ['of-calendar-day', weekDayCls],
...this.intervalSelectionHandlers(cat)
...this.intervalSelectionHandlers(cat),
ref: 'dayEl'
},
[...intervals, ...events]
)
Expand Down
2 changes: 2 additions & 0 deletions packages/oceanfront/src/lib/calendar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ export function getGroups(
width: 0,
left: 0,
columns: 1,
columnNum: 0,
offset: 0,
zIndex: 0,
columnAdjust: 0,
Expand Down Expand Up @@ -388,6 +389,7 @@ export type CalendarEventPlacement = {
left: number
columns: number
columnAdjust: number
columnNum: number
offset: number
zIndex: number
conflict: boolean
Expand Down
3 changes: 3 additions & 0 deletions packages/oceanfront/src/lib/calendar/layout/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ export default function layout(
})
const colWidth = 1.0 / columns.length
let left = 0
let i = 0
for (const c of columns) {
for (const p of c.placements) {
p.left = left
p.width = colWidth * p.columns
p.columnNum = i
}
left += colWidth
i++
}
}
3 changes: 3 additions & 0 deletions packages/oceanfront/src/lib/calendar/layout/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,16 @@ export default function layout(

const colWidth = 1.0 / columns.length
let left = 0
let i = 0
for (const c of columns) {
for (const p of c.placements) {
const offset = 0.05 * p.offset
const nColumns = p.columns + p.columnAdjust
p.left = left - p.columnAdjust * colWidth + offset
p.width = colWidth * nColumns - offset
p.columnNum = i
}
left += colWidth
i++
}
}
2 changes: 1 addition & 1 deletion packages/oceanfront/src/scss/_calendar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ div.of-date-picker-cur-year {
box-sizing: border-box;
padding-left: 2px;
padding-right: 2px;
max-width: 250px;
min-width: 30px;
&.conflict {
border-left: solid 2px var(--of-calendar-conflict-color, red);
}
Expand Down

0 comments on commit 2e66b44

Please sign in to comment.