-
Notifications
You must be signed in to change notification settings - Fork 273
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
feat: Feedback dialog #772
Merged
vpicone
merged 31 commits into
carbon-design-system:master
from
vpicone:feedback-dialog
Mar 16, 2020
Merged
Changes from 20 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
f4b4f6e
feat: initial commit and experience selector
vpicone 3e7cba1
feat: add data submission
vpicone fa0a846
feat: add text fadeout
vpicone 2078af4
fix: thicken outline when focused
vpicone b85ef59
feat: better focus handling
vpicone 02b63c0
fix: focus stealing
vpicone 6ab141c
fix: button text alignment, fieldset spacing, pointer events
vpicone 47df804
fix: focus and style tweaks, use Carbon textbox
vpicone 4371453
feat: add entrance animation
vpicone 62002f2
feat: fade on scroll
vpicone 6efec09
Merge branch 'master' into feedback-dialog
vpicone 34aa206
fix: animation choreography
vpicone 2ba30be
Merge branch 'feedback-dialog' of github.com:vpicone/gatsby-theme-car…
vpicone 68458ef
feat: add livve url
vpicone 950c3ac
fix: safari zamboni and text zoom
vpicone b86ac5e
fix: safari zamboni and resize
vpicone 7858fe7
fix: animation performance
vpicone c712134
docs: add Feedback docs
vpicone 230deb5
fix: homepage rendering and console errors
vpicone 10e523a
fix: desktop transition speed
vpicone e8de24a
fix: focus return and icon flexibility
vpicone ecdaa7d
cchore: remove unused dep
vpicone 19d0c2a
fix: list overflow weirdness
vpicone 6273273
feat: add submission indicators and mobile styles
vpicone a408fd7
chore: checkmark tweaks
vpicone fe18144
fix: launch button active and hover styles
vpicone 44a2c5c
fix: use proper focus token
vpicone a8f11ab
fix: icon visibility animation
vpicone d2b7602
fix: slow down stroke, add thanks and adjust reset
vpicone 6c9f847
fix: add background hover change
vpicone 0819436
fix: inverse 01
vpicone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/example/src/gatsby-theme-carbon/components/FeedbackDialog/FeedbackDialog.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
import ThemeFeedbackDialog from 'gatsby-theme-carbon/src/components/FeedbackDialog/FeedbackDialog'; | ||
|
||
const FeedbackDialog = ({ props }) => { | ||
const onSubmit = data => { | ||
console.log({ ...data }); | ||
}; | ||
|
||
return <ThemeFeedbackDialog {...props} onSubmit={onSubmit} />; | ||
}; | ||
|
||
export default FeedbackDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
title: FeatureCard | ||
description: Allow visitors to your website to provide feedback through a dialog | ||
--- | ||
|
||
<PageDescription> | ||
|
||
The `<FeatureDialog>` component is a modeless dialog that allows your users to provide low-friction, anonymous feedback for a specific page. | ||
|
||
</PageDescription> | ||
|
||
## Activating the dialog | ||
|
||
The Feedback button only becomes visisble once you've supplied an `onSubmit` handler. To do that, we'll need to shadow the `FeedbackDialog` component. | ||
|
||
1. Create a new javascript file under `src/gatsby-theme-carbon/components/FeedbackDialog/FeedbackDialog.js`. Matching the filepath exactly is important here. | ||
|
||
2. Copy the following snippet into your new file | ||
|
||
```jsx | ||
import React from 'react'; | ||
import ThemeFeedbackDialog from 'gatsby-theme-carbon/src/components/FeedbackDialog/FeedbackDialog'; | ||
|
||
const FeedbackDialog = ({ props }) => { | ||
const onSubmit = data => { | ||
console.log({ ...data }); | ||
}; | ||
|
||
return <ThemeFeedbackDialog {...props} onSubmit={onSubmit} />; | ||
}; | ||
|
||
export default FeedbackDialog; | ||
|
||
``` | ||
|
||
|
||
## Creating a handler | ||
|
||
Next, you'll need a place to send the data. For the Carbon website, we use a serverless function that forwards the data to a [SurveyGizmo](https://www.surveygizmo.com/) quiz. | ||
You can see that function [here](https://github.com/carbon-design-system/carbon-website/blob/master/functions/survey.js). | ||
|
||
The handler can send a fetch request off to the endpoint you create. Update the `onSubmit` handler to send the data wherever you want. This function receives the following arguments: | ||
- `experience`: "Negative", "Positive" or "Neutral" | ||
- `comment`: An optional comment | ||
- `path`: the window location when the survey was submitted | ||
|
||
```jsx | ||
const FeedbackDialog = ({ props }) => { | ||
const onSubmit = data => { | ||
fetch(process.env.API_ENDPOINT, { | ||
method: 'POST', | ||
body: JSON.stringify(data), | ||
}); | ||
|
||
return <ThemeFeedbackDialog {...props} onSubmit={onSubmit} />; | ||
}; | ||
``` | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 8 additions & 7 deletions
15
packages/gatsby-theme-carbon/src/components/BackToTopBtn/BackToTopBtn.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
import React from 'react'; | ||
import { UpToTop20 } from '@carbon/icons-react'; | ||
import ScrollToTop from 'react-scroll-up'; | ||
|
||
import { button } from './BackToTopBtn.module.scss'; | ||
|
||
const BackToTopBtn = () => ( | ||
<ScrollToTop showUnder={300} style={{ zIndex: 9999 }}> | ||
<button className={button} type="button" aria-label="Back to Top"> | ||
<UpToTop20 /> | ||
</button> | ||
</ScrollToTop> | ||
<button | ||
onClick={() => window.scrollTo({ top: 0, left: 0, behavior: 'smooth' })} | ||
vpicone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
className={button} | ||
type="button" | ||
aria-label="Back to Top" | ||
> | ||
<UpToTop20 /> | ||
</button> | ||
); | ||
|
||
export default BackToTopBtn; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/gatsby-theme-carbon/src/components/FeedbackDialog/Comment.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* eslint-disable jsx-a11y/label-has-associated-control */ | ||
// eslint doesn't know about TextArea labeling | ||
import React, { useState } from 'react'; | ||
import { TextArea } from 'carbon-components-react'; | ||
import cx from 'classnames'; | ||
import styles from './Comment.module.scss'; | ||
|
||
const Comment = () => { | ||
const [focused, setFocused] = useState(false); | ||
const handleBlur = e => { | ||
e.target.scrollTop = 0; | ||
setFocused(false); | ||
}; | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<TextArea | ||
className={styles.textarea} | ||
labelText="Comments (optional):" | ||
onBlur={handleBlur} | ||
onFocus={() => setFocused(true)} | ||
rows={5} | ||
name="feedback-form-comment" | ||
id="feedback-form-comment" | ||
/> | ||
<div | ||
className={cx(styles.fadeout, { | ||
[styles.focused]: focused, | ||
})} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Comment; |
27 changes: 27 additions & 0 deletions
27
packages/gatsby-theme-carbon/src/components/FeedbackDialog/Comment.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.container { | ||
position: relative; | ||
} | ||
|
||
.textarea { | ||
resize: none; | ||
@include carbon--type-style('body-short-02'); | ||
@include carbon--breakpoint('md') { | ||
@include carbon--type-style('body-short-01'); | ||
} | ||
} | ||
|
||
.fadeout { | ||
pointer-events: none; | ||
position: absolute; | ||
bottom: 1px; | ||
left: $spacing-03; | ||
right: $spacing-05; | ||
transition: opacity $duration--fast-02 motion(standard, productive); | ||
opacity: 1; | ||
background: linear-gradient(rgba(57, 57, 57, 0), rgba(57, 57, 57, 1)); | ||
height: 3rem; | ||
} | ||
|
||
.focused { | ||
opacity: 0; | ||
} |
95 changes: 95 additions & 0 deletions
95
packages/gatsby-theme-carbon/src/components/FeedbackDialog/Experience.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import React, { useState } from 'react'; | ||
import { | ||
FaceDissatisfied32, | ||
FaceNeutral32, | ||
FaceSatisfied32, | ||
FaceDissatisfiedFilled32, | ||
FaceNeutralFilled32, | ||
FaceSatisfiedFilled32, | ||
} from '@carbon/icons-react'; | ||
import cx from 'classnames'; | ||
|
||
import styles from './Experience.module.scss'; | ||
|
||
const NEGATIVE = 'feedback-form-negative'; | ||
const NEUTRAL = 'feedback-form-neutral'; | ||
const POSITIVE = 'feedback-form-positive'; | ||
|
||
const Experience = React.forwardRef(function Experience(props, ref) { | ||
const [selected, setSelected] = useState(NEUTRAL); | ||
|
||
const onExperienceChange = e => { | ||
setSelected(e.target.id); | ||
}; | ||
|
||
return ( | ||
<fieldset onChange={onExperienceChange}> | ||
<legend>Rate your experience:</legend> | ||
<div className={styles.experienceContainer}> | ||
<label | ||
className={cx(styles.experience, { | ||
[styles.selected]: selected === NEGATIVE, | ||
})} | ||
htmlFor={NEGATIVE} | ||
> | ||
<input | ||
ref={selected === NEGATIVE ? ref : undefined} | ||
type="radio" | ||
id={NEGATIVE} | ||
defaultChecked={selected === NEGATIVE} | ||
name="feedback-form-experience" | ||
value="Negative" | ||
/> | ||
<span>Negative</span> | ||
{selected === NEGATIVE ? ( | ||
<FaceDissatisfiedFilled32 /> | ||
) : ( | ||
<FaceDissatisfied32 /> | ||
)} | ||
</label> | ||
|
||
<label | ||
className={cx(styles.experience, { | ||
[styles.selected]: selected === NEUTRAL, | ||
})} | ||
htmlFor={NEUTRAL} | ||
> | ||
<input | ||
ref={selected === NEUTRAL ? ref : undefined} | ||
type="radio" | ||
id={NEUTRAL} | ||
defaultChecked={selected === NEUTRAL} | ||
name="feedback-form-experience" | ||
value="Neutral" | ||
/> | ||
<span>Neutral</span> | ||
{selected === NEUTRAL ? <FaceNeutralFilled32 /> : <FaceNeutral32 />} | ||
</label> | ||
|
||
<label | ||
className={cx(styles.experience, { | ||
[styles.selected]: selected === POSITIVE, | ||
})} | ||
htmlFor={POSITIVE} | ||
> | ||
<input | ||
ref={selected === POSITIVE ? ref : undefined} | ||
type="radio" | ||
id={POSITIVE} | ||
defaultChecked={selected === POSITIVE} | ||
name="feedback-form-experience" | ||
value="Positive" | ||
/> | ||
<span>Positive</span> | ||
{selected === POSITIVE ? ( | ||
<FaceSatisfiedFilled32 /> | ||
) : ( | ||
<FaceSatisfied32 /> | ||
)} | ||
</label> | ||
</div> | ||
</fieldset> | ||
); | ||
}); | ||
|
||
export default Experience; |
57 changes: 57 additions & 0 deletions
57
packages/gatsby-theme-carbon/src/components/FeedbackDialog/Experience.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
.experience-container { | ||
display: flex; | ||
background: var(--cds-ui-01); | ||
margin-top: $spacing-03; | ||
} | ||
|
||
.experience { | ||
display: flex; | ||
transition: all $duration--fast-02 motion(standard, productive); | ||
justify-content: center; | ||
align-items: center; | ||
position: relative; | ||
height: 96px; | ||
width: 100%; | ||
border-right: 1px solid var(--cds-ui-background); | ||
|
||
&:last-of-type { | ||
border-right: none; | ||
} | ||
} | ||
|
||
.experience svg { | ||
fill: var(--cds-icon-02); | ||
pointer-events: none; | ||
} | ||
|
||
.experience span { | ||
position: absolute; | ||
pointer-events: none; | ||
top: $spacing-03; | ||
left: $spacing-03; | ||
} | ||
|
||
.experience input { | ||
position: absolute; | ||
cursor: pointer; | ||
height: 100%; | ||
width: 100%; | ||
appearance: none; | ||
margin: 0; | ||
&:checked { | ||
outline: 1px solid var(--cds-ui-05); | ||
} | ||
&:focus { | ||
outline: 2px solid var(--cds-ui-05); | ||
} | ||
} | ||
|
||
.selected svg, | ||
.experience:hover svg { | ||
fill: var(--cds-icon-01); | ||
} | ||
|
||
.selected, | ||
.experience:hover { | ||
color: var(--cds-icon-01); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove react-scroll-up now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call