Skip to content

Conversation

@levkk
Copy link
Contributor

@levkk levkk commented Aug 28, 2023

Components

Introducing server-side rendered frontend components. The idea is pretty simple: use composition like in React to build UIs, except the components are type-checked and rendered by the backend.

The base component can render any other component, including just strings. To make a Sailfish template into a component, just call component! on the struct, e.g: component!(MyTemplateStruct). MyTemplateStruct must be derived from sailfish::TemplateOnce.

CLI

To help with building components, we've created a cargo command that bundles CSS and JS into their respective bundles and can also generate components.

To install the CLI:

cargo install cargo-pgml-components
npm install -g rollup
npm install -g sass

Bundling

Run this after changing Sass or JS code: cargo pgml-components bundle.

Creating new components

cargo pgml-components add component_name

This will automatically generate:

  1. A Rust struct derived from sailfish::TemplaceOnce
  2. An HTML template file
  3. A Stimulus controller.

Misc

  1. Upgrade Sailfish to 0.8.
  2. Add a /playground page where we should test and render components. Analogous to how Material UI does it: https://mui.com/material-ui/react-autocomplete/
  3. Fix search modal in dashboard being small.

@levkk levkk force-pushed the levkk-components-1 branch from 948e6dc to 88f8d13 Compare August 29, 2023 18:22
@@ -0,0 +1,10 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this extra whitespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, trim should of worked, good question.

@levkk levkk merged commit 6bdcf00 into master Aug 29, 2023
@levkk levkk deleted the levkk-components-1 branch August 29, 2023 22:25
SilasMarvin pushed a commit that referenced this pull request Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants