Skip to content

Commit

Permalink
Add modal and flash modules
Browse files Browse the repository at this point in the history
  • Loading branch information
gnapse committed Oct 31, 2017
1 parent 23c0a93 commit 124af9d
Show file tree
Hide file tree
Showing 31 changed files with 1,280 additions and 1 deletion.
60 changes: 60 additions & 0 deletions lib/flash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Component = exports.key = exports.reducer = exports.actions = exports.actionTypes = undefined;

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _redux = require('redux');

var _reactRedux = require('react-redux');

var _Snackbar = require('material-ui/Snackbar');

var _Snackbar2 = _interopRequireDefault(_Snackbar);

var _actions = require('./flash/actions');

var actions = _interopRequireWildcard(_actions);

var _actionTypes = require('./flash/actionTypes');

var actionTypes = _interopRequireWildcard(_actionTypes);

var _reducer = require('./flash/reducer');

var _reducer2 = _interopRequireDefault(_reducer);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

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

var NAME = 'flash';

var mapStateToProps = function mapStateToProps(_ref) {
var props = _ref[NAME];
return _extends({}, props);
};

var mapDispatchToProps = function mapDispatchToProps(dispatch) {
return {
onRequestClose: (0, _redux.bindActionCreators)(actions.hide, dispatch)
};
};

var Component = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(_Snackbar2.default);

exports.actionTypes = actionTypes;
exports.actions = actions;
exports.reducer = _reducer2.default;
exports.key = NAME;
exports.Component = Component;
exports.default = {
actionTypes: actionTypes,
actions: actions,
reducer: _reducer2.default,
key: NAME,
Component: Component
};
66 changes: 66 additions & 0 deletions lib/flash/__tests__/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
'use strict';

var _reduxMockStore = require('redux-mock-store');

var _reduxMockStore2 = _interopRequireDefault(_reduxMockStore);

var _reduxThunk = require('redux-thunk');

var _reduxThunk2 = _interopRequireDefault(_reduxThunk);

var _actions = require('../actions');

var _actionTypes = require('../actionTypes');

var actionTypes = _interopRequireWildcard(_actionTypes);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

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

var mockStore = (0, _reduxMockStore2.default)([_reduxThunk2.default]);

describe('show', function () {
it('dispatches a single action', function () {
var store = mockStore({});
store.dispatch((0, _actions.show)('Hello World'));
expect(store.getActions().length).toEqual(1);
});

it('dispatches FLASH/SHOW right away', function () {
var store = mockStore({});
store.dispatch((0, _actions.show)('Hello World'));
expect(store.getActions()[0].type).toEqual(actionTypes.SHOW_FLASH);
});

it('includes the message and given props in the action payload', function () {
var store = mockStore({});
store.dispatch((0, _actions.show)('Hello World', { edit: 1 }));
expect(store.getActions()[0]).toMatchObject({
type: actionTypes.SHOW_FLASH,
message: 'Hello World',
edit: 1
});
});

it('includes extra props in the action payload', function () {
var store = mockStore({});
store.dispatch((0, _actions.show)('Hello World'));
expect(store.getActions()[0]).toMatchObject({
type: actionTypes.SHOW_FLASH,
autoHideDuration: 5000
});
});

it('allows to override the default autoHideDuration', function () {
var store = mockStore({});
store.dispatch((0, _actions.show)('Hello World', { autoHideDuration: 1000 }));
expect(store.getActions()[0].autoHideDuration).toEqual(1000);
});

it('does not allow to override the message with props', function () {
var store = mockStore({});
store.dispatch((0, _actions.show)('Hello World', { message: 'Goodbye' }));
expect(store.getActions()[0].message).toEqual('Hello World');
});
});
50 changes: 50 additions & 0 deletions lib/flash/__tests__/reducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use strict';

var _actionTypes = require('../actionTypes');

var _reducer = require('../reducer');

var _reducer2 = _interopRequireDefault(_reducer);

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

describe(_actionTypes.SHOW_FLASH, function () {
it('sets open to true', function () {
expect((0, _reducer2.default)({ open: false }, { type: _actionTypes.SHOW_FLASH })).toEqual({
open: true
});
expect((0, _reducer2.default)({ open: true }, { type: _actionTypes.SHOW_FLASH })).toEqual({
open: true
});
});

it('injects any extra props in the state', function () {
expect((0, _reducer2.default)({ open: false }, { type: _actionTypes.SHOW_FLASH, custom: 1 })).toEqual({
open: true,
custom: 1
});
});

it('does not allow to set the open value via extra props', function () {
expect((0, _reducer2.default)({ open: false }, { type: _actionTypes.SHOW_FLASH, custom: 1, open: 'Yes' })).toEqual({ open: true, custom: 1 });
});

it('clears any previous props in the state', function () {
expect((0, _reducer2.default)({ open: false, message: 'Hello' }, { type: _actionTypes.SHOW_FLASH, message: 'Goodbye' })).toEqual({ open: true, message: 'Goodbye' });
});
});

describe(_actionTypes.HIDE_FLASH, function () {
it('sets open to false', function () {
expect((0, _reducer2.default)({ open: false }, { type: _actionTypes.HIDE_FLASH })).toEqual({
open: false
});
expect((0, _reducer2.default)({ open: true }, { type: _actionTypes.HIDE_FLASH })).toEqual({
open: false
});
});

it('keeps anything else in the state intact', function () {
expect((0, _reducer2.default)({ open: true, message: 'Hello', custom: 1 }, { type: _actionTypes.HIDE_FLASH })).toEqual({ open: false, message: 'Hello', custom: 1 });
});
});
7 changes: 7 additions & 0 deletions lib/flash/actionTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
var SHOW_FLASH = exports.SHOW_FLASH = 'FLASH/SHOW';
var HIDE_FLASH = exports.HIDE_FLASH = 'FLASH/HIDE';
30 changes: 30 additions & 0 deletions lib/flash/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.hide = exports.show = undefined;

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _actionTypes = require('./actionTypes');

var actionTypes = _interopRequireWildcard(_actionTypes);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

var show = exports.show = function show(message) {
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return _extends({
type: actionTypes.SHOW_FLASH,
autoHideDuration: 5000
}, props, {
message: message
});
};

var hide = exports.hide = function hide() {
return {
type: actionTypes.HIDE_FLASH
};
};
33 changes: 33 additions & 0 deletions lib/flash/reducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _actionTypes = require('./actionTypes');

var actionTypes = _interopRequireWildcard(_actionTypes);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

exports.default = function () {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { open: false };

var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

var type = _ref.type,
props = _objectWithoutProperties(_ref, ['type']);

switch (type) {
case actionTypes.SHOW_FLASH:
return _extends({}, props, { open: true });
case actionTypes.HIDE_FLASH:
return _extends({}, state, { open: false });
default:
return state;
}
};
20 changes: 19 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,25 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.withLoading = exports.TextField = exports.Tab = exports.Tabs = exports.ResponsiveTable = exports.OptionsSelect = exports.OptionsList = exports.MenuItem = exports.MaterialCard = exports.InputList = exports.Fab = exports.DropdownMenu = undefined;
exports.withLoading = exports.TextField = exports.Tab = exports.Tabs = exports.ResponsiveTable = exports.OptionsSelect = exports.OptionsList = exports.MenuItem = exports.MaterialCard = exports.InputList = exports.Fab = exports.DropdownMenu = exports.Flash = exports.Modal = undefined;

var _modal = require('./modal');

Object.defineProperty(exports, 'Modal', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_modal).default;
}
});

var _flash = require('./flash');

Object.defineProperty(exports, 'Flash', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_flash).default;
}
});

var _DropdownMenu = require('./DropdownMenu');

Expand Down
64 changes: 64 additions & 0 deletions lib/modal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Component = exports.key = exports.reducer = exports.actions = exports.actionTypes = undefined;

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _redux = require('redux');

var _reactRedux = require('react-redux');

var _Modal = require('./modal/Modal');

var _Modal2 = _interopRequireDefault(_Modal);

var _actions = require('./modal/actions');

var actions = _interopRequireWildcard(_actions);

var _actionTypes = require('./modal/actionTypes');

var actionTypes = _interopRequireWildcard(_actionTypes);

var _reducer = require('./modal/reducer');

var _reducer2 = _interopRequireDefault(_reducer);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

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

var NAME = 'modal';

var mapStateToProps = function mapStateToProps(_ref) {
var _ref$NAME = _ref[NAME],
component = _ref$NAME.component,
props = _ref$NAME.props;
return _extends({}, props, {
component: component
});
};

var mapDispatchToProps = function mapDispatchToProps(dispatch) {
return {
hide: (0, _redux.bindActionCreators)(actions.hideModal, dispatch)
};
};

var Component = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(_Modal2.default);

exports.actionTypes = actionTypes;
exports.actions = actions;
exports.reducer = _reducer2.default;
exports.key = NAME;
exports.Component = Component;
exports.default = {
actionTypes: actionTypes,
actions: actions,
reducer: _reducer2.default,
key: NAME,
Component: Component
};
Loading

0 comments on commit 124af9d

Please sign in to comment.