grab and inspect
grab
press ⇧G (Shift G off a Mac), hover an element and click it. its html,
the components that rendered it and where they live go on the clipboard:
[<button type="button" data-testid="save">Save</button> in SaveButton (at src/App.jsx:5:5) in App (at src/App.jsx:28:7)]
paste that into your agent and it can find the code.
- drag a box, or shift and a click, to gather several elements. each gets a
number, and a tray at the bottom lists them, with one note for them all.
nwrites the note. - enter,
cor the tray's copy button copies them all, numbered, the note last. - the arrows move to the parent, a child or a sibling.
- escape or
⇧Gagain turns grab off.
1. [<button type="button">Save</button> in SaveButton (at src/App.jsx:5:5)] 2. [<a href="/docs">Docs</a> in Nav (at src/Nav.jsx:12:9)] Note: same spacing for all of these
for a file, a line and a column on every component, React needs a devtools hook from its first render: the React devtools extension, or the early script.
change the key
mount({ grabKey: 'alt+shift+g' });
grab: false leaves grab out. grab(elements) copies elements from code.
send each grab
every grab also fires one knobs:grab event on window as the copy starts,
with what it copies as its detail:
window.addEventListener('knobs:grab', (event) => { console.log(event.detail.content, event.detail.entries, event.detail.note); });
grabSend sends each grab somewhere too, so nobody has to paste. a URL gets
a POST of { "type": "knobs.grab", "payload": ... } as json; it has to be
the page's own origin, or http(s) on localhost, 127.0.0.1 or a
.localhost name. a function gets the payload:
mount({ grabSend: '/api/grab' }); mount({ grabSend: (payload) => socket.send(JSON.stringify(payload)) });
with the script tag, set it on the tag:
<script src="//unpkg.com/@vinena/knobs/dist/index.global.js" data-grab-send="/api/grab"></script>
the copy still happens. the toast says Copied · Sent once it went, and
Send failed when it did not.
coming from react-grab
knobs has the same grab, the same line format and the same clipboard
type. remove react-grab, mount knobs, and pass grabKey: "meta+c"
("ctrl+c" off a Mac) to keep react-grab's key.
inspect
press ⇧C (Shift C off a Mac) and click an element to see its css in the
panel, as the browser's Elements panel shows it:
- the DOM tree on top, the element selected, with its breadcrumbs under it
- its box: margin, border, padding and content, with their sizes
- its styles, in
simplemode (what applies) oradvanced(every rule, in cascade order)
while you pick, the box is drawn on the page in the browser's colors, and a card shows the color, font, contrast and spacing.
click a value to edit it, the checkbox at a line's start turns it off and
on, and + add property adds one. as you type a name or a value, a list
suggests what the browser takes: every property it knows and the page's
custom properties, then for a value its keywords, named colors and
var(--x); an empty field shows the whole list. ↑ and ↓ pick one, ↩ or Tab
takes it, or the first where it completes what you typed (Tab in a name goes
on to the value), and esc closes the list. the changes at the foot count the edits,
changes (N): click it to show each edit as - and + lines, and it stays
as you leave it. Z undoes and ⇧Z (Shift Z off a Mac) redoes while the
focus is in the view and not in a field (⌘Z and Ctrl Z do not), and copy prompt for agent copies a prompt that asks your agent to put them in the
code.
+ new rule adds a rule for the element, its selector from the element's
classes. the chips :hover, :focus, :focus-visible, :active and
:focus-within over the rules force a state: each makes the page draw the
element in that state, and the styles show the rules of that state as
applying. a forced state is no edit, and it ends when you pick another
element or close the view.
the DOM tree can be edited too: double-click a text or an attribute to edit
it, and on the selected line a adds an attribute, F2 edits it as html,
h hides it, Delete deletes it and ⇧↑ / ⇧↓ move it among its
siblings, or use the bar under the tree. the html editor colors the html and
numbers its lines; ↩ keeps the indent, > closes the tag, ⇧↩ applies and
esc leaves. drag the grip under it to resize it, or click expand to give
it the panel's height. drag an element's line by its
handle, ⋮⋮, to move it before or after another element, or into one. those
edits go into the same changes, and the prompt asks your agent to change the
component, as a re-render may undo an edit of the DOM. <html>, <head>
and <body> and knobs' own nodes and attributes cannot be replaced,
hidden, deleted or moved.
the switch keep edits after reload in the panel's settings keeps the edits
for the page: after a reload they are made again where the page still has
them, and the changes say how many came back and which could not be found.
it is off at first, and off forgets them. html and attribute edits are
never made on load: they wait in the changes until you click apply, as a
page script could have planted them, and one that could run a script is
never made. a page keeps its first 200 edits, up to 256 KB, for 20 pages at
most; forced states are never kept. edits made in knobs' frame, for a
pinned panel or a device, are kept while it shows the same page, and made
again in the frame after a reload. kept edits hold the page's text, attribute values and markup as
edited. with the npm package they are in the page's localStorage, with the
extension in its own storage.