Skip to content

Commit 61d4c16

Browse files
committed
✨ Add Link component
1 parent 6dbe34a commit 61d4c16

File tree

8 files changed

+106
-50
lines changed

8 files changed

+106
-50
lines changed

.internal/theme.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
import { css } from '@emotion/core'
2+
3+
const Link = css`
4+
&:hover {
5+
text-decoration: underline;
6+
}
7+
`
8+
19
const theme = {
210
media: {
311
sm: '(max-width: 600px)',
@@ -13,7 +21,8 @@ const theme = {
1321
palette: {
1422
default: {
1523
bg: '#fff',
16-
fg: '#000'
24+
fg: '#000',
25+
link: 'royalblue'
1726
},
1827
gray: {
1928
bg: '#eee',
@@ -40,10 +49,12 @@ const theme = {
4049
lineHeight: 1.2
4150
},
4251
heading: {
43-
fontSize: '1.5rem',
52+
fontFamily: 'athelas, georgia, times, serif',
53+
fontSize: '2.5rem',
4454
fontWeight: 'bold'
4555
}
46-
}
56+
},
57+
Link
4758
}
4859

4960
const themeWithRems = {

docs/image.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import { Image } from 'pss-components'
4949
<Playground>
5050
<picture>
5151
<source
52-
srcset="http://placekitten.com/1024/768"
52+
srcSet="http://placekitten.com/1024/768"
5353
media="(min-width: 1024px)"
5454
/>
5555
<Image

docs/link.mdx

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
name: Link
3+
route: /link
4+
menu: Primitives
5+
---
6+
7+
import { Playground } from 'docz'
8+
import { ThemeProvider } from 'emotion-theming'
9+
import { PropsTable } from '../.internal/props-table'
10+
import { theme } from '../.internal/theme'
11+
import { Link, Box } from '../src'
12+
13+
# Link
14+
15+
## Description
16+
17+
Based on [Text](/text). Renders `<a>` element.
18+
19+
20+
## Usage
21+
22+
```js
23+
import { Link } from 'pss-components'
24+
```
25+
26+
<Playground>
27+
<Link href='http://example.com' target='_blank'>
28+
Link
29+
</Link>
30+
</Playground>
31+
32+
33+
## Props
34+
35+
<PropsTable of={Link} />

docs/text.mdx

+34-32
Original file line numberDiff line numberDiff line change
@@ -14,62 +14,64 @@ import { Text, Box } from '../src'
1414

1515
## Description
1616

17-
Text component, that renders as `<div>` with [typography prop styles](https://github.com/exah/pss/blob/master/docs/api.md#typography) and [base prop styles](https://github.com/exah/pss/blob/master/docs/api.md#base). Component inside can be changed with `as` prop.
17+
Based on [Box](/box) with [text system](https://github.com/exah/pss/blob/master/docs/api.md#text). Element inside can be changed with `use` prop, default to `<div>`,
1818

1919
## Usage
2020

21-
### Basic
22-
2321
```js
2422
import { Text } from 'pss-components'
2523
```
2624

27-
```js
28-
<Text use='p' textAlign='center'>
29-
Text
30-
</Text>
31-
```
25+
<Playground>
26+
<Text use='p'>Text</Text>
27+
</Playground>
28+
29+
30+
## Examples
31+
32+
### Change style with [text](https://github.com/exah/pss/blob/master/docs/api.md#text) props
33+
34+
<Playground>
35+
<Text
36+
use='p'
37+
textAlign='center'
38+
fontFamily='default'
39+
fontSize={24}
40+
lineHeight={2}
41+
fontWeight={300}
42+
letterSpacing='0.2px'
43+
color='tomato'
44+
>
45+
Text
46+
</Text>
47+
</Playground>
48+
3249

33-
### Add Text Styles to theme
50+
### Set variant
3451

35-
See [textStyle](https://github.com/exah/pss/blob/master/docs/api.md#textstyle) docs.
52+
See [textStyle docs](https://github.com/exah/pss/blob/master/docs/api.md#textstyle).
3653

3754
```js
3855
const theme = {
39-
fontFamily: {
40-
default: 'Helvetica, system-ui, sans-serif',
41-
serif: 'Times New Roman, serif'
42-
},
4356
textStyle: {
44-
root: {
45-
fontFamily: 'Helvetica, system-ui, sans-serif',
46-
fontSize: 16,
47-
lineHeight: 1.2
48-
},
4957
default: {
50-
fontSize: '1rem'
58+
fontFamily: 'system-ui, sans-serif',
59+
fontSize: '1rem',
60+
fontWeight: 'normal'
5161
},
5262
heading: {
53-
fontSize: '1.5rem',
63+
fontFamily: 'athelas, georgia, times, serif',
64+
fontSize: '2rem',
5465
fontWeight: 'bold'
5566
}
5667
}
5768
}
5869
```
5970

60-
## Examples
61-
62-
<Playground>
63-
<Text use='p' textAlign='center'>
64-
Text
65-
</Text>
66-
</Playground>
67-
68-
6971
<Playground>
7072
<ThemeProvider theme={theme}>
71-
<Text use='h1' variant='heading' fontFamily='serif' textAlign='center'>
72-
Text
73+
<Text use='h1' variant='heading'>
74+
Heading
7375
</Text>
7476
</ThemeProvider>
7577
</Playground>

src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export { FlexGrid } from './flex-grid'
55
export { Grid } from './grid'
66
export { Image } from './image'
77
export { Layout } from './layout'
8+
export { Link } from './link'
89
export { List } from './list'
910

1011
export {

src/link.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import use from 'reuse'
2+
import styled from '@emotion/styled'
3+
import { themePath } from 'pss'
4+
import { Text } from './text'
5+
6+
const LinkBase = styled(use('a'))(
7+
{ color: 'inherit', textDecoration: 'none' },
8+
themePath('Link')
9+
)
10+
11+
const Link = use(Text, LinkBase)
12+
13+
Link.displayName = 'Link'
14+
Link.propTypes = { ...Text.propTypes }
15+
Link.defaultProps = { ...Text.defaultProps, color: 'link' }
16+
17+
export {
18+
Link
19+
}

src/text.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,14 @@ const TextBase = base({
1515
})
1616

1717
const Text = styled(use(TextBase, Box))(
18-
{
19-
color: 'inherit',
20-
font: 'inherit',
21-
textDecoration: 'none'
22-
},
18+
{ font: 'inherit' },
2319
themePath('Text'),
2420
styles
2521
)
2622

2723
Text.displayName = 'Text'
2824
Text.propTypes = { ...styles.propTypes, ...Box.propTypes }
25+
Text.defaultProps = {}
2926

3027
export {
3128
Text

test/__snapshots__/index.js.snap

-9
Original file line numberDiff line numberDiff line change
@@ -1632,10 +1632,7 @@ exports[`Text empty 1`] = `
16321632
margin: 0;
16331633
padding: 0;
16341634
min-width: 0;
1635-
color: inherit;
16361635
font: inherit;
1637-
-webkit-text-decoration: none;
1638-
text-decoration: none;
16391636
}
16401637
16411638
<div
@@ -1650,10 +1647,7 @@ exports[`Text with text 1`] = `
16501647
margin: 0;
16511648
padding: 0;
16521649
min-width: 0;
1653-
color: inherit;
16541650
font: inherit;
1655-
-webkit-text-decoration: none;
1656-
text-decoration: none;
16571651
}
16581652
16591653
<div
@@ -1670,10 +1664,7 @@ exports[`Text with theme 1`] = `
16701664
margin: 0;
16711665
padding: 0;
16721666
min-width: 0;
1673-
color: inherit;
16741667
font: inherit;
1675-
-webkit-text-decoration: none;
1676-
text-decoration: none;
16771668
font-family: Helvetica,system-ui,sans-serif;
16781669
font-size: 1rem;
16791670
line-height: 1.2;

0 commit comments

Comments
 (0)