-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create FeedbackError component (#265)
* refactor: add icon props to ladle * refactor: fix button error on ladle * refactor: remove blank div and add FeedbackError component on home screen * chore: create snippet to import scss files * feat: create error message store * feat: finished FeedbackError component * refactor: change breakingpoint style * refactor: turn store name more generic * refactor: remove @use snippet * refactor: change breakingpoint position to bottom * test: fix failing test * refactor: add error icon on icon component * refactor: fix icon not showing on screen error * refactor: add Icon component on button storie * refactor: add icon component to show icon error * refactor: add breakingpoint * refactor: create a data file for feedbackComponent and fix ladle stories
- Loading branch information
Showing
23 changed files
with
231 additions
and
41 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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export const animationVariants = { | ||
hidden: { | ||
y: -100, | ||
opacity: 0, | ||
transition: { | ||
type: 'tween', | ||
}, | ||
}, | ||
visible: { | ||
y: 0, | ||
opacity: 1, | ||
transition: { | ||
type: 'tween', | ||
}, | ||
}, | ||
}; |
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,38 @@ | ||
@use '~styles/global.scss' as *; | ||
|
||
.wrapper { | ||
width: 100%; | ||
|
||
display: flex; | ||
gap: 1rem; | ||
|
||
align-items: center; | ||
|
||
margin-top: 3.2rem; | ||
padding-left: 1rem; | ||
border-left: 8px solid $secondaryRed; | ||
|
||
background: $secondaryRed; | ||
|
||
.errorIcon { | ||
color: $primaryWhite; | ||
} | ||
|
||
.errorMessage { | ||
color: $primaryWhite; | ||
} | ||
} | ||
|
||
@include from599 { | ||
.wrapper { | ||
background: inherit; | ||
|
||
.errorIcon { | ||
color: $secondaryRed; | ||
} | ||
|
||
.errorMessage { | ||
color: $secondaryRed; | ||
} | ||
} | ||
} |
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,17 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import FeedbackError from './FeedbackError'; | ||
|
||
describe('FeedbackEror', () => { | ||
describe('when initialize', () => { | ||
describe('there is no error', () => { | ||
it('renders nothing on screen', () => { | ||
render(<FeedbackError />); | ||
|
||
expect( | ||
screen.queryByTestId(/error-container/i) | ||
).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
}); | ||
}); |
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,24 @@ | ||
import { useEffect } from 'react'; | ||
|
||
import type { Story } from '@ladle/react'; | ||
import { useError } from 'stores/useError/useError'; | ||
|
||
import FeedbackError from './FeedbackError'; | ||
|
||
interface IFeedbackErrorProps { | ||
errorMessage: string; | ||
} | ||
|
||
export const FeedbackErrorComponent: Story<IFeedbackErrorProps> = (props) => { | ||
const setErrorMessage = useError((state) => state.setErrorMessage); | ||
|
||
useEffect(() => { | ||
setErrorMessage(props.errorMessage); | ||
}, [props.errorMessage]); | ||
|
||
return <FeedbackError />; | ||
}; | ||
|
||
FeedbackErrorComponent.args = { | ||
errorMessage: 'generic error message', | ||
}; |
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,29 @@ | ||
import { AnimatePresence, motion } from 'framer-motion'; | ||
import { useError } from 'stores/useError/useError'; | ||
|
||
import Icon from '~components/Icon/Icon'; | ||
|
||
import scss from './FeedbackError.module.scss'; | ||
|
||
import { animationVariants } from './FeedbackError.data'; | ||
|
||
function FeedbackError() { | ||
const errorMessage = useError((state) => state.errorMessage); | ||
|
||
const renderError = () => ( | ||
<motion.div | ||
initial="hidden" | ||
animate="visible" | ||
exit="hidden" | ||
className={scss.wrapper} | ||
variants={animationVariants} | ||
data-testid="error-container" | ||
> | ||
<Icon icon="error" size="large" className={scss.errorIcon} /> | ||
<p className={scss.errorMessage}>{errorMessage}</p> | ||
</motion.div> | ||
); | ||
return <AnimatePresence>{errorMessage && renderError()}</AnimatePresence>; | ||
} | ||
|
||
export default FeedbackError; |
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
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
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
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 |
---|---|---|
|
@@ -5,3 +5,4 @@ $iEmote: '\e903'; | |
$iHashtag: '\e904'; | ||
$iLink: '\e905'; | ||
$iPin: '\e906'; | ||
$iError: '\e907'; |
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 |
---|---|---|
|
@@ -60,7 +60,3 @@ | |
flex-direction: column; | ||
grid-area: input; | ||
} | ||
|
||
.gridTabs { | ||
grid-area: tabs; | ||
} |
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,46 @@ | ||
import { renderHook, act } from '@testing-library/react'; | ||
import * as zustand from 'zustand'; | ||
|
||
import { useError } from './useError'; | ||
|
||
import { myCustomCreate, storeResetFns } from '../__mocks__/zunstandMock'; | ||
|
||
vi.mock('zustand', async () => { | ||
const zustand = (await vi.importActual('zustand')) as object; | ||
|
||
return { | ||
__esModule: true, | ||
...zustand, | ||
}; | ||
}); | ||
|
||
vi.spyOn(zustand, 'create').mockImplementation(myCustomCreate as never); | ||
|
||
describe('useError', () => { | ||
afterEach(() => { | ||
act(() => { | ||
storeResetFns.forEach((resetFn) => { | ||
resetFn(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when initialize', () => { | ||
it('error message is empty', () => { | ||
const { result } = renderHook(() => useError((state) => state)); | ||
expect(result.current.errorMessage).toBe(''); | ||
}); | ||
}); | ||
|
||
describe('when change the error message', () => { | ||
it('changes the error message', () => { | ||
const { result } = renderHook(() => useError((state) => state)); | ||
|
||
act(() => { | ||
result.current.setErrorMessage('update error message'); | ||
}); | ||
|
||
expect(result.current.errorMessage).toBe('update error message'); | ||
}); | ||
}); | ||
}); |
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,8 @@ | ||
import { create } from 'zustand'; | ||
|
||
import { IUseError } from './useError.types'; | ||
|
||
export const useError = create<IUseError>()((set) => ({ | ||
errorMessage: '', | ||
setErrorMessage: (errorMessage) => set({ errorMessage }), | ||
})); |
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 @@ | ||
export interface IUseError { | ||
errorMessage: string; | ||
setErrorMessage: (errorMessage: string) => void; | ||
} |
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