This repository has been archived by the owner on Sep 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
63 changed files
with
25,116 additions
and
10,570 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 |
---|---|---|
|
@@ -5,3 +5,4 @@ node_modules | |
.npm | ||
/coverage | ||
.DS_Store | ||
yarn-error.log |
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,150 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { calculateStyles, parseColor } from '../lib/utils'; | ||
import { darkPopover } from '../style/color'; | ||
import { borderRadius } from '../style/border'; | ||
import { tooltip as tooltipZIndex } from '../style/zIndex'; | ||
|
||
import Text from '../Text'; | ||
|
||
const arrowHeight = 14; | ||
const arrowWidth = 8; | ||
|
||
const ArrowPopover = ({ | ||
children, | ||
visible, | ||
offset, | ||
oneLine, | ||
position, | ||
padded, | ||
color, | ||
backgroundColor, | ||
shadow, | ||
width, | ||
isTooltip, | ||
id, | ||
}) => { | ||
const offsetTop = position === 'above' ? -offset.top : offset.top; | ||
const style = calculateStyles({ | ||
default: { | ||
transform: `translate(${arrowWidth + offset.left}px, ${offsetTop}px)`, | ||
background: parseColor(backgroundColor), | ||
color: parseColor(color), | ||
display: 'inline-block', | ||
borderRadius, | ||
boxShadow: shadow ? '0 1px 2px 0 rgba(0,0,0,0.50)' : 'none', | ||
textAlign: 'left', | ||
position: 'absolute', | ||
left: '100%', | ||
zIndex: tooltipZIndex, | ||
}, | ||
hidden: { | ||
display: 'none', | ||
}, | ||
oneLine: { | ||
whiteSpace: 'nowrap', | ||
}, | ||
positionAbove: { | ||
bottom: 0, | ||
}, | ||
positionBelow: { | ||
top: 0, | ||
}, | ||
padded: { | ||
padding: '.25rem .75rem', | ||
}, | ||
fixedWidth: { | ||
width, | ||
}, | ||
}, { | ||
hidden: !visible, | ||
positionAbove: position === 'above', | ||
positionBelow: position === 'below', | ||
oneLine: oneLine && width === 'none', | ||
padded, | ||
fixedWidth: width !== 'none', | ||
}); | ||
|
||
const arrowStyle = calculateStyles({ | ||
default: { | ||
position: 'absolute', | ||
left: -arrowWidth, | ||
width: 0, | ||
height: 0, | ||
backgroundColor: 'transparent', | ||
borderStyle: 'solid', | ||
borderTopWidth: arrowHeight / 2.0, | ||
borderRightWidth: arrowWidth, | ||
borderBottomWidth: arrowHeight / 2.0, | ||
borderLeftWidth: 0, | ||
borderTopColor: 'transparent', | ||
borderRightColor: backgroundColor, | ||
borderBottomColor: 'transparent', | ||
borderLeftColor: 'transparent', | ||
}, | ||
positionNormal: { | ||
top: '50%', | ||
transform: 'translate(0, -50%)', | ||
}, | ||
positionAbove: { | ||
top: 'none', | ||
bottom: '6px', | ||
transform: 'none', | ||
}, | ||
positionBelow: { | ||
top: '6px', | ||
transform: 'none', | ||
}, | ||
}, { | ||
positionNormal: true, | ||
positionAbove: position === 'above', | ||
positionBelow: position === 'below', | ||
}); | ||
|
||
const aria = isTooltip ? { | ||
role: 'tooltip', | ||
'aria-hidden': !visible, | ||
} : {}; | ||
|
||
return ( | ||
<div style={style} id={id} {...aria}> | ||
<span style={arrowStyle} /> | ||
<Text color={color} size="small">{children}</Text> | ||
</div> | ||
); | ||
}; | ||
|
||
ArrowPopover.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
visible: PropTypes.bool, | ||
oneLine: PropTypes.bool, | ||
offset: PropTypes.shape({ | ||
top: PropTypes.number, | ||
left: PropTypes.number, | ||
}), | ||
position: PropTypes.oneOf(['above', 'below', 'none']), | ||
padded: PropTypes.bool, | ||
color: PropTypes.string, | ||
backgroundColor: PropTypes.string, | ||
shadow: PropTypes.bool, | ||
width: PropTypes.string, | ||
isTooltip: PropTypes.bool, | ||
id: PropTypes.string, | ||
}; | ||
|
||
ArrowPopover.defaultProps = { | ||
visible: false, | ||
oneLine: true, | ||
offset: { left: 0, top: 0 }, | ||
position: 'none', | ||
padded: true, | ||
color: 'white', | ||
backgroundColor: darkPopover, | ||
shadow: false, | ||
width: 'none', | ||
isTooltip: false, | ||
id: '', | ||
}; | ||
|
||
export default ArrowPopover; |
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,40 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
import { checkA11y } from 'storybook-addon-a11y'; | ||
import ArrowPopover from './index'; | ||
import Text from '../Text'; | ||
|
||
storiesOf('ArrowPopover') | ||
.addDecorator(checkA11y) | ||
.add('default tooltip', () => ( | ||
<div style={{ display: 'inline-block', margin: '5rem', position: 'relative', overflow: 'visible' }}> | ||
<Text>I have a Popover tooltip!</Text> | ||
<ArrowPopover visible shadow> | ||
This is a simple tooltip style Popover! | ||
</ArrowPopover> | ||
</div> | ||
)) | ||
.add('larger popover: below', () => ( | ||
<div style={{ display: 'inline-block', margin: '5rem', position: 'relative', overflow: 'visible' }}> | ||
<Text>I have a Popover!</Text> | ||
<ArrowPopover visible oneLine={false} width="300px" position="below"> | ||
<div style={{ padding: '.5rem .25rem' }}> | ||
Your posting schedule tells Buffer when to send out posts in your Queue (under the Content tab).<br /><br /> | ||
For example, the next 10 posts you add to your Queue will go out in the next 10 upcoming time/date slots you decide below. <br /><br /> | ||
You can change this schedule at any time! | ||
</div> | ||
</ArrowPopover> | ||
</div> | ||
)) | ||
.add('larger popover: above', () => ( | ||
<div style={{ display: 'inline-block', margin: '5rem', position: 'relative', overflow: 'visible' }}> | ||
<Text>I have a Popover!</Text> | ||
<ArrowPopover visible position="above" shadow> | ||
<div style={{ padding: ' .5rem .25rem' }}> | ||
Look at me!<br /> | ||
I'm so far above the rest! ✈️<br /> | ||
Later! ✌️ | ||
</div> | ||
</ArrowPopover> | ||
</div> | ||
)); |
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
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
Oops, something went wrong.