npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@quinten1997/tinycomponents

v1.0.0

Published

A simple component template for vanilla js

Downloads

1

Readme

Introduction

Thanks for checking out TinyComponents! TinyComponents is in itself a practice of could I, not should I and should be taken with a grain of salt as it is in no way claiming efficiency or domination over any similar library/package. I made this in an attempt to recreate the component based development we've grown to love as simply as possible using the most barebone approach that anyone could understand. The Main goal was to write with clarity so that the average programmer could clone this repository and immeadiatly understand whats happening "behind the curtain" to say. Not that in this approach there ever was a curtain to hide behind.

To get started:

First Download and Install Node

To build your application use the command

npm build

Tinycomponents comes preloaded with a small example of how to use the code with the two component files

LoginForm.js

LabledInput.js

The LabledInput is imported into the LoginForm component which in turn is used in App.js

Feel free to organize your file structure however when adding your components remember that App.js is your main entrypoint for rendering your components.

Creating a component

To create a component first:

  • create a new file either in the src folder or in my recommendation in the components folder ex: Example.js

  • within the file start your component by defining a function:

    or

  • next within your component you can then return your html, I recommend using template literals to allow dynamic attributes such as classname, disabled, etc.

    const ExampleComponent (inputType, isRequired) => {

    const inputId = "exampleInput"

    return `
       <input
          type="${inputType}"
          id="${inputId}
          name="${inputId}"
          ${isRequired ? " required" : ""}
       >
    `

    }

    Once you are done with your component make sure you have exported it

    ex:

    export const ExampleComponent = () => {}

    or

    const ExampleComponent (inputType, isRequired) => { const inputId = "exampleInput"

    return `
       <input 
          type="${inputType}" 
          id="${inputId} 
          name="${inputId}"
          ${isRequired ? " required" : ""}
       >
    `

    }

    export { ExampleComponent };

    Once your component is made you can render it by calling its function in App.js:

    import { ExampleComponent } from "./components/ExampleComponent.js";

    export const App = () => { return ${LoginForm()} ; };

    or by calling from a parent component:

import { LabeledInput } from "./LabledInput.js";

const LoginForm = () => {
  return `
    <form style="${style.mainForm}">
      ${LabeledInput("Email:", "email", true)}
      ${LabeledInput("Password:", "password", true)}
      <button type="submit">Submit</button>
    </form>
  `;
};

export { LoginForm };

Adding CSS

CSS can be added in multiple ways in addition the styles.css file located in the public directory you can also create CSS by importing a CSS file directly into your component like is done in this example

Another way to add CSS is to pass your CSS directly to your html from within the same component file such as is done in This Example

The bundler we are using can also be configurated to leverage more complex solutions to CSS you can read more by visiting Parcels documentation

Thanks again for checking out TinyComponents if you have any questions please feel free to DM me