react_rails_modal 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3e1bd4c454c4eb2bfc2570573bc5b970372830b2
4
+ data.tar.gz: 8c4b7ee94a683baeca1e42f1130e3ba07ca235e1
5
+ SHA512:
6
+ metadata.gz: ca10df107a558282c82c0fb4631dd97401505cb1087f9b061df76fda9995e7a3919a983873c9f306f394434279a77384ef3908b93aa9680e68695d489853b548
7
+ data.tar.gz: 3527b9daa5460435fbb0591e761cc14791a2d4dac0349e66b682f2b8d8bad60243df55971e7d8cbbd012584f7f434dc8b0bfaee08fc2ef703949e5e4c6d355fd
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 kiyodori
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,197 @@
1
+ # ReactRailsModal
2
+
3
+ Accessible modal dialog component on react-rails.
4
+
5
+ ## Pre Installation
6
+
7
+ Before using react_rails_modal, install `react-rails`.
8
+
9
+ Add `react-rails` to your gemfile:
10
+
11
+ ```ruby
12
+ gem 'react-rails'
13
+ ```
14
+
15
+ And install:
16
+
17
+ $ bundle install
18
+
19
+ Next, run the installation script:
20
+
21
+ $ rails g react:install
22
+
23
+ ## Installation
24
+
25
+ Add `react_rails_modal` to your gemfile:
26
+
27
+ ```ruby
28
+ gem 'react_rails_modal'
29
+ ```
30
+
31
+ And install:
32
+
33
+ $ bundle install
34
+
35
+ Next, run the installation script:
36
+
37
+ $ rails g react_rails_modal:install
38
+
39
+ This will place the following in your `application.js`:
40
+
41
+ ```js
42
+ //= require react_rails_modal
43
+ ```
44
+
45
+ ## Usage
46
+
47
+ ```xml
48
+ <ModalConponent
49
+ isOpen={bool}
50
+ onCloseRequest={requestCloseFunction}
51
+ style={customStyle}
52
+ >
53
+ <h1>Modal Component Content</h1>
54
+ <p>Text</p>
55
+ </Modal>
56
+ ```
57
+
58
+ ## Examples
59
+ ### Use styles to style
60
+
61
+ In app/controller/views/:
62
+
63
+ ```html
64
+ <%= react_component('Hello') %>
65
+ ```
66
+
67
+ Styles are passed as an object with 2 keys, 'overlay' and 'modal'.
68
+
69
+ In app/assets/javascripts/components/:
70
+
71
+ ```jsx
72
+ class Hello extends React.Component {
73
+ constructor(props) {
74
+ super(props);
75
+ this.closeModal = this.closeModal.bind(this);
76
+ this.openModal = this.openModal.bind(this);
77
+ this.state = { isModalOpen: false };
78
+ }
79
+
80
+ closeModal() {
81
+ this.setState({ isModalOpen: false });
82
+ }
83
+
84
+ openModal() {
85
+ this.setState({ isModalOpen: true });
86
+ }
87
+
88
+ render () {
89
+ return (
90
+ <div>
91
+ <button onClick={this.openModal}>Open Modal</button>
92
+ <ModalComponent
93
+ isOpen={this.state.isModalOpen}
94
+ onCloseRequest={this.closeModal}
95
+ style={Hello.styles}
96
+ >
97
+ <h1>Hello world!</h1>
98
+ <button onClick={this.closeModal}>Close</button>
99
+ </ModalComponent>
100
+ </div>
101
+ );
102
+ }
103
+ }
104
+
105
+ Hello.styles = {
106
+ overlay: {
107
+ backgroundColor: 'rgba(0,0,0,0.75)',
108
+ bottom: '0',
109
+ height: '100%',
110
+ position: 'fixed',
111
+ top: '0',
112
+ left: '0',
113
+ right: '0',
114
+ width: '100%',
115
+ zIndex: '1',
116
+ },
117
+ modal: {
118
+ background: '#fff',
119
+ left: '5%',
120
+ padding: '15px 30px',
121
+ position: 'relative',
122
+ top: '10%',
123
+ width: '80%',
124
+ zIndex: '2',
125
+ }
126
+ }
127
+ ```
128
+
129
+ ### Use css classes to style
130
+
131
+ If you want to use css classes, you can pass overlayClass and modalClass props to the Modal.
132
+
133
+ ```jsx
134
+ class HelloTwo extends React.Component {
135
+ constructor(props) {
136
+ super(props);
137
+ this.closeModal = this.closeModal.bind(this);
138
+ this.openModal = this.openModal.bind(this);
139
+ this.state = { isModalOpen: false };
140
+ }
141
+
142
+ closeModal() {
143
+ this.setState({ isModalOpen: false });
144
+ }
145
+
146
+ openModal() {
147
+ this.setState({ isModalOpen: true });
148
+ }
149
+
150
+ render () {
151
+ return (
152
+ <div>
153
+ <button onClick={this.openModal}>Open Modal</button>
154
+ <ModalComponent
155
+ isOpen={this.state.isModalOpen}
156
+ onCloseRequest={this.closeModal}
157
+ overlayClass='overlayClass'
158
+ modalClass='modalClass'
159
+ >
160
+ <h1>Hello world!!</h1>
161
+ <button onClick={this.closeModal}>Close</button>
162
+ </ModalComponent>
163
+ </div>
164
+ );
165
+ }
166
+ }
167
+ ```
168
+
169
+ In app/assets/stylesheets/:
170
+
171
+ ```css
172
+ .overlayClass {
173
+ background-color: rgba(0,0,0,0.7);
174
+ bottom: 0;
175
+ height: 100%;
176
+ position: fixed;
177
+ top: 0;
178
+ left: 0;
179
+ right: 0;
180
+ width: 100%;
181
+ z-index: 1;
182
+ }
183
+
184
+ .modalClass {
185
+ background: #fff;
186
+ left: 5%;
187
+ padding: 15px;
188
+ position: fixed;
189
+ top: 10%;
190
+ width: 90%;
191
+ z-index: 2;
192
+ }
193
+ ```
194
+
195
+ ## Development
196
+ * Update React assets with `rake react_rails_modal:build`
197
+ * Run tests with `rake spec`
@@ -0,0 +1,147 @@
1
+ /******/ (function(modules) { // webpackBootstrap
2
+ /******/ // The module cache
3
+ /******/ var installedModules = {};
4
+
5
+ /******/ // The require function
6
+ /******/ function __webpack_require__(moduleId) {
7
+
8
+ /******/ // Check if module is in cache
9
+ /******/ if(installedModules[moduleId])
10
+ /******/ return installedModules[moduleId].exports;
11
+
12
+ /******/ // Create a new module (and put it into the cache)
13
+ /******/ var module = installedModules[moduleId] = {
14
+ /******/ exports: {},
15
+ /******/ id: moduleId,
16
+ /******/ loaded: false
17
+ /******/ };
18
+
19
+ /******/ // Execute the module function
20
+ /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
21
+
22
+ /******/ // Flag the module as loaded
23
+ /******/ module.loaded = true;
24
+
25
+ /******/ // Return the exports of the module
26
+ /******/ return module.exports;
27
+ /******/ }
28
+
29
+
30
+ /******/ // expose the modules object (__webpack_modules__)
31
+ /******/ __webpack_require__.m = modules;
32
+
33
+ /******/ // expose the module cache
34
+ /******/ __webpack_require__.c = installedModules;
35
+
36
+ /******/ // __webpack_public_path__
37
+ /******/ __webpack_require__.p = "";
38
+
39
+ /******/ // Load entry module and return exports
40
+ /******/ return __webpack_require__(0);
41
+ /******/ })
42
+ /************************************************************************/
43
+ /******/ ([
44
+ /* 0 */
45
+ /***/ function(module, exports) {
46
+
47
+ 'use strict';
48
+
49
+ Object.defineProperty(exports, "__esModule", {
50
+ value: true
51
+ });
52
+
53
+ 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; }; }();
54
+
55
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
56
+
57
+ function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
58
+
59
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
60
+
61
+ var ModalComponent = function (_React$Component) {
62
+ _inherits(ModalComponent, _React$Component);
63
+
64
+ function ModalComponent(props) {
65
+ _classCallCheck(this, ModalComponent);
66
+
67
+ var _this = _possibleConstructorReturn(this, (ModalComponent.__proto__ || Object.getPrototypeOf(ModalComponent)).call(this, props));
68
+
69
+ _this.state = { isOpen: _this.props.isOpen };
70
+ return _this;
71
+ }
72
+
73
+ _createClass(ModalComponent, [{
74
+ key: 'componentWillReceiveProps',
75
+ value: function componentWillReceiveProps(nextProps) {
76
+ this.setState({ isOpen: nextProps.isOpen });
77
+ }
78
+ }, {
79
+ key: 'render',
80
+ value: function render() {
81
+ if (!this.state.isOpen) {
82
+ return null;
83
+ }
84
+
85
+ var overlay = this.props.style && this.props.style.overlay ? this.props.style.overlay : ModalComponent.defaultStyles.overlay;
86
+ var overlayClass = this.props.overlayClass ? {} : overlay;
87
+ var modal = this.props.style && this.props.style.modal ? this.props.style.modal : ModalComponent.defaultStyles.modal;
88
+ var modalClass = this.props.modalClass ? {} : modal;
89
+
90
+ return React.createElement(
91
+ 'div',
92
+ null,
93
+ React.createElement(
94
+ 'div',
95
+ { style: overlayClass, onClick: this.props.onCloseRequest, className: this.props.overlayClass },
96
+ React.createElement(
97
+ 'div',
98
+ { style: modalClass, className: this.props.modalClass },
99
+ this.props.children
100
+ )
101
+ )
102
+ );
103
+ }
104
+ }]);
105
+
106
+ return ModalComponent;
107
+ }(React.Component);
108
+
109
+ ModalComponent.propTypes = {
110
+ isOpen: React.PropTypes.bool.isRequired,
111
+ onCloseRequest: React.PropTypes.func,
112
+ style: React.PropTypes.objectOf(React.PropTypes.object),
113
+ overlayClassName: React.PropTypes.string,
114
+ modalClassName: React.PropTypes.string
115
+ };
116
+
117
+ ModalComponent.defaultStyles = {
118
+ overlay: {
119
+ backgroundColor: 'rgba(0,0,0,0.75)',
120
+ height: '100%',
121
+ left: 0,
122
+ position: 'fixed',
123
+ top: 0,
124
+ width: '100%',
125
+ zIndex: 1
126
+ },
127
+ modal: {
128
+ background: '#fff',
129
+ borderRadius: '5px',
130
+ boxShadow: '0 0 10 #000',
131
+ display: 'table',
132
+ left: '5%',
133
+ maxHeight: '80%',
134
+ maxWidth: '80%',
135
+ overflowY: 'scroll',
136
+ padding: '20px 50px',
137
+ position: 'fixed',
138
+ top: '10%',
139
+ width: '80%',
140
+ zIndex: 2
141
+ }
142
+ };
143
+
144
+ exports.default = window.ModalComponent = ModalComponent;
145
+
146
+ /***/ }
147
+ /******/ ]);
@@ -0,0 +1,39 @@
1
+ module ReactRailsModal
2
+ module Generators
3
+ class InstallGenerator < ::Rails::Generators::Base
4
+ desc 'Install react_rails_modal'
5
+
6
+ def inject_react_rails_modal
7
+ require_react_rails_modal = "//= require react_rails_modal\n"
8
+
9
+ if manifest.exist?
10
+ manifest_contents = File.read(manifest)
11
+ puts manifest_contents.match(/\/\/=\s+require\s+turbolinks\s+\n/)
12
+ puts manifest_contents.match(/\/\/=\s+require_tree[^\n]*/)
13
+
14
+ if match = manifest_contents.match(/\/\/=\s+require_tree[^\n]*/)
15
+ inject_into_file manifest, require_react_rails_modal, { before: match[0] }
16
+ else
17
+ append_file manifest, require_react_rails_modal
18
+ inject_react_rails
19
+ end
20
+ else
21
+ create_file manifest, require_react_rails_modal
22
+ inject_react_rails
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def manifest
29
+ Pathname.new(destination_root).join('app/assets/javascripts', 'application.js')
30
+ end
31
+
32
+ def inject_react_rails
33
+ inject_into_file manifest, "//= require react\n", {before: "//= require react_rails_modal\n"}
34
+ inject_into_file manifest, "//= require components\n", {after: "//= require react\n"}
35
+ inject_into_file manifest, "//= require react_ujs\n", {after: "//= require react\n"}
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,12 @@
1
+ module ReactRailsModal
2
+ # This class add react_rails_modal path to the sprockets environment.
3
+ class AssetVariant
4
+ GEM_ROOT = Pathname.new('../../../').expand_path(__FILE__)
5
+
6
+ attr_reader :react_rails_modal_directory
7
+
8
+ def initialize
9
+ @react_rails_modal_directory = GEM_ROOT.join('lib/assets/javascripts/').to_s
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'rails'
2
+
3
+ module ReactRailsModal
4
+ class Railtie < ::Rails::Railtie
5
+ config.react_rails_modal = ActiveSupport::OrderedOptions.new
6
+
7
+ initializer 'react_rails_modal.set_variant' do |app|
8
+ asset_variant = ReactRailsModal::AssetVariant.new
9
+ app.config.assets.paths << asset_variant.react_rails_modal_directory if app.config.respond_to?(:assets)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module ReactRailsModal
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,3 @@
1
+ require 'react_rails_modal/version'
2
+ require 'react_rails_modal/asset_variant'
3
+ require 'react_rails_modal/railtie'
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: react_rails_modal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kiyodori
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: react-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.7.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.7.0
69
+ description: React_rails_modal creates modal dialog easily on react-rails
70
+ email:
71
+ - kiyodori@yahoo.co.jp
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - LICENSE.txt
77
+ - README.md
78
+ - lib/assets/javascripts/react_rails_modal.js
79
+ - lib/generators/react_rails_modal/install_generator.rb
80
+ - lib/react_rails_modal.rb
81
+ - lib/react_rails_modal/asset_variant.rb
82
+ - lib/react_rails_modal/railtie.rb
83
+ - lib/react_rails_modal/version.rb
84
+ homepage: https://github.com/kiyodori/react_rails_modal
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.5.2
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Accessible modal dialog component on react-rails
108
+ test_files: []