Skip to content

Commit 68c4aaa

Browse files
layershifterharel
authored andcommitted
style(Sidebar): update typings and propTypes usage (Semantic-Org#1296)
1 parent 98a1bfa commit 68c4aaa

File tree

5 files changed

+63
-80
lines changed

5 files changed

+63
-80
lines changed

src/modules/Sidebar/Sidebar.js

+26-26
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,25 @@ import React, { PropTypes } from 'react'
33

44
import {
55
AutoControlledComponent as Component,
6-
META,
76
customPropTypes,
87
getUnhandledProps,
98
getElementType,
9+
META,
1010
useKeyOnly,
1111
} from '../../lib'
1212
import SidebarPushable from './SidebarPushable'
1313
import SidebarPusher from './SidebarPusher'
1414

15-
const _meta = {
16-
name: 'Sidebar',
17-
type: META.TYPES.MODULE,
18-
props: {
19-
animation: ['overlay', 'push', 'scale down', 'uncover', 'slide out', 'slide along'],
20-
direction: ['top', 'right', 'bottom', 'left'],
21-
width: ['very thin', 'thin', 'wide', 'very wide'],
22-
},
23-
}
24-
2515
/**
2616
* A sidebar hides additional content beside a page.
2717
*/
2818
class Sidebar extends Component {
29-
static _meta = _meta
30-
3119
static propTypes = {
3220
/** An element type to render as (string or function). */
3321
as: customPropTypes.as,
3422

3523
/** Animation style. */
36-
animation: PropTypes.oneOf(Sidebar._meta.props.animation),
24+
animation: PropTypes.oneOf(['overlay', 'push', 'scale down', 'uncover', 'slide out', 'slide along']),
3725

3826
/** Primary content. */
3927
children: PropTypes.node,
@@ -44,20 +32,16 @@ class Sidebar extends Component {
4432
/** Initial value of visible. */
4533
defaultVisible: PropTypes.bool,
4634

47-
/** Direction the sidebar should appear on */
48-
direction: PropTypes.oneOf(Sidebar._meta.props.direction),
35+
/** Direction the sidebar should appear on. */
36+
direction: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
4937

5038
/** Controls whether or not the sidebar is visible on the page. */
5139
visible: PropTypes.bool,
5240

53-
/** Sidebar width */
54-
width: PropTypes.oneOf(Sidebar._meta.props.width),
41+
/** Sidebar width. */
42+
width: PropTypes.oneOf(['very thin', 'thin', 'wide', 'very wide']),
5543
}
5644

57-
static Pushable = SidebarPushable
58-
59-
static Pusher = SidebarPusher
60-
6145
static defaultProps = {
6246
direction: 'left',
6347
}
@@ -66,6 +50,15 @@ class Sidebar extends Component {
6650
'visible',
6751
]
6852

53+
static _meta = {
54+
name: 'Sidebar',
55+
type: META.TYPES.MODULE,
56+
}
57+
58+
static Pushable = SidebarPushable
59+
60+
static Pusher = SidebarPusher
61+
6962
state = {}
7063

7164
startAnimating = (duration = 500) => {
@@ -83,17 +76,24 @@ class Sidebar extends Component {
8376
}
8477

8578
render() {
79+
const {
80+
animation,
81+
className,
82+
children,
83+
direction,
84+
visible,
85+
width,
86+
} = this.props
8687
const { animating } = this.state
87-
const { animation, className, children, direction, visible, width } = this.props
8888

8989
const classes = cx(
9090
'ui',
91-
'sidebar',
92-
useKeyOnly(animating, 'animating'),
91+
animation,
9392
direction,
9493
width,
95-
animation,
94+
useKeyOnly(animating, 'animating'),
9695
useKeyOnly(visible, 'visible'),
96+
'sidebar',
9797
className
9898
)
9999

src/modules/Sidebar/SidebarPushable.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,8 @@ import {
1212
* A pushable sub-component for Sidebar.
1313
*/
1414
function SidebarPushable(props) {
15-
const {
16-
className,
17-
children,
18-
} = props
19-
20-
const classes = cx(
21-
'pushable',
22-
className,
23-
)
15+
const { className, children } = props
16+
const classes = cx('pushable', className)
2417
const rest = getUnhandledProps(SidebarPushable, props)
2518
const ElementType = getElementType(SidebarPushable, props)
2619

src/modules/Sidebar/SidebarPusher.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,18 @@ import cx from 'classnames'
22
import React, { PropTypes } from 'react'
33

44
import {
5-
useKeyOnly,
65
customPropTypes,
76
getElementType,
87
getUnhandledProps,
98
META,
9+
useKeyOnly,
1010
} from '../../lib'
1111

1212
/**
1313
* A pushable sub-component for Sidebar.
1414
*/
1515
function SidebarPusher(props) {
16-
const {
17-
className,
18-
dimmed,
19-
children,
20-
} = props
16+
const { className, dimmed, children } = props
2117

2218
const classes = cx(
2319
'pusher',

src/modules/Sidebar/index.d.ts

+32-27
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,43 @@
11
import * as React from 'react';
22

3-
interface SidebarPushableProps {
3+
interface SidebarProps {
4+
[key: string]: any;
5+
46
/** An element type to render as (string or function). */
57
as?: any;
68

9+
/** Animation style. */
10+
animation?: 'overlay' | 'push' | 'scale down' | 'uncover' | 'slide out' | 'slide along';
11+
712
/** Primary content. */
813
children?: React.ReactNode;
914

1015
/** Additional classes. */
1116
className?: string;
1217

18+
/** Initial value of visible. */
19+
defaultVisible?: boolean;
20+
21+
/** Direction the sidebar should appear on. */
22+
direction?: 'top' | 'right' | 'bottom' | 'left';
23+
24+
/** Controls whether or not the sidebar is visible on the page. */
25+
visible?: boolean;
26+
27+
/** Sidebar width */
28+
width?: 'very thin' | 'thin' | 'wide' | 'very wide';
1329
}
1430

15-
export const SidebarPushable: React.ComponentClass<SidebarPushableProps>;
31+
interface SidebarComponent extends React.ComponentClass<SidebarProps> {
32+
Pushable: typeof SidebarPushable;
33+
Pusher: typeof SidebarPusher;
34+
}
35+
36+
export const Sidebar: SidebarComponent;
37+
38+
interface SidebarPushableProps {
39+
[key: string]: any;
1640

17-
interface SidebarPusherProps {
1841
/** An element type to render as (string or function). */
1942
as?: any;
2043

@@ -23,16 +46,12 @@ interface SidebarPusherProps {
2346

2447
/** Additional classes. */
2548
className?: string;
26-
27-
/** Controls whether or not the dim is displayed. */
28-
dimmed?: boolean;
2949
}
3050

31-
export const SidebarPusher: React.ComponentClass<SidebarPusherProps>;
51+
export const SidebarPushable: React.StatelessComponent<SidebarPushableProps>;
3252

33-
interface SidebarProps {
34-
/** Animation style. */
35-
animation?: 'overlay' | 'push' | 'scale down' | 'uncover' | 'slide out' | 'slide along';
53+
interface SidebarPusherProps {
54+
[key: string]: any;
3655

3756
/** An element type to render as (string or function). */
3857
as?: any;
@@ -43,22 +62,8 @@ interface SidebarProps {
4362
/** Additional classes. */
4463
className?: string;
4564

46-
/** Initial value of visible. */
47-
defaultVisible?: boolean;
48-
49-
/** Direction the sidebar should appear on */
50-
direction?: 'top' | 'right' | 'bottom' | 'left';
51-
52-
/** Controls whether or not the sidebar is visible on the page. */
53-
visible?: boolean;
54-
55-
/** Sidebar width */
56-
width?: 'very thin' | 'thin' | 'wide' | 'very wide';
57-
}
58-
59-
interface SidebarClass extends React.ComponentClass<SidebarProps> {
60-
Pushable: typeof SidebarPushable;
61-
Pusher: typeof SidebarPusher;
65+
/** Controls whether or not the dim is displayed. */
66+
dimmed?: boolean;
6267
}
6368

64-
export const Sidebar: SidebarClass;
69+
export const SidebarPusher: React.StatelessComponent<SidebarPusherProps>;
+1-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react'
2-
import _ from 'lodash'
32

43
import Sidebar from 'src/modules/Sidebar/Sidebar'
54
import * as common from 'test/specs/commonTests'
@@ -14,21 +13,11 @@ describe('Sidebar', () => {
1413
common.propValueOnlyToClassName(Sidebar, 'animation', [
1514
'overlay', 'push', 'scale down', 'uncover', 'slide out', 'slide along',
1615
])
16+
common.propValueOnlyToClassName(Sidebar, 'direction', ['top', 'right', 'bottom', 'left'])
1717
common.propValueOnlyToClassName(Sidebar, 'width', ['very thin', 'thin', 'wide', 'very wide'])
1818

1919
it('renders a <div /> element', () => {
2020
shallow(<Sidebar />)
2121
.should.have.tagName('div')
2222
})
23-
24-
it('renders children of the sidebar', () => {
25-
const wrapper = mount(<Sidebar><span /></Sidebar>)
26-
wrapper.children().at(0).should.have.tagName('span')
27-
})
28-
29-
it('adds direction value to className', () => {
30-
_.each(_.get(Sidebar, '_meta.props.direction'), propValue => {
31-
shallow(<Sidebar direction={propValue} />).should.have.className(propValue)
32-
})
33-
})
3423
})

0 commit comments

Comments
 (0)