Skip to content

Commit

Permalink
docs: center last projects row in landing (#18424)
Browse files Browse the repository at this point in the history
Co-authored-by: 翠 / green <[email protected]>
  • Loading branch information
patak-dev and sapphi-red authored Oct 23, 2024
1 parent 9b21f69 commit 3778c7a
Showing 1 changed file with 38 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,26 +244,48 @@ const numFrameworksPerRow = computed(
() => numBlocksPerRow.value - paddedBlocksPerSide.value * 2,
)
/**
* The indexes of the blocks on each row that support framework cards.
*/
const centerIndexes: ComputedRef<{ start: number; end: number }> = computed(
() => {
const startIndex = paddedBlocksPerSide.value
return {
start: startIndex,
end: numBlocksPerRow.value - paddedBlocksPerSide.value,
}
},
)
/**
* How many rows do we need to display all the frameworks?
*/
const numRows: ComputedRef<number> = computed(() => {
return Math.ceil(frameworks.length / numFrameworksPerRow.value)
})
/**
* The indexes of the blocks on each row that support framework cards.
*
* Note that the index of the returned array is 1-based.
*/
const centerIndexes: ComputedRef<{ start: number; end: number }[]> = computed(
() => {
const firstRowsStartIndex = paddedBlocksPerSide.value
const frameworksPerFirstRows =
numBlocksPerRow.value - 2 * paddedBlocksPerSide.value
const lastRowStartIndex =
paddedBlocksPerSide.value +
Math.floor(
(frameworksPerFirstRows -
(frameworks.length % frameworksPerFirstRows)) /
2,
)
return new Array(numRows.value + 1).fill(0).map((_, i) => {
return i < numRows.value ||
frameworks.length % frameworksPerFirstRows === 0
? {
start: firstRowsStartIndex,
end: numBlocksPerRow.value - paddedBlocksPerSide.value,
}
: {
start: lastRowStartIndex,
end:
lastRowStartIndex +
(frameworks.length % frameworksPerFirstRows) +
1,
}
})
},
)
/**
* Generate CSS transformations for each row, to gracefully slide between horizontal positions.
*/
Expand All @@ -289,16 +311,16 @@ const rowStyle: ComputedRef<{ transform: string }> = computed(() => {
<template v-for="columnIndex in numBlocksPerRow + 2">
<template
v-if="
columnIndex - 1 >= centerIndexes.start &&
columnIndex - 1 < centerIndexes.end
columnIndex - 1 >= centerIndexes[rowIndex].start &&
columnIndex - 1 < centerIndexes[rowIndex].end
"
>
<FrameworkCard
:framework="
frameworks[
(rowIndex - 1) * numFrameworksPerRow +
(columnIndex - 1) -
centerIndexes.start
centerIndexes[rowIndex].start
]
"
/>
Expand Down

0 comments on commit 3778c7a

Please sign in to comment.