Skip to content

Commit

Permalink
Merge pull request #9 from fyndiq/tooltip
Browse files Browse the repository at this point in the history
New Component: Tooltip
  • Loading branch information
thibautRe authored May 26, 2017
2 parents ec5df0e + 5aa5748 commit 2b7020f
Show file tree
Hide file tree
Showing 11 changed files with 277 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ This git repository is a monorepo built using [Lerna](//lernajs.io). It contains
| [`fyndiq-component-price`](/packages/fyndiq-component-price) | [![npm](https://img.shields.io/npm/v/fyndiq-component-price.svg?maxAge=3600)](https://www.npmjs.com/package/fyndiq-component-price) | Price tag component |
| [`fyndiq-component-productcard`](/packages/fyndiq-component-productcard) | [![npm](https://img.shields.io/npm/v/fyndiq-component-productcard.svg?maxAge=3600)](https://www.npmjs.com/package/fyndiq-component-productcard) | Product card component |
| [`fyndiq-component-stars`](/packages/fyndiq-component-stars) | [![npm](https://img.shields.io/npm/v/fyndiq-component-stars.svg?maxAge=3600)](https://www.npmjs.com/package/fyndiq-component-stars) | Stars component |
| [`fyndiq-component-tooltip`](/packages/fyndiq-component-tooltip) | [![npm](https://img.shields.io/npm/v/fyndiq-component-tooltip.svg?maxAge=3600)](https://www.npmjs.com/package/fyndiq-component-tooltip) | Tooltip component |
| [`fyndiq-icon-arrow`](/packages/fyndiq-icon-arrow) | [![npm](https://img.shields.io/npm/v/fyndiq-icon-arrow.svg?maxAge=3600)](https://www.npmjs.com/package/fyndiq-icon-arrow) | Arrow icon |
| [`fyndiq-icon-brand`](/packages/fyndiq-icon-brand) | [![npm](https://img.shields.io/npm/v/fyndiq-icon-brand.svg?maxAge=3600)](https://www.npmjs.com/package/fyndiq-icon-brand) | Brand icon |
| [`fyndiq-icon-checkmark`](/packages/fyndiq-icon-checkmark) | [![npm](https://img.shields.io/npm/v/fyndiq-icon-checkmark.svg?maxAge=3600)](https://www.npmjs.com/package/fyndiq-icon-checkmark) | Checkmark icon |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.10.3",
"file-loader": "^0.10.1",
"jest": "^19.0.2",
"jest": "^20.0.0",
"lerna": "2.0.0-beta.38",
"react": "^15.4.2",
"react-dom": "^15.4.2",
Expand Down
38 changes: 38 additions & 0 deletions packages/fyndiq-component-tooltip/README.md
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` |

18 changes: 18 additions & 0 deletions packages/fyndiq-component-tooltip/package.json
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"
}
}
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>
`;
37 changes: 37 additions & 0 deletions packages/fyndiq-component-tooltip/src/index.js
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
16 changes: 16 additions & 0 deletions packages/fyndiq-component-tooltip/src/index.test.js
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()
})
})
85 changes: 85 additions & 0 deletions packages/fyndiq-component-tooltip/styles.less
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;
}
}
1 change: 1 addition & 0 deletions packages/fyndiq-ui-test/.storybook/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function loadStories() {
/* eslint-disable global-require */
require('../stories/component-button')
require('../stories/component-dropdown')
require('../stories/component-tooltip')
require('../stories/component-checkbox')
require('../stories/component-stars')
require('../stories/component-price')
Expand Down
1 change: 1 addition & 0 deletions packages/fyndiq-ui-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"fyndiq-component-checkbox": "^0.1.1",
"fyndiq-component-stars": "^0.1.1",
"fyndiq-component-dropdown": "^0.1.1",
"fyndiq-component-tooltip": "*",
"fyndiq-icon-brand": "^0.1.1",
"fyndiq-icon-loader": "^0.1.1",
"fyndiq-styles-fonts": "^0.1.1"
Expand Down
28 changes: 28 additions & 0 deletions packages/fyndiq-ui-test/stories/component-tooltip.js
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>
))

0 comments on commit 2b7020f

Please sign in to comment.