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

mireco

v3.1.0

Published

MIcro REact COmponents - extensible library for interfaces with no heavy deps

Downloads

9,912

Readme

mireco

npm version Downloads

Mireco is an extensible library for user interfaces with no heavy dependencies (especially css).

"The golden teaspoon of date pickers"

- Luke Hodkinson

Looking for a Mireco interface but styled to your favourite web theme? Check out our styled wrappers:

Check out the live demo page here.

Above all else, Mireco aims to be the best interface for dealing with input components. All components adhere to the following guidelines:

React Interface Philosophy

  • All input props take the form of a singular value and onChange
  • All components are stateless where practical, following the Tri-State Value System
  • Input's onChange is a function callback with the new value as an argument (consumers do no direct reading from dom elements with refs)
  • The onChange callback and value prop both use the same value format, which is always a primitive or predefined shape of primitives
  • For basic use cases, all inputs are expected to be used by Mireco consumers as flat components - eg. the Checkbox component uses a convenience label="label contents" prop instead of requiring <Label><Checkbox/> label contents</Label>

Non battle-tested guidelines:

  • Existing html properties such as style and className should be passed through - with prefixes where there are multiple injection points eg. containerStyle and inputStyle
  • The style prop refers to the outermost container of a Mireco component. More specific style overrides are given with explicit references eg. inputStyle and labelStyle. Where these overlap and refer to the same element as the style prop, they are merged with the more specific name taking precedent.

HTML Design Philosophy

All Mireco components should be designed with the following in mind:

  • No external static file requirements - all images are inline svg so they support css styling, only use native fonts
  • Adhere to strict html components where reasonable for accessibilty
  • Minimal html element hierarchy eg. no enormous chains of <div>
  • Everything should still be usable without any css
  • Inputs should still render a basic html form value
  • All components should work by default on any platform (mobile, desktop)
  • All css selectors are namespaced to avoid clashes
  • Use native browser focus, and support keyboard navigation with js events
  • All size units are in rem (except for em for line-heights relative to font-size)
  • Like normal html form inputs, all form components are rendered as inline or inline-block by default. For convenience, the Mireco api provides a block version of all inputs by passing a block prop
  • No media queries are used in scaling inputs - they should size to their container and not the screen, using flex-basis to take up multiple rows when necessary
  • There is no hard coded minimum width for any input

Installation

Install the package from npm:

npm install mireco

Make sure your html document is encoded properly (required by parse-duration micro symbol):

<html>
  <head>
    <meta charset="utf-8">
  </head>
</html>

Add the stylesheets:

<link rel="stylesheet" href="node_modules/mireco/dist/mireco-layout.css" />
<link rel="stylesheet" href="node_modules/mireco/dist/mireco-theme.css" />

To support inputs that have modal dropdowns, ensure that the body of your document (and any absolutely positioned content blocks such as modals) all have a padding of at least 15rem at the bottom.

Development Setup

Environment Install

For convenience install mise to manage your environment.

When it's installed setup mise with:

mise install

This will install the required versions of node and ruby.

Project Install

To install the project dependencies:

bundle
npm install
( cd demo && npm install )

This will install the gems (for demo site hosting) and node_modules (for package building).

Building Mireco

With the environment and project installation complete, you can build mireco with:

npm run build

Or more likely for development convenience, you'll want to watch for changes with:

npm run watch

Building the Demo

With mireco built, you can build the demo site (using your local copy of mireco) with:

( cd demo && npm run build )

Or again for convenience, you will want to both watch for changes and host the site with:

( cd demo && npm run start )

This will use jekyll to host the demo site on your computer.

Components

Check out the API Documentation.

Basic form inputs:

  • [ ] Abstract Duration (understands months, years)
  • [x] Button
  • [x] CalendarMonth
  • [x] Date
  • [x] Duration
  • [x] Month
  • [x] Select
  • [x] Text
  • [x] Time

Compound form inputs:

  • [ ] DateRange
  • [x] Datetime
  • [x] DatetimeRange

Layout:

  • [ ] Label
  • [ ] Modal

Tri-State Values

Having properly bound components in React is tricky when the components that the user needs to interact with are required to sometimes be in invalid states.

The best example of this is a date selector with a text input component - if a user is typing in a value of 31/3/2012, between each keystroke the value when parsed could either be completely different (31/3 would resolve to the current year) or invalid (31 would be of the current month which does not necessarily contain 31 days).

Most packages get around this with a variety of strategies that have their own drawbacks:

  • Requiring some kind of "commitment" action to the value, for instance typing only highlights a day on a calendar and the user must click the day to select it (clunky to use and does not report new values to higher components early enough to integrate well)
  • Completely detaching the state from its value prop (so the parent cannot change the value whilst the user is interacting with the widget)

All Mireco components should instead follow this flow of value update:

  • The component always updates its parent when any part of it is changed:
    • A value of undefined means that a true value cannot in any way be understood from the various state contents
    • A value of null means that the value is explicitly set to nothing
    • A true value (of whatever data type is appropriate for your input, eg. milliseconds integer) is reported when the value can be parsed with the most generous rules possible (does not have to be perfect)
  • When a Mireco component receives a new prop value, it is compared to the current various state contents. If it has changed:
    • If the prop value is set to undefined, do absolutely nothing
    • If the prop value is set to a true value or null:
      • If this is different from the current parsed various state contents:
        • Update the various state contents to a perfectly formatted representation of the new prop value, as this means the parent has explicitly overridden our value
      • Otherwise, do nothing as this update was likely initiated by this component itself
  • When a Mireco component is blurred:
    • If the prop value is set to a true value:
      • Set the various state contents to a perfectly formatted representation of the prop value
    • Otherwise:
      • Reset the various state contents to defaults

Following this flow, self-initiated updates of value are non destructive to the current state whilst still allowing the parent to change its value. Also, as undefined and null are often interchangeable you can simply take the given value onChange without any validation or workflow in Mireco consumers.