Repository navigation
CodeBlock, with variants; and a pop-up list as wide as its widest option - #46
Merged
Merged
Conversation
…ependency, with Copy in its corner
…long YAML lines stay linear, and Copy never outlives its code or its block
… in one bar across the block's top
… and moves left to stay inside its window
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A
CodeBlockfor code people copy, such as a snippet to paste into a program or a command to run.<pre><code>on the page's ground (--desk-page, with the accent tint). It is monospace, and its lines keep their length, so a long one scrolls sideways. The block is a named region that takes focus, so it scrolls from the keyboard. Its name islabel, which is also shown above the code, or failing that "Python code", "YAML code" and so on, or "Code" fortext. One trailing newline is not drawn, but it is still copied.desk-code-comment,-string,-keyword,-number,-key), and the spans are built as React nodes, so code is always text and never HTML. The rules that keep it honest:#starts a comment only at the start of a word in shell and YAML.--desk-code-comment|string|keyword|number|keyare set for light, system dark and chosen dark. A test readstokens.cssand checks each one at 4.5:1 against the page ground, tinted and untinted. Looks never change colour tokens, so every look is covered.highlight. A host's own highlighter, used instead of the built-in one.Buttonin a column of its own at the top right, so it never sits over the code. It says Copy, then Copied for 2 s, and arole="status"region announces it. When there is no clipboard (plain http, or the browser refuses), it selects the code and triesexecCommand('copy'). If that fails too, the button says "Press ⌘C" or "Press Ctrl+C" and the code stays selected.copydefaults to true.variants, the block gets a bar across the top of its frame: the tabs on the left and Copy on the right, so the block reads as one card, as on iOS, rather than a control above a box.SegmentedControlsitting in the bar, so they are one tab stop and the arrow keys move between them.valueandonValueChangelet the host hold it.labelnames the tabs and the region, and is not drawn.codeandlanguageorvariants, never both.CodeBlock,CodeBlockProps,CodeLanguageandCodeVariant, from@liberation-data/desk/react.llms.txt(in the controls list, plus the tokens under Styling), the README (under Controls),docs/guide.md(in the Choosing a component table), and a Code subsection in the HIG under §6 Controls on when to use a code block rather than a read-onlyTextFieldor inline<code>.scripts/size.mjssays why.A fix in the same release: the pop-up list is as wide as its widest option
.desk-popup-listwas positioned inside an anchor only as wide as its button. So a short button squeezed the menu to its own width and wrapped each label, checkmark and all ("Your world" broke over two lines). The fix is its own commit:width: max-content, withmin-width: 100%andmax-width: min(360px, calc(100vw - 32px)).white-space: nowrap), and its description may wrap within that maximum.collections.test.tsxread the stylesheet for the width rules and the one-line label, and check the left shift: it moves to fit, stops at the left edge, and doesn't move when it fits.Tests
test/react/codeBlock.test.tsxhas 36 tests:#inside a Python string is not a comment.Don'tandhttp://x/#topstay text.$#is not a comment,--if-existsis not a keyword, and a heredoc apostrophe doesn't open a string./*colours only its own line.<script>and<img onerror>stay text.highlightprop replaces the built-in highlighting.execCommandfallback, and the select-and-press-keys fallback.valueis followed.npm run checkpasses: typecheck, 61 files and 632 tests, the build, and size (react 65.8 of 68, css 19.7 of 20).