-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moves IconWithTooltip to atoms/ and adds tests
- Loading branch information
1 parent
5528292
commit 995f38d
Showing
9 changed files
with
867 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import * as React from 'react'; | ||
import IconWithTooltip from './IconWithTooltip'; | ||
import TestIcon from '@material-ui/icons/Help'; | ||
import { create } from 'react-test-renderer'; | ||
|
||
describe('IconWithTooltip', () => { | ||
it('renders without height or weight', () => { | ||
const tree = create( | ||
<IconWithTooltip Icon={TestIcon} iconColor='green' tooltip='test icon tooltip' /> | ||
); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders with height and weight', () => { | ||
const tree = create( | ||
<IconWithTooltip Icon={TestIcon} height={20} width={20} iconColor='green' | ||
tooltip='test icon tooltip' /> | ||
); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
}); |
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 @@ | ||
/* | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import * as React from 'react'; | ||
import Tooltip from '@material-ui/core/Tooltip'; | ||
import { SvgIconProps } from '@material-ui/core/SvgIcon'; | ||
|
||
interface IconWithTooltipProps { | ||
Icon: React.ComponentType<SvgIconProps>; | ||
height?: number; | ||
iconColor: string; | ||
tooltip: string; | ||
width?: number; | ||
} | ||
|
||
export default (props: IconWithTooltipProps) => { | ||
const { height, Icon, iconColor, tooltip, width } = props; | ||
|
||
return ( | ||
<Tooltip title={tooltip}> | ||
<Icon style={{ | ||
color: iconColor, | ||
height: height || 16, | ||
width: width || 16 | ||
}}/> | ||
</Tooltip> | ||
); | ||
}; |
69 changes: 69 additions & 0 deletions
69
frontend/src/atoms/__snapshots__/IconWithTooltip.test.tsx.snap
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,69 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`IconWithTooltip renders with height and weight 1`] = ` | ||
<svg | ||
aria-describedby={null} | ||
aria-hidden="true" | ||
className="MuiSvgIcon-root-9" | ||
color={undefined} | ||
focusable="false" | ||
onBlur={[Function]} | ||
onFocus={[Function]} | ||
onMouseLeave={[Function]} | ||
onMouseOver={[Function]} | ||
onTouchEnd={[Function]} | ||
onTouchStart={[Function]} | ||
role="presentation" | ||
style={ | ||
Object { | ||
"color": "green", | ||
"height": 20, | ||
"width": 20, | ||
} | ||
} | ||
title="test icon tooltip" | ||
viewBox="0 0 24 24" | ||
> | ||
<path | ||
d="M0 0h24v24H0z" | ||
fill="none" | ||
/> | ||
<path | ||
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 17h-2v-2h2v2zm2.07-7.75l-.9.92C13.45 12.9 13 13.5 13 15h-2v-.5c0-1.1.45-2.1 1.17-2.83l1.24-1.26c.37-.36.59-.86.59-1.41 0-1.1-.9-2-2-2s-2 .9-2 2H8c0-2.21 1.79-4 4-4s4 1.79 4 4c0 .88-.36 1.68-.93 2.25z" | ||
/> | ||
</svg> | ||
`; | ||
|
||
exports[`IconWithTooltip renders without height or weight 1`] = ` | ||
<svg | ||
aria-describedby={null} | ||
aria-hidden="true" | ||
className="MuiSvgIcon-root-9" | ||
color={undefined} | ||
focusable="false" | ||
onBlur={[Function]} | ||
onFocus={[Function]} | ||
onMouseLeave={[Function]} | ||
onMouseOver={[Function]} | ||
onTouchEnd={[Function]} | ||
onTouchStart={[Function]} | ||
role="presentation" | ||
style={ | ||
Object { | ||
"color": "green", | ||
"height": 16, | ||
"width": 16, | ||
} | ||
} | ||
title="test icon tooltip" | ||
viewBox="0 0 24 24" | ||
> | ||
<path | ||
d="M0 0h24v24H0z" | ||
fill="none" | ||
/> | ||
<path | ||
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 17h-2v-2h2v2zm2.07-7.75l-.9.92C13.45 12.9 13 13.5 13 15h-2v-.5c0-1.1.45-2.1 1.17-2.83l1.24-1.26c.37-.36.59-.86.59-1.41 0-1.1-.9-2-2-2s-2 .9-2 2H8c0-2.21 1.79-4 4-4s4 1.79 4 4c0 .88-.36 1.68-.93 2.25z" | ||
/> | ||
</svg> | ||
`; |
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
Oops, something went wrong.