|
1 | | -<nav><ul><li><a href="/">TinyBase</a></li><li><a href="/demos/">Demos</a></li><li><a href="/demos/ui-components/">UI Components</a></li><li><a href="/demos/ui-components/editablecellview/"><EditableCellView /></a></li></ul></nav><section class="s1" id="/demos/ui-components/editablecellview/" data-id="<ECV"><h1><EditableCellView /></h1><iframe srcdoc="<html><head><script src="/umd/react.production.min.js"></script><script src="/umd/react-dom.production.min.js"></script><script src="/umd/tinybase/index.js"></script><script src="/umd/tinybase/ui-react/index.js"></script><script src="/umd/tinybase/ui-react-dom/index.js"></script><style>#loading{animation:spin 1s infinite linear;height:2rem;margin:40vh auto;width:2rem}#loading::before{content:url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" height="2rem" viewBox="0 0 100 100"><path d="M50 10A40 40 0 1 1 10 50" stroke="black" fill="none" stroke-width="4" /></svg>')}@keyframes spin{from{transform:rotate(0)}to{transform:rotate(360deg)}}@font-face{font-family:Inter;src:url(https://tinybase.org/fonts/inter.woff2) format('woff2')}*{box-sizing:border-box}body{align-items:flex-start;color:#333;display:flex;font-family:Inter,sans-serif;font-size:.8rem;min-height:100vh;justify-content:space-around;letter-spacing:-.04rem;line-height:1.5rem;margin:0;user-select:none}table{background:#fff;border-collapse:collapse;box-shadow:0 0 1rem #0004;font-size:inherit;line-height:inherit;margin:2rem;table-layout:fixed}table td,table th{overflow:hidden;padding:.25rem .5rem;white-space:nowrap;border-width:1px 0;border-style:solid;border-color:#eee;text-align:left}table thead th{border-bottom-color:#ccc}table button,table input{border:1px solid #ccc}a{color:inherit}#edit{align-self:flex-start;background:#fff;box-shadow:0 0 1rem #0004;margin:2rem;min-width:16rem;padding:.5rem 1rem 1rem}.editableCell button{width:4rem;margin-right:.5rem}</style></head><body></body><script>(()=>{let l=React.createElement,n=TinyBase.createStore,{Provider:s,useCreateStore:i}=TinyBaseUiReact,{EditableCellView:e,TableInHtmlTable:t}=TinyBaseUiReactDom,{useMemo:r,useState:d}=React,a=()=>{let e=i(n),[t,a]=d(!0);return r(async()=>{await b(e,"genres"),a(!1)},[]),l(s,{store:e},l(t?o:c,null))},o=(addEventListener("load",()=>ReactDOM.createRoot(document.body).render(l(a,null))),()=>l("div",{id:"loading"})),c=()=>l(React.Fragment,null,l(t,{tableId:"genres",editable:!0}),l("div",{id:"edit"},"Genre 5 name:",l(e,{tableId:"genres",rowId:"5",cellId:"name"}))),h=/^[\d\.]+$/,b=async(l,n)=>{l.startTransaction();let e=(await(await fetch(`https://tinybase.org/assets/${n}.tsv`)).text()).split(` |
2 | | -`),s=e.shift().split("\t");e.forEach(e=>{e=e.split("\t");if(e.length==s.length){let a=e.shift();e.forEach((e,t)=>{""!=e&&(h.test(e)&&(e=parseFloat(e)),l.setCell(n,a,s[t+1],e))})}}),l.finishTransaction()}})()</script></html>"></iframe><p>In this demo, we showcase the <a href="/api/ui-react-dom/functions/store-components/editablecellview/"><code>EditableCellView</code></a> component, which allows you to edit <a href="/api/store/type-aliases/store/cell/"><code>Cell</code></a> values in the <a href="/api/store/interfaces/store/store/"><code>Store</code></a> in a web environment.</p><p>Rather than building the whole demo and boilerplate from scratch, we're making changes to the <a href="/demos/ui-components/tableinhtmltable/"><TableInHtmlTable /></a> demo to show this new component.</p><h3 id="set-up">Set Up</h3><p>We start off by simply adding the component to the imports:</p><pre><code><span class="deleted-sign"><span class="prefix">-</span><span class="keyword">const</span> <span class="punctuation">{</span>TableInHtmlTable<span class="punctuation">}</span> <span class="operator">=</span> TinyBaseUiReactDom<span class="punctuation">;</span> |
| 1 | +<nav><ul><li><a href="/">TinyBase</a></li><li><a href="/demos/">Demos</a></li><li><a href="/demos/ui-components/">UI Components</a></li><li><a href="/demos/ui-components/editablecellview/"><EditableCellView /></a></li></ul></nav><section class="s1" id="/demos/ui-components/editablecellview/" data-id="<ECV"><h1><EditableCellView /></h1><iframe srcdoc="<html><head><script src="/umd/react.production.min.js"></script><script src="/umd/react-dom.production.min.js"></script><script src="/umd/tinybase/index.js"></script><script src="/umd/tinybase/ui-react/index.js"></script><script src="/umd/tinybase/ui-react-dom/index.js"></script><style>#loading{animation:spin 1s infinite linear;height:2rem;margin:40vh auto;width:2rem}#loading::before{content:url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" height="2rem" viewBox="0 0 100 100"><path d="M50 10A40 40 0 1 1 10 50" stroke="black" fill="none" stroke-width="4" /></svg>')}@keyframes spin{from{transform:rotate(0)}to{transform:rotate(360deg)}}@font-face{font-family:Inter;src:url(https://tinybase.org/fonts/inter.woff2) format('woff2')}*{box-sizing:border-box}body{align-items:flex-start;color:#333;display:flex;font-family:Inter,sans-serif;font-size:.8rem;min-height:100vh;justify-content:space-around;letter-spacing:-.04rem;line-height:1.5rem;margin:0;user-select:none}table{background:#fff;border-collapse:collapse;box-shadow:0 0 1rem #0004;font-size:inherit;line-height:inherit;margin:2rem;table-layout:fixed}table td,table th{overflow:hidden;padding:.25rem .5rem;white-space:nowrap;border-width:1px 0;border-style:solid;border-color:#eee;text-align:left}table thead th{border-bottom-color:#ccc}table button,table input{border:1px solid #ccc}a{color:inherit}#edit{align-self:flex-start;background:#fff;box-shadow:0 0 1rem #0004;margin:2rem;min-width:16rem;padding:.5rem 1rem 1rem}.editableCell button{width:4rem;margin-right:.5rem}</style></head><body></body><script>(()=>{let l=React.createElement,n=TinyBase.createStore,{Provider:s,useCreateStore:i}=TinyBaseUiReact,{EditableCellView:e,TableInHtmlTable:t}=TinyBaseUiReactDom,{useMemo:r,useState:d}=React,a=()=>{let e=i(n),[t,a]=d(!0);return r(async()=>{await h(e,"genres"),a(!1)},[]),l(s,{store:e},l(t?o:c,null))},o=(addEventListener("load",()=>ReactDOM.createRoot(document.body).render(l(a,null))),()=>l("div",{id:"loading"})),c=()=>l(React.Fragment,null,l(t,{tableId:"genres",editable:!0}),l("div",{id:"edit"},"Genre 5 name:",l(e,{tableId:"genres",rowId:"g05",cellId:"name"}))),g=/^[\d\.]+$/,h=async(l,n)=>{l.startTransaction();let e=(await(await fetch(`https://tinybase.org/assets/${n}.tsv`)).text()).split(` |
| 2 | +`),s=e.shift().split("\t");e.forEach(e=>{e=e.split("\t");if(e.length==s.length){let a=e.shift();e.forEach((e,t)=>{""!=e&&(g.test(e)&&(e=parseFloat(e)),l.setCell(n,a,s[t+1],e))})}}),l.finishTransaction()}})()</script></html>"></iframe><p>In this demo, we showcase the <a href="/api/ui-react-dom/functions/store-components/editablecellview/"><code>EditableCellView</code></a> component, which allows you to edit <a href="/api/store/type-aliases/store/cell/"><code>Cell</code></a> values in the <a href="/api/store/interfaces/store/store/"><code>Store</code></a> in a web environment.</p><p>Rather than building the whole demo and boilerplate from scratch, we're making changes to the <a href="/demos/ui-components/tableinhtmltable/"><TableInHtmlTable /></a> demo to show this new component.</p><h3 id="set-up">Set Up</h3><p>We start off by simply adding the component to the imports:</p><pre><code><span class="deleted-sign"><span class="prefix">-</span><span class="keyword">const</span> <span class="punctuation">{</span>TableInHtmlTable<span class="punctuation">}</span> <span class="operator">=</span> TinyBaseUiReactDom<span class="punctuation">;</span> |
3 | 3 | </span><span class="inserted-sign"><span class="prefix">+</span><span class="keyword">const</span> <span class="punctuation">{</span>EditableCellView<span class="punctuation">,</span> TableInHtmlTable<span class="punctuation">}</span> <span class="operator">=</span> TinyBaseUiReactDom<span class="punctuation">;</span> |
4 | 4 | </span></code></pre><h3 id="using-the-editablecellview-component">Using the <a href="/api/ui-react-dom/functions/store-components/editablecellview/"><code>EditableCellView</code></a> Component</h3><p>The <a href="/api/ui-react-dom/functions/store-components/editablecellview/"><code>EditableCellView</code></a> component simply needs a tableId, rowId, and cellId to render the <a href="/api/store/type-aliases/store/cell/"><code>Cell</code></a> and make it editable. We replace two of the tables from the original demo to add the control:</p><pre><code><span class="deleted-sign"><span class="prefix">-</span> <span class="tag"><span class="tag"><span class="punctuation"><</span><span class="class-name"><a href="/api/ui-react-dom/functions/store-components/tableinhtmltable/">TableInHtmlTable</a></span></span> <span class="attr-name">tableId</span><span class="attr-value"><span class="punctuation">=</span><span class="punctuation">'</span>genres<span class="punctuation">'</span></span> <span class="attr-name">headerRow</span><span class="script"><span class="script-punctuation">=</span><span class="punctuation">{</span><span class="boolean">false</span><span class="punctuation">}</span></span> <span class="attr-name">idColumn</span><span class="script"><span class="script-punctuation">=</span><span class="punctuation">{</span><span class="boolean">false</span><span class="punctuation">}</span></span> <span class="punctuation">/></span></span> |
5 | 5 | <span class="prefix">-</span> <span class="tag"><span class="tag"><span class="punctuation"><</span><span class="class-name"><a href="/api/ui-react-dom/functions/store-components/tableinhtmltable/">TableInHtmlTable</a></span></span> <span class="attr-name">tableId</span><span class="attr-value"><span class="punctuation">=</span><span class="punctuation">'</span>genres<span class="punctuation">'</span></span> <span class="attr-name">customCells</span><span class="script"><span class="script-punctuation">=</span><span class="punctuation">{</span>customCells<span class="punctuation">}</span></span> <span class="punctuation">/></span></span> |
6 | 6 | </span><span class="inserted-sign"><span class="prefix">+</span> <span class="tag"><span class="tag"><span class="punctuation"><</span>div</span> <span class="attr-name">id</span><span class="attr-value"><span class="punctuation">=</span><span class="punctuation">'</span>edit<span class="punctuation">'</span></span><span class="punctuation">></span></span><span class="plain-text"> |
7 | 7 | <span class="prefix">+</span> Genre 5 name: |
8 | | -<span class="prefix">+</span> </span><span class="tag"><span class="tag"><span class="punctuation"><</span><span class="class-name"><a href="/api/ui-react-dom/functions/store-components/editablecellview/">EditableCellView</a></span></span> <span class="attr-name">tableId</span><span class="attr-value"><span class="punctuation">=</span><span class="punctuation">'</span>genres<span class="punctuation">'</span></span> <span class="attr-name">rowId</span><span class="attr-value"><span class="punctuation">=</span><span class="punctuation">'</span>5<span class="punctuation">'</span></span> <span class="attr-name">cellId</span><span class="attr-value"><span class="punctuation">=</span><span class="punctuation">'</span>name<span class="punctuation">'</span></span> <span class="punctuation">/></span></span><span class="plain-text"> |
| 8 | +<span class="prefix">+</span> </span><span class="tag"><span class="tag"><span class="punctuation"><</span><span class="class-name"><a href="/api/ui-react-dom/functions/store-components/editablecellview/">EditableCellView</a></span></span> <span class="attr-name">tableId</span><span class="attr-value"><span class="punctuation">=</span><span class="punctuation">'</span>genres<span class="punctuation">'</span></span> <span class="attr-name">rowId</span><span class="attr-value"><span class="punctuation">=</span><span class="punctuation">'</span>g05<span class="punctuation">'</span></span> <span class="attr-name">cellId</span><span class="attr-value"><span class="punctuation">=</span><span class="punctuation">'</span>name<span class="punctuation">'</span></span> <span class="punctuation">/></span></span><span class="plain-text"> |
9 | 9 | <span class="prefix">+</span> </span><span class="tag"><span class="tag"><span class="punctuation"></</span>div</span><span class="punctuation">></span></span> |
10 | 10 | </span><span class="unchanged"><span class="prefix"> </span> <span class="tag"><span class="tag"><span class="punctuation"></</span></span><span class="punctuation">></span></span> |
11 | 11 | <span class="prefix"> </span> <span class="punctuation">)</span><span class="punctuation">;</span> |
|
0 commit comments