Skip to content

Commit

Permalink
fix: correct calculation of number of rows with new chip dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
jenniferarnesen committed Dec 9, 2024
1 parent dcebd92 commit ca8bcc0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test('getRowsFromHeight returns an integer', () => {
})

const testCases = [
{ height: 0, rows: 0 },
{ height: 0, rows: 1 },
{ height: 36, rows: 1 },
{ height: 100, rows: 3 },
{ height: 200, rows: 5 },
Expand Down
10 changes: 7 additions & 3 deletions src/components/DashboardsBar/getRowsFromHeight.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
But in order to keep the calculation simple, we'll just use 38px for all rows, while
subtracting 3px from PADDING_TOP (which is actually 6px)
*/
const FIRST_ROW_HEIGHT = 35 // 32px chip + 3px gap (only 1/2 of the gap for first row)
const ROW_HEIGHT = 38 // 32px chip + 6px gap
const PADDING_TOP = 3
const PADDING_TOP = 6

export const getRowsFromHeight = (height) => {
return Math.abs(Math.round(
(height - PADDING_TOP) / ROW_HEIGHT
if (height <= PADDING_TOP + FIRST_ROW_HEIGHT) {
return 1
}
return 1 + Math.abs(Math.round(
(height - PADDING_TOP - FIRST_ROW_HEIGHT) / ROW_HEIGHT
))
}
13 changes: 7 additions & 6 deletions src/components/styles/App.css
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
:root {
/* control bar variables */
/* dashboards bar variables */
--user-rows-count: 1;
--controlbar-padding: 3px;
--row-height: 38px;
--dashboardsbar-padding: 6px;
--first-row-height: 35px; /* 32px chip height + 6px/2 gap (bottom of chip only) */
--row-height: 38px; /* 32px chip height + 6px gap */
--min-rows-height: calc(
var(--controlbar-padding) + (1 * var(--row-height))
var(--dashboardsbar-padding) + (1 * var(--first-row-height))
);
--max-rows-height: calc(
var(--controlbar-padding) + (10 * var(--row-height))
var(--dashboardsbar-padding) + (1 * var(--first-row-height)) + (9 * var(--row-height))
);
--user-rows-height: calc(
var(--controlbar-padding) + (var(--user-rows-count) * var(--row-height))
var(--dashboardsbar-padding) + (1 * var(--first-row-height)) + ((var(--user-rows-count) - 1) * var(--row-height))
);
--sm-expanded-controlbar-height: calc(
(var(--vh, 1vh) * 100) - var(--headerbar-height) - 32px
Expand Down

0 comments on commit ca8bcc0

Please sign in to comment.