A Save button for an app that saves to a Solid Pod. It's a split button: the left half saves, and the right half says where saves go, this browser or the Pod, and opens a panel to connect a Pod or disconnect it.
Try it in the playground, in each of its states, with its themes and custom properties.
It imports nothing from Solid Accord, and knows nothing about what's being saved. It calls the app's handlers when the
user acts, and the app tells it where things stand with show. Its state has the same shape as the client's in
@viboko/solid-accord-browser, failures and all, so an
app on that client passes its state straight on, and TypeScript checks that the two still match where it does. It
describes each failure itself, from its code. The first app to use it is solid-blocks.
No dependencies. MIT licensed. In English unless the app gives its own words: see In other languages.
import {createSolidSaveButton} from '@viboko/solid-save-button';
import '@viboko/solid-save-button/style.css';
const saveButton = createSolidSaveButton(document.querySelector('#save-button')!);
// `client` is Solid Accord's, from createClient.
saveButton.onSave = () => client.save(currentWork());
saveButton.onConnect = webId => client.connectPod(webId, currentWork());
saveButton.onDisconnect = client.disconnectPod;
client.onStateChange = saveButton.show;
editor.onChange = saveButton.showUnsaved;
createSolidSaveButton(container, options?) fills container with the button, and gives it the class
solid-save-button. options.text gives the app's own words: see In other languages.
| Member | What it is |
|---|---|
onSave |
Called when Save is pressed. |
onConnect(webId) |
Called with the WebID the user typed, once it's a web address. |
onDisconnect |
Called when the user disconnects their Pod, from the panel's menu. The right half and the panel's corner spin, and Save waits, until the promise it returns settles. |
show(state) |
Shows where things stand. Call it each time either half of the state changes. |
showUnsaved() |
Says the work has changed since it was saved, until the next save lands. |
show takes {pod, work}.
pod.status |
Means | The right half shows |
|---|---|---|
not-connected |
Saves stay in this browser. | This computer |
connecting |
A WebID is being checked, or the page has come back from logging in. | A spinner |
connected |
Saves go to the Pod at webId. |
The Pod |
failed |
Connecting didn't work, and failure says why. |
This computer, with the WebID form open, saying why. When the failure is about the WebID, it's marked as wrong |
work.status |
Means | Save shows |
|---|---|---|
none |
Nothing is saved yet. | Save |
saving-locally, saving-to-pod |
A save is under way. | A spinner |
saved-locally, saved-to-pod |
The last save landed. | A tick, once it's where saves go |
logging-in |
The page is leaving to log in, with the work kept in the browser. | A spinner |
failed |
The last save didn't land, and the failure says why. | An alert, with a badge on the right half |
work.kept is the client's too: whether the work is safe, so leaving the page loses nothing. Once it's true, the button
stops saying there are unsaved changes, until the next showUnsaved.
Save is disabled while anything is under way, a Pod being connected included. A save that lands or fails pulses the
right half. One that's already saved as the page loads doesn't, so the first
show should give the state as the page found it.
A failure, as the work or as the pod's failure, is {status: 'failed', code, params, message}, as the client reports
it. The button says what went wrong from code, mentioning params where it helps, such as the host that couldn't be
reached. message is the client's own, for developers, and the button never says it.
code can be one the button doesn't know, from a newer client than it was built for, and TypeScript accepts it, so a new
kind of failure in the client isn't a breaking change for an app. The button says something general for it,
errorUnknown: "Something went wrong. Try again."
Everything the button says is in ENGLISH, which it exports. An app in another language gives its own words for any of
them as text, and each one it leaves out stays English. The words that say what went wrong start with error, such as
errorNetworkFailed, and are functions of the failure's params. ERROR_KEYS, which the button exports too, says
which is for which failure code, and errorUnknown is what to say for a code the button doesn't know.
import {createSolidSaveButton} from '@viboko/solid-save-button';
const saveButton = createSolidSaveButton(container, {text: {
save: 'Zapisz',
errorNetworkFailed: ({url}) => `Nie można połączyć się z ${url}.`
}});
Every rule in style.css starts from .solid-save-button, so the page's own rules for buttons and inputs don't reach
inside. Its colours, font, sizes and shape are custom properties: set them on the container, with a selector that
outweighs .solid-save-button, such as its ID. The defaults draw an outlined box with rounded corners, for a light
page.
#save-button {
--ssb-font: Fredoka, system-ui, sans-serif;
--ssb-local-soft: #fdf3d8;
}
| Property | What it colours |
|---|---|
--ssb-paper, --ssb-surface |
The button's and the panel's background, and what's under a hover |
--ssb-ink, --ssb-muted |
Text, and quieter text |
--ssb-line, --ssb-outline |
The panel's border, and the button's outline and focus ring |
--ssb-local, --ssb-local-soft |
The right half while saves stay in this browser |
--ssb-pod, --ssb-pod-soft |
The right half and the panel once a Pod is connected |
--ssb-button, --ssb-button-text |
The panel's main button |
--ssb-error, --ssb-error-soft |
A failure |
--ssb-shadow |
The panel's and the menu's shadow |
--ssb-font |
Every piece of text |
--ssb-panel-pod |
Solid's colour in the panel, if it differs from the right half's, as on a dark panel. Defaults to --ssb-pod |
--ssb-hover |
What's under Save while the pointer is on it. Defaults to --ssb-surface |
--ssb-where-hover |
A shade laid over the right half while the pointer is on it. Defaults to none |
--ssb-sweep |
The sheen across Save while saving |
| Property | What it sizes or shapes |
|---|---|
--ssb-font-size, --ssb-font-weight |
Save's text, and the weight of all the text |
--ssb-panel-font-size |
The panel's text. Its headings, smaller text and icons scale with it |
--ssb-icon-size |
The icons on the button. Defaults to a little larger than the text |
--ssb-height |
The button's height |
--ssb-radius |
The button's corners |
--ssb-border, --ssb-divider |
The button's outline, and the line between its halves, as a border, such as none |
--ssb-background |
The button's background, behind Save. Defaults to --ssb-paper |
--ssb-chevron, --ssb-chevron-size, --ssb-chevron-gap |
The right half's chevron: an image whose shape is drawn in the right half's colour, its size, and the gap before it |
--ssb-panel-offset |
How far below the button the panel opens |
--ssb-panel-width, --ssb-panel-radius |
The panel's width, and its corners |
For a toolbar, the button can be drawn as a pill instead, with the panel in the bar's colour:
#save-button {
--ssb-font-size: 12px;
--ssb-panel-font-size: 12px;
--ssb-font-weight: bold;
--ssb-height: 2rem;
--ssb-radius: 8px;
--ssb-border: none;
--ssb-divider: 1px solid rgb(0 0 0 / 0.15);
--ssb-background: rgb(255 255 255 / 0.15);
--ssb-paper: #2b2340;
--ssb-ink: #ffffff;
}
The package is published on npm. A project installs it with:
npm install @viboko/solid-save-button
It doesn't need Solid Accord installed, but an app that uses it with Solid Accord installs the browser client and core, as its README says.
From the root of the repository, just test and just build run these for every package. For this one alone, run
them from this folder:
npm test runs its tests, in jsdom, a browser page simulated in Node.npm run build builds it into dist/, with style.css copied beside the code.just docs, then just docs-serve, from the root, builds the playground and serves it on
http://localhost:4003/solid-save-button/.
A Save button for an app that saves to a Solid Pod: a split button, whose left half saves and whose right half says where saves go.
The left half saves, always: in the browser, and to the Pod when one is connected. Its label always says Save, and the icon beside it tells the state: a spinner while saving, a tick once saved, an alert if it failed. The right half shows where saves go, this computer or the Pod, with a spinner while a Pod is being connected, and opens a panel to connect a Pod, or to see where saves go and, from a menu, disconnect it, which is rarely wanted. The button alone shows the state: what it says in words, such as "Saved to your Pod.", is only for screen readers.
It imports nothing from Solid Accord, and knows nothing about what's being saved: it calls its
on…handlers, and is told where things stand withshow, each time they change. Its state has the same shape as the state of Solid Accord's browser client, failures and all, so an app passes the client's state straight on, and TypeScript checks the two still match where it does. It says everything in English unless the app gives its own words, astext.Its look is in
style.css, which the app imports alongside it, and themes by setting its--ssb-…custom properties.