diff options
author | Anike Arni <anikarni@gmail.com> | 2017-03-13 18:41:59 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-13 18:41:59 -0300 |
commit | 99a6a41ffea6de9e4b3df43265282d76c3391fd1 (patch) | |
tree | 2b4d7b3c5ebd267ad252ab05c440a90033e4f962 /web-ui/src/common | |
parent | 8595d3d4f31b761574c08d6f9cdf5bfc00f53a99 (diff) | |
parent | 412d95d64b5d26d4f5e00a85b7b62da23e9bb168 (diff) |
Merge branch 'master' into makefile-tests
Diffstat (limited to 'web-ui/src/common')
-rw-r--r-- | web-ui/src/common/app.js | 45 | ||||
-rw-r--r-- | web-ui/src/common/footer/footer.js | 40 | ||||
-rw-r--r-- | web-ui/src/common/footer/footer.scss | 53 | ||||
-rw-r--r-- | web-ui/src/common/footer/footer.spec.js | 17 | ||||
-rw-r--r-- | web-ui/src/common/header/header.js | 46 | ||||
-rw-r--r-- | web-ui/src/common/header/header.scss | 88 | ||||
-rw-r--r-- | web-ui/src/common/header/header.spec.js | 17 | ||||
-rw-r--r-- | web-ui/src/common/i18n.js | 40 | ||||
-rw-r--r-- | web-ui/src/common/input_field/input_field.js | 47 | ||||
-rw-r--r-- | web-ui/src/common/input_field/input_field.scss | 43 | ||||
-rw-r--r-- | web-ui/src/common/input_field/input_field.spec.js | 20 | ||||
-rw-r--r-- | web-ui/src/common/materialPixTheme.js | 31 | ||||
-rw-r--r-- | web-ui/src/common/submit_button/submit_button.js | 57 | ||||
-rw-r--r-- | web-ui/src/common/submit_button/submit_button.scss | 40 | ||||
-rw-r--r-- | web-ui/src/common/submit_button/submit_button.spec.js | 20 | ||||
-rw-r--r-- | web-ui/src/common/util.js | 8 | ||||
-rw-r--r-- | web-ui/src/common/util.spec.js | 20 |
17 files changed, 632 insertions, 0 deletions
diff --git a/web-ui/src/common/app.js b/web-ui/src/common/app.js new file mode 100644 index 00000000..b8302000 --- /dev/null +++ b/web-ui/src/common/app.js @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2017 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. + */ + +import React from 'react'; +import { I18nextProvider } from 'react-i18next'; + +import internationalization from 'src/common/i18n'; +import injectTapEventPlugin from 'react-tap-event-plugin'; +import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'; +import materialPixTheme from 'src/common/materialPixTheme'; + +injectTapEventPlugin(); + +const App = ({ i18n = internationalization, child }) => ( + <MuiThemeProvider muiTheme={materialPixTheme}> + <I18nextProvider i18n={i18n}> + {child} + </I18nextProvider> + </MuiThemeProvider> +); + +App.propTypes = { + i18n: React.PropTypes.object, // eslint-disable-line react/forbid-prop-types + child: React.PropTypes.element.isRequired +}; + +App.defaultProps = { + i18n: internationalization +}; + +export default App; diff --git a/web-ui/src/common/footer/footer.js b/web-ui/src/common/footer/footer.js new file mode 100644 index 00000000..c2138c21 --- /dev/null +++ b/web-ui/src/common/footer/footer.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2017 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. + */ + +import React from 'react'; +import { translate } from 'react-i18next'; +import './footer.scss'; + +export const Footer = ({ t }) => ( + <footer className='footer-wrapper'> + <div className='footer-content'> + <img className='footer-image' src='/public/images/lab.svg' alt='' /> + <div> + {t('footer-text')} + <a className='footer-link' href='mailto:team@pixelated-project.org'> + {' team@pixelated-project.org'} + </a> + </div> + </div> + </footer> +); + +Footer.propTypes = { + t: React.PropTypes.func.isRequired +}; + +export default translate('', { wait: true })(Footer); diff --git a/web-ui/src/common/footer/footer.scss b/web-ui/src/common/footer/footer.scss new file mode 100644 index 00000000..c1d6a285 --- /dev/null +++ b/web-ui/src/common/footer/footer.scss @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2017 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. + */ +@import "~scss/base/colors"; + +.footer-wrapper { + display: flex; + justify-content: center; + font-size: 0.8em; + color: $dark_slate_gray; +} + +.footer-content { + display: inline; + margin: 2% 3%; + margin-bottom: 1em; + display: flex; + align-items: center; +} + +.footer-image { + margin: 0 0.7em; +} + +.footer-link { + color: $white; + font-style: normal; + font-weight: 500; +} + +@media only screen and (min-width : 500px) { + .footer-wrapper { + font-size: 0.6em; + } + + .footer-content { + margin: 0; + margin-bottom: 1em; + } +} diff --git a/web-ui/src/common/footer/footer.spec.js b/web-ui/src/common/footer/footer.spec.js new file mode 100644 index 00000000..f1247233 --- /dev/null +++ b/web-ui/src/common/footer/footer.spec.js @@ -0,0 +1,17 @@ +import { shallow } from 'enzyme'; +import expect from 'expect'; +import React from 'react'; +import { Footer } from 'src/common/footer/footer'; + +describe('Footer', () => { + let footer; + + beforeEach(() => { + const mockTranslations = key => key; + footer = shallow(<Footer t={mockTranslations} />); + }); + + it('renders the footer content', () => { + expect(footer.find('footer').text()).toContain('footer-text'); + }); +}); diff --git a/web-ui/src/common/header/header.js b/web-ui/src/common/header/header.js new file mode 100644 index 00000000..50c863b5 --- /dev/null +++ b/web-ui/src/common/header/header.js @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2017 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. + */ + +import React from 'react'; +import { translate } from 'react-i18next'; +import './header.scss'; + +export const Header = ({ t }) => ( + <header className='header-wrapper'> + <div className='header-content'> + <a href='/'> + <img + className='header-logo' + src='/public/images/logo-orange.svg' + alt='Pixelated' + /> + </a> + <div className='header-icons'> + <a href='/'> + <span>{t('logout')}</span> + <i className='fa fa-sign-out' aria-hidden='true' /> + </a> + </div> + </div> + </header> +); + +Header.propTypes = { + t: React.PropTypes.func.isRequired +}; + +export default translate('', { wait: true })(Header); diff --git a/web-ui/src/common/header/header.scss b/web-ui/src/common/header/header.scss new file mode 100644 index 00000000..d56629bf --- /dev/null +++ b/web-ui/src/common/header/header.scss @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2017 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. + */ +@import "~scss/base/colors"; + +.header-wrapper { + display: flex; + justify-content: center; + align-items: center; + + background: $white; + box-shadow: 0 2px 3px 0 $shadow; + padding: 7px 0; +} + +.header-content { + display: flex; + align-items: center; +} + +.header-logo { + width: 120px; +} + +.header-icons { + display: flex; + align-items: center; + + position: absolute; + right: 6%; + top: 13px; + + span { + display: none; + } + + .fa { + font-size: 1.3em; + margin-left: 0.4em; + color: $medium_light_grey; + } +} + + +@media only screen and (min-width : 960px) { + .header-content { + flex-basis: 64%; + max-width: 820px; + justify-content: space-between; + } + + .header-icons { + position: relative; + right: 0; + top: 0; + + a { + display: flex; + align-items: center; + } + + span { + display: inline; + color: $medium_light_grey; + font-style: normal; + font-size: 0.7em; + padding-bottom: 0.1em; + } + + .fa { + font-size: 1em; + margin-right: 0; + } + } +} diff --git a/web-ui/src/common/header/header.spec.js b/web-ui/src/common/header/header.spec.js new file mode 100644 index 00000000..82e29e1c --- /dev/null +++ b/web-ui/src/common/header/header.spec.js @@ -0,0 +1,17 @@ +import { shallow } from 'enzyme'; +import expect from 'expect'; +import React from 'react'; +import { Header } from 'src/common/header/header'; + +describe('Header', () => { + let header; + + beforeEach(() => { + const mockTranslations = key => key; + header = shallow(<Header t={mockTranslations} />); + }); + + it('renders the header content', () => { + expect(header.find('header').text()).toContain('logout'); + }); +}); diff --git a/web-ui/src/common/i18n.js b/web-ui/src/common/i18n.js new file mode 100644 index 00000000..db107dc7 --- /dev/null +++ b/web-ui/src/common/i18n.js @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2017 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. + */ +import i18n from 'i18next'; +import i18nBackend from 'i18nextXHRBackend'; +import I18nDetector from 'i18nextBrowserLanguageDetector'; + +const detector = new I18nDetector(); +const detect = detector.detect.bind(detector); + +detector.detect = (detectionOrder) => { + const result = detect(detectionOrder); + return result.replace('-', '_'); +}; + +i18n + .use(i18nBackend) + .use(detector) + .init({ + fallbackLng: 'en_US', + parseMissingKeyHandler: key => (`"${key} untranslated"`), + backend: { + loadPath: 'public/locales/{{lng}}/{{ns}}.json' + } + }); + +export default i18n; diff --git a/web-ui/src/common/input_field/input_field.js b/web-ui/src/common/input_field/input_field.js new file mode 100644 index 00000000..f50fc2b1 --- /dev/null +++ b/web-ui/src/common/input_field/input_field.js @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2017 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. + */ + +import React from 'react'; +import TextField from 'material-ui/TextField'; + +import './input_field.scss'; + +const InputField = ({ label, name, type = 'text', ...other }) => ( + <div className='input-field-group'> + <TextField + hintText={label} + floatingLabelText={label} + name={name} + type={type} + fullWidth + floatingLabelFocusStyle={{ color: '#178ca6' }} + {...other} + /> + </div> +); + +InputField.propTypes = { + label: React.PropTypes.string.isRequired, + name: React.PropTypes.string.isRequired, + type: React.PropTypes.string +}; + +InputField.defaultProps = { + type: 'text' +}; + +export default InputField; diff --git a/web-ui/src/common/input_field/input_field.scss b/web-ui/src/common/input_field/input_field.scss new file mode 100644 index 00000000..d550a281 --- /dev/null +++ b/web-ui/src/common/input_field/input_field.scss @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. + */ + +@import "~scss/base/colors"; + +.input-field-group { + position:relative; + margin: 1.5em 0; + width: 100%; +} + +input:-webkit-autofill { + -webkit-box-shadow: 0 0 0px 1000px white inset; +} + +@media only screen and (min-width : 500px) { + .input-field-group { + width: 70%; + align-self: center; + } +} + +@media only screen and (min-width : 960px) { + .input-field-group { + width: 300px; + align-self: flex-start; + font-size: 1em; + } +} diff --git a/web-ui/src/common/input_field/input_field.spec.js b/web-ui/src/common/input_field/input_field.spec.js new file mode 100644 index 00000000..ae55653d --- /dev/null +++ b/web-ui/src/common/input_field/input_field.spec.js @@ -0,0 +1,20 @@ +import { shallow } from 'enzyme'; +import expect from 'expect'; +import React from 'react'; +import InputField from 'src/common/input_field/input_field'; + +describe('InputField', () => { + let inputField; + + beforeEach(() => { + inputField = shallow(<InputField label='Email' name='email' />); + }); + + it('renders an input of type text for email', () => { + expect(inputField.find('TextField').props().name).toEqual('email'); + }); + + it('renders a label for the email', () => { + expect(inputField.find('TextField').props().floatingLabelText).toEqual('Email'); + }); +}); diff --git a/web-ui/src/common/materialPixTheme.js b/web-ui/src/common/materialPixTheme.js new file mode 100644 index 00000000..34be7870 --- /dev/null +++ b/web-ui/src/common/materialPixTheme.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2017 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. + */ +import getMuiTheme from 'material-ui/styles/getMuiTheme'; + +const mediumLightGrey = '#999999'; +const darkBlue = '#178ca6'; + +const materialPixTheme = getMuiTheme({ + fontFamily: 'Open Sans, sans-serif', + palette: { + disabledColor: mediumLightGrey, + primary1Color: darkBlue, + borderColor: darkBlue + } +}); + +export default materialPixTheme; diff --git a/web-ui/src/common/submit_button/submit_button.js b/web-ui/src/common/submit_button/submit_button.js new file mode 100644 index 00000000..1224c7bd --- /dev/null +++ b/web-ui/src/common/submit_button/submit_button.js @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2017 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. + */ + +import React from 'react'; +import RaisedButton from 'material-ui/RaisedButton'; + +import './submit_button.scss'; + +const labelStyle = { + textTransform: 'none', + fontSize: '1em', + lineHeight: '48px' +}; + +const buttonStyle = { + height: '48px' +}; + +const SubmitButton = ({ buttonText, disabled = false }) => ( + <div className='submit-button'> + <RaisedButton + type='submit' + label={buttonText} + disabled={disabled} + labelStyle={labelStyle} + buttonStyle={buttonStyle} + overlayStyle={buttonStyle} + fullWidth + primary + /> + </div> +); + +SubmitButton.propTypes = { + buttonText: React.PropTypes.string.isRequired, + disabled: React.PropTypes.bool +}; + +SubmitButton.defaultProps = { + disabled: false +}; + +export default SubmitButton; diff --git a/web-ui/src/common/submit_button/submit_button.scss b/web-ui/src/common/submit_button/submit_button.scss new file mode 100644 index 00000000..851899f7 --- /dev/null +++ b/web-ui/src/common/submit_button/submit_button.scss @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2017 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see <http://www.gnu.org/licenses/>. + */ + +@import "~scss/base/colors"; + +.submit-button { + width: 100%; + margin-bottom: 1em; + font-size: 1em; +} + +@media only screen and (min-width : 500px) { + .submit-button { + width: 70%; + align-self: center; + } +} + +@media only screen and (min-width : 960px) { + .submit-button { + width: 300px; + align-self: flex-start; + font-size: 0.8em; + margin-bottom: 1em; + } +} diff --git a/web-ui/src/common/submit_button/submit_button.spec.js b/web-ui/src/common/submit_button/submit_button.spec.js new file mode 100644 index 00000000..0ba8137c --- /dev/null +++ b/web-ui/src/common/submit_button/submit_button.spec.js @@ -0,0 +1,20 @@ +import { shallow } from 'enzyme'; +import expect from 'expect'; +import React from 'react'; +import SubmitButton from 'src/common/submit_button/submit_button'; + +describe('SubmitButton', () => { + let submitButton; + + beforeEach(() => { + submitButton = shallow(<SubmitButton buttonText='Add Email' />); + }); + + it('renders an input of type submit for add email', () => { + expect(submitButton.find('RaisedButton').props().label).toEqual('Add Email'); + }); + + it('renders button in enabled state', () => { + expect(submitButton.find('RaisedButton').props().disabled).toEqual(false); + }); +}); diff --git a/web-ui/src/common/util.js b/web-ui/src/common/util.js new file mode 100644 index 00000000..effb3d9c --- /dev/null +++ b/web-ui/src/common/util.js @@ -0,0 +1,8 @@ +export const hasQueryParameter = (param) => { + const decodedUri = decodeURIComponent(window.location.search.substring(1)); + return !(decodedUri.split('&').indexOf(param) < 0); +}; + +export default { + hasQueryParameter +}; diff --git a/web-ui/src/common/util.spec.js b/web-ui/src/common/util.spec.js new file mode 100644 index 00000000..805d9dd5 --- /dev/null +++ b/web-ui/src/common/util.spec.js @@ -0,0 +1,20 @@ +import expect from 'expect'; +import Util from 'src/common/util'; + +describe('Utils', () => { + describe('.hasQueryParameter', () => { + global.window = { + location: { + search: '?auth-error&lng=pt-BR' + } + }; + + it('checks if param included in query parameters', () => { + expect(Util.hasQueryParameter('auth-error')).toBe(true); + }); + + it('checks if param not included in query parameters', () => { + expect(Util.hasQueryParameter('error')).toBe(false); + }); + }); +}); |