-
Notifications
You must be signed in to change notification settings - Fork 5
Hint #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Kanonir87
wants to merge
8
commits into
roistat:master
Choose a base branch
from
Kanonir87:Hint
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Hint #41
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0535bf8
Hint
9c47a63
Hint
7540045
Hint
5a0d8e2
Update Hint.jsx
Kanonir87 31e44cc
Update story.jsx
Kanonir87 9aa56c6
Update Hint.md
Kanonir87 334857d
Update Hint.jsx
Kanonir87 80ed846
Update Hint.jsx
Kanonir87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,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 ( | ||
| <View styles={[STYLE.hint, ...(props.styles || {})]} > | ||
| <View | ||
| styles={[ | ||
| STYLE.triangle, | ||
| (['leftTop', 'rightTop', 'leftBottom', 'rightBottom'].indexOf(tailPosition) != -1) && STYLE.triangleHorizontal, | ||
| (['topLeft', 'topRight', 'bottomLeft', 'bottomRight'].indexOf(tailPosition) != -1) && STYLE.triangleVertical, | ||
| STYLE.getPreset(tailPosition, '') | ||
| ]} | ||
| /> | ||
| <View className={css(STYLE.textBox)}> | ||
| <Text className={css(STYLE.hintText)}> | ||
| {props.children} | ||
| </Text> | ||
| </View> | ||
| </View> | ||
| ) | ||
| } | ||
|
|
||
| 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; |
This file contains hidden or 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,34 @@ | ||
| ### Usage | ||
|
|
||
| ```js | ||
| import Hint from '@roistat/ui/lib/Hint'; | ||
| ``` | ||
|
|
||
| const View = require('../View').default; | ||
| const StateProvider = require('../StateProvider').default; | ||
|
|
||
| *Hint* | ||
|
|
||
| <View> | ||
| <div>tailPosition:</div> | ||
| <select id='tailPosition' style={{marginBottom:15+'px'}} onChange={() => setState({ tailPosition: document.getElementById("tailPosition").options[document.getElementById("tailPosition").selectedIndex].value })}> | ||
| <option value="leftTop">leftTop</option> | ||
| <option value="rightTop">rightTop</option> | ||
| <option value="topLeft">topLeft</option> | ||
| <option value="topRight">topRight</option> | ||
| <option value="leftBottom">leftBottom</option> | ||
| <option value="rightBottom">rightBottom</option> | ||
| <option value="bottomLeft">bottomLeft</option> | ||
| <option value="bottomRight">bottomRight</option> | ||
| </select> | ||
| <Hint tailPosition={state.tailPosition}>Hint</Hint> | ||
| </View> | ||
|
|
||
| *Hint, showed on hover* | ||
|
|
||
| <View> | ||
| <button onMouseEnter={() => setState({ isHovered: true })} onMouseLeave={() => setState({ isHovered: false })}> | ||
| Button | ||
| </button> | ||
| { state.isHovered && <Hint tailPosition={'topLeft'} style={{marginTop:5+'px'}}>Hint</Hint> } | ||
| </View> | ||
This file contains hidden or 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 './Hint'; |
This file contains hidden or 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,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', () => ( | ||
| <View> | ||
| <StateProvider> | ||
| {(state, setState) => ( | ||
| <div> | ||
| <div>tailPosition:</div> | ||
| <select id='tailPosition' style={{marginBottom:15+'px'}} onChange={() => setState({ tailPosition: document.getElementById("tailPosition").options[document.getElementById("tailPosition").selectedIndex].value })}> | ||
| <option value="leftTop">leftTop</option> | ||
| <option value="rightTop">rightTop</option> | ||
| <option value="topLeft">topLeft</option> | ||
| <option value="topRight">topRight</option> | ||
| <option value="leftBottom">leftBottom</option> | ||
| <option value="rightBottom">rightBottom</option> | ||
| <option value="bottomLeft">bottomLeft</option> | ||
| <option value="bottomRight">bottomRight</option> | ||
| </select> | ||
| <Hint tailPosition={state.tailPosition}>Hint</Hint> | ||
| </div> | ||
| )} | ||
| </StateProvider> | ||
| </View> | ||
| )) | ||
|
|
||
| .add('Hint, showed on hover', () => ( | ||
| <View> | ||
| <StateProvider> | ||
| {(state, setState) => ( | ||
| <div> | ||
| <button onMouseEnter={() => setState({ isHovered: true })} onMouseLeave={() => setState({ isHovered: false })}> | ||
| Button | ||
| </button> | ||
| { state.isHovered && <Hint tailPosition={'topLeft'} style={{marginTop:5+'px'}}>Hint</Hint> } | ||
| </div> | ||
| )} | ||
| </StateProvider> | ||
| </View> | ||
| )); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше сделать нативный селект с возможными позициями и в зависимости от выбора менять tailPosition
Это будет один хороший пример демонстрирующий все возможные подсказки