Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new components #118

Merged
merged 29 commits into from Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0a4c925
add heading, sidenote, and blockquote components
freeman-lab Jan 3, 2022
fccd3ea
merge with main
freeman-lab Feb 2, 2022
5b3c5e9
package lock
freeman-lab Feb 2, 2022
5b7bc07
prettier config
freeman-lab Feb 2, 2022
387bfa8
remove blockquote
freeman-lab Feb 2, 2022
7f5cb0a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 2, 2022
3def96f
11.2.0-develop.0
freeman-lab Feb 2, 2022
676da73
Merge branch 'freeman-lab/new-components' of github.com:carbonplan/co…
freeman-lab Feb 2, 2022
ff2e832
heading fix
freeman-lab Feb 2, 2022
82ecee3
add additional components
freeman-lab Feb 4, 2022
50be608
fix alt handling
freeman-lab Feb 5, 2022
fb7a2ab
fixes for PR
freeman-lab Feb 5, 2022
11b8cae
remove log
freeman-lab Feb 5, 2022
18473b0
fix sx handling and link group cleanup
freeman-lab Feb 5, 2022
5fa157d
blockquote and avatar fixes and add colors
freeman-lab Feb 5, 2022
d091b9f
improve header
freeman-lab Feb 6, 2022
26094ed
11.2.0-develop.2
freeman-lab Feb 6, 2022
15b683b
fix for property removal
freeman-lab Feb 6, 2022
7120aed
bump dep
freeman-lab Feb 6, 2022
c91d4e0
add comment
freeman-lab Feb 6, 2022
9f0803f
basic improved print layout handling
freeman-lab Feb 7, 2022
25d03d1
bump
freeman-lab Feb 7, 2022
13e2b69
name change
freeman-lab Feb 7, 2022
b484777
bump
freeman-lab Feb 7, 2022
0e81a99
respond to PR feedback
freeman-lab Feb 7, 2022
b2fab02
bump
freeman-lab Feb 7, 2022
afeb88c
cleaner handling of extra props
freeman-lab Feb 7, 2022
e8b94a9
bump
freeman-lab Feb 7, 2022
0306915
11.2.0
freeman-lab Feb 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Expand Up @@ -3,6 +3,9 @@ repos:
rev: 'v2.5.1'
hooks:
- id: prettier
additional_dependencies:
- 'prettier@2.5.1'
- '@carbonplan/prettier@1.2.0'
language_version: system
files: "\\.(\
css|less|scss\
Expand All @@ -18,6 +21,9 @@ repos:
rev: 'v2.5.1'
hooks:
- id: prettier
additional_dependencies:
- 'prettier@2.5.1'
- '@carbonplan/prettier@1.2.0'
language_version: system
name: prettier-markdown
entry: prettier --write --parser mdx
Expand Down
8 changes: 0 additions & 8 deletions .prettierrc.json

This file was deleted.

17 changes: 15 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
@@ -1,12 +1,12 @@
{
"name": "@carbonplan/components",
"version": "11.1.4",
"version": "11.2.0-develop.7",
"description": "shared components for our websites",
"main": "dst/index.js",
"module": "dst/index.esm.js",
"scripts": {
"build": "rimraf dst && microbundle src/index.js -o dst/index.js --no-compress --jsx React.createElement -f modern,es,cjs --jsxFragment React.Fragment",
"watch": "microbundle watch src/index.js -o dst/index.js --no-compress --jsx React.createElement -f modern,es,cjs --jsxFragment React.Fragment",
"build": "rimraf dst && microbundle src/index.js -o dst/index.js --jsx React.createElement -f modern,es,cjs --jsxFragment React.Fragment",
"watch": "microbundle watch src/index.js -o dst/index.js --jsx React.createElement -f modern,es,cjs --jsxFragment React.Fragment",
"format": "prettier --write 'src/**/*.js' '*.css'"
},
"repository": {
Expand Down Expand Up @@ -35,6 +35,7 @@
"@carbonplan/icons": "^1.0.0",
"@theme-ui/color": ">=0.11.1"
},
"prettier": "@carbonplan/prettier",
"peerDependencies": {
"@emotion/react": "^11.1.5",
"next": "^10.1.3 || ^11.0.1 || || ^12.0.4",
Expand All @@ -43,6 +44,7 @@
"theme-ui": ">=0.11.1"
},
"devDependencies": {
"@carbonplan/prettier": "^1.2.0",
"microbundle": "^0.13.0",
"prettier": "^2.2.1",
"rimraf": "3.0.2"
Expand Down
79 changes: 79 additions & 0 deletions src/avatar-group.js
@@ -0,0 +1,79 @@
import React from 'react'
import Avatar from './avatar'
import Row from './row'
import Column from './column'
import Group from './group'

const sizes = {
xs: [1],
sm: [3],
md: [5],
lg: [7],
xl: [9],
}

const AvatarGroup = ({
members,
direction = 'horizontal',
align,
spacing = 'md',
width,
maxWidth,
fixedCount,
sx,
...props
}) => {
if (members.length > fixedCount) {
throw Error(
`cannot render '${members.length}' avatars with a fixed count of '${fixedCount}'`
)
}

let gap
if (sizes.hasOwnProperty(spacing)) {
gap = sizes[spacing]
} else {
gap = spacing
}

let start = (idx) => 'auto'
if (align) {
if (!Array.isArray(align)) {
align = [align]
}
start = (idx) =>
align.map((d) => {
if (d === 'left') {
return 'auto'
} else if (d === 'right') {
const offset = Math.max(1, fixedCount - members.length + 1)
return offset + idx
} else {
throw Error(`alignment '${align}' not recognized`)
}
})
}

return (
<>
{fixedCount && (
<Row columns={fixedCount} gap={gap} sx={sx} {...props}>
{members.map((props, idx) => (
<Column key={idx} start={start(idx)}>
<Avatar {...props} width={width} maxWidth={maxWidth} />
</Column>
))}
</Row>
)}
{!fixedCount && (
<Group direction={direction} spacing={spacing} sx={sx} {...props}>
{members.map((props, idx) => (
<Avatar key={idx} {...props} width={width} maxWidth={maxWidth} />
))}
</Group>
)}
</>
)
}

export default AvatarGroup
66 changes: 66 additions & 0 deletions src/avatar.js
@@ -0,0 +1,66 @@
import React from 'react'
import { Box, Image } from 'theme-ui'

const Avatar = ({
color = 'transparent',
width = '90px',
maxWidth,
name,
github,
alt,
src,
sx,
...props
}) => {
if (!name && !src && !github) {
console.warn('must specify either name, github, or src')
}

let srcProp, altProp
if (name) {
srcProp = `https://images.carbonplan.org/team/${name
.toLowerCase()
.replace(' ', '-')}.png`
altProp = alt || name
} else if (github) {
srcProp = `https://github.com/${github}.png`
altProp = alt || github
} else {
srcProp = src
altProp = alt
}

return (
<Box
sx={{
width: width,
maxWidth: maxWidth,
height: 'auto',
borderRadius: '50%',
position: 'relative',
display: 'inline-block',
verticalAlign: 'top',
bg: color,
...sx,
}}
{...props}
>
<Image
alt={altProp}
src={srcProp}
sx={{
opacity: color && color !== 'transparent' ? 0.25 : 1,
filter:
color && color !== 'transparent'
? 'grayscale(100%) contrast(200%) brightness(100%)'
: 'none',
width: '100%',
borderRadius: '50%',
display: 'block',
}}
/>
</Box>
)
}

export default Avatar
42 changes: 42 additions & 0 deletions src/blockquote.js
@@ -0,0 +1,42 @@
import React, { cloneElement, Children } from 'react'
import { Box } from 'theme-ui'

const specialChars = ['“', '"', "'", '‘']

const Blockquote = ({ children }) => {
let firstChar = ''

if (
Array.isArray(children) &&
children[0].props &&
typeof children[0].props.children === 'string'
) {
firstChar = children[0].props.children.slice(0, 1)
children = Children.map(children, (d, i) => {
if (i == 0) {
return cloneElement(d, { children: d.props.children.slice(1) })
} else return d
})
} else if (children.props && typeof children.props.children === 'string') {
firstChar = children.props.children.slice(0, 1)
children = cloneElement(children, {
children: children.props.children.slice(1),
})
} else if (typeof children === 'string') {
firstChar = children.slice(0, 1)
children = children.slice(1)
}

return (
<Box variant='styles.blockquote'>
{specialChars.includes(firstChar) && (
<Box as='span' sx={{ position: 'absolute', ml: '-0.4em' }}>
{firstChar}
</Box>
)}
{children}
</Box>
)
}

export default Blockquote
5 changes: 3 additions & 2 deletions src/button.js
Expand Up @@ -25,7 +25,8 @@ const Button = (

let offset, margin, top, height, width, strokeWidth

const color = sx && sx.color ? sx.color : null
const { color, ...sxProp } = sx || {}

const baseColor = color || (inverted ? 'secondary' : 'primary')
const hoverColor = color ? 'primary' : inverted ? 'primary' : 'secondary'

Expand Down Expand Up @@ -162,7 +163,7 @@ const Button = (
...suffixHover,
...prefixHover,
},
...sx,
...sxProp,
}

const Inner = (
Expand Down
34 changes: 34 additions & 0 deletions src/caption.js
@@ -0,0 +1,34 @@
import React from 'react'
import { Box } from 'theme-ui'

const Caption = ({ number, children, label = 'figure' }) => {
return (
<Box
as='figcaption'
sx={{
color: 'secondary',
mt: [3, 3, 3, 4],
mb: [6, 6, 6, 7],
fontSize: [2, 2, 2, 3],
}}
>
{number && (
<>
<Box
sx={{
textTransform: 'uppercase',
letterSpacing: 'smallcaps',
display: 'inline-block',
}}
>
{label} {number}
</Box>{' '}
<Box sx={{ display: 'inline-block', mx: [1], pr: [1] }}>/</Box>
</>
)}
{children}
</Box>
)
}

export default Caption