Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better modal #2554

Merged
merged 79 commits into from
Jan 11, 2019
Merged
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
4d384a9
Rework styling using styled-components
paulmelnikow Dec 12, 2018
bbf0bfa
Fix unit tests
paulmelnikow Dec 12, 2018
6931880
WIP
paulmelnikow Dec 13, 2018
79e88d6
Fields with labels and example text
paulmelnikow Dec 13, 2018
5c73711
Reorder query params in snippet
paulmelnikow Dec 13, 2018
828d0dc
Layout is looking good
paulmelnikow Dec 14, 2018
7a0c18c
Refactor
paulmelnikow Dec 14, 2018
600b3f4
Wire up the path builder
paulmelnikow Dec 14, 2018
dc6f6e8
Renames
paulmelnikow Dec 14, 2018
bea32af
Rm console.log
paulmelnikow Dec 14, 2018
6c79b77
Merge branch 'master' into styled-components
paulmelnikow Dec 16, 2018
e9e2c42
Exclude pages/_document.js
paulmelnikow Dec 16, 2018
a86360d
Fix a bunch of alignment issues
paulmelnikow Dec 17, 2018
3574bbb
Use text-align: left for everything
paulmelnikow Dec 17, 2018
17740bf
Restore original width
paulmelnikow Dec 17, 2018
bc07e83
Don’t truncate built URL
paulmelnikow Dec 17, 2018
64bc474
Merge branch 'master' into styled-components
paulmelnikow Dec 18, 2018
36b816e
Prevent labels from floating left when the window is wide
paulmelnikow Dec 18, 2018
ea110a2
Merge branch 'styled-components' into better-modal
paulmelnikow Dec 18, 2018
c4d6648
Merge branch 'master' into better-modal
paulmelnikow Dec 18, 2018
0cf9cb9
Update lockfile
paulmelnikow Dec 18, 2018
1c59fca
Merge branch 'master' into better-modal
paulmelnikow Dec 21, 2018
582af6b
Update lockfile
paulmelnikow Dec 21, 2018
61ddc2f
Fix key warning
paulmelnikow Dec 21, 2018
4a3719d
Remove some dead code
paulmelnikow Dec 21, 2018
687a05e
Some renames
paulmelnikow Dec 21, 2018
c0b0a59
Improve readability
paulmelnikow Dec 21, 2018
c0a9952
Reorganize into folder
paulmelnikow Dec 21, 2018
3412751
Add initial version of query string builder
paulmelnikow Dec 21, 2018
ef23fa3
Check boxes working
paulmelnikow Dec 21, 2018
8e83253
Add line break + space between
paulmelnikow Dec 21, 2018
7b8a88e
Show space before query params + improve formatting
paulmelnikow Dec 21, 2018
33fe6c1
Merge branch 'master' into better-modal
paulmelnikow Dec 23, 2018
f8224ed
Update lockfile
paulmelnikow Dec 23, 2018
0eb7e75
Clean lint
paulmelnikow Dec 23, 2018
684fc4d
Support badge options
paulmelnikow Dec 23, 2018
9f54e97
Add dropdown format picker
paulmelnikow Dec 27, 2018
d461018
Get markdown button working
paulmelnikow Dec 28, 2018
fdc6409
Merge branch 'master' into better-modal
paulmelnikow Dec 28, 2018
dfcb028
Update lockfile
paulmelnikow Dec 28, 2018
51faabd
Refactor RequestMarkupButton
paulmelnikow Dec 28, 2018
003dbf4
Try to avoid opening the menu when clicking the main part of the button
paulmelnikow Dec 28, 2018
7c930bb
Merge branch 'master' into better-modal
paulmelnikow Jan 2, 2019
64fbbf6
WIP
paulmelnikow Jan 3, 2019
ad51de1
Merge branch 'master' into better-modal
paulmelnikow Jan 4, 2019
470c77a
Update lockfile
paulmelnikow Jan 4, 2019
313de3d
Link copying is working
paulmelnikow Jan 4, 2019
c663c05
Copied content indicator working
paulmelnikow Jan 4, 2019
c5a3c52
Clean that up
paulmelnikow Jan 4, 2019
1cdcf54
Clean lint
paulmelnikow Jan 4, 2019
bf06546
Generate working markup on staging
paulmelnikow Jan 4, 2019
fafdb7b
Fix to previous
paulmelnikow Jan 4, 2019
98ed5ab
Rm dead code
paulmelnikow Jan 4, 2019
32b420b
Clean lint
paulmelnikow Jan 4, 2019
038915b
Merge branch 'master' into better-modal
paulmelnikow Jan 5, 2019
040accd
Merge branch 'master' into better-modal
paulmelnikow Jan 8, 2019
959447b
Merge branch 'better-modal' of github.com:badges/shields into better-…
paulmelnikow Jan 8, 2019
d5cd20c
Rm dead code and unused dep
paulmelnikow Jan 8, 2019
d911d6a
Rm unnecessary indirection
paulmelnikow Jan 8, 2019
38f46e1
Rm more dead code
paulmelnikow Jan 8, 2019
6891491
Make box-sizing global
paulmelnikow Jan 8, 2019
0da999e
Make the styling API for PathLiteral less permissive
paulmelnikow Jan 8, 2019
14a3961
Use static property for propTypes
paulmelnikow Jan 8, 2019
47c22c8
Avoid duplicating font styles
paulmelnikow Jan 8, 2019
c955455
Explain the filtering
paulmelnikow Jan 8, 2019
0c6e825
Unit test for getPath
paulmelnikow Jan 8, 2019
b47cc39
event -> evt
paulmelnikow Jan 8, 2019
ca6ab34
Fix error in previous
paulmelnikow Jan 8, 2019
d7629c8
Change copied content indicator to “Copied”
paulmelnikow Jan 8, 2019
0a3c5c2
Merge branch 'master' into better-modal
paulmelnikow Jan 8, 2019
7893d26
Merge branch 'master' into better-modal
paulmelnikow Jan 9, 2019
c7b51ac
PosedContentIndicator: Keep it in the DOM
paulmelnikow Jan 9, 2019
c660dc1
Merge branch 'better-modal' of github.com:badges/shields into better-…
paulmelnikow Jan 9, 2019
d4454bf
Set will-change
paulmelnikow Jan 9, 2019
ea53667
Merge branch 'master' into better-modal
paulmelnikow Jan 10, 2019
90efb7b
Use Object.freeze
paulmelnikow Jan 10, 2019
4617564
Clear key warning
paulmelnikow Jan 10, 2019
9cc1d9c
Change styling var to a boolean
paulmelnikow Jan 10, 2019
ff37c71
Merge branch 'master' into better-modal
paulmelnikow Jan 11, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions frontend/components/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import React from 'react'
import PropTypes from 'prop-types'
import styled, { css } from 'styled-components'

const noAutocorrect = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Maybe do Object.freeze on this to ensure it's not mutated anywhere?

If the repo were using strong typing, it'd be fine (eg. in Flow you can annotate an object as $ReadOnly and then Flow will throw a type error if you try to mutate it.

autoComplete: 'off',
autoCorrect: 'off',
autoCapitalize: 'off',
spellCheck: 'false',
}

const nonBreakingSpace = '\u00a0'

const BaseFont = styled.div`
Expand Down Expand Up @@ -94,11 +101,13 @@ const VerticalSpace = styled.hr`
`

export {
noAutocorrect,
nonBreakingSpace,
BaseFont,
H2,
H3,
Badge,
StyledInput,
InlineInput,
BlockInput,
VerticalSpace,
Expand Down
10 changes: 8 additions & 2 deletions frontend/components/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import styled, { createGlobalStyle } from 'styled-components'
import groupBy from 'lodash.groupby'
import {
categories,
Expand All @@ -21,6 +21,12 @@ import { CategoryHeadings, CategoryNav } from './category-headings'
import BadgeExamples from './badge-examples'
import { BaseFont } from './common'

const GlobalStyle = createGlobalStyle`
* {
box-sizing: border-box;
}
`

const AppContainer = styled(BaseFont)`
text-align: center;
`
Expand Down Expand Up @@ -147,13 +153,13 @@ export default class Main extends React.Component {

return (
<AppContainer id="app">
<GlobalStyle />
<Meta />
<Header />
<MarkupModal
example={selectedExample}
onRequestClose={this.dismissMarkupModal}
baseUrl={baseUrl}
key={selectedExample}
/>
<section>
<SuggestionAndSearch
Expand Down
48 changes: 48 additions & 0 deletions frontend/components/markup-modal/builder-common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'

const BuilderOuterContainer = styled.div`
margin-top: 10px;
margin-bottom: 10px;
`

// The inner container is inline-block so that its width matches its columns.
const BuilderInnerContainer = styled.div`
display: inline-block;
padding: 11px 14px 10px;
border-radius: 4px;
background: #eef;
`

const BuilderContainer = ({ children }) => (
<BuilderOuterContainer>
<BuilderInnerContainer>{children}</BuilderInnerContainer>
</BuilderOuterContainer>
)
BuilderContainer.propTypes = {
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
]),
}

const labelFont = `
font-family: system-ui;
font-size: 11px;
text-transform: lowercase;
`

const BuilderLabel = styled.label`
${labelFont}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

`

const BuilderCaption = styled.span`
${labelFont}
color: #999;
`

export { BuilderContainer, BuilderLabel, BuilderCaption }
74 changes: 74 additions & 0 deletions frontend/components/markup-modal/copied-content-indicator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React from 'react'
import PropTypes from 'prop-types'
import posed from 'react-pose'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really cool! I haven't done much frontend webdev work in a while (most of the things I work on at work are more backend-related these days), but this library looks really good.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was impressed with how well it worked out of the box! Though I feel like I hit a moderate hill after an initially easy learning curve. I would definitely use it again.

import styled from 'styled-components'

const ContentAnchor = styled.span`
position: relative;
display: inline-block;
`

// 100vw allows providing styled content which is wider than its container.
const ContentContainer = styled.span`
width: 100vw;
position: absolute;
left: 50%;
transform: translateX(-50%);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't seen this centering hack in a while 😛

Does margin: 0 auto or flexbox not work for this use case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe. I'm still learning layout. I fiddled with it for a long time and I'd love to find a better way. 😝

This is what it looks like now. It glides up, centered over the button as intended. Normally it would then disappear but I turned that off for the screenshot.

screen shot 2019-01-08 at 12 58 15 pm

If I remove left and transform and set margin: 0 auto it's way off to the right. It might be centered over the right bound of the parent position: relative element; not sure.

screen shot 2019-01-08 at 12 56 30 pm

Btw this is all live in the review app. Click one of the examples with colons, fill in the boxes, and click the button, and you can see what the animation is supposed to do.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a design / UX perspective, I think it would be nicer if didn't have the actual text was copied but just a simple 'copied' as the content of the indicator. I've seen that on other sites used a lot and think that would be a better solution since no one would be able to read the text in that short period of time. On the other hand, it would be nice to see the text before it gets copied to the clipboard.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with "copied."

We could experiment with showing the actual text. Seeing unfinished markup before you start filling the form looks like a mistake and I think is confusing. We could show an empty rectangle with a message "your markup will appear here" or "some parameters missing," similarly to the way the preview badge is handled.

During editing, I think the changing text will be distracting for some and comforting for others. It's about adding something new, so let's revisit it. If we decide on a design process in #1899 that will put us on good ground for the future work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I'll write it down and we leave like this here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the indicator to show Copied.

will-change: opacity, top;
pointer-events: none;
`

const PosedContentContainer = posed(ContentContainer)({
hidden: { opacity: 0, transition: { duration: 100 } },
effectStart: { top: '-10px', opacity: 1.0, transition: { duration: 0 } },
effectEnd: { top: '-75px', opacity: 0.5 },
})

// When `trigger()` is called, render copied content that floats up, then
// disappears.
export default class CopiedContentIndicator extends React.Component {
state = {
pose: 'hidden',
}

trigger() {
this.setState({ pose: 'effectStart' })
}

handlePoseComplete = () => {
const { pose } = this.state
if (pose === 'effectStart') {
this.setState({ pose: 'effectEnd' })
} else {
this.setState({ pose: 'hidden' })
}
}

render() {
const { pose } = this.state
return (
<ContentAnchor>
<PosedContentContainer
pose={pose}
onPoseComplete={this.handlePoseComplete}
>
{this.props.copiedContent}
</PosedContentContainer>
{this.props.children}
</ContentAnchor>
)
}
}
CopiedContentIndicator.propTypes = {
copiedContent: PropTypes.oneOfType([
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we end up with any consensus about whether to use static typing (like Flow or TypeScript) rather than runtime type checking?

Copy link
Member Author

@paulmelnikow paulmelnikow Jan 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We decided not to do it for the server because it raises the barrier to contributing, especially among non-JS devs, and doesn't create enough payoff to compensate for that.

I'd like to do it for the frontend, because I think would actually lower the barrier. The types make the code easier to change, and when it comes to the frontend, I'd rather try to appeal to seasoned React devs than non-frontend devs.

PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
]),
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
]),
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import React from 'react'
import PropTypes from 'prop-types'
import Modal from 'react-modal'
import styled from 'styled-components'
import { badgeUrlFromPath, badgeUrlFromPattern } from '../../lib/make-badge-url'
import generateAllMarkup from '../lib/generate-image-markup'
import { advertisedStyles } from '../../supported-features.json'
import { Snippet } from './snippet'
import { BaseFont, H3, Badge, BlockInput } from './common'
import {
badgeUrlFromPath,
badgeUrlFromPattern,
} from '../../../lib/make-badge-url'
import { advertisedStyles } from '../../../supported-features.json'
import generateAllMarkup from '../../lib/generate-image-markup'
import { Snippet } from '../snippet'
import { BaseFont, H3, Badge, BlockInput } from '../common'
import MarkupModalContent from './markup-modal-content'

const ContentContainer = styled(BaseFont)`
text-align: center;
Expand Down Expand Up @@ -176,6 +180,8 @@ export default class MarkupModal extends React.Component {
const { onRequestClose, example: { title } = {} } = this.props
const { link, badgeUrl, exampleUrl, style } = this.state

const hasModernExample = isOpen && this.props.example.example.pattern

const common = {
autoComplete: 'off',
autoCorrect: 'off',
Expand All @@ -190,63 +196,69 @@ export default class MarkupModal extends React.Component {
contentLabel="Example Modal"
ariaHideApp={false}
>
<ContentContainer>
<form action="">
<H3>{title}</H3>
{isOpen && this.renderLivePreview()}
<p>
<label>
Link&nbsp;
<BlockInput
type="url"
value={link}
onChange={event => {
this.setState({ link: event.target.value })
}}
{...common}
/>
</label>
</p>
<p>
<label>
Path&nbsp;
<BlockInput
type="url"
value={badgeUrl}
onChange={event => {
this.setState({ badgeUrl: event.target.value })
}}
{...common}
/>
</label>
</p>
{exampleUrl && (
{hasModernExample ? (
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing has changed here besides adding the conditional.

<ContentContainer>
<MarkupModalContent {...this.props} />
</ContentContainer>
) : (
<ContentContainer>
<form action="">
<H3>{title}</H3>
{isOpen && this.renderLivePreview()}
<p>
<label>
Link&nbsp;
<BlockInput
type="url"
value={link}
onChange={event => {
this.setState({ link: event.target.value })
}}
{...common}
/>
</label>
</p>
<p>
<label>
Path&nbsp;
<BlockInput
type="url"
value={badgeUrl}
onChange={event => {
this.setState({ badgeUrl: event.target.value })
}}
{...common}
/>
</label>
</p>
{exampleUrl && (
<p>
Example&nbsp;
<Snippet fontSize="10pt" snippet={exampleUrl} />
</p>
)}
<p>
Example&nbsp;
<Snippet fontSize="10pt" snippet={exampleUrl} />
<label>
Style&nbsp;
<select
value={style}
onChange={event => {
this.setState({ style: event.target.value })
}}
>
{advertisedStyles.map(style => (
<option key={style} value={style}>
{style}
</option>
))}
</select>
</label>
</p>
)}
<p>
<label>
Style&nbsp;
<select
value={style}
onChange={event => {
this.setState({ style: event.target.value })
}}
>
{advertisedStyles.map(style => (
<option key={style} value={style}>
{style}
</option>
))}
</select>
</label>
</p>
{isOpen && this.renderMarkup()}
{isOpen && this.renderDocumentation()}
</form>
</ContentContainer>
{isOpen && this.renderMarkup()}
{isOpen && this.renderDocumentation()}
</form>
</ContentContainer>
)}
</Modal>
)
}
Expand Down
Loading