Skip to content

Commit

Permalink
Merge pull request #32 from kadirahq/issue-26
Browse files Browse the repository at this point in the history
Use react-cdk #26
  • Loading branch information
arunoda committed Oct 13, 2016
2 parents 2d27aa7 + 087b4b3 commit 8ed4724
Show file tree
Hide file tree
Showing 30 changed files with 396 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": ["es2015", "stage-0", "react"]
"presets": ["es2015", "stage-0", "react", "react-app"]
}
25 changes: 25 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": "airbnb",
"rules": {
# We use _ to define private variables and methods in clases
"no-underscore-dangle": 0,
# This seems to be buggy we don't want eslint to check this
"import/no-extraneous-dependencies": 0,
# This is a depricated rule. So we turned off it.
"react/require-extension": 0,
# We can write JSX in anyfile we want.
"react/jsx-filename-extension": 0,
# We don't like this rule.
"arrow-body-style": 0,
# We don't like this rule. We write arrow functions only when we needed.
"prefer-arrow-callback": 0,
# We don't need to write function names always.
"func-names": 0,
# propTypes can be object
"react/forbid-prop-types": 0,

"react/prefer-stateless-function": 0,

"class-methods-use-this": 0,
},
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
node_modules
*.log
.idea
dist
.DS_Store
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
src
.babelrc
.DS_Store
11 changes: 11 additions & 0 deletions .scripts/get_gh_pages_url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// IMPORTANT
// ---------
// This is an auto generated file with React CDK.
// Do not modify this file.

const parse = require('git-url-parse');
var ghUrl = process.argv[2];
const parsedUrl = parse(ghUrl);

const ghPagesUrl = 'https://' + parsedUrl.owner + '.github.io/' + parsedUrl.name;
console.log(ghPagesUrl);
34 changes: 34 additions & 0 deletions .scripts/mocha_runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// IMPORTANT
// ---------
// This is an auto generated file with React CDK.
// Do not modify this file.
// Use `.scripts/user/pretest.js instead`.

process.env.NODE_ENV = 'development';
require('babel-core/register');
require('babel-polyfill');

// Add jsdom support, which is required for enzyme.
var jsdom = require('jsdom').jsdom;

var exposedProperties = ['window', 'navigator', 'document'];

global.document = jsdom('');
global.window = document.defaultView;
Object.keys(document.defaultView).forEach((property) => {
if (typeof global[property] === 'undefined') {
exposedProperties.push(property);
global[property] = document.defaultView[property];
}
});

global.navigator = {
userAgent: 'node.js'
};

process.on('unhandledRejection', function (error) {
console.error('Unhandled Promise Rejection:');
console.error(error && error.stack || error);
});

require('./user/pretest.js');
6 changes: 0 additions & 6 deletions .scripts/npm-prepublish.js

This file was deleted.

16 changes: 16 additions & 0 deletions .scripts/prepublish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# IMPORTANT
# ---------
# This is an auto generated file with React CDK.
# Do not modify this file.
# Use `.scripts/user/prepublish.sh instead`.

echo "=> Transpiling 'src' into ES5 ..."
echo ""
rm -rf ./dist
NODE_ENV=production ./node_modules/.bin/babel --ignore tests,stories --plugins "transform-runtime" ./src --out-dir ./dist
echo ""
echo "=> Transpiling completed."

. .scripts/user/prepublish.sh
47 changes: 47 additions & 0 deletions .scripts/publish_storybook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

# IMPORTANT
# ---------
# This is an auto generated file with React CDK.
# Do not modify this file.

set -e # exit with nonzero exit code if anything fails

# get GIT url

GIT_URL=`git config --get remote.origin.url`
if [[ $GIT_URL == "" ]]; then
echo "This project is not configured with a remote git repo".
exit 1
fi

# clear and re-create the out directory
rm -rf .out || exit 0;
mkdir .out;

# run our compile script, discussed above
build-storybook -o .out

# go to the out directory and create a *new* Git repo
cd .out
git init

# inside this git repo we'll pretend to be a new user
git config user.name "GH Pages Bot"
git config user.email "hello@ghbot.com"

# The first and only commit to this new Git repo contains all the
# files present with the commit message "Deploy to GitHub Pages".
git add .
git commit -m "Deploy Storybook to GitHub Pages"

# Force push from the current repo's master branch to the remote
# repo's gh-pages branch. (All previous history on the gh-pages branch
# will be lost, since we are overwriting it.) We redirect any output to
# /dev/null to hide any sensitive credential data that might otherwise be exposed.
git push --force --quiet $GIT_URL master:gh-pages > /dev/null 2>&1
cd ..
rm -rf .out

echo ""
echo "=> Storybook deployed to: `node .scripts/get_gh_pages_url.js $GIT_URL`"
1 change: 1 addition & 0 deletions .scripts/user/prepublish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Use this file to your own code to run at NPM `prepublish` event.
1 change: 1 addition & 0 deletions .scripts/user/pretest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Use this file to setup any test utilities.
14 changes: 12 additions & 2 deletions .storybook/config.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
import * as storybook from '@kadira/storybook';
storybook.configure(() => require('./stories'), module);
// IMPORTANT
// ---------
// This is an auto generated file with React CDK.
// Do not modify this file.

import { configure } from '@kadira/storybook';

function loadStories() {
require('../src/stories');
}

configure(loadStories, module);
File renamed without changes.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Your Name. <name@emailprovider.io>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
44 changes: 35 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
"description": "Comments addon for Storybook",
"main": "preview.js",
"scripts": {
"deploy-storybook": "storybook-to-ghpages",
"prepublish": "node .scripts/npm-prepublish.js",
"prepublish": ". ./.scripts/prepublish.sh",
"lint": "eslint src",
"lintfix": "eslint src --fix",
"testonly": "mocha --require .scripts/mocha_runner src/**/tests/**/*.js",
"test": "npm run lint && npm run testonly",
"test-watch": "npm run testonly -- --watch --watch-extensions js",
"storybook": "STORYBOOK_CLOUD_SERVER='http://localhost:3003/graphql' STORYBOOK_CLOUD_APPID='test-app' STORYBOOK_CLOUD_DATABASE='test-db' start-storybook -p 3006",
"storybook-local": "STORYBOOK_CLOUD_SERVER='http://localhost:3003/graphql' start-storybook -p 3006",
"test": "echo \"Error: no test specified\" && exit 1"
"publish-storybook": "bash .scripts/publish_storybook.sh"
},
"repository": {
"type": "git",
Expand All @@ -23,18 +27,36 @@
},
"homepage": "https://github.com/kadirahq/storybook-addon-comments#readme",
"devDependencies": {
"react": "^15.3.2",
"react-dom": "^15.3.2",
"babel-loader": "^6.2.5",
"babel-polyfill": "^6.13.0",
"babel-preset-react-app": "^0.2.1",
"babel-cli": "^6.14.0",
"babel-core": "^6.14.0",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-preset-es2015": "^6.14.0",
"babel-preset-react": "^6.11.1",
"babel-preset-stage-0": "^6.5.0",
"eslint": "^3.6.0",
"babel-eslint": "^6.1.2",
"eslint-config-airbnb": "^12.0.0",
"eslint-plugin-import": "^1.16.0",
"eslint-plugin-jsx-a11y": "^2.2.2",
"eslint-plugin-react": "^6.3.0",
"mocha": "^3.0.2",
"chai": "^3.5.0",
"sinon": "^1.17.6",
"enzyme": "^2.2.0",
"react-addons-test-utils": "^15.3.2",
"jsdom": "^9.5.0",
"git-url-parse": "^6.0.1",
"@kadira/storybook": "^2.24.0",
"@kadira/storybook-addons": "^1.5.0",
"@kadira/storybook-database-cloud": "^2.3.0",
"@kadira/storybook-deployer": "^1.2.0",
"@kadira/storybook-ui": "^3.4.1",
"babel-cli": "^6.14.0",
"babel-preset-es2015": "^6.14.0",
"babel-preset-react": "^6.11.1",
"babel-preset-stage-0": "^6.5.0",
"chokidar": "^1.6.0",
"react": "^15.3.1",
"react-dom": "^15.3.1",
"shelljs": "^0.7.4"
},
"peerDependencies": {
Expand All @@ -43,11 +65,15 @@
"react-dom": "^0.14.7 || ^15.0.0"
},
"dependencies": {
"babel-runtime": "^6.11.6",
"deep-equal": "^1.0.1",
"moment": "^2.15.1",
"react-render-html": "^0.1.6",
"react-textarea-autosize": "^4.0.5",
"insert-css": "^1.0.0",
"marked": "^0.3.6"
},
"engines": {
"npm": "^3.0.0"
}
}
27 changes: 27 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';

const buttonStyles = {
border: '1px solid #eee',
borderRadius: 3,
backgroundColor: '#FFFFFF',
cursor: 'pointer',
fontSize: 15,
padding: '3px 10px',
};

const Button = ({ children, onClick, style = {} }) => (
<button
style={{ ...buttonStyles, ...style }}
onClick={onClick}
>
{children}
</button>
);

Button.propTypes = {
children: React.PropTypes.string.isRequired,
onClick: React.PropTypes.func,
style: React.PropTypes.object,
};

export default Button;
31 changes: 16 additions & 15 deletions src/manager/components/CommentForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import marked from 'marked';
import style from './style';

const renderer = new marked.Renderer();
renderer.heading = function (text, level) {
renderer.heading = function (text) {
return text;
}
};

marked.setOptions({
renderer: renderer,
renderer,
gfm: true,
tables: false,
breaks: true,
pedantic: false,
sanitize: true,
smartLists: true,
smartypants: false
smartypants: false,
});

export default class CommentForm extends Component {
Expand All @@ -30,13 +30,6 @@ export default class CommentForm extends Component {
this.setState({ text });
}

handleKeyDown(e) {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
this.onSubmit();
}
}

onSubmit() {
const { addComment } = this.props;
const text = this.state.text.trim();
Expand All @@ -48,21 +41,25 @@ export default class CommentForm extends Component {
this.setState({ text: '' });
}

handleKeyDown(e) {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
this.onSubmit();
}
}

render() {
const { text } = this.state;
return (
<div style={style.wrapper}>
<Textarea
ref="commentBox"
style={style.input}
onChange={e => this.onChange(e)}
onKeyDown={e => this.handleKeyDown(e)}
placeholder="Add your comment..."
value={text}
>
</Textarea>
/>
<button
ref="submitBtn"
style={style.submitButton}
onClick={() => this.onSubmit()}
>Submit
Expand All @@ -71,3 +68,7 @@ export default class CommentForm extends Component {
);
}
}

CommentForm.propTypes = {
addComment: React.PropTypes.func,
};
2 changes: 1 addition & 1 deletion src/manager/components/CommentForm/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ export default {
fontFamily: 'sans-serif',
resize: 'none',
},
}
};
Loading

0 comments on commit 8ed4724

Please sign in to comment.