Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
298764b
Update to doctocat@0.17.0
BinaryMuse Feb 27, 2020
19ed689
Initial take on Popover
BinaryMuse Feb 27, 2020
55ca841
remove unused imports
BinaryMuse Feb 27, 2020
635e204
:art:
BinaryMuse Feb 27, 2020
2afbe39
Let 'TextInput' use 'maxWidth' and 'minWidth' from 'styled-system'
smockle Mar 23, 2020
5f7ac49
Add docs for 'maxWidth' and 'minWidth' props
smockle Mar 23, 2020
370c724
Fix DropdownProps type intersections
clayplumridge Mar 23, 2020
9ce2b30
Add `className` and `css` to `BaseProps`
BinaryMuse Mar 23, 2020
d11f886
update prop type to node
Mar 23, 2020
d67caa2
update version
Mar 23, 2020
38b9cf4
Merge pull request #725 from clayplumridge/patch-1
Mar 23, 2020
0bec91b
add minWidth & maxWidth functions to TextInput
Mar 23, 2020
59c211e
lint
Mar 23, 2020
cfb1936
lint x2
Mar 23, 2020
0b50cd0
Merge branch 'minor' into mkt/add-classname-and-css
Mar 23, 2020
4ca1186
Merge pull request #726 from primer/mkt/add-classname-and-css
Mar 23, 2020
c5a1322
Merge pull request #727 from primer/underlinenav-type
Mar 23, 2020
8d3317d
Merge pull request #723 from primer/textinput-minmaxwidth
Mar 24, 2020
613ec51
Merge remote-tracking branch 'origin/master' into mkt/popover-component
BinaryMuse Mar 25, 2020
1cd2244
Fix theme namespace for Popover
BinaryMuse Mar 25, 2020
1e3078d
Give Popover a background color
BinaryMuse Mar 25, 2020
7a8019f
Fix typo
BinaryMuse Mar 25, 2020
27b5744
Remove unnecessary props
BinaryMuse Mar 25, 2020
1de4a78
Add Popover typings
BinaryMuse Mar 25, 2020
78d5455
Remove redundant system props
BinaryMuse Mar 25, 2020
7cc88b8
Refactor caret positions
BinaryMuse Mar 25, 2020
d21ba83
Add Popover tests
BinaryMuse Mar 25, 2020
e5821ef
Update snapshots from theme change
BinaryMuse Mar 25, 2020
5da5a2a
Remove old copy-paste CSS
BinaryMuse Mar 25, 2020
f40da92
Reword positioning docs
BinaryMuse Mar 25, 2020
b9a7f4a
Fix Popover typings
BinaryMuse Mar 25, 2020
2777673
Add System Props section to Popover docs
BinaryMuse Mar 25, 2020
623f55e
Fix system props style overrides for Popover
BinaryMuse Mar 25, 2020
2cd0ec7
Let's get some bundle sizes in here
BinaryMuse Mar 26, 2020
223616e
Merge pull request #703 from primer/mkt/popover-component
Mar 26, 2020
70480da
Fix bundlesize config typo
BinaryMuse Mar 27, 2020
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
23 changes: 23 additions & 0 deletions .github/workflows/bundlesize.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: 💾 Bundlesize
on:
push:
branches-ignore:
- master

jobs:
bundlesize:
name: Check Bundle Size
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
path: 'old'
ref: 'master'
- uses: actions/checkout@v2
with:
path: 'new'

- name: Check Bundle Size Change
uses: "BinaryMuse/action-bundlesize@master"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
110 changes: 110 additions & 0 deletions docs/content/Popover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
---
title: Popover
---

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

Two components make up a popover; the `Popover` component controls the absolute positioning of the popover, and `Popover.Content` renders the inner content of the popover as well as the caret.

By default, the popover renders with absolute positioning, meaning it should usually be wrapped in an element with a relative position in order to be positioned properly. To render the popover with relative positioning, use the `relative` property.

It can be useful to give the `Popover.Content` element a margin to help align the popover.

## Default Example

```jxs live
<Relative>
<Text textAlign="center" display="block">
<ButtonPrimary>Hello!</ButtonPrimary>
</Text>

<Popover relative open={true} caret="top">
<Popover.Content mt={2}>
<Heading fontSize={2}>Popover heading</Heading>
<Text as="p">Message about this particular piece of UI.</Text>
<Button>Got it!</Button>
</Popover.Content>
</Popover>
</Relative>
```

## 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.

```javascript live noinline
function PopoverDemo(props) {
const [pos, setPos] = React.useState('top')
const [open, setOpen] = React.useState(true)

return (
<Box>
<Heading as="h3" fontSize={3}>Caret Position</Heading>
<CaretSelector current={pos} onChange={setPos} />
<Heading as="h3" fontSize={3}>Popover Visibility</Heading>
<Box my={2}>
<label>
<input type="checkbox" value={open} checked={open}
onChange={() => setOpen(open => !open)}/> Open
</label>
</Box>

<Relative pt={4}>
<Popover relative open={open} caret={pos}>
<Popover.Content>
<Heading fontSize={2}><code>{pos}</code> caret</Heading>
<Text as="p">Message about this particular piece of UI.</Text>
<Button onClick={() => setOpen(false)}>Got it!</Button>
</Popover.Content>
</Popover>
</Relative>
</Box>
)
}

function CaretSelector(props) {
const choices = [
'top', 'bottom', 'left', 'right',
'left-bottom', 'left-top', 'right-bottom', 'right-top',
'top-left', 'bottom-left', 'top-right', 'bottom-right'
].map((dir) => (
<label>
<input key={dir} type='radio' name='caret' value={dir}
checked={dir === props.current} onChange={() => props.onChange(dir)} /> {dir}
</label>
))

return (
<Grid gridTemplateColumns="repeat(4, auto)" gridGap={3} my={2}>
{choices}
</Grid>
)
}

render(<PopoverDemo />)
```

## System props

`Popover` components get `COMMON`, `LAYOUT`, and `POSITION` system props. `Popover.Content` components get `COMMON`, `LAYOUT`, and `BORDER` system props. Read our [System Props](/system-props) doc page for a full list of available props.

## Component props

### Popover

| Name | Type | Default | Description |
| :- | :- | :-: | :- |
| as | String | 'div' | Sets the HTML tag for the component. |
| caret | String | 'top' | Controls the position of the caret. See below for the list of caret positions. |
| open | Boolean | false | Controls the visibility of the popover. |
| relative | Boolean | false | Set to true to render the popover using relative positioning. |

#### Caret Positions

The `caret` prop can be one of the following values: `top`, `bottom`, `left`, `right`, `bottom-left`, `bottom-right`, `top-left`, `top-right`, `left-bottom`, `left-top`, `right-bottom`, or `right-top`.

### Popover.Content

| Name | Type | Default | Description |
| :- | :- | :-: | :- |
| as | String | 'div' | Sets the HTML tag for the component. |
2 changes: 2 additions & 0 deletions docs/content/TextInput.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ Native `<input>` attributes are forwarded to the underlying React `input` compon
| block | Boolean | | Adds `display: block` to element |
| variant | String | | Can be either `small` or `large`. Creates a smaller or larger input than the default.
| width | String or Number | | Set the width of the input |
| maxWidth | String or Number or [Array](https://styled-system.com/guides/array-props) | | Set the maximum width of the input |
| minWidth | String or Number or [Array](https://styled-system.com/guides/array-props) | | Set the minimum width of the input |
| icon | Node (pass Octicon react component) | | Icon to be used inside of input. Positioned on the right edge. |
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"node": "10.x"
},
"dependencies": {
"@primer/gatsby-theme-doctocat": "^0.16.10",
"@primer/gatsby-theme-doctocat": "^0.17.0",
"@primer/octicons-react": "^9.2.0",
"@styled-system/prop-types": "^5.1.0",
"@styled-system/theme-get": "^5.1.0",
Expand Down
2 changes: 2 additions & 0 deletions docs/src/@primer/gatsby-theme-doctocat/nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
url: /Link
- title: PointerBox
url: /PointerBox
- title: Popover
url: /Popover
- title: Position
url: /Position
- title: ProgressBar
Expand Down
8 changes: 4 additions & 4 deletions docs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1234,10 +1234,10 @@
react-is "16.10.2"
styled-system "5.1.2"

"@primer/gatsby-theme-doctocat@^0.16.10":
version "0.16.10"
resolved "https://registry.yarnpkg.com/@primer/gatsby-theme-doctocat/-/gatsby-theme-doctocat-0.16.10.tgz#9798bca7b08b548e8b9bd62f8ca7a8be9003d5a5"
integrity sha512-173EeoIEwf1cAO3te4XDYg+kjQwLhtlOU2LAHty8T7Hb8hjOLysBPO3rmmtz583+eWhASA0GBb6cvR5S6/OQHg==
"@primer/gatsby-theme-doctocat@^0.17.0":
version "0.17.0"
resolved "https://registry.yarnpkg.com/@primer/gatsby-theme-doctocat/-/gatsby-theme-doctocat-0.17.0.tgz#01295b47729fc1ae6c245b5bcc717fc33c088051"
integrity sha512-0vshaWRPogBo7F9nhmxdhuf7SwgFrsgNJ3FXEO4GisCWQ2BWb3VzYtMx2q7f7z4z99O0g/cIQUzDTU5xPVgGug==
dependencies:
"@babel/preset-env" "^7.5.5"
"@babel/preset-react" "^7.0.0"
Expand Down
34 changes: 33 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ declare module '@primer/components' {

export interface BaseProps extends React.Props<any> {
as?: React.ReactType
className?: string
css?: string
title?: string
// NOTE(@mxstbr): Necessary workaround to make <Component as={Link} to="/bla" /> work
to?: History.LocationDescriptor
Expand Down Expand Up @@ -145,7 +147,7 @@ declare module '@primer/components' {

export const StyledOcticon: React.FunctionComponent<StyledOcticonProps>

export interface DropdownProps extends React.Props<any>, StyledSystem.ColorProps, StyledSystem.SpaceProps, ButtonProps {
export interface DropdownProps extends React.Props<any>, StyledSystem.ColorProps, StyledSystem.SpaceProps, Omit<ButtonProps, 'title'> {
as?: React.ReactType
title?: string | React.ReactNode
}
Expand Down Expand Up @@ -221,6 +223,30 @@ declare module '@primer/components' {

export const PointerBox: React.FunctionComponent<PointerBoxProps>

export interface PopoverProps extends CommonProps, LayoutProps, PositionProps {
caret?:
| 'top'
| 'bottom'
| 'left'
| 'right'
| 'bottom-left'
| 'bottom-right'
| 'top-left'
| 'top-right'
| 'left-bottom'
| 'left-top'
| 'right-bottom'
| 'right-top'
open?: boolean
relative?: boolean
}

export interface PopoverContentProps extends BorderBoxProps { }

export const Popover: React.FunctionComponent<PopoverProps> & {
Content: React.FunctionComponent<PopoverContentProps>
}

export interface PositionComponentProps
extends PositionProps,
CommonProps,
Expand Down Expand Up @@ -269,6 +295,8 @@ declare module '@primer/components' {
export interface TextInputProps
extends CommonProps,
StyledSystem.WidthProps,
StyledSystem.MaxWidthProps,
StyledSystem.MinWidthProps,
Omit<React.InputHTMLAttributes<HTMLInputElement>, 'color' | 'size' | 'width'> {
block?: boolean
icon?: React.ReactElement
Expand Down Expand Up @@ -506,6 +534,10 @@ declare module '@primer/components/src/PointerBox' {
import {PointerBox} from '@primer/components'
export default PointerBox
}
declare module '@primer/components/src/Popover' {
import {Popover} from '@primer/components'
export default Popover
}
declare module '@primer/components/src/Relative' {
import {Relative} from '@primer/components'
export default Relative
Expand Down
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@primer/components",
"version": "16.2.0",
"version": "16.3.0",
"description": "Primer react components",
"main": "dist/index.umd.js",
"module": "dist/index.esm.js",
Expand Down Expand Up @@ -83,5 +83,18 @@
"peerDependencies": {
"react": "^16.8.0",
"styled-components": "4.x || 5.x"
},
"actionBundlesize": {
"build": "yarn && yarn dist",
"files": [
{
"path": "dist/index.esm.js",
"name": "ESM Build"
},
{
"path": "dist/index.umd.js",
"name": "UMD Build"
}
]
}
}
Loading