From a04af080646112dc0054d3c043dd4f599d689264 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 9 Jul 2017 20:02:10 -0700 Subject: [PATCH] Polish --- frontend/components/Button/Button.js | 6 ++- frontend/components/HelpText/HelpText.js | 10 ++++ frontend/components/HelpText/index.js | 3 ++ frontend/components/Icon/AddIcon.js | 21 ++++++++ frontend/components/Input/Input.js | 47 ++++++++++++---- frontend/components/Layout/Layout.js | 35 ++++++++++-- .../components/LoadingIndicator/style.scss | 0 frontend/components/Modal/Modal.js | 53 +++++++++++++++---- .../components/NewCollection/NewCollection.js | 6 --- frontend/components/NewCollection/index.js | 3 -- frontend/models/Document.js | 4 +- .../scenes/CollectionNew/CollectionNew.js | 51 ++++++++++++------ frontend/scenes/Document/Document.js | 2 +- frontend/stores/CollectionsStore.js | 8 +++ frontend/styles/animations.js | 14 +++++ frontend/styles/constants.js | 2 +- 16 files changed, 209 insertions(+), 56 deletions(-) create mode 100644 frontend/components/HelpText/HelpText.js create mode 100644 frontend/components/HelpText/index.js create mode 100644 frontend/components/Icon/AddIcon.js create mode 100644 frontend/components/LoadingIndicator/style.scss delete mode 100644 frontend/components/NewCollection/NewCollection.js delete mode 100644 frontend/components/NewCollection/index.js create mode 100644 frontend/styles/animations.js diff --git a/frontend/components/Button/Button.js b/frontend/components/Button/Button.js index 31b826dd0..988d67052 100644 --- a/frontend/components/Button/Button.js +++ b/frontend/components/Button/Button.js @@ -25,13 +25,17 @@ const RealButton = styled.button` &:hover { background: ${darken(0.05, color.primary)}; } + &:disabled { + background: ${color.slateLight}; + } `; const Label = styled.span` - padding: 2px 12px; + padding: 4px 16px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; + font-weight: 500; `; const Inner = styled.span` diff --git a/frontend/components/HelpText/HelpText.js b/frontend/components/HelpText/HelpText.js new file mode 100644 index 000000000..ac4b96673 --- /dev/null +++ b/frontend/components/HelpText/HelpText.js @@ -0,0 +1,10 @@ +// @flow +import styled from 'styled-components'; +import { color } from 'styles/constants'; + +const HelpText = styled.p` + user-select: none; + color: ${color.slateDark}; +`; + +export default HelpText; diff --git a/frontend/components/HelpText/index.js b/frontend/components/HelpText/index.js new file mode 100644 index 000000000..968c478b8 --- /dev/null +++ b/frontend/components/HelpText/index.js @@ -0,0 +1,3 @@ +// @flow +import HelpText from './HelpText'; +export default HelpText; diff --git a/frontend/components/Icon/AddIcon.js b/frontend/components/Icon/AddIcon.js new file mode 100644 index 000000000..688202cfc --- /dev/null +++ b/frontend/components/Icon/AddIcon.js @@ -0,0 +1,21 @@ +// @flow +import React from 'react'; +import Icon from './Icon'; +import type { Props } from './Icon'; + +export default function AddIcon(props: Props) { + return ( + + + + + + + ); +} diff --git a/frontend/components/Input/Input.js b/frontend/components/Input/Input.js index 9ac8641e6..b8420ed1a 100644 --- a/frontend/components/Input/Input.js +++ b/frontend/components/Input/Input.js @@ -2,13 +2,18 @@ import React from 'react'; import styled from 'styled-components'; import Flex from 'components/Flex'; -import { size } from 'styles/constants'; +import { size, color } from 'styles/constants'; const RealTextarea = styled.textarea` border: 0; flex: 1; padding: 8px 12px; outline: none; + background: none; + + &::placeholder { + color: ${color.slate}; + } `; const RealInput = styled.input` @@ -16,36 +21,56 @@ const RealInput = styled.input` flex: 1; padding: 8px 12px; outline: none; + background: none; + + &::placeholder { + color: ${color.slateLight}; + } `; -const Wrapper = styled(Flex)` +const Wrapper = styled.div` + +`; + +const Outline = styled(Flex)` display: flex; flex: 1; margin: 0 0 ${size.large}; color: inherit; - border-width: 2px; + border-width: 1px; border-style: solid; - border-color: ${props => (props.hasError ? 'red' : 'rgba(0, 0, 0, .15)')}; - border-radius: ${size.small}; + border-color: ${props => (props.hasError ? 'red' : color.slateLight)}; + border-radius: 4px; + font-weight: normal; - &:focus, - &:active { - border-color: rgba(0, 0, 0, .25); + &:focus { + border-color: ${color.slate} } `; +const LabelText = styled.div` + font-weight: 500; + padding-bottom: 4px; +`; + export type Props = { type: string, value: string, + label?: string, className?: string, }; -export default function Input({ type, ...rest }: Props) { - const Component = type === 'textarea' ? RealTextarea : RealInput; +export default function Input({ type, label, ...rest }: Props) { + const InputComponent = type === 'textarea' ? RealTextarea : RealInput; return ( - + ); } diff --git a/frontend/components/Layout/Layout.js b/frontend/components/Layout/Layout.js index 0fdf3d977..aead835ca 100644 --- a/frontend/components/Layout/Layout.js +++ b/frontend/components/Layout/Layout.js @@ -14,6 +14,7 @@ import { LoadingIndicatorBar } from 'components/LoadingIndicator'; import Scrollable from 'components/Scrollable'; import Avatar from 'components/Avatar'; import Modal from 'components/Modal'; +import AddIcon from 'components/Icon/AddIcon'; import CollectionNew from 'scenes/CollectionNew'; import SidebarCollection from './components/SidebarCollection'; @@ -72,7 +73,7 @@ type Props = { }; render() { - const { user, auth, ui } = this.props; + const { user, auth, collections, history, ui } = this.props; return ( @@ -123,10 +124,10 @@ type Props = { Home Starred - - Create new collection - + + + {ui.activeCollection ? - + ); } } +const CreateCollection = styled.a` + position: absolute; + top: 8px; + right: ${layout.hpadding}; + + svg { + opacity: .35; + width: 16px; + height: 16px; + } + + &:hover { + svg { + opacity: 1; + } + } +`; + const Container = styled(Flex)` position: relative; width: 100%; @@ -200,6 +224,7 @@ const Header = styled(Flex)` const LinkSection = styled(Flex)` flex-direction: column; padding: 10px 0; + position: relative; `; export default withRouter(inject('user', 'auth', 'ui', 'collections')(Layout)); diff --git a/frontend/components/LoadingIndicator/style.scss b/frontend/components/LoadingIndicator/style.scss new file mode 100644 index 000000000..e69de29bb diff --git a/frontend/components/Modal/Modal.js b/frontend/components/Modal/Modal.js index 3735386d2..21f734182 100644 --- a/frontend/components/Modal/Modal.js +++ b/frontend/components/Modal/Modal.js @@ -2,6 +2,10 @@ import React, { Component } from 'react'; import styled from 'styled-components'; import ReactModal from 'react-modal'; +import { modalFadeIn } from 'styles/animations'; + +import CloseIcon from '../Icon/CloseIcon'; +import Flex from '../Flex'; class Modal extends Component { render() { @@ -13,24 +17,53 @@ class Modal extends Component { } = this.props; return ( - -
- - {title} -
- {children} -
+ +

{title}

+ + {children} +
+ ); } } -const Header = styled.div` - text-align: center; - font-weight: semibold; +const Content = styled(Flex)` + width: 640px; + max-width: 100%; + position: relative; +`; + +const StyledModal = styled(ReactModal)` + animation: ${modalFadeIn} 250ms ease; + + position: absolute; + top: 0; + left: 0; + bottom: 0; + right: 0; + display: flex; + justify-content: center; + align-items: flex-start; + overflow-x: hidden; + overflow-y: auto; + background: white; + padding: 15vh 2rem 2rem +`; + +const Close = styled.a` + position: fixed; + top: 3rem; + right: 3rem; + opacity: .5; + + &:hover { + opacity: 1; + } `; export default Modal; diff --git a/frontend/components/NewCollection/NewCollection.js b/frontend/components/NewCollection/NewCollection.js deleted file mode 100644 index a4a008b2b..000000000 --- a/frontend/components/NewCollection/NewCollection.js +++ /dev/null @@ -1,6 +0,0 @@ -// @flow -import React from 'react'; - -const NewCollection = () => NEW COLLECTION; - -export default NewCollection; diff --git a/frontend/components/NewCollection/index.js b/frontend/components/NewCollection/index.js deleted file mode 100644 index d65518ed9..000000000 --- a/frontend/components/NewCollection/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// @flow -import NewCollection from './NewCollection'; -export default NewCollection; diff --git a/frontend/models/Document.js b/frontend/models/Document.js index 37cca9905..e106a722b 100644 --- a/frontend/models/Document.js +++ b/frontend/models/Document.js @@ -152,9 +152,9 @@ class Document { return this; }; - updateData(data: Object = {}) { + updateData(data: Object = {}, dirty: boolean = false) { if (data.text) data.title = parseHeader(data.text); - data.hasPendingChanges = true; + if (dirty) data.hasPendingChanges = true; extendObservable(this, data); } diff --git a/frontend/scenes/CollectionNew/CollectionNew.js b/frontend/scenes/CollectionNew/CollectionNew.js index e49ff931a..113d449d2 100644 --- a/frontend/scenes/CollectionNew/CollectionNew.js +++ b/frontend/scenes/CollectionNew/CollectionNew.js @@ -3,24 +3,41 @@ import React, { Component } from 'react'; import { observer } from 'mobx-react'; import Button from 'components/Button'; import Input from 'components/Input'; +import HelpText from 'components/HelpText'; + import Collection from 'models/Collection'; +import CollectionsStore from 'stores/CollectionsStore'; @observer class CollectionNew extends Component { + props: { + history: Object, + collection: Collection, + collections: CollectionsStore, + onCollectionCreated: () => void, + }; + state: { name: string, isSaving: boolean }; + state = { name: '', isSaving: false }; + static defaultProps = { collection: new Collection(), }; handleSubmit = async (ev: SyntheticEvent) => { ev.preventDefault(); - await this.props.collection.save(); + this.setState({ isSaving: true }); + const { collection, collections } = this.props; + + collection.updateData(this.state); + await collection.save(); + collections.add(collection); + + this.setState({ isSaving: false }); + this.props.onCollectionCreated(); + this.props.history.push(collection.url); }; handleNameChange = (ev: SyntheticInputEvent) => { - this.props.collection.updateData({ name: ev.target.value }); - }; - - handleDescriptionChange = (ev: SyntheticInputEvent) => { - this.props.collection.updateData({ description: ev.target.value }); + this.setState({ name: ev.target.value }); }; render() { @@ -29,21 +46,23 @@ import Collection from 'models/Collection'; return (
{collection.errors.errors.map(error => {error})} + + Collections are for grouping your Atlas. They work best when organized + around a topic or internal team — Product or Engineering for example. + - -
); diff --git a/frontend/scenes/Document/Document.js b/frontend/scenes/Document/Document.js index bc104f2e6..7b1ce0db0 100644 --- a/frontend/scenes/Document/Document.js +++ b/frontend/scenes/Document/Document.js @@ -120,7 +120,7 @@ type Props = { onChange = text => { if (!this.document) return; - this.document.updateData({ text }); + this.document.updateData({ text }, true); }; onCancel = () => { diff --git a/frontend/stores/CollectionsStore.js b/frontend/stores/CollectionsStore.js index ae8e26446..39f62fe3d 100644 --- a/frontend/stores/CollectionsStore.js +++ b/frontend/stores/CollectionsStore.js @@ -42,6 +42,14 @@ class CollectionsStore { return _.find(this.data, { id }); }; + @action add = (collection: Collection): void => { + this.data.push(collection); + }; + + @action remove = (id: string): void => { + this.data.splice(this.data.indexOf(id), 1); + }; + constructor(options: Options) { this.client = client; this.errors = stores.errors; diff --git a/frontend/styles/animations.js b/frontend/styles/animations.js new file mode 100644 index 000000000..a042aaf72 --- /dev/null +++ b/frontend/styles/animations.js @@ -0,0 +1,14 @@ +// @flow +import { keyframes } from 'styled-components'; + +export const modalFadeIn = keyframes` + from { + opacity: 0; + transform: scale(.98); + } + + to { + opacity: 1; + transform: scale(1); + } +`; diff --git a/frontend/styles/constants.js b/frontend/styles/constants.js index d3a09f953..18c368771 100644 --- a/frontend/styles/constants.js +++ b/frontend/styles/constants.js @@ -40,7 +40,7 @@ export const color = { text: '#171B35', /* Brand */ - primary: '#73DF7B', + primary: '#2B8FBF', /* Dark Grays */ slate: '#9BA6B2',