Skip to content
Merged
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
9 changes: 6 additions & 3 deletions docs/content/BorderBox.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ BorderBox is a Box component with a border. When no `borderColor` is present, th
<BorderBox>This is a BorderBox</BorderBox>
```

Note that `BorderBox` has default props set for `borderWidth`, `borderStyle`, and `borderColor`. This means that you cannot use `border={0} borderBottom={1}` or similar patterns; instead, use individual properties like `borderWidth={0} borderBottomWidth={1}`.

## System props

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

## Component props

| Prop name | Type | Default | Description |
| :- | :- | :-: | :- |
| border | String | 'borders.1' (from theme) | Sets the border, use theme values or provide your own. |
| borderWidth | String | '1px' | Sets the border, use theme values or provide your own. |
| borderStyle | String | 'solid' | Sets the border style, use theme values or provide your own. |
| borderColor | String | 'gray.2' (from theme) | Sets the border color, use theme values or provide your own. |
| borderRadius | String or Number| 'radii.1' (from theme)| Sets the border radius, use theme values or provide your own. |
| borderRadius | String or Number| 2 (from theme)| Sets the border radius, use theme values or provide your own. |
| boxShadow | String | | Sets box shadow, use theme values or provide your own. |
2 changes: 1 addition & 1 deletion docs/content/Box.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The Box component serves as a wrapper component for most layout related needs. U

## System props

Box components get the `COMMON` and `LAYOUT` categories of system props. Read our [System Props](/system-props) doc page for a full list of available props.
Box components get the `COMMON`, `LAYOUT`, and `FLEX` categories of system props. Read our [System Props](/system-props) doc page for a full list of available props.

## Component props

Expand Down
3 changes: 2 additions & 1 deletion docs/content/FilteredSearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ The FilteredSearch component helps style a Dropdown and a TextInput side-by-side

```jsx live
<FilteredSearch>
<Dropdown title="Filter">
<Dropdown>
<Dropdown.Button>Filter</Dropdown.Button>
<Dropdown.Menu direction="sw">
<Dropdown.Item>Item 1</Dropdown.Item>
<Dropdown.Item>Item 2</Dropdown.Item>
Expand Down
5 changes: 2 additions & 3 deletions docs/content/Flex.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
title: Flex
---

Flex is a component that will allow you to use flexbox properties.
The `Flex` component behaves the same as the `Box` component except that it has `display: flex` set by default.

*Previously, `Flex.Item` was used for flex item specific properties - we've added all properties to the `Flex` component, but are keeping Flex.Item around for backwards compatibility.*
*Previously, a `Flex.Item` component was used for flex item specific properties; `Box` now contains all those properties and should be used in its place.*

## Default example

Expand All @@ -28,7 +28,6 @@ Flex is a component that will allow you to use flexbox properties.

Flex components get `FLEX`, `COMMON`, and `LAYOUT` system props.


Read our [System Props](/system-props) doc page for a full list of available props.

## Component props
Expand Down
2 changes: 1 addition & 1 deletion docs/content/PointerBox.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ PointerBox is a [BorderBox](./BorderBox) component with a caret added to it.

## System props

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

## Component props

Expand Down
2 changes: 1 addition & 1 deletion docs/content/Popover.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ 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.
`Popover` components get `COMMON`, `LAYOUT`, and `POSITION` system props. `Popover.Content` components get `COMMON`, `LAYOUT`, `BORDER`, and `FLEX` system props. Read our [System Props](/system-props) doc page for a full list of available props.

## Component props

Expand Down
4 changes: 2 additions & 2 deletions docs/content/SideNav.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Add the `variant="lightweight"` prop to `SideNav` to render an alternative, more

```jsx live
<BorderBox p={3} backgroundColor='gray.0' maxWidth={360}>
<BorderBox border='none' borderBottom={1} mb={2} pb={1}>
<BorderBox borderWidth={0} borderBottomWidth={1} borderRadius={0} mb={2} pb={1}>
<Heading as="h5" fontSize={1} color="gray.7">Menu</Heading>
</BorderBox>
<SideNav variant="lightweight">
Expand Down Expand Up @@ -133,7 +133,7 @@ If using React Router, you can use the `as` prop to render the element as a `Nav

## System props

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

## Component props

Expand Down
48 changes: 48 additions & 0 deletions docs/src/@primer/gatsby-theme-doctocat/components/code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {Absolute, BorderBox, Relative, Text} from '@primer/components'
import Highlight, {defaultProps} from 'prism-react-renderer'
import githubTheme from 'prism-react-renderer/themes/github'
import React from 'react'
import ClipboardCopy from '@primer/gatsby-theme-doctocat/src/components/clipboard-copy'
import LiveCode from '@primer/gatsby-theme-doctocat/src/components/live-code'

function Code({className, children, live, noinline}) {
const language = className ? className.replace(/language-/, '') : ''
const code = children.trim()

if (live) {
return <LiveCode code={code} language={language} noinline={noinline} />
}

return (
<Relative>
<Absolute top={0} right={0} p={2}>
<ClipboardCopy value={code} />
</Absolute>
<Highlight {...defaultProps} code={code} language={language} theme={githubTheme}>
{({className, style, tokens, getLineProps, getTokenProps}) => (
<BorderBox
as="pre"
className={className}
mt={0}
mb={3}
p={3}
borderWidth={0}
style={{...style, overflow: 'auto'}}
>
{tokens.map((line, i) => (
// eslint-disable-next-line react/no-array-index-key
<div key={i} {...getLineProps({line, key: i})}>
{line.map((token, key) => (
// eslint-disable-next-line react/no-array-index-key
<Text key={key} fontFamily="mono" fontSize={1} {...getTokenProps({token, key})} />
))}
</div>
))}
</BorderBox>
)}
</Highlight>
</Relative>
)
}

export default Code
88 changes: 88 additions & 0 deletions docs/src/@primer/gatsby-theme-doctocat/components/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import {BorderBox, Box, Flex, Grid, Heading, Position, Text, Details, StyledOcticon} from '@primer/components'
import {ChevronDown, ChevronRight} from '@primer/octicons-react'
import React from 'react'
import Head from '@primer/gatsby-theme-doctocat/src/components/head'
import Header, {HEADER_HEIGHT} from '@primer/gatsby-theme-doctocat/src/components/header'
import PageFooter from '@primer/gatsby-theme-doctocat/src/components/page-footer'
import Sidebar from '@primer/gatsby-theme-doctocat/src/components/sidebar'
import SourceLink from '@primer/gatsby-theme-doctocat/src/components/source-link'
import StatusLabel from '@primer/gatsby-theme-doctocat/src/components/status-label'
import TableOfContents from '@primer/gatsby-theme-doctocat/src/components/table-of-contents'

function Layout({children, pageContext}) {
const {title, description, status, source, additionalContributors = []} = pageContext.frontmatter

return (
<Flex flexDirection="column" minHeight="100vh">
<Head title={title} description={description} />
<Header />
<Flex flex="1 1 auto" flexDirection="row" css={{zIndex: 0}}>
<Box display={['none', null, null, 'block']}>
<Sidebar />
</Box>
<Grid
id="skip-nav"
maxWidth="100%"
gridTemplateColumns={['100%', null, 'minmax(0, 65ch) 220px']}
gridTemplateAreas={['"heading" "content"', null, '"heading ." "content table-of-contents"']}
gridColumnGap={[null, null, 6, 7]}
gridRowGap={3}
mx="auto"
p={[5, 6, null, 7]}
css={{alignItems: 'start', alignSelf: 'start'}}
>
<BorderBox css={{gridArea: 'heading'}} borderWidth={0} borderBottomWidth={1} borderRadius={0} pb={2}>
<Heading>{title}</Heading>
</BorderBox>
{pageContext.tableOfContents.items ? (
<Position
display={['none', null, 'block']}
css={{gridArea: 'table-of-contents', overflow: 'auto'}}
position="sticky"
top={HEADER_HEIGHT + 24}
maxHeight={`calc(100vh - ${HEADER_HEIGHT}px - 24px)`}
>
<Text display="inline-block" fontWeight="bold" mb={1}>
Table of contents
</Text>
<TableOfContents items={pageContext.tableOfContents.items} />
</Position>
) : null}
<Box css={{gridArea: 'content'}}>
{status || source ? (
<Flex mb={3} alignItems="center">
{status ? <StatusLabel status={status} /> : null}
<Box mx="auto" />
{source ? <SourceLink href={source} /> : null}
</Flex>
) : null}
{pageContext.tableOfContents.items ? (
<Box display={['block', null, 'none']} mb={3}>
<Details>
{({open}) => (
<>
<Text as="summary" fontWeight="bold">
<StyledOcticon icon={open ? ChevronDown : ChevronRight} mr={2} />
Table of contents
</Text>
<Box pt={1}>
<TableOfContents items={pageContext.tableOfContents.items} />
</Box>
</>
)}
</Details>
</Box>
) : null}
{children}
<PageFooter
editUrl={pageContext.editUrl}
contributors={pageContext.contributors.concat(additionalContributors.map(login => ({login})))}
/>
</Box>
</Grid>
</Flex>
</Flex>
)
}

export default Layout
131 changes: 131 additions & 0 deletions docs/src/@primer/gatsby-theme-doctocat/components/nav-drawer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/* eslint-disable jsx-a11y/click-events-have-key-events */
/* eslint-disable jsx-a11y/no-static-element-interactions */
//
// ^- these area here because Doctocat has eslint errors that are not reported
// in Doctocat but are in this project. Since the error exists in an area
// of JSX code where the disable-line comment does not work, we must disable
// it for the whole file until the problem is fixed upstream.
import {BorderBox, Flex, Link, StyledOcticon, Text} from '@primer/components'
import {ChevronDown, ChevronUp, X} from '@primer/octicons-react'
import {Link as GatsbyLink} from 'gatsby'
import debounce from 'lodash.debounce'
import React from 'react'
import navItems from '@primer/gatsby-theme-doctocat/src/nav.yml'
import primerNavItems from '@primer/gatsby-theme-doctocat/src/primer-nav.yml'
import useSiteMetadata from '@primer/gatsby-theme-doctocat/src/use-site-metadata'
import DarkButton from '@primer/gatsby-theme-doctocat/src/components/dark-button'
import Details from '@primer/gatsby-theme-doctocat/src/components/details'
import Drawer from '@primer/gatsby-theme-doctocat/src/components/drawer'
import NavItems from '@primer/gatsby-theme-doctocat/src/components/nav-items'

export function useNavDrawerState(breakpoint) {
// Handle string values from themes with units at the end
if (typeof breakpoint === 'string') {
breakpoint = parseInt(breakpoint, 10)
}
const [isOpen, setOpen] = React.useState(false)

const onResize = React.useCallback(() => {
if (window.innerWidth >= breakpoint) {
setOpen(false)
}
}, [setOpen, breakpoint])

const debouncedOnResize = React.useCallback(debounce(onResize, 250), [onResize])

React.useEffect(() => {
if (isOpen) {
window.addEventListener('resize', debouncedOnResize)
return () => {
// cancel any debounced invocation of the resize handler
debouncedOnResize.cancel()
window.removeEventListener('resize', debouncedOnResize)
}
}
}, [isOpen, debouncedOnResize])

return [isOpen, setOpen]
}

function NavDrawer({isOpen, onDismiss}) {
const siteMetadata = useSiteMetadata()
return (
<Drawer isOpen={isOpen} onDismiss={onDismiss}>
<Flex
flexDirection="column"
height="100%"
bg="gray.9"
style={{overflow: 'auto', WebkitOverflowScrolling: 'touch'}}
>
<Flex flexDirection="column" flex="1 0 auto" color="blue.2" bg="gray.9">
<BorderBox borderWidth={0} borderRadius={0} borderBottom={1} borderColor="gray.7">
<Flex py={3} pl={4} pr={3} alignItems="center" justifyContent="space-between">
<Link href="https://primer.style" fontFamily="mono" color="inherit">
Primer
</Link>
<DarkButton aria-label="Close" onClick={onDismiss}>
<StyledOcticon icon={X} />
</DarkButton>
</Flex>
</BorderBox>
<Flex flexDirection="column">
<PrimerNavItems items={primerNavItems} />
</Flex>
</Flex>
{navItems.length > 0 ? (
<Flex flexDirection="column" flex="1 0 auto" color="gray.7" bg="gray.0">
<Link as={GatsbyLink} to="/" display="inline-block" color="inherit" fontFamily="mono" mx={4} my={4}>
{siteMetadata.title}
</Link>
<NavItems items={navItems} />
</Flex>
) : null}
</Flex>
</Drawer>
)
}

function PrimerNavItems({items}) {
return items.map((item, index) => {
return (
<BorderBox
key={item.title}
borderWidth={0}
borderRadius={0}
borderTop={index !== 0 ? 1 : 0}
borderColor="gray.7"
p={4}
>
{item.children ? (
// eslint-disable-next-line react/no-array-index-key
<Details key={index}>
{({open, toggle}) => (
<>
<summary onClick={toggle} style={{cursor: 'pointer'}}>
<Flex alignItems="center" justifyContent="space-between">
<Text>{item.title}</Text>
<StyledOcticon icon={open ? ChevronUp : ChevronDown} />
</Flex>
</summary>
<Flex flexDirection="column" mt={2}>
{item.children.map(child => (
<Link key={child.title} href={child.url} py={1} mt={2} fontSize={1} color="inherit">
{child.title}
</Link>
))}
</Flex>
</>
)}
</Details>
) : (
// eslint-disable-next-line react/no-array-index-key
<Link key={index} href={item.url} color="inherit" display="block">
{item.title}
</Link>
)}
</BorderBox>
)
})
}

export default NavDrawer
Loading