KScript docs
EN

Components

Component styles

A component can implement the optional fn style() method to keep its stylesheet beside its render() method. The renderer validates the HTML returned by render() as a KScript page fragment.

<type name="Badge" extends="Component">
  <field name="label" type="string" />

  <fn name="render" value="```html
      &lt;span class=&quot;note-badge&quot;>{$label}&lt;/span>
      ```" />

  <fn name="style" override="yes" value="```css
      .note-badge {
        padding: 0.25rem;
      }
      ```" />
</type>
type Badge extends Component {
  label: string

  fn render() => ```html
  <span class="note-badge">{$label}</span>
  ```

  override fn style() => ```css
  .note-badge {
    padding: 0.25rem;
  }
  ```
}

Use css for browser-ready CSS or ks.css to run it through KScript.Style. In ks.css, $vars holds the component fields. Rules follow normal CSS selector scope, so use a class specific to the component. SCSS fences can be edited in the editor. Sass compilation uses the existing stylesheet build.