-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: how to add new (frontend) components #847
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good addition to the docs! Feel free to disregard any stylistic changes you don't agree with.
|
||
## Build a Frontend component | ||
|
||
Sometimes it is beneficial to build a component directly in the frontend. This are several reasons for this: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes it is beneficial to build a component directly in the frontend. This are several reasons for this: | |
Sometimes it is beneficial to build a component directly in the frontend. There are several reasons for this: |
|
||
Sometimes it is beneficial to build a component directly in the frontend. This are several reasons for this: | ||
|
||
* Lower latency/performance: If a component is very performance-critical, it might be beneficial to build it in the frontend as it does not require a roundtrip to the server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Lower latency/performance: If a component is very performance-critical, it might be beneficial to build it in the frontend as it does not require a roundtrip to the server. | |
* Lower latency/performance: If the responsiveness of a component is critical, it might be beneficial to build it in the frontend as interactions would not require a roundtrip to the server. |
|
||
* Lower latency/performance: If a component is very performance-critical, it might be beneficial to build it in the frontend as it does not require a roundtrip to the server. | ||
* Direct access to the DOM: If you need to interact with the DOM directly, it might be beneficial to build a component in the frontend. | ||
* Simpler: Sometimes it is just simpler to build a component in the frontend and Solara. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Simpler: Sometimes it is just simpler to build a component in the frontend and Solara. | |
* Simpler: Sometimes it is just simpler to build a component in the frontend than in Python. |
|
||
In solara itself, we use Vue to write new frontend components. The main reason is that we build Solara on top of [Vuetify](https://v2.vuetifyjs.com/), which is a Vue component library. | ||
|
||
Vue is easy to use for non-front-end developers, and it is easy to learn and is the default option for the Solara dev itself. No frontend tools are needed (like webpack, etc.), and you can write your components directly in file or inline string in python. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vue is easy to use for non-front-end developers, and it is easy to learn and is the default option for the Solara dev itself. No frontend tools are needed (like webpack, etc.), and you can write your components directly in file or inline string in python. | |
Vue is easy to use for non-front-end developers, and easy to learn. It is also the default option for the Solara.dev website itself. No frontend tools are needed (like webpack, etc.), and you can write your components directly in a template `.vue` file or as an inline string in python. |
The downside of using Vue, is that we are currently limited to Vue 2, and our ipyvue library has no support for ESM modules, introducing a bit of boilerplate code | ||
to load external libraries. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The downside of using Vue, is that we are currently limited to Vue 2, and our ipyvue library has no support for ESM modules, introducing a bit of boilerplate code | |
to load external libraries. | |
There are two main limitations to using Vue components: | |
* we are currently limited to Vue 2 | |
* ipyvue has no support for ES modules, meaning some boilerplate code is required to load external libraries. |
|
||
[https://solara.dev/documentation/api/utilities/component_vue] | ||
|
||
We will first start with a component which is meant to be use inside of a single application, which will fetch the 3rd party library from a CDN. The goal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will first start with a component which is meant to be use inside of a single application, which will fetch the 3rd party library from a CDN. The goal | |
We will start by making a component that shows a button, which shows confetti when clicked. The component is meant to be use inside of a single application, and will fetch a 3rd party library from a CDN. The goal |
We will first start with a component which is meant to be use inside of a single application, which will fetch the 3rd party library from a CDN. The goal | ||
is to get something work with the minimal amount of effort. | ||
|
||
Our goal is to create a button, that when clicked, will show confetti. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our goal is to create a button, that when clicked, will show confetti. |
|
||
## Loading the confetti library. | ||
|
||
Now that we have our skeleton setup, we can add the confetti library. We will use the [`canvas-confetti`](https://www.npmjs.com/package/canvas-confetti) library, which is available on a CDN. We will add this to our `button-confetti.vue` file with unfortunately a bit of boilerplate code to load the library.: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we have our skeleton setup, we can add the confetti library. We will use the [`canvas-confetti`](https://www.npmjs.com/package/canvas-confetti) library, which is available on a CDN. We will add this to our `button-confetti.vue` file with unfortunately a bit of boilerplate code to load the library.: | |
Now that we have our skeleton setup, we can add the confetti library. We will use the [`canvas-confetti`](https://www.npmjs.com/package/canvas-confetti) library, which is available on a CDN. We will add this to our `button-confetti.vue` file using a bit of boilerplate code: |
this.showConfetti(); | ||
}, | ||
async showConfetti() { | ||
// make sure it is loaded by waiting on the Promise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// make sure it is loaded by waiting on the Promise | |
// make sure the package is loaded by waiting on the Promise |
async showConfetti() { | ||
// make sure it is loaded by waiting on the Promise | ||
await this.loadedConfetti; | ||
await new Promise((resolve) => setTimeout(resolve, 1000)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing this should either be removed or somehow commented on?
await new Promise((resolve) => setTimeout(resolve, 1000)) |
cded5b2
to
32af76f
Compare
No description provided.