Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrip committed Jul 18, 2018
1 parent 9ec0aea commit 65e0df0
Show file tree
Hide file tree
Showing 7 changed files with 537 additions and 168 deletions.
62 changes: 62 additions & 0 deletions lib/__tests__/integration-tests/kitchen-sink-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,66 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
null,
"Column C"
)
));

(0, _testRender2.default)("Columns, rows, section styles should all work together", _react2.default.createElement(
"div",
{ align: "center", border: { horizontal: "#", vertical: "#" } },
"Some App",
_react2.default.createElement("br", null),
_react2.default.createElement(
"div",
{ horizontal: true },
_react2.default.createElement(
"div",
{ align: "center", border: { horizontal: "*", vertical: "*" } },
"\u2714\uFE0E Step 1",
_react2.default.createElement("br", null),
"\u25EF Step 2",
_react2.default.createElement("br", null),
"\u25EF Step 3"
),
_react2.default.createElement(
"div",
{ border: { horizontal: "-", vertical: "|" } },
"Some messages for this app"
)
),
_react2.default.createElement(
"div",
{ align: "center" },
"Some stuff for this app is done! \uD83E\uDD18",
_react2.default.createElement("br", null),
"Heres some more informative stuff about your app",
_react2.default.createElement("br", null),
"browser",
_react2.default.createElement("br", null),
"\u2199\u2197 \u2196\u2198",
_react2.default.createElement(
"div",
{ horizontal: true },
_react2.default.createElement(
"div",
{ align: "center", border: { horizontal: "-", vertical: "|" } },
"server",
_react2.default.createElement("br", null),
"(initial response)",
_react2.default.createElement("br", null),
"localhost:3000"
),
_react2.default.createElement(
"div",
{ align: "center", border: { horizontal: "-", vertical: "|" } },
"dev-server",
_react2.default.createElement("br", null),
"(app bundle)",
_react2.default.createElement("br", null),
"localhost:8080",
_react2.default.createElement("br", null),
"websocket server (for HMR)",
_react2.default.createElement("br", null),
"localhost:8081"
)
)
)
));
49 changes: 49 additions & 0 deletions lib/__tests__/section-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,53 @@ test("sections should be able to align text center", function (done) {
expect(outputString).toMatchSnapshot();
done();
}, "+");
});

test("sections should be able to render a border", function (done) {
_index2.default.render(React.createElement(
"div",
null,
React.createElement(
"div",
{
align: "center",
border: {
horizontal: "-",
vertical: "|",
cornerTopLeft: "*",
cornerTopRight: "*",
cornerBottomLeft: "*",
cornerBottomRight: "*"
}
},
"Test section with border"
)
), undefined, 50, function (outputString) {
expect(outputString).toMatchSnapshot();
done();
}, "+");

_index2.default.render(React.createElement(
"div",
{ horizontal: true, border: { horizontal: "*", vertical: "*" } },
"Some Text",
React.createElement(
"div",
{
align: "center",
border: {
horizontal: "-",
vertical: "|",
cornerTopLeft: "*",
cornerTopRight: "*",
cornerBottomLeft: "*",
cornerBottomRight: "*"
}
},
"Test section with border"
)
), undefined, 50, function (outputString) {
expect(outputString).toMatchSnapshot();
done();
}, "+");
});
98 changes: 98 additions & 0 deletions lib/components.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Break = exports.Text = exports.Section = undefined;

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); // strict

var _wrapAnsi = require("wrap-ansi");

var _wrapAnsi2 = _interopRequireDefault(_wrapAnsi);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

// this module is helpful for dealing with ansi characters, but it returns a
// string with embedded new lines. We need it as an array, so we'll split it here
var wrapAnsi = function wrapAnsi(input, columns) {
return (0, _wrapAnsi2.default)(input, columns).split("\n");
};

var Border = function () {
function Border(_ref) {
var vertical = _ref.vertical,
horizontal = _ref.horizontal,
cornerTopLeft = _ref.cornerTopLeft,
cornerTopRight = _ref.cornerTopRight,
cornerBottomLeft = _ref.cornerBottomLeft,
cornerBottomRight = _ref.cornerBottomRight;

_classCallCheck(this, Border);

this.vertical = vertical;
this.horizontal = horizontal;
this.cornerTopLeft = cornerTopLeft;
this.cornerTopRight = cornerTopRight;
this.cornerBottomLeft = cornerBottomLeft;
this.cornerBottomRight = cornerBottomRight;
}

_createClass(Border, [{
key: "horizontalWidth",
value: function horizontalWidth() {
return Math.max(this.vertical ? this.vertical.length : 0, this.cornerTopLeft ? this.cornerTopLeft.length : 0, this.cornerBottomLeft ? this.cornerBottomLeft.length : 0) + Math.max(this.vertical ? this.vertical.length : 0, this.cornerTopRight ? this.cornerTopRight.length : 0, this.cornerBottomRight ? this.cornerBottomRight.length : 0);
}
}, {
key: "verticalHeight",
value: function verticalHeight() {
return Math.max(this.horizontal ? this.horizontal.length : 0, this.cornerTopLeft ? this.cornerTopLeft.length : 0, this.cornerTopRight ? this.cornerTopRight.length : 0) + Math.max(this.horizontal ? this.horizontal.length : 0, this.cornerBottomLeft ? this.cornerBottomLeft.length : 0, this.cornerBottomRight ? this.cornerBottomRight.length : 0);
}
}]);

return Border;
}();

var Section = exports.Section = function () {
function Section(_ref2) {
var _ref2$useHorizontalOr = _ref2.useHorizontalOrientation,
useHorizontalOrientation = _ref2$useHorizontalOr === undefined ? false : _ref2$useHorizontalOr,
_ref2$align = _ref2.align,
align = _ref2$align === undefined ? "left" : _ref2$align,
_ref2$border = _ref2.border,
border = _ref2$border === undefined ? {} : _ref2$border;

_classCallCheck(this, Section);

this.children = [];

this.orientation = useHorizontalOrientation ? "horizontal" : "vertical";
this.align = align;
this.border = new Border(border);
}

_createClass(Section, [{
key: "convertTextToArray",
value: function convertTextToArray(text, totalWidth) {
return wrapAnsi(text.text, totalWidth - this.border.horizontalWidth());
}
}]);

return Section;
}();

Section.type = "div";

var Text = exports.Text = function Text(text) {
_classCallCheck(this, Text);

this.text = text;
};

var Break = exports.Break = function Break() {
_classCallCheck(this, Break);
};

Break.type = "br";
Loading

0 comments on commit 65e0df0

Please sign in to comment.