Giter Club home page Giter Club logo

basemax / mithrilts-jsx Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 2.0 132 KB

Create a SPA project using Mithril JS framework and design layout by JSX syntax and use Typescript and Vite for build system.

Home Page: https://basemax.github.io/MithrilTS-JSX/dist/

License: GNU General Public License v3.0

HTML 9.56% CSS 8.19% TypeScript 82.25%
mithril mithriljs ts typescript vite vitejs vitets vite-template mithril-template mithriljs-template js javascript jsx jsx-syntax jsx-renderer

mithrilts-jsx's Introduction

Mithril TS(Type script) JSX

Create a SPA project using Mithril JS framework and design layout by JSX syntax and use Typescript and Vite for build system.

Why MithrilJS with JSX?

If you already know MithrilJS, you have to write the tempalte and layout in HybridScript way and you cannot do that in such a way like ReactJS. So in this example we are going to create a simple project with Mithril framework but with a JSX way.

Features

  • TypeScript (TS)
  • Support JSX syntax
  • Write CSS styles for each component in a seperate file, so it's easy to manage style conflicting
  • Auto build system (Vite is really fast and perfect system)
  • Use MithrilJS and what we love to use for what we are building

Mithril-JS/Type script with support of JSX syntax

First component: a counter which you can increase a number between 0 and infinity :)

Second component: you can add name of your friends and its work dynamically.

Example component

import m from "mithril"
import classes from "./Friends.module.css"

const Name = (elm) => {
    return {
        view: () => {
        return (
            <li>
                {elm.attrs.name}
            </li>
        )}
    }
}

export const Friends = () => {
    let names = []
    let field_name = ""
    const add_friend = () => {
        field_name = field_name.trim()
        if(field_name !== "")
            names.push(field_name)
        field_name = ""
    }
    const nameTyping = (e) => {
        console.log(e.keyCode, e.target.value);
        if(e.key === 'Enter' || e.keyCode === 13) {
            add_friend()
            e.target.value = ""
        }
        else {
            field_name = e.target.value
        }
    }
    return {
        view: () => {
        return (
            <section className={classes.section}>
                <h2 className={classes.sectionTitle}>Friends</h2>
                <input type="text" onkeyup={(e) => nameTyping(e)} value={field_name} />
                <button onclick={() => add_friend()}>Insert</button>
                <ul>
                    {names.map(name =>
                        <Name name={name} />
                    )}
                </ul>
            </section>
        )},
    }
}

Using

  • $ npm install
  • $ npm run dev
  • $ npm run build
  • $ npm run preview

Credit

Thank you from Arthur Clemens, and Kevin Fiol for helping me to config a Build system correctly. Now I have really a good feel while it's possible to config JSX syntax inside MithrilJS library on front of TypeScript which is a good tool for big project.

© Copyright 2021, Max Base

mithrilts-jsx's People

Contributors

dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

maicol07 quillee

mithrilts-jsx's Issues

Use vite 3

Hi.
can you upgrade the template to Vite 3?
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.