-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Create colour block component (#30)
Co-authored-by: Rohan Gupta <rohan.gupta@gameskraft.com> Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com> Co-authored-by: Restyled.io <commits@restyled.io>
- Loading branch information
1 parent
fc2bba7
commit 1e68b66
Showing
10 changed files
with
99 additions
and
42 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
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,21 @@ | ||
import React, { useCallback } from 'react'; | ||
import { copyTextToClipboard } from '../../../utils'; | ||
import classes from './styles.module.scss'; | ||
|
||
const ColourBlock: React.FC<ColourBlockProps> = (props) => { | ||
const { colour, className = '', style = {} } = props; | ||
|
||
const handleBlockClick = useCallback(() => { | ||
copyTextToClipboard(colour); | ||
}, [colour]); | ||
|
||
return ( | ||
<span | ||
className={`${classes.colourBlock} ${className}`} | ||
style={{ ...style, backgroundColor: colour }} | ||
onClick={handleBlockClick} | ||
/> | ||
); | ||
}; | ||
|
||
export default ColourBlock; |
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 '../../../utils/mixins.scss'; | ||
|
||
.colourBlock { | ||
@include circle (0.7rem); | ||
@include spacing ($margin: 0 0.5rem 0 0.25rem); | ||
display: inline-block; | ||
|
||
&:hover { | ||
cursor: pointer; | ||
} | ||
} |
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,20 @@ | ||
import { copyTextToClipboard } from '..'; | ||
|
||
test('copyTextToClipboard with an empty string', async () => { | ||
const isTextCopied = await copyTextToClipboard(''); | ||
expect(isTextCopied).toBeFalsy(); | ||
}); | ||
|
||
test('copyTextToClipboard with a non-empty string', async () => { | ||
try { | ||
const text = 'hello world'; | ||
const isTextCopied = await copyTextToClipboard(text); | ||
if (isTextCopied) { | ||
expect(isTextCopied).toBeTruthy(); | ||
} else { | ||
expect(isTextCopied).toBeFalsy(); | ||
} | ||
} catch (err) { | ||
expect(err).toMatch('error'); | ||
} | ||
}); |