Avatar

jxnblk

Bicycle riding cat from the future
Joined April 28, 2024
Public vals
45
jxnblk avatar
tuna_tests
@jxnblk
Script
An interactive, runnable TypeScript val by jxnblk
jxnblk avatar
caviar_tests
@jxnblk
Script
An interactive, runnable TypeScript val by jxnblk
jxnblk avatar
caviar
@jxnblk
Script
Simple CSS Vars library import { caviar } from "https://esm.town/v/jxnblk/caviar"; const vars = caviar({ dark: { text: "#000", bg: "#fff", }, light: { text: "#fff", bg: "#000", }, }); // JSX example <div style={vars.style.light}> <h1 style={{ color: vars.text, backgroundColor: vars.bg, }}> Hello </h1> </div> Can also be used for non-dynamic CSS vars import { caviar } from "https://esm.town/v/jxnblk/caviar"; const vars = caviar({ blue: "#0cf", }); // <div style={vars.style} /> Tests: https://www.val.town/v/jxnblk/caviar_tests TODO [ ] Fallback for missing mode keys
jxnblk avatar
tuna
@jxnblk
Script
🐟 Simple CSS library for Val Town import { css } from "https://esm.town/v/jxnblk/tuna"; const styles = css({ body: { // special keyword for <body> element fontFamily: "system-ui, sans-serif", margin: 0, backgroundColor: "#f5f5f5", }, container: { padding: 32, // numbers are converted to pixel units margin: "0 auto", maxWidth: 1024, }, input: { fontFamily: "inherit", fontSize: "inherit", lineHeight: "1.5", padding: "2px 8px", border: "1px solid #ccc", borderRadius: "4px", }, }); // JSX example const html = render( <div className={styles.container}> <style {...styles.tag} /> <h1>Tuna Example</h1> <input type="text" defaultValue="hi" className={styles.input} /> </div> ); // get raw CSS string styles.css Nested selectors and pseudoselectors const styles = css({ button: { background-color: "tomato", "&:hover": { background-color: "magenta", }, "& > svg": { fill: "currentColor", }, }, }); Media queries const styles = css({ box: { padding: 16, "@media screen and (min-width: 768px)": { padding: 32, "&:hover": { color: "tomato", }, }, } }); Limitations Does not support HTML element selectors (other than body ) Tests: https://www.val.town/v/jxnblk/tuna_tests
jxnblk avatar
tuna_example
@jxnblk
HTTP (deprecated)
// Example of using tuna and caviar with React (resrv) on Val Town
jxnblk avatar
resrv_example
@jxnblk
HTTP (deprecated)
@jsxImportSource https://esm.sh/react
jxnblk avatar
resrv
@jxnblk
Script
React SSR and client-side hydration for Val Town For streaming responses use ReactStream Usage /** @jsxImportSource https://esm.sh/react */ import resrv, { React } from "https://esm.town/v/jxnblk/resrv"; function App() { const [count, setCount] = React.useState(0); return ( <div> <h1>Resrv</h1> <p>React SSR with client-side hydration in Val Town</p> <pre>{count}</pre> <button onClick={() => setCount(count - 1)}>-</button> <button onClick={() => setCount(count + 1)}>+</button> </div> ); } export default resrv(App, import.meta.url); Live example React requires matching versions for SSR and hydration. Import React from https://esm.town/v/jxnblk/resrv to ensure your component uses the same version as this library (currently react@18.3.1). HTML Root Hydration To render a component that includes a <head> and <body> tag, pass root: true to the third options argument: function App ({ script }) { return ( <body> <h1>Hello</h1> {script} </body> ); } export default resrv(App, import.meta.url, { root: true }); Inspired by https://www.val.town/v/stevekrouse/react_http
jxnblk avatar
contrast_swatch
@jxnblk
HTTP (deprecated)
@jsxImportSource https://esm.sh/preact
jxnblk avatar
color_contrast
@jxnblk
HTTP (deprecated)
Forked from jxnblk/head
jxnblk avatar
png_card
@jxnblk
HTTP (deprecated)
Forked from jxnblk/blushPorcupine
jxnblk avatar
svg_card
@jxnblk
Script
Forked from jxnblk/rosePelican
jxnblk avatar
pie
@jxnblk
HTTP (deprecated)
Forked from jxnblk/svg
Next