From f1184e450ececa2949975a8be543d6e8f71e85e2 Mon Sep 17 00:00:00 2001 From: Stuart Colville Date: Thu, 16 Jul 2015 11:00:51 +0100 Subject: [PATCH] Add modal component (fixes #188) --- public/js/apps/management/app.jsx | 3 ++ public/js/components/modal.jsx | 46 ++++++++++++++++++ public/management.html | 1 + public/scss/_modal.scss | 57 +++++++++++++++++++++++ public/scss/main.scss | 1 + styleguide/jsx/modal.jsx | 8 ++++ styleguide/pages/modal.md | 12 +++++ styleguide/templates/base-styleguide.html | 2 + tasks/webpack.js | 1 + 9 files changed, 131 insertions(+) create mode 100644 public/js/components/modal.jsx create mode 100644 public/scss/_modal.scss create mode 100644 styleguide/jsx/modal.jsx create mode 100644 styleguide/pages/modal.md diff --git a/public/js/apps/management/app.jsx b/public/js/apps/management/app.jsx index 4621d0a..7c21a75 100644 --- a/public/js/apps/management/app.jsx +++ b/public/js/apps/management/app.jsx @@ -6,6 +6,8 @@ var { AccordionContent, AccordionSection} = require('components/accordion'); +var Modal = require('components/modal'); + var gettext = require('utils').gettext; @@ -81,6 +83,7 @@ var Management = React.createClass({ module.exports = { component: Management, init: function() { + React.render(, document.getElementById('modal')); React.render(, document.getElementById('view')); }, }; diff --git a/public/js/components/modal.jsx b/public/js/components/modal.jsx new file mode 100644 index 0000000..ec0f836 --- /dev/null +++ b/public/js/components/modal.jsx @@ -0,0 +1,46 @@ +'use strict'; + +var React = require('react'); +var gettext = require('utils').gettext; +var cx = require('classnames'); + + +module.exports = React.createClass({ + + displayName: 'Modal', + + propTypes: { + children: React.PropTypes.array.required, + close: React.PropTypes.func, + showModal: React.PropTypes.bool, + title: React.PropTypes.string, + }, + + getDefaultProps: function() { + return { + showModal: true, + }; + }, + + render: function() { + + var classes = cx(['modal', {'active': this.props.showModal}]); + + return ( +
+
+
+ {this.props.title ?

{this.props.title}

: null} + + {gettext('Close')} + +
+
+ {this.props.children} +
+
+
+ ); + }, +}); + diff --git a/public/management.html b/public/management.html index 639f01a..6aa6bd0 100644 --- a/public/management.html +++ b/public/management.html @@ -9,6 +9,7 @@
+
diff --git a/public/scss/_modal.scss b/public/scss/_modal.scss new file mode 100644 index 0000000..17bb29e --- /dev/null +++ b/public/scss/_modal.scss @@ -0,0 +1,57 @@ +.modal { + + &.active { + opacity: 1; + } + + background: rgba(0, 0, 0, 0.5); + bottom: 0; + left: 0; + opacity: 0; + position: fixed; + right: 0; + top: 0; + // Ensure transform on .inner doesn't + // render on half a pixel thus causing fuzziness. + transform-style: preserve-3d; + z-index: 20; + + .inner { + background: #fff; + border-radius: 3px; + border: 1px solid #C3CFD8; + box-shadow: 0 3px 7px rgba(0, 0, 0, 0.5); + height: 468px; + margin: 0 auto; + padding: 20px; + position: relative; + top: 50%; + transform: translateY(-50%); + width: 318px; + } + + .close { + color: #666; + font-size: $large-font; + line-height: 1ex; + padding: 10px; + position: absolute; + right: -5px; + text-decoration: none; + top: -5px; + z-index: 30; + + &:before { + content: '×'; + } + } + + header { + text-align: center; + + h2 { + margin: 1.5em; + font-weight: 400; + } + } +} diff --git a/public/scss/main.scss b/public/scss/main.scss index f8ec3cc..74ac117 100644 --- a/public/scss/main.scss +++ b/public/scss/main.scss @@ -16,6 +16,7 @@ @import '_tooltip'; @import '_app-error'; @import '_management'; +@import '_modal'; @import '_card-listing'; @import '_complete-payment'; diff --git a/styleguide/jsx/modal.jsx b/styleguide/jsx/modal.jsx new file mode 100644 index 0000000..a124b09 --- /dev/null +++ b/styleguide/jsx/modal.jsx @@ -0,0 +1,8 @@ +'use strict'; + +var React = require('react'); +var Modal = require('components/modal'); +var CardForm = require('components/card-form'); +React.render( + + , document.getElementById('modal')); diff --git a/styleguide/pages/modal.md b/styleguide/pages/modal.md new file mode 100644 index 0000000..c6b44a0 --- /dev/null +++ b/styleguide/pages/modal.md @@ -0,0 +1,12 @@ +# Modal Dialogue + +This is the modal dialogue component. + +```iframe +sourcecodeSelector: '#modal' +dynamicSource: true +title: Modal Dialogue +renderer: nunjucks +template: jsx.html +bundle: modal +``` diff --git a/styleguide/templates/base-styleguide.html b/styleguide/templates/base-styleguide.html index 3686b36..14d2789 100644 --- a/styleguide/templates/base-styleguide.html +++ b/styleguide/templates/base-styleguide.html @@ -9,6 +9,8 @@
+
diff --git a/tasks/webpack.js b/tasks/webpack.js index f26ccfc..11d41a5 100644 --- a/tasks/webpack.js +++ b/tasks/webpack.js @@ -21,6 +21,7 @@ module.exports = { styleguide: { entry: { // Explicit entries for the styleguide. + 'modal': './styleguide/jsx/modal', 'app-error': './styleguide/jsx/app-error', 'card-form': './styleguide/jsx/card-form', 'spinner': './styleguide/jsx/spinner',