0.3.1 • Published 9 months ago

@gramex/ui v0.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

@gramex/ui

Commonly used UI components and interactions.

Installation

Install via npm:

npm install @gramex/ui

Formats

JavaScript supports the Intl object to format numbers, dates, lists, etc. based on locale.

These utility functions provide commonly used number, percentage and date formats.

Import the functions as:

import { num, num0, num2, pc, pc0, pc1 } from "https://cdn.jsdelivr.net/npm/@gramex/ui@0.3/dist/format.js";
0.00380.0380.383.8138138,1043,810,369.24
num(val)0.00380.0380.383.838138K3.8M
num0(val)000438138,1043,810,369
num2(val)00.040.383.81381.0438,103.693,810,369.24
pc(val)0.38%3.8%38%381%
pc0(val)0%4%38%381%
pc1(val)0.4%3.8%38.1%381.0%
  • num(value): Use by default. Shows 2-3 significant digits and shortens to "K", "M", etc.
  • num0(value): Integers. Use when values are typically between 1 - 1,000,000
  • num2(value): 2 decimal numbers. Use when values are typically between 1 - 1,000
  • pc(value): Use by default. Shows 2-3 digits
  • pc0(value): 0 decimal percent. Use if % is between 10-100% and never below 1%
  • pc1(value): 1 decimal percent. Use if % is between 1-10% and never below 0.1%

See the source to create your own formats. Refer to Intl.NumberFormat().

The following date formats are supported:

import { dmy, mdy, dm, md, wdmy } from "https://cdn.jsdelivr.net/npm/@gramex/ui@0.3/dist/format.js";
Function23 Jan 2023
dmy(val)23 Jan 2023
mdy(val)Jan 23, 2023
dm(val)23 Jan
md(val)Jan 23
wdmy(val)Mon, 23 Jan 2023

Dark theme

This code adds a dropdown to switch the Bootstrap color mode between light and dark themes.

Dark theme example

Source code

Setup

To run this project locally:

  • Clone this repo, and run npm install to install dependencies
  • Run npm run build to compile
  • Open index.html using a HTTP server (e.g. python -m http.server)

To release, run:

npm version minor
npm publish
git push --tags

Release notes

Authors

Anand S root.node@gmail.com

License

MIT

0.3.1

9 months ago

0.3.0

2 years ago

0.2.0

2 years ago