Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/content/Popover.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: Popover
---
import State from '../components/State'

Popovers are used to bring attention to specific user interface elements, typically to suggest an action or to guide users through a new experience.

Expand Down Expand Up @@ -28,6 +29,18 @@ It can be useful to give the `Popover.Content` element a margin to help align th
</Relative>
```

## Border color

The `borderColor` system prop (read our [System Props](/system-props) doc page for more info) also affects the color of the caret.

```jsx live
<Popover relative open={true}>
<Popover.Content borderColor='blue.5'>
<Text>Hi there!</Text>
</Popover.Content>
</Popover>
```

## Caret position

`Popover` supports various caret positions, which you can specify via the `caret` property. This demo shows all the valid values for the prop. The default is `top`. Note that the `top-left`, `bottom-left`, `top-right`, and `bottom-right` values modify the horizontal alignment of the popover.
Expand Down
3 changes: 2 additions & 1 deletion src/BorderBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const BorderBox = styled(Box)(BORDER)

BorderBox.defaultProps = {
theme,
border: '1px solid',
borderWidth: '1px',
borderStyle: 'solid',
borderColor: 'gray.2',
borderRadius: 2
}
Expand Down
16 changes: 12 additions & 4 deletions src/Popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ const Popover = styled.div.attrs(({className, caret}) => {
${POSITION};
`

function getPopoverBorderColor(props) {
if (props.borderColor) {
return get(`colors.${props.borderColor}`)(props)
} else {
return get('popovers.colors.caret')(props)
}
}

Popover.Content = styled(BorderBox)`
position: relative;
width: 232px;
Expand All @@ -44,7 +52,7 @@ Popover.Content = styled(BorderBox)`
top: -${get('space.3')};
margin-left: -9px;
border: ${get('space.2')} solid transparent; // TODO: solid?
border-bottom-color: ${get('popovers.colors.caret')};
border-bottom-color: ${getPopoverBorderColor};
}

&::after {
Expand All @@ -66,7 +74,7 @@ Popover.Content = styled(BorderBox)`

&::before {
bottom: -${get('space.3')};
border-top-color: ${get('popovers.colors.caret')};
border-top-color: ${getPopoverBorderColor};
}

&::after {
Expand Down Expand Up @@ -145,7 +153,7 @@ Popover.Content = styled(BorderBox)`
${Popover}.caret-pos--right-bottom & {
&::before {
right: -${get('space.3')};
border-left-color: ${get('popovers.colors.caret')};
border-left-color: ${getPopoverBorderColor};
}

&::after {
Expand All @@ -161,7 +169,7 @@ Popover.Content = styled(BorderBox)`
${Popover}.caret-pos--left-bottom & {
&::before {
left: -${get('space.3')};
border-right-color: ${get('popovers.colors.caret')};
border-right-color: ${getPopoverBorderColor};
}

&::after {
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/Position.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('position components', () => {
it('can render other components with the is prop', () => {
const result = render(<Absolute as={BorderBox} />)
expect(result).toHaveStyleRule('position', 'absolute')
expect(result).toHaveStyleRule('border', '1px solid')
expect(result).not.toHaveStyleRule('border-style')
})

it('respects the "as" prop', () => {
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('position components', () => {
it('can render other components with the is prop', () => {
const result = render(<Fixed as={BorderBox} />)
expect(result).toHaveStyleRule('position', 'fixed')
expect(result).toHaveStyleRule('border', '1px solid')
expect(result).not.toHaveStyleRule('border-style')
})
})

Expand Down Expand Up @@ -103,7 +103,7 @@ describe('position components', () => {
it('can render other components with the is prop', () => {
const result = render(<Relative as={BorderBox} />)
expect(result).toHaveStyleRule('position', 'relative')
expect(result).toHaveStyleRule('border', '1px solid')
expect(result).not.toHaveStyleRule('border-style')
})
})

Expand Down Expand Up @@ -132,7 +132,7 @@ describe('position components', () => {
it('can render other components with the is prop', () => {
const result = render(<Sticky as={BorderBox} />)
expect(result).toHaveStyleRule('position', 'sticky')
expect(result).toHaveStyleRule('border', '1px solid')
expect(result).not.toHaveStyleRule('border-style')
})
})
})
9 changes: 6 additions & 3 deletions src/__tests__/__snapshots__/PointerBox.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
exports[`PointerBox passes the "bg" prop to both <BorderBox> and <Caret> 1`] = `
.c1 {
background-color: #d73a49;
border: 1px solid;
border-width: 1px;
border-style: solid;
border-color: #e1e4e8;
border-radius: 6px;
}
Expand Down Expand Up @@ -54,7 +55,8 @@ exports[`PointerBox passes the "bg" prop to both <BorderBox> and <Caret> 1`] = `
exports[`PointerBox passes the "borderColor" prop to both <BorderBox> and <Caret> 1`] = `
.c1 {
border-color: #d73a49;
border: 1px solid;
border-width: 1px;
border-style: solid;
border-radius: 6px;
}

Expand Down Expand Up @@ -103,7 +105,8 @@ exports[`PointerBox passes the "borderColor" prop to both <BorderBox> and <Caret

exports[`PointerBox renders a <Caret> in <BorderBox> with relative positioning 1`] = `
.c1 {
border: 1px solid;
border-width: 1px;
border-style: solid;
border-color: #e1e4e8;
border-radius: 6px;
}
Expand Down
Loading