Code Monkey home page Code Monkey logo

dops-components's Introduction

DOPS Components

Shared components for DOPS projects

Developing

To launch a development server:

gulp

Then open http://localhost:8085/demo.html in your browser. Any changes you make to SCSS or JS/JSX files should be updated as your save.

If you wish to compile a bundle (which shouldn't be something you do in this package, but I'll indulge you), you can run:

gulp webpack:build-dev

You can use that build script from the gulpfile as an example when developing your own JS projects which use dops-components.

Using DOPS Components in your project

Installing

npm install automattic/dops-components --save-dev

Using components

You'll need to require them using a full path from the module name, e.g.:

AbTest = require('@automattic/dops-components/client/components/tracks-ab-test');

Developing against a live checkout

It's handy to link the checked-out dops-components code directly into your project. You can do that as follows.

In the dops-components directory:

npm link

In the directory of a project that uses dops-components:

npm link @automattic/dops-components

Assuming you use webpack in your project, you'll want to add the paths for compiling JSX to your JSX loader, like this:

{
	test: /\.jsx?$/,
	loaders: jsLoader,

	// include both typical npm-linked locations and default module locations to handle both cases
	include: [
		path.join(__dirname, 'client'), 
		path.join(__dirname, '../dops-components/client'), 
		path.join(__dirname, 'node_modules/@automattic/dops-components/client')
	]
}

Note: the above snippet assumes your project is checked out in the same directory as dops-components. Also note that we need 2 entries because of weirdness that webpack currently has following symlinks when hot-loading.

Usage

Requires a functioning browserify or webpack environment.

A/B test example

var React = require('react'),
	PwywSlider = require('pwyw-slider'),
	AbTest = require('@automattic/dops-components/client/components/tracks-ab-test');

var MyComponent = React.createClass({
	//... other things ...
	render: function() {
		return (
			<div>
				<AbTest.Experiment name="slider">
					<AbTest.Variant name="normal">
						<PwywSlider value={this.state.value} defaultValue={this.props.defaultQty} onChange={this.handlePwywChange} interval={this.props.interval}/>
					</AbTest.Variant>
					<AbTest.Variant name="skip6">
						<PwywSlider value={this.state.value} defaultValue={this.props.defaultQty} skipValues={[6]} onChange={this.handlePwywChange} interval={this.props.interval}/>
					</AbTest.Variant>
				</AbTest.Experiment>
			</div>
		);
	}
});

module.exports = MyComponent;

dops-components's People

Contributors

gravityrail avatar ryelle avatar michaelarestad avatar dereksmart avatar eliorivero avatar zinigor avatar jeffgolenski avatar oskosk avatar tug avatar samhotchkiss avatar retrofox avatar gziolo avatar eoigal avatar sirreal avatar

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.