Skip to content

Commit bf42c94

Browse files
authored
Redesign row page as a vertical list of fields (#3052)
* Redesign row page as a vertical list of fields The row page showed its single row as a one-row table, which for wide tables scrolled far off to the right and left the page mostly blank. It now renders a new _row_fields.html template: one field per line, column name on the left and value on the right, stacking on narrow screens. - Each field with a value has a button that copies its raw value to the clipboard - Null and empty string values are shown muted - Long values are clamped with a "Show all N characters" toggle - Snake_case column names wrap at underscores - The row's label is shown under the heading - "Links from other tables" becomes "Referenced by", below the fields Per-table _table-*.html overrides still apply to the row page, but a site-wide _table.html no longer does. The "null", "empty string" and "Show all N characters" / "Show less" labels on the row page are now CSS generated content from a data-label attribute, with user-select: none, so copying a section of the page leaves them out. The expand toggle also gets a matching aria-label. Copy buttons now have a "Copy to clipboard" title tooltip. On the row page the Export data button now sits next to the Row actions menu, in a flex row that is flex all the way down so the two line up exactly.
1 parent f2dd3eb commit bf42c94

9 files changed

Lines changed: 589 additions & 106 deletions

File tree

‎datasette/static/app.css‎

Lines changed: 308 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3529,10 +3529,18 @@ dialog.column-stats-dialog {
35293529
margin: 0 0 0.75rem;
35303530
}
35313531

3532-
button.table-insert-row {
3532+
/* Same box as .quiet-button and the actions menu trigger. Needs .core
3533+
to outrank the button.core[type=button] defaults. */
3534+
button.core.table-insert-row {
35333535
display: inline-flex;
35343536
align-items: center;
3535-
gap: 0.4rem;
3537+
gap: 0.35rem;
3538+
box-sizing: border-box;
3539+
min-height: 1.75rem;
3540+
padding: 0.2rem 0.6rem;
3541+
border-radius: 5px;
3542+
font-size: 0.875rem;
3543+
line-height: 1.2;
35363544
}
35373545

35383546
button.table-insert-row svg {
@@ -5615,28 +5623,32 @@ dl.column-descriptions dd {
56155623
.actions-menu-links {
56165624
display: inline;
56175625
}
5626+
/* The "Table actions" / "Row actions" trigger shares its box with
5627+
.quiet-button (height, border, font size, line height, radius, icon gap)
5628+
so the two line up exactly when they sit side by side. */
56185629
.page-action-menu .icon-text {
56195630
display: inline-flex;
56205631
align-items: center;
5621-
border-radius: .25rem;
5622-
padding: 5px 12px 3px 7px;
5632+
gap: 0.35rem;
5633+
box-sizing: border-box;
5634+
min-height: 1.75rem;
5635+
padding: 0.2rem 0.6rem 0.2rem 0.5rem;
5636+
border: 1px solid var(--accent, #1a56db);
5637+
border-radius: 5px;
56235638
color: #fff;
56245639
font-weight: 400;
5625-
font-size: 0.8em;
5640+
font-size: 0.875rem;
5641+
line-height: 1.2;
56265642
background: var(--accent, #1a56db);
56275643
}
5628-
.page-action-menu .icon-text span {
5629-
/* Nudge text up a bit */
5630-
position: relative;
5631-
top: -2px;
5632-
}
56335644
.page-action-menu .icon-text:hover {
56345645
cursor: pointer;
56355646
}
56365647
.page-action-menu .icon {
5637-
width: 18px;
5638-
height: 18px;
5639-
margin-right: 4px;
5648+
display: block;
5649+
flex-shrink: 0;
5650+
width: 16px;
5651+
height: 16px;
56405652
}
56415653

56425654
header.app-header {
@@ -5688,7 +5700,10 @@ header.app-header .actor {
56885700
}
56895701
.page-action-menu .datasette-menu-trigger {
56905702
display: inline-flex;
5691-
border-radius: .25rem;
5703+
/* Top-aligned so the inline <details> adds no space below the
5704+
baseline, keeping the menu exactly the trigger's height */
5705+
vertical-align: top;
5706+
border-radius: 5px;
56925707
}
56935708
button.column-menu-trigger {
56945709
display: inline-flex;
@@ -5911,3 +5926,282 @@ button.column-menu-trigger[aria-expanded="true"] {
59115926
font-size: 16px;
59125927
}
59135928
}
5929+
5930+
/* Row page: one field per line, name on the left and value on the right.
5931+
Stacks name above value on narrow screens. See _row_fields.html. */
5932+
.row-heading-label {
5933+
display: block;
5934+
margin-top: 0.15rem;
5935+
font-size: 1.05rem;
5936+
font-weight: 500;
5937+
color: #536978;
5938+
}
5939+
5940+
/* Row actions menu and Export data button side by side */
5941+
.row-page-actions {
5942+
display: flex;
5943+
flex-wrap: wrap;
5944+
align-items: center;
5945+
gap: 0.5rem;
5946+
margin: 0 0 1rem;
5947+
}
5948+
/* Flex all the way down so the menu trigger is never laid out on a text
5949+
line (which browsers snap to whole pixels differently from flex items)
5950+
and lines up exactly with the Export data button beside it */
5951+
.row-page-actions .page-action-menu,
5952+
.row-page-actions .actions-menu-links,
5953+
.row-page-actions .datasette-menu-trigger {
5954+
display: flex;
5955+
}
5956+
.row-page-actions .page-action-menu {
5957+
margin-bottom: 0;
5958+
}
5959+
5960+
.row-referenced-by {
5961+
max-width: 60rem;
5962+
margin: 0 0 1.5rem;
5963+
}
5964+
.row-referenced-by h2 {
5965+
margin: 0 0 0.5rem;
5966+
font-size: 1.05rem;
5967+
}
5968+
.row-referenced-by ul {
5969+
margin: 0;
5970+
padding: 0;
5971+
list-style: none;
5972+
}
5973+
.row-referenced-by li {
5974+
padding: 0.3rem 0;
5975+
}
5976+
.row-referenced-by-via {
5977+
color: #6b6b6b;
5978+
font-size: 0.8125rem;
5979+
}
5980+
5981+
.row-fields {
5982+
--rule: #d8e6f5;
5983+
--muted: #6b6b6b;
5984+
--link: #276890;
5985+
--link-visited: #2d7a62;
5986+
--accent: #1a56db;
5987+
box-sizing: border-box;
5988+
max-width: 60rem;
5989+
margin: 0 0 1.5rem;
5990+
border: 1px solid var(--rule);
5991+
border-radius: 8px;
5992+
background: #fff;
5993+
box-shadow: 0 1px 2px rgba(15, 40, 70, 0.04);
5994+
font-variant-numeric: tabular-nums;
5995+
}
5996+
.row-field {
5997+
display: grid;
5998+
grid-template-columns: minmax(8rem, 14rem) minmax(0, 1fr);
5999+
gap: 0.25rem 1.25rem;
6000+
padding: 0.55rem 0.85rem;
6001+
border-top: 1px solid var(--rule);
6002+
}
6003+
.row-field:first-child {
6004+
border-top: none;
6005+
}
6006+
.row-field:hover {
6007+
background: rgba(0, 110, 255, 0.03);
6008+
}
6009+
.row-field dt {
6010+
margin: 0;
6011+
min-width: 0;
6012+
}
6013+
.row-field-name {
6014+
display: block;
6015+
font-weight: 600;
6016+
font-size: 0.875rem;
6017+
color: #536978;
6018+
overflow-wrap: break-word;
6019+
}
6020+
.row-field-description {
6021+
display: block;
6022+
margin-top: 0.1rem;
6023+
font-size: 0.75rem;
6024+
color: var(--muted);
6025+
}
6026+
.row-field dd {
6027+
display: flex;
6028+
align-items: flex-start;
6029+
gap: 0.5rem;
6030+
margin: 0;
6031+
min-width: 0;
6032+
}
6033+
.row-field-value,
6034+
.row-field-long {
6035+
flex: 1 1 auto;
6036+
min-width: 0;
6037+
white-space: pre-wrap;
6038+
overflow-wrap: anywhere;
6039+
}
6040+
.row-field[data-is-pk] .row-field-value {
6041+
font-weight: 600;
6042+
}
6043+
.row-field-value em {
6044+
color: var(--muted);
6045+
font-size: 0.8125em;
6046+
font-style: normal;
6047+
}
6048+
.row-field-value a:link {
6049+
color: var(--link);
6050+
text-decoration: none;
6051+
}
6052+
.row-field-value a:visited {
6053+
color: var(--link-visited);
6054+
text-decoration: none;
6055+
}
6056+
.row-field-value a:hover {
6057+
text-decoration: underline;
6058+
}
6059+
.row-field-empty {
6060+
flex: 1 1 auto;
6061+
color: var(--muted);
6062+
font-size: 0.8125rem;
6063+
font-style: italic;
6064+
user-select: none;
6065+
-webkit-user-select: none;
6066+
}
6067+
/* Generated content is never included when the page is copied */
6068+
.row-field-empty::before {
6069+
content: attr(data-label);
6070+
}
6071+
6072+
/* Long values show the first few lines, with a toggle to reveal the rest */
6073+
.row-field-long:not(.is-expanded) > .row-field-value {
6074+
max-height: 6lh;
6075+
overflow: hidden;
6076+
-webkit-mask-image: linear-gradient(#000 calc(100% - 2lh), transparent);
6077+
mask-image: linear-gradient(#000 calc(100% - 2lh), transparent);
6078+
}
6079+
/* row-fields.js adds .fits when the whole value is visible within the clamp */
6080+
.row-field-long.fits > .row-field-value {
6081+
-webkit-mask-image: none;
6082+
mask-image: none;
6083+
}
6084+
.row-field-long.fits > .row-field-expand {
6085+
display: none;
6086+
}
6087+
.row-field-expand {
6088+
margin-top: 0.35rem;
6089+
padding: 0;
6090+
border: none;
6091+
background: none;
6092+
color: var(--link);
6093+
font: inherit;
6094+
font-size: 0.8125rem;
6095+
font-weight: 600;
6096+
cursor: pointer;
6097+
}
6098+
.row-field-expand:hover {
6099+
text-decoration: underline;
6100+
}
6101+
/* Generated content, like the null labels, so it is never copied */
6102+
.row-field-expand {
6103+
user-select: none;
6104+
-webkit-user-select: none;
6105+
}
6106+
.row-field-expand::before {
6107+
content: attr(data-label);
6108+
}
6109+
6110+
/* Copy button: quiet until the field is hovered or the button focused */
6111+
.row-field-copy {
6112+
flex: none;
6113+
display: inline-flex;
6114+
align-items: center;
6115+
justify-content: center;
6116+
width: 1.75rem;
6117+
height: 1.75rem;
6118+
margin: -0.2rem -0.3rem -0.2rem 0;
6119+
padding: 0;
6120+
border: 1px solid transparent;
6121+
border-radius: 6px;
6122+
background: none;
6123+
color: var(--muted);
6124+
cursor: pointer;
6125+
opacity: 0.35;
6126+
transition: opacity 0.12s, background-color 0.12s, color 0.12s;
6127+
}
6128+
.row-field:hover .row-field-copy,
6129+
.row-field-copy:focus-visible,
6130+
.row-field-copy.is-copied {
6131+
opacity: 1;
6132+
}
6133+
.row-field-copy:hover {
6134+
background: #eef6ff;
6135+
border-color: var(--rule);
6136+
color: var(--accent);
6137+
}
6138+
.row-field-copy:focus-visible {
6139+
outline: 2px solid var(--accent);
6140+
outline-offset: 1px;
6141+
}
6142+
.row-field-copy .icon-copied,
6143+
.row-field-copy.is-copied .icon-copy {
6144+
display: none;
6145+
}
6146+
.row-field-copy.is-copied .icon-copied {
6147+
display: block;
6148+
}
6149+
.row-field-copy.is-copied {
6150+
color: #1f7a4d;
6151+
}
6152+
.row-field-copy-status {
6153+
position: absolute;
6154+
width: 1px;
6155+
height: 1px;
6156+
overflow: hidden;
6157+
clip: rect(0 0 0 0);
6158+
white-space: nowrap;
6159+
}
6160+
6161+
@media (hover: none) {
6162+
.row-field-copy {
6163+
opacity: 0.7;
6164+
}
6165+
}
6166+
6167+
/* Narrow screens: match the stacked cards of the table page exactly (see
6168+
the max-width: 576px block under Overrides), with the copy button tucked
6169+
into the label line so values get the same width as on the table page. */
6170+
@media (max-width: 576px) {
6171+
.row-fields {
6172+
max-width: none;
6173+
margin-bottom: 0.75rem;
6174+
overflow: hidden;
6175+
color: #0f0f0f;
6176+
font-size: 0.9375rem;
6177+
line-height: 1.4;
6178+
}
6179+
.row-field {
6180+
display: block;
6181+
position: relative;
6182+
padding: 0.45rem 0.75rem 0.5rem;
6183+
}
6184+
.row-field:hover {
6185+
background: none;
6186+
}
6187+
.row-field:first-child {
6188+
background: #eef6ff;
6189+
}
6190+
.row-field dt {
6191+
margin: 0 0 1px;
6192+
padding-right: 1.75rem;
6193+
}
6194+
.row-field-name {
6195+
font-size: 0.75rem;
6196+
line-height: 1.4;
6197+
}
6198+
.row-field dd {
6199+
display: block;
6200+
}
6201+
.row-field-copy {
6202+
position: absolute;
6203+
top: 0.2rem;
6204+
right: 0.35rem;
6205+
margin: 0;
6206+
}
6207+
}

0 commit comments

Comments
 (0)