1
1
mirror of https://github.com/primer/css.git synced 2024-12-13 06:38:07 +03:00
css/docs/landing/index.js

176 lines
5.8 KiB
JavaScript
Raw Normal View History

2018-12-14 08:41:41 +03:00
import React from 'react'
import PropTypes from 'prop-types'
import {BorderBox, Box, Flex, Heading, Link, Text} from '@primer/components'
import {getAssetPath} from '../utils'
import UtilitiesImage from './UtilitiesImage.svg'
import ObjectsImage from './ObjectsImage.svg'
import ComponentsImage from './ComponentsImage.svg'
import SpacingImage from './SpacingImage.svg'
import ColorImage from './ColorImage.svg'
2019-01-09 20:58:48 +03:00
export {default as HeaderImage} from './HeaderImage.svg'
const OverviewTitle = props => <Heading fontSize={3} fontWeight="normal" is="div" {...props} />
2019-01-09 20:58:48 +03:00
const OverviewText = props => <Text fontSize={1} {...props} />
2018-12-14 08:41:41 +03:00
export function StylesOverview(props) {
const styleTypes = [
{
name: 'Utilities',
desc: 'Single purpose, immutable styles, that do one thing well.',
image: UtilitiesImage
},
{
name: 'Objects',
desc: 'Scaffolding for common page and content layouts.',
image: ObjectsImage
},
{
name: 'Components',
desc: 'Abstracted patterns for frequently used visual styles.',
image: ComponentsImage
}
]
return (
<Flex {...props}>
{styleTypes.map(({name, desc, image}) => (
<Flex.Item is={Text} textAlign="center" mx={4} key={name}>
2018-12-14 08:41:41 +03:00
<Image src={image} height={90} mb={2} />
<OverviewTitle>{name}</OverviewTitle>
<OverviewText>{desc}</OverviewText>
</Flex.Item>
))}
</Flex>
)
}
StylesOverview.propTypes = {
2018-12-14 09:29:46 +03:00
types: PropTypes.arrayOf(
PropTypes.shape({
name: PropTypes.node,
desc: PropTypes.node,
image: PropTypes.func
})
)
2018-12-14 08:41:41 +03:00
}
export function PrimitivesOverview(props) {
const primitiveTypes = [
{
name: 'Highly composable spacing scale',
desc: `The base-8 spacing scale is highly composable and works with the density of GitHubs content. Margin and padding spacers bring consistency to vertical and horizontal rhythm, while remaining flexible so you can tweak layouts to work for every context.`,
image: SpacingImage
},
{
name: 'Customizable typography',
desc: `Font size and line-height options work together to result in more sensible numbers. Font styles come in a range of weights and sizes so that we can style appropriately for content and readability. Type utilities allow us to change the visual styles while keeping markup semantic.`,
image: getAssetPath('typography.png')
},
{
name: 'Meaningful color',
desc: `The color system allows us to add meaningful signals to content and interactions. Color variables and utilities offer thematic styling options without being tied to structure. Text and background colors come in a range of accessible combinations to ensure we build inclusive interfaces.`,
image: ColorImage
}
]
return (
2018-12-14 09:29:46 +03:00
<Box width={['auto', 'auto', 10 / 12]} mx="auto" {...props}>
2018-12-14 08:41:41 +03:00
{primitiveTypes.map(({name, desc, image}) => (
<Flex key={name} my={6} alignItems="center">
<Box width={300} mr={6} py={2}>
<Image src={image} />
</Box>
<Box>
<OverviewTitle>{name}</OverviewTitle>
<OverviewText>{desc}</OverviewText>
</Box>
</Flex>
))}
</Box>
)
}
PrimitivesOverview.propTypes = {
2018-12-14 09:29:46 +03:00
types: PropTypes.arrayOf(
PropTypes.shape({
name: PropTypes.node,
desc: PropTypes.node,
image: PropTypes.func
})
)
2018-12-14 08:41:41 +03:00
}
function Image(props) {
const {src, ...rest} = props
switch (typeof src) {
case 'string':
return <Box is="img" width="100%" alt="" {...props} />
2018-12-14 08:41:41 +03:00
case 'function':
return <Box is={src} {...rest} />
2018-12-14 08:41:41 +03:00
default:
throw new Error(`Unrecognized Image.src type: "${typeof src}"`)
}
}
export function PrimerPackageBox({data = {}, count, ...rest}) {
2018-12-14 08:41:41 +03:00
return (
<Flex justifyContent="space-around" {...rest}>
<BorderBox bg="gray.1" width="auto" px={6} py={3} my={4}>
<Flex alignItems="center" justifyContent="space-around">
<Text fontSize={3} fontWeight="bold" mb={2} textAlign="center">
2018-12-14 09:29:46 +03:00
<Link href={packageSourceURL('primer')} color="inherit">
Primer
</Link>{' '}
<Link href={packageURL('primer')}>{data.version}</Link>
2018-12-14 08:41:41 +03:00
</Text>
<Link href="https://travis-ci.org/primer/primer" mt={-1}>
<img alt="Build Status" src="https://travis-ci.org/primer/primer.svg?branch=master" />
</Link>
</Flex>
{count ? (
<Text is="div" textAlign="center">
2018-12-14 08:41:41 +03:00
This package includes all {count} Primer modules.
</Text>
) : null}
</BorderBox>
</Flex>
)
}
export function MetaPackageBox({children, data = {}, title, ...rest}) {
2018-12-14 08:41:41 +03:00
const deps = data.dependencies || []
return (
<Flex.Item is={BorderBox} bg="white" maxWidth={220} {...rest}>
2019-01-17 09:43:03 +03:00
<BorderBox bg="gray.1" border={0} borderBottom={1} borderRadius={0} px={3} py={2}>
<Heading is="div" fontSize={2}>
2019-01-17 09:43:03 +03:00
<Link href={packageSourceURL(data.name)} color="inherit">
{title}
</Link>{' '}
<Link href={packageURL(data.name)}>{data.version}</Link>
</Heading>
</BorderBox>
<Text is="div" fontSize={1} p={3}>
2018-12-14 08:41:41 +03:00
{children}
2019-01-17 09:43:03 +03:00
<Text is="div" fontWeight="bold" mt={4} mb={2}>
2018-12-14 08:41:41 +03:00
{deps.length} packages:
</Text>
<ul className="list-style-none pl-0">
{deps.map(dep => (
2018-12-14 09:29:46 +03:00
<li key={dep}>
<Link href={packageURL(dep)}>{dep}</Link>
</li>
2018-12-14 08:41:41 +03:00
))}
</ul>
</Text>
</Flex.Item>
)
}
function packageURL(name) {
return `https://www.npmjs.com/package/${name}`
}
function packageSourceURL(name, branch = 'master') {
2018-12-14 08:41:41 +03:00
// TODO get this from Metalsmith or page metadata???
return `https://github.com/primer/primer/blob/${branch}/modules/${name}`
2018-12-14 08:41:41 +03:00
}