-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from fyndiq/tooltip
New Component: Tooltip
- Loading branch information
Showing
11 changed files
with
277 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# fyndiq-component-tooltip [![npm](https://img.shields.io/npm/v/fyndiq-component-tooltip.svg?maxAge=3600)](https://www.npmjs.com/package/fyndiq-component-tooltip) | ||
|
||
[Preview](http://developers.fyndiq.com/fyndiq-ui/?selectedKind=Tooltip&selectedStory=default) | ||
|
||
A tooltip component for Fyndiq | ||
|
||
# Installation | ||
|
||
The component can be installed through NPM: | ||
|
||
``` bash | ||
npm i -S fyndiq-component-tooltip | ||
``` | ||
|
||
# Usage | ||
|
||
``` js | ||
import React from 'react' | ||
import Tooltip from 'fyndiq-component-tooltip' | ||
|
||
// Normal usage | ||
<Tooltip text="Help text">Hover me</Tooltip | ||
|
||
// Different position | ||
<Tooltip text="Top help text" position="tl"> | ||
Hover me | ||
</Tooltip> | ||
``` | ||
|
||
# API | ||
|
||
The component `Stars` has the following customizable props: | ||
|
||
| Name | Type | Description | Default value | | ||
|---|---|---|---| | ||
| **text** | String | The tooltip text | (required) | | ||
| **position** | String | The position of the tooltip (see [Dropdown's API](../fyndiq-component-dropdown#api) for possible values) | `bc` | | ||
|
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,18 @@ | ||
{ | ||
"name": "fyndiq-component-tooltip", | ||
"version": "0.0.5", | ||
"author": "Thibaut REMY <[email protected]>", | ||
"main": "lib/index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/fyndiq/fyndiq-ui.git" | ||
}, | ||
"homepage": "http://developers.fyndiq.com/fyndiq-ui/?selectedKind=Tooltip&selectedStory=default", | ||
"dependencies": { | ||
"fyndiq-component-dropdown": "^0.1.0", | ||
"fyndiq-styles-colors": "^0.0.5" | ||
}, | ||
"peerDependencies": { | ||
"react": "^0.14.0 || ^15.0.0" | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
packages/fyndiq-component-tooltip/src/__snapshots__/index.test.js.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,51 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`fyndiq-component-tooltip should be rendered without props 1`] = ` | ||
<Dropdown | ||
button={ | ||
<span> | ||
tooltip | ||
</span> | ||
} | ||
hoverMode={true} | ||
margin={5} | ||
noArrow={false} | ||
noWrapperStyle={true} | ||
opened={false} | ||
position="bc" | ||
> | ||
<div | ||
className=" | ||
tooltip | ||
position-bc | ||
" | ||
> | ||
help | ||
</div> | ||
</Dropdown> | ||
`; | ||
|
||
exports[`fyndiq-component-tooltip should have the right position 1`] = ` | ||
<Dropdown | ||
button={ | ||
<span> | ||
tooltip | ||
</span> | ||
} | ||
hoverMode={true} | ||
margin={5} | ||
noArrow={false} | ||
noWrapperStyle={true} | ||
opened={false} | ||
position="tr" | ||
> | ||
<div | ||
className=" | ||
tooltip | ||
position-tr | ||
" | ||
> | ||
help | ||
</div> | ||
</Dropdown> | ||
`; |
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 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import Dropdown from 'fyndiq-component-dropdown' | ||
|
||
import styles from '../styles.less' | ||
|
||
const Tooltip = ({ text, children, position }) => ( | ||
<Dropdown | ||
button={<span>{children}</span>} | ||
hoverMode | ||
noWrapperStyle | ||
position={position} | ||
> | ||
<div | ||
className={` | ||
${styles.tooltip} | ||
${styles['position-' + position]} | ||
`} | ||
> | ||
{text} | ||
</div> | ||
</Dropdown> | ||
) | ||
|
||
Tooltip.propTypes = { | ||
text: PropTypes.string, | ||
children: PropTypes.node, | ||
position: Dropdown.propTypes.position, | ||
} | ||
|
||
Tooltip.defaultProps = { | ||
text: '', | ||
children: '', | ||
position: 'bc', | ||
} | ||
|
||
export default Tooltip |
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 React from 'react' | ||
import { shallow } from 'enzyme' | ||
|
||
import Tooltip from './' | ||
|
||
describe('fyndiq-component-tooltip', () => { | ||
test('should be rendered without props', () => { | ||
expect(shallow(<Tooltip text="help">tooltip</Tooltip>)).toMatchSnapshot() | ||
}) | ||
|
||
test('should have the right position', () => { | ||
expect(shallow( | ||
<Tooltip text="help" position="tr">tooltip</Tooltip> | ||
)).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,85 @@ | ||
@import "~fyndiq-styles-colors/colors.less"; | ||
|
||
.tooltip { | ||
background-color: fadeout(@black, 10%); | ||
color: @white; | ||
padding: 3px 5px; | ||
border-radius: 3px; | ||
max-width: 200px; | ||
|
||
&:before { | ||
position: absolute; | ||
content: ' '; | ||
width: 0; | ||
height: 0; | ||
border-style: solid; | ||
border-width: 0 4px 4px; | ||
border-color: transparent transparent @black transparent; | ||
} | ||
|
||
&:empty { | ||
display: none; | ||
} | ||
} | ||
|
||
.position-b:before { | ||
top: -4px; | ||
border-width: 0 4px 4px; | ||
border-color: transparent transparent @black transparent; | ||
} | ||
|
||
.position-t:before { | ||
bottom: -4px; | ||
border-width: 4px 4px 0; | ||
border-color: @black transparent transparent; | ||
} | ||
|
||
.position-bl { | ||
composes: position-b; | ||
|
||
&:before { | ||
left: 10px; | ||
} | ||
} | ||
|
||
.position-bc { | ||
composes: position-b; | ||
|
||
&:before { | ||
left: 50%; | ||
transform: translateX(-50%); | ||
} | ||
} | ||
|
||
.position-br { | ||
composes: position-b; | ||
|
||
&:before { | ||
right: 10px; | ||
} | ||
} | ||
|
||
.position-tl { | ||
composes: position-t; | ||
|
||
&:before { | ||
left: 10px; | ||
} | ||
} | ||
|
||
.position-tc { | ||
composes: position-t; | ||
|
||
&:before { | ||
left: 50%; | ||
transform: translateX(-50%); | ||
} | ||
} | ||
|
||
.position-tr { | ||
composes: position-t; | ||
|
||
&:before { | ||
right: 10px; | ||
} | ||
} |
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,28 @@ | ||
import React from 'react' | ||
import { storiesOf } from '@kadira/storybook' | ||
import Tooltip from 'fyndiq-component-tooltip' | ||
|
||
storiesOf('Tooltip', module) | ||
.addWithInfo('default', () => ( | ||
<Tooltip text="info text">Hello world</Tooltip> | ||
)) | ||
.addWithInfo('long text info', () => ( | ||
<Tooltip text="Long text info, dont mind me, just checking out" position="bl">Hover me</Tooltip> | ||
)) | ||
.addWithInfo('change tooltip position', () => ( | ||
<div> | ||
<Tooltip text="tooltip" position="bl">Bottom-left</Tooltip> | ||
{' '} | ||
<Tooltip text="tooltip" position="bc">Bottom-center</Tooltip> | ||
{' '} | ||
<Tooltip text="tooltip" position="br">Bottom-right</Tooltip> | ||
|
||
<hr /> | ||
|
||
<Tooltip text="tooltip" position="tl">Top-left</Tooltip> | ||
{' '} | ||
<Tooltip text="tooltip" position="tc">Top-center</Tooltip> | ||
{' '} | ||
<Tooltip text="tooltip" position="tr">Top-right</Tooltip> | ||
</div> | ||
)) |