Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

maartenbreddels
Copy link
Contributor

No description provided.

Copy link
Collaborator

@iisakkirotko iisakkirotko left a 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:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* 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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* 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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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.

Comment on lines +33 to +34
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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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.:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// 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))
Copy link
Collaborator

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?

Suggested change
await new Promise((resolve) => setTimeout(resolve, 1000))

@maartenbreddels maartenbreddels force-pushed the master branch 2 times, most recently from cded5b2 to 32af76f Compare December 20, 2024 12:52
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