"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([["8875"],{7240:function(e,t,o){o.r(t),o.d(t,{default:()=>p,frontMatter:()=>l,metadata:()=>s,assets:()=>d,simpleConfig:()=>c,toc:()=>h,contentTitle:()=>a});var s=JSON.parse('{"id":"features/display-modes","title":"Display Modes","description":"The configuration option mode, also available as query param, can be used to select different display modes.","source":"@site/docs/features/display-modes.mdx","sourceDirName":"features","slug":"/features/display-modes","permalink":"/docs/features/display-modes","draft":false,"unlisted":false,"editUrl":"https://github.com/live-codes/livecodes/tree/develop/docs/docs/features/display-modes.mdx","tags":[],"version":"current","frontMatter":{},"sidebar":"docsSidebar","previous":{"title":"Code to Image","permalink":"/docs/features/code-to-image"},"next":{"title":"Default View","permalink":"/docs/features/default-view"}}'),n=o("5893"),i=o("65"),r=o("3365");let l={},a="Display Modes",d={},c={mode:"simple",layout:"vertical",activeEditor:"script",editor:"monaco",tools:{status:"none"},script:{language:"jsx",content:`import { atom, useAtom } from 'jotai'; const countAtom = atom(0); const Counter = () => { const [count, setCount] = useAtom(countAtom); const inc = () => setCount((c) => c + 1); return ( <> {count} > ); }; const App = () => (
full",id:"full",level:2},{value:"focus",id:"focus",level:2},{value:"simple",id:"simple",level:2},{value:"lite",id:"lite",level:2},{value:"editor",id:"editor",level:2},{value:"codeblock",id:"codeblock",level:2},{value:"result",id:"result",level:2},{value:"Display Mode vs Default View",id:"display-mode-vs-default-view",level:2}];function u(e){let t={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",header:"header",img:"img",p:"p",...(0,i.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.header,{children:(0,n.jsx)(t.h1,{id:"display-modes",children:"Display Modes"})}),"\n","\n",(0,n.jsxs)(t.p,{children:["The ",(0,n.jsx)(t.a,{href:"/docs/configuration/configuration-object",children:"configuration"})," option ",(0,n.jsx)(t.a,{href:"/docs/configuration/configuration-object#mode",children:(0,n.jsx)(t.code,{children:"mode"})}),", also available as ",(0,n.jsx)(t.a,{href:"/docs/configuration/query-params",children:"query param"}),", can be used to select different display modes.\nThe following display modes are supported:"]}),"\n",(0,n.jsx)(t.h2,{id:"full",children:(0,n.jsx)(t.code,{children:"full"})}),"\n",(0,n.jsx)(t.p,{children:"This is the default mode with toolbars, editor and result panes."}),"\n",(0,n.jsxs)(t.p,{children:["Example: ",(0,n.jsx)(t.a,{href:"https://livecodes.io/?template=react",children:"https://livecodes.io/?template=react"})]}),"\n",(0,n.jsx)(t.p,{children:"Screenshot: (App in full mode)"}),"\n",(0,n.jsx)(t.p,{children:(0,n.jsx)(t.img,{alt:"full-mode",src:o(4590).Z+"",width:"2240",height:"1400"})}),"\n",(0,n.jsx)(t.p,{children:"Demo: (Embedded playground in full mode)"}),"\n",(0,n.jsx)(r.Z,{template:"react"}),"\n",(0,n.jsx)(t.h2,{id:"focus",children:(0,n.jsx)(t.code,{children:"focus"})}),"\n",(0,n.jsxs)(t.p,{children:["This hides most of UI buttons and menus and keeps only the essential elements: editors, editor titles, result page, console, and run and share buttons. It can be toggled during runtime from the full mode through the UI from a button in the lower left corner. Also the query param ",(0,n.jsx)(t.code,{children:"?mode=focus"}),"."]}),"\n",(0,n.jsxs)(t.p,{children:["Example: ",(0,n.jsx)(t.a,{href:"https://livecodes.io/?template=react&mode=focus",children:"https://livecodes.io/?template=react&mode=focus"})]}),"\n",(0,n.jsx)(t.p,{children:"Screenshot: (focus mode)"}),"\n",(0,n.jsx)(t.p,{children:(0,n.jsx)(t.img,{alt:"focus-mode",src:o(6251).Z+"",width:"2240",height:"1400"})}),"\n",(0,n.jsx)(t.h2,{id:"simple",children:(0,n.jsx)(t.code,{children:"simple"})}),"\n",(0,n.jsxs)(t.p,{children:["This mode is mainly useful for embedded playgrounds.\nIt shows only 1 editor with the output (result page +/- console). The content of other editors can be set using ",(0,n.jsx)(t.a,{href:"/docs/sdk/",children:"SDK"})," ",(0,n.jsx)(t.a,{href:"/docs/configuration/configuration-object",children:"config"})," even though the editors are not shown.\nBy default, ",(0,n.jsx)(t.code,{children:"codemirror"})," editor is used, however, this can be changed by the ",(0,n.jsx)(t.a,{href:"/docs/configuration/configuration-object#editor",children:(0,n.jsx)(t.code,{children:"editor"})})," option.\nBy default, the layout is ",(0,n.jsx)(t.code,{children:"responsive"})," but can also be overridden by the ",(0,n.jsx)(t.a,{href:"/docs/configuration/configuration-object#layout",children:(0,n.jsx)(t.code,{children:"layout"})})," option to ",(0,n.jsx)(t.code,{children:"vertical"})," or ",(0,n.jsx)(t.code,{children:"horizontal"}),"."]}),"\n",(0,n.jsx)(t.p,{children:"Demo: JS with console"}),"\n",(0,n.jsx)(r.Z,{params:{mode:"simple",js:'console.log("hello world")',layout:"vertical",console:"full"}}),"\n",(0,n.jsx)(t.p,{children:"Demo: JSX & Result page (Monaco editor, add CSS)"}),"\n","\n",(0,n.jsx)(r.Z,{config:c,height:"400px"}),"\n",(0,n.jsx)(t.h2,{id:"lite",children:(0,n.jsx)(t.code,{children:"lite"})}),"\n",(0,n.jsxs)(t.p,{children:["Loads a light-weight, minimal code editor, with limited playground features.\nSee the section about ",(0,n.jsx)(t.a,{href:"/docs/features/lite",children:"lite mode"})," for details"]}),"\n",(0,n.jsxs)(t.p,{children:["Example: ",(0,n.jsx)(t.a,{href:"https://livecodes.io/?mode=lite&template=react",children:"https://livecodes.io/?mode=lite&template=react"})]}),"\n",(0,n.jsx)(t.p,{children:"Demo:"}),"\n",(0,n.jsx)(r.Z,{config:{mode:"lite"},template:"react"}),"\n",(0,n.jsx)(t.h2,{id:"editor",children:(0,n.jsx)(t.code,{children:"editor"})}),"\n",(0,n.jsx)(t.p,{children:"Hides the results pane and works as editor only."}),"\n",(0,n.jsxs)(t.p,{children:["Example: ",(0,n.jsx)(t.a,{href:"https://livecodes.io/?mode=editor&template=react",children:"https://livecodes.io/?mode=editor&template=react"})]}),"\n",(0,n.jsx)(t.p,{children:"Demo:"}),"\n",(0,n.jsx)(r.Z,{config:{mode:"editor"},template:"react"}),"\n",(0,n.jsx)(t.h2,{id:"codeblock",children:(0,n.jsx)(t.code,{children:"codeblock"})}),"\n",(0,n.jsx)(t.p,{children:"A read-only mode showing only the code block without editor interface. On mouse-over a copy button appears that allows to copy the code. This is specially useful when embedded."}),"\n",(0,n.jsxs)(t.p,{children:["Example: ",(0,n.jsx)(t.a,{href:"https://livecodes.io/?mode=codeblock&template=react",children:"https://livecodes.io/?mode=codeblock&template=react"})]}),"\n",(0,n.jsx)(t.p,{children:"Demo:"}),"\n",(0,n.jsx)(r.Z,{config:{mode:"codeblock"},template:"react"}),"\n",(0,n.jsxs)(t.p,{children:["By default, in ",(0,n.jsx)(t.code,{children:"codeblock"})," mode, the light-weight ",(0,n.jsx)(t.code,{children:"CodeJar"})," editor is used (in read-only mode). You can override this by setting the ",(0,n.jsx)(t.code,{children:"editor"})," option. Refer to ",(0,n.jsx)(t.a,{href:"/docs/features/editor-settings#code-editor",children:"Editor Settings"})," for details."]}),"\n",(0,n.jsxs)(t.p,{children:["Example: ",(0,n.jsx)(t.a,{href:"https://livecodes.io/?mode=codeblock&editor=monaco&template=react",children:"https://livecodes.io/?mode=codeblock&editor=monaco&template=react"})]}),"\n",(0,n.jsx)(t.p,{children:"Demo:"}),"\n",(0,n.jsx)(r.Z,{config:{mode:"codeblock",editor:"monaco"},template:"react"}),"\n",(0,n.jsx)(t.h2,{id:"result",children:(0,n.jsx)(t.code,{children:"result"})}),"\n",(0,n.jsx)(t.p,{children:"Shows the result page only, with a drawer at the bottom (which can be closed) that allows opening the project in the full playground."}),"\n",(0,n.jsxs)(t.p,{children:["Example: ",(0,n.jsx)(t.a,{href:"https://livecodes.io/?mode=result&template=react",children:"https://livecodes.io/?mode=result&template=react"})]}),"\n",(0,n.jsx)(t.p,{children:"Demo:"}),"\n",(0,n.jsx)(r.Z,{params:{mode:"result",template:"react"}}),"\n",(0,n.jsxs)(t.p,{children:["The tools pane (e.g. console/compiled code viewer) is hidden by default in ",(0,n.jsx)(t.code,{children:"result"})," mode. It can be shown if set to ",(0,n.jsx)(t.code,{children:"open"})," or ",(0,n.jsx)(t.code,{children:"full"}),". Refer to ",(0,n.jsx)(t.a,{href:"/docs/features/tools-pane",children:"Tools pane"})," documentation for details."]}),"\n",(0,n.jsxs)(t.p,{children:["Example: ",(0,n.jsx)(t.a,{href:"https://livecodes.io/?mode=result&tools=console%7Cfull&&js=console.log(%22Hello%20World",children:'https://livecodes.io/?mode=result&tools=console|full&&js=console.log("Hello%20World'}),'!")']}),"\n",(0,n.jsx)(t.p,{children:"Demo:"}),"\n",(0,n.jsx)(r.Z,{params:{mode:"result",tools:"console|full",js:'console.log("Hello World!")'}}),"\n",(0,n.jsx)(t.h2,{id:"display-mode-vs-default-view",children:"Display Mode vs Default View"}),"\n",(0,n.jsxs)(t.admonition,{type:"info",children:[(0,n.jsxs)(t.p,{children:['"Display Mode" is different from "',(0,n.jsx)(t.a,{href:"/docs/features/default-view",children:"Default View"}),'".']}),(0,n.jsxs)(t.p,{children:["In ",(0,n.jsx)(t.code,{children:"editor"})," display mode, only the editor is loaded and the result page is not available. While ",(0,n.jsx)(t.code,{children:"editor"})," default view shows the editor by default, and the result page can be shown by dragging the split gutter."]}),(0,n.jsxs)(t.p,{children:["The same applies for ",(0,n.jsx)(t.code,{children:"result"})," display mode and default view."]})]})]})}function p(e={}){let{wrapper:t}={...(0,i.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(u,{...e})}):u(e)}},6251:function(e,t,o){o.d(t,{Z:function(){return s}});let s=o.p+"assets/images/mode-focus-cfaa1455bdd069375859aa7cefbbc82d.jpg"},4590:function(e,t,o){o.d(t,{Z:function(){return s}});let s=o.p+"assets/images/mode-full-25f311a4ee364ffd5331c99c03160894.jpg"},3365:function(e,t,o){o.d(t,{Z:()=>g});var s=o("5893"),n=o("4200"),i=o("7294"),r=o("8294");function l(e){let t=(0,i.useRef)(null),[o,n]=(0,i.useState)(e.className||""),[l,a]=(0,i.useState)(e.style||{}),[d,c]=(0,i.useState)(e.height),[h,u]=(0,i.useState)(),[p,m]=(0,i.useState)(JSON.stringify(e.config||"")),[f,g]=(0,i.useState)("");return(0,i.useEffect)(()=>{if(!t.current)return;let{className:o,style:s,height:i,sdkReady:l,config:d,...y}=e;if(n(o||""),a(s||{}),c(i),h&&f===JSON.stringify(y)){if(p===JSON.stringify(d))return;m(JSON.stringify(d)),"string"==typeof d?fetch(d).then(e=>e.json()).then(e=>{h?.setConfig(e)}):d&&h.setConfig(d)}else g(JSON.stringify(y)),h?.destroy(),(0,r.T)(t.current,{config:d,...y}).then(e=>{u(e),"function"==typeof l&&l(e)})},[e]),(0,i.useEffect)(()=>()=>{h?.destroy()},[]),(0,s.jsx)("div",{ref:t,className:o,style:l,"data-height":d})}var a=o("1858"),d=o("3262"),c=o("1705"),h=o("7645"),u=o("8168"),p=o("8228"),m=o("5050");function f(e){let[t,o]=(0,i.useState)(e.js),[n,r]=(0,i.useState)(e.ts),[l,a]=(0,i.useState)(e.react),[f,g]=(0,i.useState)(e.vue),[y,j]=(0,i.useState)(e.svelte),v="3.7rem",[x,b]=(0,i.useState)(!0),[w,S]=(0,i.useState)(v),E=(0,i.useRef)(null),C=()=>{setTimeout(()=>{S(`calc(${E.current.offsetHeight}px + ${v})`)},5),setTimeout(()=>{S(`calc(${E.current.offsetHeight}px + ${v})`)},255)};return(0,i.useEffect)(()=>{if(d.Z.canUseDOM){let e=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"js";try{return window.prettier?.format(e,{parser:"html"===t?"html":"babel",plugins:window.prettierPlugins})}catch{return e}};o(e(t,"js")),r(e(n,"ts")),a(e(l,"jsx")),g(e(f,"html")),j(e(y,"html"))}},[]),(0,s.jsxs)("details",{className:`alert alert--info ${m.Z.details} ${p.Z.details}`,"data-collapsed":x,style:{height:x?v:w,overflow:"hidden",willChange:"height",transition:`height ${x?"250ms":"265ms"} ease-in-out 0s`,margin:"1em 0"},children:[(0,s.jsx)("summary",{onClick:()=>{b(!x),C()},children:"show code"}),(0,s.jsx)("div",{ref:E,style:{display:"block",overflow:"hidden"},children:(0,s.jsx)("div",{className:m.Z.collapsibleContent,children:(0,s.jsxs)(u.Z,{groupId:"sdk-code",children:[(0,s.jsx)(h.Z,{value:"js",label:"JS",attributes:{onMouseDown:C},children:(0,s.jsx)(c.Z,{language:"js",children:t})}),(0,s.jsx)(h.Z,{value:"ts",label:"TS",attributes:{onMouseDown:C},children:(0,s.jsx)(c.Z,{language:"ts",children:n})}),(0,s.jsx)(h.Z,{value:"react",label:"React",attributes:{onMouseDown:C},children:(0,s.jsx)(c.Z,{language:"jsx",children:l})}),(0,s.jsx)(h.Z,{value:"vue",label:"Vue",attributes:{onMouseDown:C},children:(0,s.jsx)(c.Z,{language:"html",children:f})}),(0,s.jsx)(h.Z,{value:"svelte",label:"Svelte",attributes:{onMouseDown:C},children:(0,s.jsx)(c.Z,{language:"html",children:y})})]})})})]})}function g(e){let{className:t,style:o,showCode:i,height:r,...d}=e,{colorMode:c}=(0,n.I)(),h=e=>JSON.stringify(e,null,2),u=`
import { createPlayground } from 'livecodes';
const options = ${h(d)};
createPlayground('#container', options);
`.trimStart(),p=`
import { createPlayground, type EmbedOptions } from 'livecodes';
const options: EmbedOptions = ${h(d)};
createPlayground('#container', options);
`.trimStart(),m=`
import LiveCodes from 'livecodes/react';
export default function App() {
const options = ${h(d)};
return (