To make a Gleam web app, you will need to follow these steps:
Step 1: Set up your HTML structure
First, create a new HTML file in your favorite code editor. Start by adding the basic HTML structure with the , , and tags. Inside the tag, link to the Gleam library by adding the following script tag:
<script src="https://cdn.jsdelivr.net/npm/gleam@latest"></script>
Step 2: Create a container for your Gleam app
Next, create a
<div id="app"></div>
Step 3: Initialize the Gleam app
Now, you need to initialize the Gleam app inside a tag. Add the following code just before the closing tag:
<script>
const app = new gleam.App({
target: document.getElementById('app'),
});
</script>
This code creates a new Gleam app and attaches it to the container with the ID ‘app’. You can customize the Gleam app by passing in options to the gleam.App constructor.
Step 4: Add some content to your Gleam app
Now that you have set up the basic structure of your Gleam app, you can add some content to it. Gleam uses HTML-like syntax to build its UI components. Here’s an example of how you can add a text element to your Gleam app:
<script>
const app = new gleam.App({
target: document.getElementById('app'),
props: {
children: ['Hello, Gleam!']
}
});
</script>
This code adds a text element with the content ‘Hello, Gleam!’ to the Gleam app. You can add more complex UI components by combining different Gleam elements like buttons, input fields, and more.
Step 5: Styling your Gleam app
You can style your Gleam app using CSS just like you would with a regular web app. You can add a tag inside the tag to write custom CSS styles for your Gleam app.
<style>
#app {
background-color: #f9f9f9;
padding: 20px;
border-radius: 10px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
</style>
This CSS code adds some basic styling to the container with the ID ‘app’, giving it a light gray background, padding, rounded corners, and a slight drop shadow.
Step 6: Launch your Gleam app
To launch your Gleam app, simply open your HTML file in a web browser. You should see your Gleam app rendered in the browser with the content you added.
Congratulations! You have successfully created a Gleam web app using HTML tags. You can now continue building out your Gleam app by adding more complex UI components, handling user interactions, and integrating with external APIs. Have fun building with Gleam!
Captain Gogoi reporting for duty sir!