-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #343 from wwnorton/feedback-modal
Feedback modal
- Loading branch information
Showing
12 changed files
with
385 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
@use 'tokens'; | ||
@use '../../util'; | ||
|
||
@mixin style { | ||
@include util.declare(tokens.$name) { | ||
.nds-#{tokens.$name} { | ||
&__container { | ||
display: flex; | ||
gap: 1rem; | ||
} | ||
|
||
&__icon-container { | ||
min-width: tokens.$icon-width; | ||
} | ||
|
||
&__icon { | ||
width: tokens.$icon-width; | ||
height: tokens.$icon-width; | ||
|
||
&--correct { | ||
color: tokens.$correct; | ||
} | ||
|
||
&--incorrect { | ||
color: tokens.$incorrect; | ||
} | ||
} | ||
|
||
&__heading { | ||
margin-bottom: 0; | ||
} | ||
} | ||
} | ||
} |
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,4 @@ | ||
$name: 'feedback-modal'; | ||
$icon-width: 2.5rem; | ||
$correct: var(--nds-green-60); | ||
$incorrect: var(--nds-red-60); |
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
63 changes: 63 additions & 0 deletions
63
packages/react/src/components/FeedbackModal/FeedbackModal.tsx
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,63 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import { Modal } from '../Modal'; | ||
import { Button } from '../Button'; | ||
import { Icon } from '../Icon'; | ||
import { FeedbackModalProps } from './types'; | ||
import { css } from './tokens'; | ||
|
||
/** | ||
* A modal dialog that provides feedback about the chosen answer after it is submitted. | ||
* | ||
* Supplementary Feedback can be passed in `children`. | ||
*/ | ||
export const FeedbackModal = ({ | ||
isCorrect, choiceLabel, choiceText, ...modalProps | ||
}: FeedbackModalProps) => { | ||
const title = isCorrect ? 'Correct' : 'Incorrect'; | ||
const icon = isCorrect ? 'check-circle' : 'cancel'; | ||
|
||
return ( | ||
<Modal | ||
title={title} | ||
actions={( | ||
<div> | ||
<Button variant="outline" onClick={modalProps.onRequestClose}>Close</Button> | ||
</div> | ||
)} | ||
{...modalProps} | ||
> | ||
<div className={css.container}> | ||
<div className={css.iconContainer}> | ||
<Icon | ||
className={ | ||
classNames( | ||
css.icon, | ||
{ [css.iconCorrect]: isCorrect, [css.iconIncorrect]: !isCorrect }, | ||
) | ||
} | ||
variant={icon} | ||
/> | ||
</div> | ||
<div> | ||
<p className={css.heading}> | ||
<strong> | ||
Your answer was | ||
{' '} | ||
{' '} | ||
{title.toLowerCase()} | ||
: | ||
</strong> | ||
</p> | ||
<p> | ||
{choiceLabel} | ||
. | ||
{' '} | ||
{choiceText} | ||
</p> | ||
{modalProps.children} | ||
</div> | ||
</div> | ||
</Modal> | ||
); | ||
}; |
41 changes: 41 additions & 0 deletions
41
packages/react/src/components/FeedbackModal/index.stories.tsx
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,41 @@ | ||
import React from 'react'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { FeedbackModal } from '.'; | ||
|
||
const meta: Meta<typeof FeedbackModal> = { | ||
title: 'FeedbackModal', | ||
component: FeedbackModal, | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof FeedbackModal>; | ||
|
||
const template: Story = { | ||
render: ({ ...args }) => ( | ||
<FeedbackModal {...args}> | ||
<p> | ||
Answer feedback lorem ipsum dolor sit amet, consectetur adipiscing elit, | ||
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | ||
</p> | ||
</FeedbackModal> | ||
), | ||
}; | ||
|
||
export const Incorrect: Story = { | ||
...template, | ||
args: { | ||
isOpen: true, | ||
choiceText: 'Answer Choice 3', | ||
choiceLabel: 'C', | ||
}, | ||
}; | ||
|
||
export const Correct: Story = { | ||
...template, | ||
args: { | ||
isOpen: true, | ||
isCorrect: true, | ||
choiceText: 'Answer Choice 3', | ||
choiceLabel: 'C', | ||
}, | ||
}; |
Oops, something went wrong.