-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/improves screen components (#8)
* Adds word button component * Disables import/order eslint rule * Adds ScreenText component * Modifies Screen component and moves it to organisms
- Loading branch information
Showing
20 changed files
with
1,347 additions
and
154 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Word from "./index"; | ||
|
||
const Template = (props) => <Word {...props} />; | ||
|
||
export const Default = Template.bind({}); | ||
export const NotActive = () => <Word word="Plane" />; | ||
export const Active = () => <Word word="Plane" active />; | ||
|
||
export default { | ||
title: "Atoms/Word", | ||
}; |
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,14 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import Word from "./index"; | ||
|
||
describe("Word", () => { | ||
it("renders without crash", () => { | ||
render(<Word word="apple" />); | ||
}); | ||
|
||
it("renders the given word", () => { | ||
const word = "apple"; | ||
render(<Word word={word} />); | ||
expect(screen.getByText(word)).toBeTruthy(); | ||
}); | ||
}); |
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,62 @@ | ||
/** | ||
* Core dependencies | ||
*/ | ||
import PropTypes from "prop-types"; | ||
|
||
/** | ||
* UI components | ||
*/ | ||
import { ButtonBase, createStyles, makeStyles } from "@material-ui/core"; | ||
|
||
const useStyles = makeStyles((theme) => | ||
createStyles({ | ||
root: (active) => ({ | ||
textAlign: "left", | ||
verticalAlign: "top", | ||
textDecoration: active ? "underline" : "inherit", | ||
wordWrap: "break-word", | ||
display: "inline !important", | ||
fontWeight: 700, | ||
}), | ||
focusVisible: { | ||
border: "1px solid red", | ||
borderColor: theme.palette.primary.dark, | ||
}, | ||
}) | ||
); | ||
|
||
/** | ||
* Button component used to render attention on the given word | ||
*/ | ||
const Word = ({ word, active }) => { | ||
const classes = useStyles(active); | ||
|
||
return ( | ||
<ButtonBase | ||
component="span" | ||
classes={{ | ||
root: classes.root, | ||
focusVisible: classes.focusVisible, | ||
}} | ||
> | ||
{word} | ||
</ButtonBase> | ||
); | ||
}; | ||
|
||
Word.propTypes = { | ||
/** | ||
Word that will be printed on the button | ||
*/ | ||
word: PropTypes.string.isRequired, | ||
/** | ||
If true, it will render a decoration | ||
*/ | ||
active: PropTypes.bool, | ||
}; | ||
|
||
Word.defaultProps = { | ||
active: false, | ||
}; | ||
|
||
export default Word; |
2 changes: 1 addition & 1 deletion
2
frontend/src/components/layouts/MainLayout/MainLayout.stories.jsx
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
31 changes: 0 additions & 31 deletions
31
frontend/src/components/molecules/Screen/Screen.stories.jsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
frontend/src/components/molecules/ScreenText/ScreenText.stories.jsx
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,23 @@ | ||
import ScreenText from "./index"; | ||
import getWord from "../../../utils/getWord"; | ||
|
||
const Template = (props) => <ScreenText {...props} />; | ||
|
||
const appleWord = getWord("345", 0, "Apple"); | ||
const bananaWord = getWord("543", 0, "Banana"); | ||
const melonWord = getWord("645", 0, "Melon"); | ||
const pineAppleWord = getWord("6745564", 0, "Pineapple"); | ||
const emptySpace = getWord("0", 0, " "); | ||
const fruits = [appleWord, emptySpace, bananaWord, emptySpace, melonWord]; | ||
|
||
export const Default = Template.bind({}); | ||
|
||
export const WithText = () => <ScreenText words={fruits} />; | ||
|
||
export const WithActiveWord = () => ( | ||
<ScreenText words={fruits} activeWord={pineAppleWord} /> | ||
); | ||
|
||
export default { | ||
title: "Molecules/ScreenText", | ||
}; |
50 changes: 50 additions & 0 deletions
50
frontend/src/components/molecules/ScreenText/ScreenText.test.jsx
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,50 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { ThemeProvider } from "@material-ui/core/styles"; | ||
import darkTheme from "../../../themes/darkTheme"; | ||
import ScreenText from "./index"; | ||
import getWord from "../../../utils/getWord"; | ||
|
||
describe("ScreenText", () => { | ||
beforeAll(() => { | ||
window.HTMLElement.prototype.scrollIntoView = jest.fn(); | ||
}); | ||
|
||
it("renders without crash", () => { | ||
render( | ||
<ThemeProvider theme={darkTheme}> | ||
<ScreenText /> | ||
</ThemeProvider> | ||
); | ||
}); | ||
|
||
it("renders all words", () => { | ||
const words = [getWord("4545", 0, "apple"), getWord("45455", 0, "applex")]; | ||
render( | ||
<ThemeProvider theme={darkTheme}> | ||
<ScreenText words={words} /> | ||
</ThemeProvider> | ||
); | ||
words.forEach((word) => expect(screen.getByText(word.chosen)).toBeTruthy()); | ||
}); | ||
|
||
it("renders active word", () => { | ||
const words = [getWord("4545", 0, "apple"), getWord("45455", 0, "applex")]; | ||
const activeWord = getWord("777", 3, "active"); | ||
render( | ||
<ThemeProvider theme={darkTheme}> | ||
<ScreenText words={words} activeWord={activeWord} /> | ||
</ThemeProvider> | ||
); | ||
expect(screen.getByText(activeWord.chosen)).toBeTruthy(); | ||
}); | ||
|
||
it("renders last word as active if active word is not present", () => { | ||
const words = [getWord("4545", 0, "apple"), getWord("45455", 1, "applex")]; | ||
render( | ||
<ThemeProvider theme={darkTheme}> | ||
<ScreenText words={words} /> | ||
</ThemeProvider> | ||
); | ||
expect(screen.getByText(words[words.length - 1].chosen)).toBeTruthy(); | ||
}); | ||
}); |
Oops, something went wrong.