Skip to content

Commit a49c929

Browse files
committed
Add doc comments
1 parent 3c110e8 commit a49c929

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

packages/block-editor/src/components/grid-visualizer/grid-item-resizer.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,19 @@ export function GridItemResizer( { clientId, onChange } ) {
8585
);
8686
}
8787

88+
/**
89+
* Given a grid-template-columns or grid-template-rows CSS property value, gets the start and end
90+
* position in pixels of each grid track.
91+
*
92+
* https://css-tricks.com/snippets/css/complete-guide-grid/#aa-grid-track
93+
*
94+
* @param {string} template The grid-template-columns or grid-template-rows CSS property value.
95+
* Only supports fixed sizes in pixels.
96+
* @param {number} gap The gap between grid tracks in pixels.
97+
*
98+
* @return {Array<{start: number, end: number}>} An array of objects with the start and end
99+
* position in pixels of each grid track.
100+
*/
88101
function getGridTracks( template, gap ) {
89102
const tracks = [];
90103
for ( const size of template.split( ' ' ) ) {
@@ -96,6 +109,19 @@ function getGridTracks( template, gap ) {
96109
return tracks;
97110
}
98111

112+
/**
113+
* Given an array of grid tracks and a position in pixels, gets the index of the closest track to
114+
* that position.
115+
*
116+
* @param {Array<{start: number, end: number}>} tracks An array of objects with the start and end
117+
* position in pixels of each grid track.
118+
* @param {number} position The position in pixels.
119+
* @param {string} edge The edge of the track to compare the
120+
* position to. Either 'start' or 'end'.
121+
*
122+
* @return {number} The index of the closest track to the position. 0-based, unlike CSS grid which
123+
* is 1-based.
124+
*/
99125
function getClosestTrack( tracks, position, edge = 'start' ) {
100126
return tracks.reduce(
101127
( closest, track, index ) =>

0 commit comments

Comments
 (0)