Giter VIP home page Giter VIP logo

ui's People

Contributors

chadly avatar mdarens avatar

Watchers

 avatar  avatar  avatar

ui's Issues

[react-bootstrap] Detect if bootstrap CSS is present and load it or a subset if necessary

For example if a consuming app is built on a namespaced bootstrap (we could also take bootstrap namespace as a config option), the global classNames won't have any effect.

Example implementation:

export const bs4test = () => {
	const el = document.createElement("div");

	el.setAttribute("style", "display: block;");
	el.setAttribute("class", "d-inline");
	
	document.body.appendChild(el);
	const result = (getComputedStyle(el) === "inline");
	document.body.removeChild(el);

	return result;
}

Runly js API sketch

API layers, bottom to top

React hooks

Connects you to runly data, bring your own components, styles etc

import { useRun } from "@runly/js";

const myRun = useRun(runId);

const myRunWithSideEffects = useRun({
	runId: runId2,
	onChange: interestedSubscriber
});

React components

Provides components, theme context.

classNames styling is implemented with JSS, inline styles are passed through.
some props can accept functions which are provided with the same data returned from hooks at that scope.

Instead of providing a 'bare-bones' style in a public API, consider this the shared conventions for the themed components outlined next.

import { RunStatus } from "@runly/react";

const stylesStatic = {
	failureBar: { background: "#f60" }
}

const stylesDynamic = runProps => {
	return {
		failureBar: {
			// do stuff like get redder if there's more fails
		}
	}
}
ReactDOM.render(
	<>
		<style>{
			`
				.runly-success-bar {
					background: #0f0;
				}
			`
		}</style>
		<RunStatus
			runId={runid}
			onChange={interestedSubscriber}
			classNames={{ successBar: "runly-success-bar" }}
			styles={stylesDynamic} />
	</>,
	document.body);

Pre-themed React

Provides pre-styled components for bootstrap, material, โ€ฆ, bulma, foundation etc.
full component API is still available for customization.

import { RunStatus } from "@runly/react-bootstrap";

Otherwise same API as components above.

Global vanilla JS

exposes a global Runly constructor which is initialized manually.
this is for people who don't want to add React/JSX etc to their build, or even have a build for their frontend at all, but still know some js.
For example, injecting some Runly components into a dynamic app that uses jQuery.
defers loading of libraries, components etc as long as possible unless init method is called.

<script src="cdnUrl"></script>

or

import Runly from "@runly/js";
const defaultConfig = runly.config(); // default config obj
const { isInitialized } = Runly; // false


const runly = new Runly();

runly.config({
	theme: "bootstrap",
	styles: {
		successBar: {
			outline: "3px solid #0f0"
		}
	}
});

// also scans dom for data attributes. Or maybe this should be refresh or update?
Runly.init();

HTML

Once the DOM is ready, data-runly-* attributes are converted to a config object for Runly#config, then Runly#init is called. Portion of data attribute after data-runly- is split on dashes and converted to a path to be set on the config object. If a match is not found in the default config, log a warning. Before paths from attribute are assigned to the object, they are sorted on path depth ascending. This allows setting the config to arbitrary depths with json/object notation, but deeper attributes to take precedence, like selector specificity.

<script src="cdnUrl"></script>
<style>
	.runly-failure-bar {
		outline: 1px dotted currentColor;
	}
	.runly-success-bar {
		text-shadow: 1px 1px 0 #000;
	}
</style>
<div data-runly-runId="runId" data-runly-classNames="{ 'failureBar': 'runly-failure-bar'  }" data-runly-classNames-successBar="runly-success-bar"></div>

i18n

accept locale prop and use appropriate language in public js components. detect if not passed.

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.