-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
68 changed files
with
2,326 additions
and
239 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
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,6 @@ | ||
import hook from 'css-modules-require-hook'; | ||
|
||
// Support for CSS modules | ||
hook({ | ||
generateScopedName: '[name]__[local]___[hash:base64:5]', | ||
}); |
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 @@ | ||
import { Window } from 'happy-dom'; | ||
|
||
// Setup happy-dom | ||
const window = new Window(); | ||
global.window = window; | ||
|
||
// Register global window extensions | ||
[ | ||
'document', | ||
'Element', | ||
'getComputedStyle', | ||
'HTMLElement', | ||
'SVGElement' | ||
].forEach((key) => { | ||
global[key] = global.window[key]; | ||
}); |
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 {cleanup} from '@testing-library/react'; | ||
|
||
const withAsyncAndTeardown = (test) => { | ||
return async (t) => { | ||
t.teardown(cleanup); | ||
await test(t); | ||
t.end(); | ||
}; | ||
} | ||
|
||
export default withAsyncAndTeardown; |
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,30 @@ | ||
{ | ||
"name": "tape", | ||
"version": "0.2.0", | ||
"description": "", | ||
"scripts": { | ||
"test": "TZ=UTC ts-node --esm -P tsconfig.json ../../node_modules/.bin/tape -r ./helpers/css.ts -r ./helpers/happydom.ts tests/**/*.test.tsx" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@blueprintjs/icons": "4.16.0", | ||
"@floating-ui/react-dom-interactions": "0.10.3", | ||
"clsx": "2.1.0", | ||
"date-fns": "2.29.3", | ||
"framer-motion": "7.5.3", | ||
"react": "18.2.0", | ||
"react-dom": "18.2.0" | ||
}, | ||
"devDependencies": { | ||
"@testing-library/react": "14.2.1", | ||
"@testing-library/user-event": "14.5.2", | ||
"css-modules-require-hook": "4.2.3", | ||
"happy-dom": "13.6.2", | ||
"sinon": "17.0.1", | ||
"tape": "5.7.5", | ||
"tape-describe": "1.0.3", | ||
"ts-node": "10.9.2", | ||
"typescript": "5.3.3" | ||
} | ||
} |
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 @@ | ||
replica* |
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 @@ | ||
.main { | ||
border: 1px solid transparent; | ||
border-radius: 8px; | ||
display: flex; | ||
font-size: 14px; | ||
padding: 16px; | ||
} | ||
|
||
.error { | ||
background: var(--R50); | ||
border-color: var(--R400); | ||
color: var(--R400); | ||
} | ||
|
||
/* stylelint-disable-next-line selector-max-type, selector-max-combinators */ | ||
.error a, .error strong { color: inherit } | ||
|
||
.info { | ||
background: var(--N50); | ||
border-color: var(--N400); | ||
color: var(--N400); | ||
} | ||
|
||
/* stylelint-disable-next-line selector-max-type, selector-max-combinators */ | ||
.info a, .info strong { color: inherit } | ||
|
||
.success { | ||
background: var(--G50); | ||
border-color: var(--G400); | ||
color: var(--G400); | ||
} | ||
|
||
/* stylelint-disable-next-line selector-max-type, selector-max-combinators */ | ||
.success a, .success strong { color: inherit } | ||
|
||
.warning { | ||
background: var(--Y50); | ||
border-color: var(--Y400); | ||
color: var(--Y500); | ||
} | ||
|
||
/* stylelint-disable-next-line selector-max-type, selector-max-combinators */ | ||
.warning a, .warning strong { color: inherit } | ||
|
||
.icon { | ||
margin-right: 16px; | ||
} | ||
|
||
.title { | ||
color: inherit; | ||
font-weight: bold; | ||
margin: 0 0 8px; | ||
} | ||
|
||
.text { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.children { color: var(--COLOR-GRAY-800) } |
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,28 @@ | ||
import describe from 'tape-describe'; | ||
import Alert from '.'; | ||
import React from 'react'; | ||
import {render} from '@testing-library/react'; | ||
import withAsyncAndTeardown from '../../../helpers/wrapper'; | ||
|
||
describe('<Alert />', (test) => { | ||
test('should render the given message', withAsyncAndTeardown((t) => { | ||
const {getByText} = render(<Alert>Hello World</Alert>); | ||
t.ok(getByText('Hello World')); | ||
})); | ||
|
||
test('should render with only a title', withAsyncAndTeardown((t) => { | ||
const {getByText} = render(<Alert title='Hello World' />); | ||
t.ok(getByText('Hello World')); | ||
})); | ||
|
||
test('should support all the different icons', withAsyncAndTeardown((t) => { | ||
const {getByLabelText, rerender} = render(<Alert intent='warning' />); | ||
t.ok(getByLabelText('warning-sign')); | ||
|
||
rerender(<Alert intent='info' />) | ||
t.ok(getByLabelText('info-sign')); | ||
|
||
rerender(<Alert intent='success' />) | ||
t.ok(getByLabelText('tick-circle')); | ||
})); | ||
}); |
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,48 @@ | ||
import Icon, {IconNames} from '../Icon'; | ||
import clsx from 'clsx'; | ||
import React from 'react'; | ||
import styles from './Alert.module.css'; | ||
|
||
type IntentType = 'error' | 'info' | 'success' | 'warning'; | ||
|
||
type PropsType = { | ||
className?: string | null, | ||
children?: React.ReactNode, | ||
intent?: IntentType, | ||
title?: string | null, | ||
} | ||
|
||
const getIcon = (intent: IntentType) => { | ||
switch (intent) { | ||
case 'info': return IconNames.InfoSign; | ||
case 'success': return IconNames.TickCircle; | ||
case 'warning': return IconNames.WarningSign; | ||
case 'error': return IconNames.Error; | ||
} | ||
return IconNames.Error; | ||
}; | ||
|
||
const Alert = ({ | ||
className, | ||
children, | ||
intent = 'error', | ||
title, | ||
}: PropsType) => { | ||
const classes = clsx(styles.main, styles[intent], className); | ||
|
||
return ( | ||
<div className={classes} role='alert'> | ||
<Icon | ||
className={styles.icon} | ||
name={getIcon(intent)} /> | ||
<div className={styles.text}> | ||
{title ? <h4 className={styles.title}>{title}</h4> : null} | ||
{children ? ( | ||
<div className={styles.children}>{children}</div> | ||
) : null} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Alert; |
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 @@ | ||
export {default} from './Alert'; |
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,9 @@ | ||
.main { | ||
align-items: center; | ||
border-radius: 100%; | ||
display: inline-flex; | ||
font-size: 15px; | ||
height: 40px; | ||
justify-content: center; | ||
width: 40px; | ||
} |
Oops, something went wrong.