-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: initial commit and experience selector * feat: add data submission * feat: add text fadeout * fix: thicken outline when focused * feat: better focus handling * fix: focus stealing * fix: button text alignment, fieldset spacing, pointer events * fix: focus and style tweaks, use Carbon textbox * feat: add entrance animation * feat: fade on scroll * fix: animation choreography * feat: add livve url * fix: safari zamboni and text zoom * fix: safari zamboni and resize * fix: animation performance * docs: add Feedback docs * fix: homepage rendering and console errors * fix: desktop transition speed * fix: focus return and icon flexibility * cchore: remove unused dep * fix: list overflow weirdness * feat: add submission indicators and mobile styles * chore: checkmark tweaks * fix: launch button active and hover styles * fix: use proper focus token * fix: icon visibility animation * fix: slow down stroke, add thanks and adjust reset * fix: add background hover change * fix: inverse 01 Co-authored-by: Vince Picone <Vincent.Patrick.Picone@ibm.com>
- Loading branch information
Showing
28 changed files
with
839 additions
and
169 deletions.
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' })} | ||
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
20 changes: 20 additions & 0 deletions
20
packages/gatsby-theme-carbon/src/components/FeedbackDialog/Checkmark.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,20 @@ | ||
import React from 'react'; | ||
import styles from './Checkmark.module.scss'; | ||
|
||
const Checkmark = () => { | ||
return ( | ||
<svg className={styles.svg} width="20" viewBox="0 0 28 28"> | ||
<circle r="14" cx="14" cy="14" fill="#fff" /> | ||
<polyline | ||
className={styles.path} | ||
points="7.8 13.75 12 17.95 20.2 9.8" | ||
fill="white" | ||
stroke="#0f62fe" | ||
strokeMiterlimit="10" | ||
strokeWidth="2.5" | ||
/> | ||
</svg> | ||
); | ||
}; | ||
|
||
export default Checkmark; |
18 changes: 18 additions & 0 deletions
18
packages/gatsby-theme-carbon/src/components/FeedbackDialog/Checkmark.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,18 @@ | ||
.svg { | ||
position: absolute; | ||
right: 10px; | ||
top: 10px; | ||
padding: 2px; | ||
} | ||
|
||
.path { | ||
stroke-dasharray: 30px; | ||
stroke-dashoffset: 30px; | ||
animation: drawStroke 1200ms forwards; | ||
} | ||
|
||
@keyframes drawStroke { | ||
to { | ||
stroke-dashoffset: 0; | ||
} | ||
} |
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; |
Oops, something went wrong.
cb12399
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.
Successfully deployed to following URLs: