This repository has been archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
feat(Popup): add pointing
prop
#1198
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e620c1e
feat(Popup): add `pointing` prop
layershifter bc05e57
Merge branches 'feat/popup-pointing' and 'master' of https://github.c…
layershifter 89e267e
simplify styles
layershifter 7c2811f
polish styles
layershifter 9cf8eef
Merge branches 'feat/popup-pointing' and 'master' of https://github.c…
layershifter 7a3439f
wip
layershifter 35761cf
rework variables and fix RTL
layershifter 58f4fe0
fix UTs
layershifter 42068f8
Merge branches 'feat/popup-pointing' and 'master' of https://github.c…
layershifter 5d9a56b
add changelog entry
layershifter 5f603c5
rework styles
layershifter 9a933e2
remove cruft variables
layershifter 827fc97
remove cruft, add breaking change for colors
layershifter ba949d5
reduce to `pointerSize`
layershifter bba2d9e
wip2
layershifter 6473751
Merge branch 'master' of https://github.com/stardust-ui/react into fe…
layershifter 6be1f24
rework border
layershifter 2cacc2b
replace padding with margin
layershifter e89fc09
fix backrground
layershifter c504a33
Merge branches 'feat/popup-pointing' and 'master' of https://github.c…
layershifter 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 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
57 changes: 57 additions & 0 deletions
57
docs/src/examples/components/Popup/Types/PopupExamplePointing.shorthand.tsx
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,57 @@ | ||
import * as React from 'react' | ||
import { Button, Grid, Popup } from '@stardust-ui/react' | ||
|
||
const PopupWithButton = props => ( | ||
<Popup | ||
align={props.align} | ||
content={{ | ||
content: ( | ||
<> | ||
<p>A popup with a pointer.</p> | ||
<p> | ||
Is aligned to <code>{props.align}</code>. | ||
</p> | ||
</> | ||
), | ||
}} | ||
pointing | ||
position={props.position} | ||
trigger={ | ||
<Button | ||
icon={props.icon} | ||
styles={{ padding: props.padding, height: '38px', minWidth: '64px' }} | ||
/> | ||
} | ||
/> | ||
) | ||
|
||
const triggers = [ | ||
{ position: 'above', align: 'start', icon: 'arrow circle up', padding: '5px 42px 18px 5px' }, | ||
{ position: 'above', align: 'center', icon: 'arrow circle up', padding: '5px 5px 18px 5px' }, | ||
{ position: 'above', align: 'end', icon: 'arrow circle up', padding: '5px 5px 18px 42px' }, | ||
{ position: 'below', align: 'start', icon: 'arrow circle down', padding: '18px 42px 5px 5px' }, | ||
{ position: 'below', align: 'center', icon: 'arrow circle down', padding: '18px 5px 5px 5px' }, | ||
{ position: 'below', align: 'end', icon: 'arrow circle down', padding: '18px 5px 5px 42px' }, | ||
{ position: 'before', align: 'top', icon: 'arrow circle left', padding: '5px 42px 18px 5px' }, | ||
{ position: 'before', align: 'center', icon: 'arrow circle left', padding: '5px 42px 5px 5px' }, | ||
{ position: 'before', align: 'bottom', icon: 'arrow circle left', padding: '18px 42px 5px 5px' }, | ||
{ position: 'after', align: 'top', icon: 'arrow circle right', padding: '5px 5px 18px 42px' }, | ||
{ position: 'after', align: 'center', icon: 'arrow circle right', padding: '5px 5px 5px 42px' }, | ||
{ position: 'after', align: 'bottom', icon: 'arrow circle right', padding: '18px 5px 5px 42px' }, | ||
] | ||
|
||
const PopupExamplePointing = () => ( | ||
<Grid columns="repeat(3, 30px)" variables={{ padding: '30px', gridGap: '80px' }}> | ||
{triggers.map(({ position, align, icon, padding }) => ( | ||
<PopupWithButton | ||
align={align} | ||
icon={icon} | ||
key={`${position}-${align}`} | ||
padding={padding} | ||
position={position} | ||
/> | ||
))} | ||
</Grid> | ||
) | ||
|
||
export default PopupExamplePointing |
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
5 changes: 0 additions & 5 deletions
5
packages/react/src/themes/teams-dark/components/Popup/popupVariables.ts
This file was deleted.
Oops, something went wrong.
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
5 changes: 0 additions & 5 deletions
5
packages/react/src/themes/teams-high-contrast/components/Popup/popupVariables.ts
This file was deleted.
Oops, something went wrong.
92 changes: 80 additions & 12 deletions
92
packages/react/src/themes/teams/components/Popup/popupContentStyles.ts
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 |
---|---|---|
@@ -1,20 +1,88 @@ | ||
import { PopperChildrenProps } from 'react-popper' | ||
import { ComponentSlotStylesInput, ICSSInJSStyle } from '../../../types' | ||
import { pxToRem } from '../../../../lib' | ||
import { PopupContentProps } from '../../../../components/Popup/PopupContent' | ||
import { PopupContentVariables } from './popupContentVariables' | ||
|
||
const rtlMapping = { | ||
left: 'right', | ||
right: 'left', | ||
} | ||
|
||
const getPointerStyles = ( | ||
v: PopupContentVariables, | ||
rtl: boolean, | ||
popperPlacement?: PopperChildrenProps['placement'], | ||
) => { | ||
const placementValue = (popperPlacement || '').split('-', 1).pop() | ||
const placement = (rtl && rtlMapping[placementValue]) || placementValue | ||
|
||
const rootStyles = { | ||
top: { | ||
marginBottom: v.pointerMargin, | ||
}, | ||
right: { | ||
marginLeft: v.pointerMargin, | ||
}, | ||
bottom: { | ||
marginTop: v.pointerMargin, | ||
}, | ||
left: { | ||
marginRight: v.pointerMargin, | ||
}, | ||
} | ||
const pointerStyles = { | ||
top: { | ||
bottom: `-${v.pointerOffset}`, | ||
transform: 'rotate(45deg)', | ||
}, | ||
right: { | ||
left: `-${v.pointerOffset}`, | ||
transform: 'rotate(135deg)', | ||
}, | ||
bottom: { | ||
top: `-${v.pointerOffset}`, | ||
transform: 'rotate(-135deg)', | ||
}, | ||
left: { | ||
right: `-${v.pointerOffset}`, | ||
transform: 'rotate(-45deg)', | ||
}, | ||
} | ||
|
||
return { | ||
root: rootStyles[placement], | ||
pointer: pointerStyles[placement], | ||
} | ||
} | ||
|
||
const popupContentStyles: ComponentSlotStylesInput<PopupContentProps, PopupContentVariables> = { | ||
root: ({ variables }): ICSSInJSStyle => { | ||
const { borderColor, padding } = variables | ||
|
||
return { | ||
display: 'block', | ||
padding, | ||
border: `1px solid ${borderColor}`, | ||
borderRadius: pxToRem(3), | ||
boxShadow: `0 2px 4px 0 ${borderColor}, 0 2px 10px 0 ${borderColor}`, | ||
} | ||
}, | ||
root: ({ props: p, theme: t, variables: v }): ICSSInJSStyle => ({ | ||
borderRadius: v.borderRadius, | ||
display: 'block', | ||
|
||
...(p.pointing && getPointerStyles(v, t.rtl, p.placement).root), | ||
}), | ||
pointer: ({ props: p, theme: t, variables: v }): ICSSInJSStyle => ({ | ||
display: 'block', | ||
position: 'absolute', | ||
|
||
backgroundColor: 'inherit', | ||
borderBottom: `${v.borderSize} solid ${v.borderColor}`, | ||
borderRight: `${v.borderSize} solid ${v.borderColor}`, | ||
|
||
height: v.pointerSize, | ||
width: v.pointerSize, | ||
|
||
...getPointerStyles(v, t.rtl, p.placement).pointer, | ||
}), | ||
content: ({ props: p, variables: v }): ICSSInJSStyle => ({ | ||
display: 'block', | ||
padding: v.padding, | ||
|
||
border: `${v.borderSize} solid ${v.borderColor}`, | ||
borderRadius: 'inherit', | ||
boxShadow: `0 2px 4px 0 ${v.borderColor}, 0 2px 10px 0 ${v.borderColor}`, | ||
}), | ||
} | ||
|
||
export default popupContentStyles |
14 changes: 12 additions & 2 deletions
14
packages/react/src/themes/teams/components/Popup/popupContentVariables.ts
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 |
---|---|---|
@@ -1,15 +1,25 @@ | ||
import { pxToRem } from '../../../../lib' | ||
|
||
export interface PopupContentVariables { | ||
[key: string]: string | number | ||
|
||
borderColor: string | ||
borderRadius: string | ||
borderSize: string | ||
padding: string | ||
|
||
pointerMargin: string | ||
pointerOffset: string | ||
pointerSize: string | ||
} | ||
|
||
export default (siteVars: any): PopupContentVariables => { | ||
return { | ||
borderColor: siteVars.gray06, | ||
borderRadius: pxToRem(3), | ||
borderSize: '1px', | ||
padding: `${pxToRem(10)} ${pxToRem(14)}`, | ||
|
||
pointerOffset: pxToRem(5), | ||
pointerMargin: pxToRem(10), | ||
pointerSize: pxToRem(10), | ||
} | ||
} |
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
2 changes: 0 additions & 2 deletions
2
packages/react/src/themes/teams/components/Popup/popupVariables.ts
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.
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.
Moved to
popupContentStyles
...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.
Talk to @kuzhelov. In #1121 he intentionally moved the styles from
popupContentStyles
to here.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.
these styles should be left here, as we popup expects any content to be rendered with this set of styles, not just
PopupContent
. Also, please, ensure thatPopupContent
just CSS-inherits this set of colors.These two requirements are necessary for introducing correct semantics around these styles, as well as for expected effects of theme switching.
FYI #1121