diff --git a/app/src/components/ThemeSamplePage.js b/app/src/components/ThemeSamplePage.js index 02006c91..d191974d 100644 --- a/app/src/components/ThemeSamplePage.js +++ b/app/src/components/ThemeSamplePage.js @@ -166,9 +166,12 @@ export function ThemeSamplePage() { - {/* Status colours a reading that carries meaning. Check these in night, where - there is no hue to spend and the value has to read by brightness. */} - + {/* Status colours a reading that carries meaning. Check these in night and amber, + where there is no hue to spend and the value has to read some other way. */} + {/* The group above ends in a label, and a heading has no margin of its own, so + without this the two run together. */} +
Coloured readings, as Status draws them
+ diff --git a/app/src/components/ui/ui-layout.cy.js b/app/src/components/ui/ui-layout.cy.js index 39c26bc0..5af14f51 100644 --- a/app/src/components/ui/ui-layout.cy.js +++ b/app/src/components/ui/ui-layout.cy.js @@ -1,5 +1,5 @@ import React from 'react'; -import {ActionInput, Button, PathInput, Statistic, StatisticGroup, TextInput} from './index'; +import {ActionInput, Button, Header, PathInput, Statistic, StatisticGroup, TextInput} from './index'; import {themeNames} from '../../themes/names'; /* @@ -133,12 +133,13 @@ describe('ActionInput', () => { }); }); -describe('StatisticGroup rules every row it ends up with', () => { +describe('StatisticGroup separates its statistics with nothing but space', () => { /* - * The group wraps: `auto-fit` with a 150px minimum gives seven statistics one row on a - * desktop and four on a phone, and how many rows there are is decided by the viewport at - * paint time. Only a browser can say -- jsdom has no tracks, no rows and no widths -- so - * the row-separator claims live here. + * The group has no frame, no rules between cells and no surface of its own: the + * statistics sit on whatever they were dropped onto and take its colour. That leaves + * the gap as the only thing keeping them apart, and `auto-fit` decides how many rows + * there are at paint time -- so whether they actually stay apart is a question only a + * browser can answer. jsdom has no tracks, no rows and no widths. */ // Narrow enough that six statistics cannot fit on one row at a 150px minimum. @@ -164,12 +165,12 @@ describe('StatisticGroup rules every row it ends up with', () => { expect(rowTops($cells).length, 'rows the group wrapped into').to.be.greaterThan(1)); }); - it('draws a hairline between wrapped rows', () => { + it('leaves real space between wrapped rows', () => { /* - * This is the defect: the old group put a `border-right` on every cell but the last, - * which rules between columns and says nothing about rows. Wrapped rows sat flush - * against each other, so the Docs page's seven statistics ran together into one block - * on a phone. A row boundary must be a visible 1px of border colour. + * With nothing drawn between them, the space *is* the separation. The old group ruled + * columns only -- a `border-right` on every cell but the last, which says nothing about + * rows -- so wrapped rows sat flush and the Docs page's seven statistics ran together + * into one block on a phone. A row boundary has to be a gap you can see. */ cy.mountUI(inNarrowColumn(sixStatistics)); @@ -181,72 +182,99 @@ describe('StatisticGroup rules every row it ends up with', () => { const previousRowBottom = Math.max(...cells .filter((rect) => Math.round(rect.top) === tops[row - 1]) .map((rect) => rect.bottom)); - const separation = tops[row] - previousRowBottom; - expect(separation, `hairline above row ${row + 1}`).to.be.closeTo(1, 0.6); + expect(tops[row] - previousRowBottom, `space above row ${row + 1}`) + .to.be.at.least(12); } }); }); - it('draws a hairline between columns too', () => { + it('leaves more space between columns than between rows', () => { + /* + * Two statistics side by side have only air between them, and a value sitting close to + * the label of the one beside it reads as a single column of text. Stacked statistics + * already have the label's own line between them, so they need less. + */ cy.mountUI(inNarrowColumn(sixStatistics)); + cy.get('.wrolpi-statistic-group').should(($group) => { + const styles = getComputedStyle($group[0]); + const columnGap = parseFloat(styles.columnGap); + const rowGap = parseFloat(styles.rowGap); + expect(rowGap, 'row gap').to.be.at.least(12); + expect(columnGap, 'column gap is the wider of the two').to.be.greaterThan(rowGap); + }); + cy.get('.wrolpi-statistic-cell').should(($cells) => { const cells = [...$cells].map((cell) => cell.getBoundingClientRect()); - const firstRowTop = rowTops($cells)[0]; const firstRow = cells - .filter((rect) => Math.round(rect.top) === firstRowTop) + .filter((rect) => Math.round(rect.top) === rowTops($cells)[0]) .sort((a, b) => a.left - b.left); expect(firstRow.length, 'columns in the first row').to.be.greaterThan(1); for (let column = 1; column < firstRow.length; column++) { - expect(firstRow[column].left - firstRow[column - 1].right, 'hairline between columns') - .to.be.closeTo(1, 0.6); + expect(firstRow[column].left - firstRow[column - 1].right, 'space between columns') + .to.be.at.least(20); } }); }); - it('does not double the outer border where a row ends', () => { + it('takes no colour of its own, so it sits on the surface it is given', () => { /* - * The old code suppressed `border-right` on the last child only, so the cell ending - * every earlier row -- there is one per wrap -- drew its own hairline directly onto the - * group's outer border, giving a 2px edge on the right and a 1px edge on the left. - * Now no cell has a border at all and the single outer one is the edge. + * This is the point of having no chrome: dropped on the page it reads as page, dropped + * in a Panel it reads as panel. A background on the group or a cell -- which is how + * this was built first, to carry hairlines -- would show as a patch of the wrong colour + * on every surface but the one it was picked for. */ - cy.mountUI(inNarrowColumn(sixStatistics)); + cy.mountUI(
{sixStatistics}
); - cy.get('.wrolpi-statistic-cell').each(($cell) => - expect(getComputedStyle($cell[0]).borderRightWidth, 'cell draws no border of its own') - .to.equal('0px')); - cy.get('.wrolpi-statistic-group').should(($group) => - expect(getComputedStyle($group[0]).borderRightWidth, 'one outer hairline').to.equal('1px')); + cy.get('.wrolpi-statistic-group').should(($group) => { + const styles = getComputedStyle($group[0]); + expect(styles.backgroundColor, 'group is transparent').to.equal('rgba(0, 0, 0, 0)'); + expect(styles.borderTopWidth, 'no frame').to.equal('0px'); + expect(styles.borderRightWidth, 'no frame').to.equal('0px'); + expect(styles.borderBottomWidth, 'no frame').to.equal('0px'); + expect(styles.borderLeftWidth, 'no frame').to.equal('0px'); + expect(styles.outlineStyle, 'no outline standing in for a frame').to.equal('none'); + }); + + cy.get('.wrolpi-statistic-cell').each(($cell) => { + const styles = getComputedStyle($cell[0]); + expect(styles.backgroundColor, 'cell is transparent').to.equal('rgba(0, 0, 0, 0)'); + expect(styles.borderRightWidth, 'no rule between cells').to.equal('0px'); + expect(styles.outlineStyle, 'no rule between cells').to.equal('none'); + }); }); - it('leaves no painted block in a track no statistic landed in', () => { + it('clears whatever precedes it, but does not indent itself', () => { /* - * An odd count leaves the last row short: seven statistics in two columns fill the - * eighth slot with nothing. Ruling the gaps with a border-coloured background behind - * the grid -- the obvious way to do it -- painted that empty slot a solid block of - * border grey, which read as a broken cell. The hairlines are outlines on the cells - * instead, so a track with no cell in it is just surface. + * Nothing frames the group any more, so a Header directly above it put the heading + * text against the first row of values. A plain `margin-top` fixed that and broke + * Apps, which opens each of its Panels with a group: the values were pushed down off + * the panel's top padding while the bottom stayed put, leaving every panel lopsided. + * So the margin is conditional on having a sibling before it. */ - cy.mountUI(inNarrowColumn( - - - - - - - - )); + cy.mountUI(
+
+ + + +
+
+
Files
+ + + +
+
); - cy.get('.wrolpi-statistic-cell').should(($cells) => { - // An odd number of cells over an even number of columns, or this proves nothing. - expect($cells.length % 2, 'a short last row').to.equal(1); - }); - cy.get('.wrolpi-statistic-group').should(($group) => { - const group = getComputedStyle($group[0]); - expect(group.backgroundColor, 'the empty track shows surface, not hairline') - .to.not.equal(group.borderRightColor); + cy.get('.probe-panel .wrolpi-statistic-group').should(($group) => + expect(getComputedStyle($group[0]).marginTop, 'first child of a panel adds nothing') + .to.equal('0px')); + + cy.get('.probe-with-header').then(($panel) => { + const header = $panel[0].querySelector('.wrolpi-header').getBoundingClientRect(); + const group = $panel[0].querySelector('.wrolpi-statistic-group').getBoundingClientRect(); + expect(group.top - header.bottom, 'space below a heading').to.be.at.least(10); }); }); @@ -255,13 +283,13 @@ describe('StatisticGroup rules every row it ends up with', () => { * Status omits the fan reading on a device with no fan connector -- most of them -- * by returning null from FanRPMStatistic. The group still emits its cell, because it * cannot render a child to find out, so `:empty` has to take the cell out of the grid. - * Left in, it was a blank padded panel and a stray hairline in the middle of the row. + * Left in, it held a track open and opened a hole in the middle of the row. */ const NoFanFitted = () => null; cy.mountUI( - + ); cy.get('.wrolpi-statistic-cell').should('have.length', 3); @@ -271,27 +299,21 @@ describe('StatisticGroup rules every row it ends up with', () => { }); themeNames.forEach((theme) => { - it(`takes its hairline and surface from ${theme}'s tokens`, () => { - // Drawn from --border and --panel rather than a fixed grey, which is what lets the - // group survive night mode without putting a non-red pixel on the screen. + it(`reads its value and label from ${theme}'s tokens`, () => { + // The contrast between value and label is all that structures a statistic now that + // there is no cell around it, so both colours have to resolve in every theme. cy.mountUI(inNarrowColumn(sixStatistics), {theme}); - cy.get('.wrolpi-statistic-group').then(($group) => { - const group = getComputedStyle($group[0]); + cy.get('.wrolpi-statistic-value').first().then(($value) => { + const value = getComputedStyle($value[0]).color; - cy.get('.wrolpi-statistic-cell').first().should(($cell) => { - const cell = getComputedStyle($cell[0]); - - // The inner hairlines are the cells' outlines and the outer one is the - // group's border; they meet at every edge, so a theme that resolved them - // to different values would show a two-tone frame. - expect(cell.outlineColor, 'inner hairline matches the outer') - .to.equal(group.borderRightColor); - // And the hairline has to be visible against the surface it sits on -- - // both resolved from tokens, so a theme that forgot one shows up here. - expect(cell.outlineColor, 'hairline is not the surface colour') - .to.not.equal(cell.backgroundColor); - expect(cell.backgroundColor, 'cell has a surface').to.not.equal('rgba(0, 0, 0, 0)'); + cy.get('.wrolpi-statistic-label').first().should(($label) => { + const label = getComputedStyle($label[0]).color; + expect(value, 'value colour resolved').to.match(/^rgba?\(/); + expect(label, 'label colour resolved').to.match(/^rgba?\(/); + // The label is the muted token and the value is body text; if either fell + // back the two would come out the same and the statistic would flatten. + expect(label, 'label is distinct from the value').to.not.equal(value); }); }); }); diff --git a/app/src/components/ui/ui.css b/app/src/components/ui/ui.css index 4983221c..106a1f82 100644 --- a/app/src/components/ui/ui.css +++ b/app/src/components/ui/ui.css @@ -865,38 +865,44 @@ html[data-theme="amber"] .wrolpi-card-tag { } /* - * The group's hairlines are an outline on each cell, drawn into a 1px grid gap. + * The group is spacing and nothing else: no frame, no rules between cells, and + * no surface of its own, so the statistics sit on whatever they are dropped onto + * -- the page in one place, a Panel in another -- and pick up its colour. * - * Not a border per cell: a border can only separate the siblings the author can - * count -- the old code suppressed `border-right` on the last child -- and - * `auto-fit` wraps, so the seven statistics on the Docs page became four rows on - * a phone with no rule between them, while the cell ending each earlier row drew - * its border straight onto the outer one. + * That also settles a question this went round twice on. Ruling the cells needs + * a technique that survives wrapping, because `auto-fit` decides the number of + * rows at paint time: a `border-right` per cell rules columns but not rows, and + * a border-coloured background behind a 1px gap rules both but paints every + * track no cell landed in. With no rules at all, neither problem exists. * - * Nor a border-coloured background behind the gaps, which rules both axes but - * also paints every track no cell landed in: seven statistics in two columns - * left the eighth slot a solid grey block. An outline is drawn outside the - * cell, so it appears only where a cell actually is. Adjacent outlines meet in - * the same 1px of gap, and the outer ones land on the group's own border, all in - * the same colour, so every rule reads as a single hairline. + * The gap is wider across than down. Two statistics side by side have nothing + * between them but air, so they need enough of it not to read as one column of + * text; stacked ones are already separated by the label's line. */ .wrolpi-statistic-group { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); - gap: 1px; - background-color: var(--panel); - border: 1px solid var(--border); + gap: 18px 30px; } -.wrolpi-statistic-cell { - background-color: var(--panel); - outline: 1px solid var(--border); - padding: 14px 16px; +/* + * With the frame gone there is nothing holding the group off whatever precedes it, and on + * most pages that is a Header -- the first row of values sat directly against the heading. + * + * Only when something does precede it, though. Apps opens each of its Panels with a group, + * and a blanket `margin-top` there pushed the values down off the panel's own top padding + * while leaving the bottom where it was, so the whole panel read as lopsided. + */ +* + .wrolpi-statistic-group { + margin-top: 18px; } /* * A statistic that renders nothing -- Status omits the fan reading on a device - * with no fan connector -- must not leave a padded cell and a hairline behind. + * with no fan connector -- must not hold a track open. The group cannot know in + * advance, since it would have to render the child to find out, so the cell is + * emitted either way and this takes the empty ones back out. It is also why the + * cells carry no inline style: there is nothing here for it to outrank. */ .wrolpi-statistic-cell:empty { display: none; diff --git a/app/src/components/ui/ui.test.js b/app/src/components/ui/ui.test.js index bf58ae9f..a314246d 100644 --- a/app/src/components/ui/ui.test.js +++ b/app/src/components/ui/ui.test.js @@ -725,8 +725,8 @@ describe('StatisticGroup', () => { it('leaves a cell empty when its statistic renders nothing', () => { // `FanRPMStatistic` returns null on a device with no fan connector, which is most of // them. The group cannot know that in advance, so the cell is still emitted and - // `.wrolpi-statistic-cell:empty` hides it -- which only works while the cell has no - // padding or background of its own inline for that rule to have to outrank. + // `.wrolpi-statistic-cell:empty` takes it back out -- which only works while the cell + // has nothing of its own inline for that rule to have to outrank. const Nothing = () => null; const {container} = renderUI( @@ -738,21 +738,30 @@ describe('StatisticGroup', () => { expect(cells[1].getAttribute('style')).toBeNull(); }); - it('draws its hairlines with the grid, not a border per cell', () => { - // A per-cell border can only separate siblings the author can count -- the old code - // suppressed `borderRight` on the last child -- and `auto-fit` wraps. Seven - // statistics on a phone became four rows with no rule between them, while the cell - // ending each earlier row drew its border straight onto the outer one. A 1px gap - // over a border-coloured background rules both axes however the tracks fall. + it('draws no chrome of its own, in markup or in style', () => { + // The group is spacing only: the statistics sit on whatever surface they were dropped + // onto and take its colour. An inline border or background here would override the + // stylesheet and could not be themed, so nothing may set one. const {container} = renderUI( ); + const group = container.querySelector('.wrolpi-statistic-group'); + expect(group.style.border).toBe(''); + expect(group.style.background).toBe(''); + expect(group.style.backgroundColor).toBe(''); for (const cell of container.querySelectorAll('.wrolpi-statistic-cell')) { - expect(cell.style.borderRight).toBe(''); + expect(cell.getAttribute('style')).toBeNull(); } - expect(container.querySelector('.wrolpi-statistic-group')).toBeInTheDocument(); + }); + + it('still passes a style from the caller through', () => { + const {container} = renderUI( + + ); + + expect(container.querySelector('.wrolpi-statistic-group')).toHaveStyle({maxWidth: '600px'}); }); });