Skip to content

Commit 95ab3d2

Browse files
committed
♻️ Remove extend utility
1 parent 88cdfbf commit 95ab3d2

File tree

5 files changed

+34
-46
lines changed

5 files changed

+34
-46
lines changed

docs/image.mdx

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ menu: Primitives
55
---
66

77
import { Playground } from 'docz'
8+
import { PropsTable } from '../.internal/props-table'
89
import { Image } from '../src'
910

1011
# Image
@@ -18,3 +19,8 @@ import { Image } from 'pss-components'
1819
<Playground>
1920
<Image src='http://placekitten.com/500' width={1 / 2} alt='' />
2021
</Playground>
22+
23+
24+
## Props Table
25+
26+
<PropsTable of={Image} />

src/image.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
import React from 'react'
1+
import use from 'reuse'
2+
import styled from '@emotion/styled'
3+
import { themePath } from 'pss'
24
import { Box } from './box'
3-
import { extend } from './utils'
45

5-
const Image = extend(props => (
6-
<Box
7-
use='img'
8-
display='block'
9-
maxWidth='100%'
10-
height='auto'
11-
{...props}
12-
/>
13-
))
6+
const Image = styled(use(Box, 'img'))(
7+
themePath('image')
8+
)
149

1510
Image.displayName = 'Image'
11+
Image.propTypes = { ...Box.propTypes }
12+
13+
Image.defaultProps = {
14+
display: 'block',
15+
maxWidth: '100%',
16+
height: 'auto'
17+
}
1618

1719
export {
1820
Image

src/layout.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import React from 'react'
22
import { Flex } from './flex'
33
import { Box } from './box'
4-
import { extend } from './utils'
4+
import { withRef } from './utils'
55

6-
const Layout = extend(props => (
6+
const Layout = withRef((props) => (
77
<Flex flex='1 1 auto' {...props} />
88
))
99

10-
const LayoutSide = extend(props => (
10+
const LayoutSide = withRef((props) => (
1111
<Box flex='0 0 auto' {...props} />
1212
))
1313

14-
const LayoutContent = extend(props => (
14+
const LayoutContent = withRef((props) => (
1515
<Box flex='1 1 auto' {...props} />
1616
))
1717

src/utils.js

+1-21
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import React from 'react'
22
import PropTypes from 'prop-types'
3-
import { filterObj, isStr, flatten, identity } from '@exah/utils'
3+
import { filterObj, isStr, identity } from '@exah/utils'
44

55
export const omit = (blacklist = []) => filterObj((key) => !blacklist.includes(key))
66
export const omitStyles = (styles) => omit(Object.keys(Object(styles.propTypes)))
7-
export const cx = (...args) => flatten(args).filter(isStr).join(' ')
87

98
export const withRef = (render) => React.forwardRef(
109
(props, ref) => render({ ref, ...props })
@@ -42,22 +41,3 @@ export function base ({
4241
}
4342
})
4443
}
45-
46-
const generateClassName = ((id) => () => {
47-
id++
48-
return 'pss-' + id
49-
})(-1)
50-
51-
export function extend (render) {
52-
const className = generateClassName()
53-
54-
const Comp = withRef((props) =>
55-
render({ ...props, className: cx(props.className, className) })
56-
)
57-
58-
return Object.defineProperties(Comp, {
59-
toString: {
60-
value: () => `.${className}`
61-
}
62-
})
63-
}

test/__snapshots__/index.js.snap

+10-10
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ exports[`Grid basic 1`] = `
14731473
`;
14741474

14751475
exports[`Image empty 1`] = `
1476-
.emotion-0 {
1476+
.emotion-1 {
14771477
box-sizing: border-box;
14781478
border: 0;
14791479
margin: 0;
@@ -1485,26 +1485,26 @@ exports[`Image empty 1`] = `
14851485
}
14861486
14871487
<img
1488-
className="pss-3 emotion-0 emotion-1"
1488+
className="emotion-0 emotion-1 emotion-2"
14891489
/>
14901490
`;
14911491

14921492
exports[`Image with image 1`] = `
1493-
.emotion-0 {
1493+
.emotion-1 {
14941494
box-sizing: border-box;
14951495
border: 0;
14961496
margin: 0;
14971497
padding: 0;
14981498
min-width: 0;
1499+
width: 50%;
14991500
display: block;
15001501
max-width: 100%;
15011502
height: auto;
1502-
width: 50%;
15031503
}
15041504
15051505
<img
15061506
alt=""
1507-
className="pss-3 emotion-0 emotion-1"
1507+
className="emotion-0 emotion-1 emotion-2"
15081508
src="http://placekitten.com/500"
15091509
/>
15101510
`;
@@ -1549,15 +1549,15 @@ exports[`Layout Holy Grail 1`] = `
15491549
}
15501550
15511551
<div
1552-
className="pss-0 emotion-6 emotion-7 emotion-1"
1552+
className="emotion-6 emotion-7 emotion-1"
15531553
>
15541554
<header
15551555
className="emotion-0 emotion-1"
15561556
>
15571557
Header
15581558
</header>
15591559
<main
1560-
className="pss-2 emotion-2 emotion-1"
1560+
className="emotion-2 emotion-1"
15611561
>
15621562
Main
15631563
</main>
@@ -1608,15 +1608,15 @@ exports[`Layout Media Object 1`] = `
16081608
}
16091609
16101610
<div
1611-
className="pss-0 emotion-4 emotion-5 emotion-1"
1611+
className="emotion-4 emotion-5 emotion-1"
16121612
>
16131613
<div
1614-
className="pss-1 emotion-0 emotion-1"
1614+
className="emotion-0 emotion-1"
16151615
>
16161616
Side
16171617
</div>
16181618
<div
1619-
className="pss-2 emotion-2 emotion-1"
1619+
className="emotion-2 emotion-1"
16201620
>
16211621
Content
16221622
</div>

0 commit comments

Comments
 (0)