diff --git a/src/Hint/Hint.jsx b/src/Hint/Hint.jsx new file mode 100644 index 0000000..d659f32 --- /dev/null +++ b/src/Hint/Hint.jsx @@ -0,0 +1,134 @@ +'use strict'; + +import React, { PropTypes } from 'react'; + +import View from '../View'; +import Text from '../Text'; +import { COLOR, FONT } from '../const/theme'; + +import { StyleSheet, css } from '../helpers/styles'; + +const Hint = (props) => { + const { tailPosition } = props; + return ( + + + + + {props.children} + + + + ) +} + +Hint.propTypes = { + /** + * Tail position + */ + tailPosition: PropTypes.oneOf( + [ + 'leftTop', + 'rightTop', + 'topLeft', + 'leftBottom', + 'rightBottom', + 'topRight', + 'bottomLeft', + 'bottomRight' + ] + ).isRequired +}; + +Hint.defaultProps = { + tailPosition: 'leftTop' +}; + +const STYLE = StyleSheet.create({ + hint: { + position: 'relative', + border: '1px dashed #d7d8d9', + background: COLOR.GRAY_HOVER, + overflow: 'visible', + borderRadius: '0.1rem', + padding: '.4rem' + }, + triangle: { + position: 'absolute', + width: '0.4rem', + height: '0.4rem', + background: COLOR.GRAY_HOVER + }, + triangleHorizontal: { + borderTop: 'none', + borderBottom: '1px dashed #d7d8d9', + borderLeft: '1px dashed #d7d8d9', + borderRight: 'none' + }, + triangleVertical: { + borderTop: '1px dashed #d7d8d9', + borderBottom: 'none', + borderLeft: 'none', + borderRight: '1px dashed #d7d8d9' + }, + leftTop: { + transform: 'rotate(45deg)', + left: '-4px', + top: '6px' + }, + rightTop: { + transform: 'rotate(225deg)', + right: '-4px', + top: '6px' + }, + topLeft: { + transform: 'rotate(-45deg)', + left: '6px', + top: '-4px' + }, + topRight: { + transform: 'rotate(-45deg)', + right: '6px', + top: '-4px' + }, + leftBottom: { + transform: 'rotate(45deg)', + left: '-4px', + bottom: '6px' + }, + rightBottom: { + transform: 'rotate(225deg)', + right: '-4px', + bottom: '6px' + }, + bottomLeft: { + transform: 'rotate(135deg)', + left: '6px', + bottom: '-4px' + }, + bottomRight: { + transform: 'rotate(135deg)', + right: '6px', + bottom: '-4px' + }, + textBox: { + flex: 1, + zIndex: 10, + overflow: 'hidden' + }, + hintText: { + color: COLOR.SUB_TEXT, + overflow: 'hidden', + fontSize: FONT.SIZE_SUB_TEXT, + lineHeight: '.95rem' + } +}); + +export default Hint; diff --git a/src/Hint/Hint.md b/src/Hint/Hint.md new file mode 100644 index 0000000..9cbd3ce --- /dev/null +++ b/src/Hint/Hint.md @@ -0,0 +1,34 @@ +### Usage + +```js +import Hint from '@roistat/ui/lib/Hint'; +``` + +const View = require('../View').default; +const StateProvider = require('../StateProvider').default; + +*Hint* + + + tailPosition: + setState({ tailPosition: document.getElementById("tailPosition").options[document.getElementById("tailPosition").selectedIndex].value })}> + leftTop + rightTop + topLeft + topRight + leftBottom + rightBottom + bottomLeft + bottomRight + + Hint + + +*Hint, showed on hover* + + + setState({ isHovered: true })} onMouseLeave={() => setState({ isHovered: false })}> + Button + + { state.isHovered && Hint } + diff --git a/src/Hint/index.js b/src/Hint/index.js new file mode 100644 index 0000000..0f50375 --- /dev/null +++ b/src/Hint/index.js @@ -0,0 +1 @@ +export { default } from './Hint'; diff --git a/src/Hint/story.jsx b/src/Hint/story.jsx new file mode 100644 index 0000000..e27dea5 --- /dev/null +++ b/src/Hint/story.jsx @@ -0,0 +1,45 @@ +import React from 'react'; +import { storiesOf, action } from '@kadira/storybook'; +import Hint from './Hint'; +import View from '../View'; +import StateProvider from '../StateProvider'; + +storiesOf('Hint', module) + + .add('Hint', () => ( + + + {(state, setState) => ( + + tailPosition: + setState({ tailPosition: document.getElementById("tailPosition").options[document.getElementById("tailPosition").selectedIndex].value })}> + leftTop + rightTop + topLeft + topRight + leftBottom + rightBottom + bottomLeft + bottomRight + + Hint + + )} + + + )) + + .add('Hint, showed on hover', () => ( + + + {(state, setState) => ( + + setState({ isHovered: true })} onMouseLeave={() => setState({ isHovered: false })}> + Button + + { state.isHovered && Hint } + + )} + + + ));