9 lines
6.3 KiB
JavaScript
9 lines
6.3 KiB
JavaScript
import{_ as e,c as a,o as s,N as n}from"./chunks/framework.0799945b.js";const h=JSON.parse('{"title":"Coercable Components","description":"","frontmatter":{},"headers":[],"relativePath":"guide/important-concepts/coercable.md","lastUpdated":1681217552000}'),o={name:"guide/important-concepts/coercable.md"},t=n(`<h1 id="coercable-components" tabindex="-1">Coercable Components <a class="header-anchor" href="#coercable-components" aria-label="Permalink to "Coercable Components""></a></h1><p>Most times a feature has some sort of dynamic display, it'll allow you to pass a "Coercable Component", or rather, something that can be coerced into a Vue component. This page goes over the different types of values you can use</p><h2 id="template-strings" tabindex="-1">Template Strings <a class="header-anchor" href="#template-strings" aria-label="Permalink to "Template Strings""></a></h2><p>If you provide a string, it will be wrapped in a component using it as the template. This is the simplest method, although not suitable for complex displays, and realistically cannot use Vue components as none are registered globally (by default). Recommended for static or simple dynamic displays, such as displays on features.</p><p>Template strings need to be wrapped in some HTML element. By default, they'll be wrapped in a <code><span></code> element, although certain features may wrap things in div or header elements instead, as appropriate.</p><h2 id="render-functions-jsx" tabindex="-1">Render Functions (JSX) <a class="header-anchor" href="#render-functions-jsx" aria-label="Permalink to "Render Functions (JSX)""></a></h2><p>You can provide a render function and it will be wrapped in a component as well. The intended use for this is to write JSX inside a function, which will get automatically converted into a render function. You can read more about that process on the Vue docs on <a href="https://vuejs.org/guide/extras/render-function.html#render-functions-jsx" target="_blank" rel="noreferrer">Render Functions & JSX</a>. Note that JSX must be returned in a function - it does not work "standalone". The CoercableComponent type will enforce this for you.</p><p>JSX can use imported components, making this suited for writing the display properties on things like Tabs or Layers. There are also built-in functions to <code>render</code> features (either as their own or in a layout via <code>renderRow</code> and <code>renderCol</code>), so you don't need to import the Vue component for every feature you plan on using.</p><p>Typically a feature will accept a <code>Computable<CoercableComponent></code>, which means functions would (normally) be wrapped in a computed (see <a href="./reactivity#computable">Computable</a> for more details). This would break render functions, so when passing a render function as a CoercableComponent it must be specially marked that it shouldn't be cached. You can use the built-in <code>jsx</code> function to mark a function for you.</p><h4 id="example" tabindex="-1">Example <a class="header-anchor" href="#example" aria-label="Permalink to "Example""></a></h4><div class="language-ts"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">{</span></span>
|
||
<span class="line"><span style="color:#F07178;"> </span><span style="color:#FFCB6B;">display</span><span style="color:#89DDFF;">:</span><span style="color:#F07178;"> </span><span style="color:#82AAFF;">jsx</span><span style="color:#F07178;">(</span><span style="color:#89DDFF;">()</span><span style="color:#F07178;"> </span><span style="color:#C792EA;">=></span><span style="color:#F07178;"> (</span></span>
|
||
<span class="line"><span style="color:#F07178;"> </span><span style="color:#89DDFF;"><></span></span>
|
||
<span class="line"><span style="color:#F07178;"> </span><span style="color:#89DDFF;"><</span><span style="color:#A6ACCD;">MainDisplay</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">resource</span><span style="color:#89DDFF;">={</span><span style="color:#A6ACCD;">points</span><span style="color:#89DDFF;">}</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;">color</span><span style="color:#89DDFF;">={</span><span style="color:#A6ACCD;">color</span><span style="color:#89DDFF;">}</span><span style="color:#F07178;"> </span><span style="color:#89DDFF;">/></span></span>
|
||
<span class="line"><span style="color:#F07178;"> </span><span style="color:#89DDFF;">{</span><span style="color:#A6ACCD;font-style:italic;">render</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;font-style:italic;">resetButton</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">}</span></span>
|
||
<span class="line"><span style="color:#F07178;"> </span><span style="color:#89DDFF;">{</span><span style="color:#A6ACCD;font-style:italic;">renderRow</span><span style="color:#F07178;">(</span><span style="color:#A6ACCD;font-style:italic;">upgrade1</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;font-style:italic;">upgrade2</span><span style="color:#89DDFF;">,</span><span style="color:#F07178;"> </span><span style="color:#A6ACCD;font-style:italic;">upgrade3</span><span style="color:#F07178;">)</span><span style="color:#89DDFF;">}</span></span>
|
||
<span class="line"><span style="color:#F07178;"> </span><span style="color:#89DDFF;"></></span></span>
|
||
<span class="line"><span style="color:#F07178;"> ))</span><span style="color:#89DDFF;">,</span></span>
|
||
<span class="line"><span style="color:#89DDFF;">}</span></span></code></pre></div><h2 id="components" tabindex="-1">Components <a class="header-anchor" href="#components" aria-label="Permalink to "Components""></a></h2><p>This one might be the most obvious, but you can also just give it a Vue component to display outright. Keep in mind it will not be passed any props, so it should not depend on any. You can read more about creating Vue components on <a href="https://vuejs.org/guide/essentials/component-basics.html" target="_blank" rel="noreferrer">Components Basics</a>.</p>`,13),l=[t];function p(r,c,i,d,u,y){return s(),a("div",null,l)}const F=e(o,[["render",p]]);export{h as __pageData,F as default};
|