Skip to content

Commit df2f197

Browse files
author
Alexander Fedyashov
committed
wip
1 parent d09f519 commit df2f197

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+295
-245
lines changed

src/addons/Responsive/Responsive.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@ import React, { Component } from 'react'
55
import {
66
customPropTypes,
77
eventStack,
8-
getElementType,
98
getUnhandledProps,
109
META,
10+
withElementType,
1111
} from '../../lib'
1212

13-
const ElementType = getElementType()
14-
1513
/**
1614
* Responsive can control visibility of content.
1715
*/
18-
export default class Responsive extends Component {
16+
class Responsive extends Component {
1917
static propTypes = {
2018
/** An element type to render as (string or function). */
2119
as: customPropTypes.as,
@@ -49,12 +47,6 @@ export default class Responsive extends Component {
4947
type: META.TYPES.ADDON,
5048
}
5149

52-
static onlyMobile = { minWidth: 320, maxWidth: 767 }
53-
static onlyTablet = { minWidth: 768, maxWidth: 991 }
54-
static onlyComputer = { minWidth: 992 }
55-
static onlyLargeScreen = { minWidth: 1200, maxWidth: 1919 }
56-
static onlyWidescreen = { minWidth: 1920 }
57-
5850
constructor(...args) {
5951
super(...args)
6052
this.state = { width: window.innerWidth }
@@ -112,10 +104,20 @@ export default class Responsive extends Component {
112104
// ----------------------------------------
113105

114106
render() {
115-
const { children } = this.props
107+
const { as: ElementType, children } = this.props
116108
const rest = getUnhandledProps(Responsive, this.props)
117-
109+
console.error(ElementType)
118110
if (this.isVisible()) return <ElementType {...rest}>{children}</ElementType>
119111
return null
120112
}
121113
}
114+
115+
const ResponsiveEnc = withElementType(Responsive)
116+
117+
ResponsiveEnc.onlyMobile = { minWidth: 320, maxWidth: 767 }
118+
ResponsiveEnc.onlyTablet = { minWidth: 768, maxWidth: 991 }
119+
ResponsiveEnc.onlyComputer = { minWidth: 992 }
120+
ResponsiveEnc.onlyLargeScreen = { minWidth: 1200, maxWidth: 1919 }
121+
ResponsiveEnc.onlyWidescreen = { minWidth: 1920 }
122+
123+
export default ResponsiveEnc

src/elements/Flag/Flag.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import React, { Component } from 'react'
55
import {
66
createShorthandFactory,
77
customPropTypes,
8-
getElementType,
98
getUnhandledProps,
109
META,
1110
shallowEqual,
11+
withElementType,
1212
} from '../../lib'
1313

1414
export const names = [
@@ -84,15 +84,14 @@ class Flag extends Component {
8484
}
8585

8686
render() {
87-
const { className, name } = this.props
87+
const { as: ElementType, className, name } = this.props
8888
const classes = cx(name, 'flag', className)
8989
const rest = getUnhandledProps(Flag, this.props)
90-
const ElementType = getElementType(Flag, this.props)
9190

9291
return <ElementType {...rest} className={classes} />
9392
}
9493
}
9594

9695
Flag.create = createShorthandFactory(Flag, value => ({ name: value }))
9796

98-
export default Flag
97+
export default withElementType(Flag)

src/elements/Icon/Icon.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@ import React, { Component } from 'react'
66
import {
77
createShorthandFactory,
88
customPropTypes,
9-
getElementType,
109
getUnhandledProps,
1110
META,
1211
shallowEqual,
1312
SUI,
1413
useKeyOnly,
1514
useValueAndKey,
15+
withElementType,
1616
} from '../../lib'
1717
import IconGroup from './IconGroup'
1818

19-
const ElementType = getElementType()
20-
2119
/**
2220
* An icon is a glyph used to represent something else.
2321
* @see Image
@@ -87,6 +85,7 @@ class Icon extends Component {
8785

8886
render() {
8987
const {
88+
as: ElementType,
9089
bordered,
9190
circular,
9291
className,
@@ -128,4 +127,4 @@ class Icon extends Component {
128127

129128
Icon.create = createShorthandFactory(Icon, value => ({ name: value }))
130129

131-
export default Icon
130+
export default withElementType(Icon)

src/elements/Icon/IconGroup.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@ import React from 'react'
55

66
import {
77
customPropTypes,
8-
getElementType,
98
getUnhandledProps,
109
META,
1110
SUI,
11+
withElementType,
1212
} from '../../lib'
1313

14-
const ElementType = getElementType()
15-
1614
/**
1715
* Several icons can be used together as a group.
1816
*/
1917
function IconGroup(props) {
20-
const { children, className, size } = props
18+
const { as: ElementType, children, className, size } = props
2119
const classes = cx(
2220
size,
2321
'icons',
@@ -52,4 +50,4 @@ IconGroup.defaultProps = {
5250
as: 'i',
5351
}
5452

55-
export default IconGroup
53+
export default withElementType(IconGroup)

src/elements/Image/Image.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import {
77
childrenUtils,
88
createShorthandFactory,
99
customPropTypes,
10-
getElementType,
1110
getUnhandledProps,
1211
META,
1312
SUI,
1413
useKeyOnly,
1514
useKeyOrValueAndKey,
1615
useValueAndKey,
1716
useVerticalAlignProp,
17+
withElementType,
1818
} from '../../lib'
1919
import Dimmer from '../../modules/Dimmer'
2020
import Label from '../Label/Label'
@@ -123,14 +123,9 @@ class Image extends Component {
123123

124124
static Group = ImageGroup
125125

126-
computeElementType = () => {
127-
const { dimmer, children, label, wrapped } = this.props
128-
129-
if (!_.isNil(dimmer) || !_.isNil(label) || !_.isNil(wrapped) || !childrenUtils.isNil(children)) return 'div'
130-
}
131-
132126
render() {
133127
const {
128+
as: ElementType,
134129
alt,
135130
avatar,
136131
bordered,
@@ -173,7 +168,6 @@ class Image extends Component {
173168
className,
174169
)
175170
const rest = getUnhandledProps(Image, this.props)
176-
const ElementType = getElementType(Image, this.props, this.computeElementType)
177171

178172
if (!childrenUtils.isNil(children)) {
179173
return <ElementType {...rest} className={classes}>{children}</ElementType>
@@ -195,4 +189,6 @@ class Image extends Component {
195189

196190
Image.create = createShorthandFactory(Image, value => ({ src: value }))
197191

198-
export default Image
192+
export default withElementType(Image, ({ dimmer, children, label, wrapped }) => {
193+
if (!_.isNil(dimmer) || !_.isNil(label) || !_.isNil(wrapped) || !childrenUtils.isNil(children)) return 'div'
194+
})

src/elements/Image/ImageGroup.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@ import React from 'react'
44

55
import {
66
customPropTypes,
7-
getElementType,
87
getUnhandledProps,
98
META,
109
SUI,
10+
withElementType,
1111
} from '../../lib'
1212

1313
/**
1414
* A group of images.
1515
*/
1616
function ImageGroup(props) {
17-
const { children, className, size } = props
17+
const { as: ElementType, children, className, size } = props
1818
const classes = cx('ui', size, className, 'images')
1919
const rest = getUnhandledProps(ImageGroup, props)
20-
const ElementType = getElementType(ImageGroup, props)
2120

2221
return <ElementType {...rest} className={classes}>{children}</ElementType>
2322
}
@@ -42,4 +41,4 @@ ImageGroup.propTypes = {
4241
size: PropTypes.oneOf(SUI.SIZES),
4342
}
4443

45-
export default ImageGroup
44+
export default withElementType(ImageGroup)

src/elements/Label/Label.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import {
88
createShorthand,
99
createShorthandFactory,
1010
customPropTypes,
11-
getElementType,
1211
getUnhandledProps,
1312
META,
1413
SUI,
1514
useKeyOnly,
1615
useKeyOrValueAndKey,
1716
useValueAndKey,
17+
withElementType,
1818
} from '../../lib'
1919
import Icon from '../Icon/Icon'
2020
import Image from '../Image/Image'
@@ -24,7 +24,7 @@ import LabelGroup from './LabelGroup'
2424
/**
2525
* A label displays content classification.
2626
*/
27-
export default class Label extends Component {
27+
class Label extends Component {
2828
static propTypes = {
2929
/** An element type to render as (string or function). */
3030
as: customPropTypes.as,
@@ -212,3 +212,5 @@ export default class Label extends Component {
212212
}
213213

214214
Label.create = createShorthandFactory(Label, value => ({ content: value }))
215+
216+
export default withElementType(Label)

src/elements/Label/LabelDetail.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ import React from 'react'
55
import {
66
childrenUtils,
77
customPropTypes,
8-
getElementType,
98
getUnhandledProps,
109
META,
10+
withElementType,
1111
} from '../../lib'
1212

1313
function LabelDetail(props) {
1414
const { children, className, content } = props
1515
const classes = cx('detail', className)
1616
const rest = getUnhandledProps(LabelDetail, props)
17-
const ElementType = getElementType(LabelDetail, props)
1817

1918
return (
2019
<ElementType {...rest} className={classes}>
@@ -43,4 +42,4 @@ LabelDetail.propTypes = {
4342
content: customPropTypes.contentShorthand,
4443
}
4544

46-
export default LabelDetail
45+
export default withElementType(LabelDetail)

src/elements/Label/LabelGroup.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ import React from 'react'
44

55
import {
66
customPropTypes,
7-
getElementType,
87
getUnhandledProps,
98
META,
109
SUI,
1110
useKeyOnly,
11+
withElementType,
1212
} from '../../lib'
1313

1414
/**
1515
* A label can be grouped.
1616
*/
1717
function LabelGroup(props) {
1818
const {
19+
as: ElementType,
1920
children,
2021
circular,
2122
className,
@@ -34,7 +35,6 @@ function LabelGroup(props) {
3435
className,
3536
)
3637
const rest = getUnhandledProps(LabelGroup, props)
37-
const ElementType = getElementType(LabelGroup, props)
3838

3939
return <ElementType {...rest} className={classes}>{children}</ElementType>
4040
}
@@ -68,4 +68,4 @@ LabelGroup.propTypes = {
6868
tag: PropTypes.bool,
6969
}
7070

71-
export default LabelGroup
71+
export default withElementType(LabelGroup)

src/elements/Rail/Rail.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@ import React from 'react'
55

66
import {
77
customPropTypes,
8-
getElementType,
98
getUnhandledProps,
109
META,
1110
SUI,
1211
useKeyOnly,
1312
useKeyOrValueAndKey,
13+
withElementType,
1414
} from '../../lib'
1515

1616
/**
1717
* A rail is used to show accompanying content outside the boundaries of the main view of a site.
1818
*/
1919
function Rail(props) {
2020
const {
21+
as: ElementType,
2122
attached,
2223
children,
2324
className,
@@ -40,7 +41,6 @@ function Rail(props) {
4041
className,
4142
)
4243
const rest = getUnhandledProps(Rail, props)
43-
const ElementType = getElementType(Rail, props)
4444

4545
return <ElementType {...rest} className={classes}>{children}</ElementType>
4646
}
@@ -82,4 +82,4 @@ Rail.propTypes = {
8282
size: PropTypes.oneOf(_.without(SUI.SIZES, 'medium')),
8383
}
8484

85-
export default Rail
85+
export default withElementType(Rail)

0 commit comments

Comments
 (0)