Skip to content

Commit 196dc0b

Browse files
authored
Add scroll component (#68)
* Add scroll component * Swap width and height for maxWidth and maxHeight
1 parent 907b8d2 commit 196dc0b

3 files changed

Lines changed: 79 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React from 'react'
2+
import { shallow } from 'enzyme'
3+
4+
import { NAMESPACE } from '../../../constants'
5+
import { Scroll } from '../'
6+
7+
describe('<Scroll />', () => {
8+
it('passes in an optional className override', () => {
9+
const $ = shallow(<Scroll className="something else">_</Scroll>)
10+
expect($.hasClass(`${NAMESPACE}c-scroll`)).toBe(true)
11+
expect($.hasClass('something else')).toBe(true)
12+
})
13+
14+
it('renders a defined tag type', () => {
15+
const $ = shallow(<Scroll tag="article">_</Scroll>)
16+
expect($.type()).toBe('article')
17+
})
18+
19+
it('renders a div by default', () => {
20+
const $ = shallow(<Scroll>_</Scroll>)
21+
expect($.type()).toBe('div')
22+
})
23+
24+
it('renders with attributes', () => {
25+
const $ = shallow(
26+
<Scroll style={{ position: 'relative' }} ariaHidden>
27+
_
28+
</Scroll>
29+
)
30+
expect($.prop('style')).toEqual({
31+
position: 'relative'
32+
})
33+
expect($.prop('ariaHidden')).toBe(true)
34+
})
35+
36+
it('renders children', () => {
37+
const $ = shallow(<Scroll>test child</Scroll>)
38+
expect($.contains('test child')).toBe(true)
39+
})
40+
41+
it('renders a maxWidth and maxHeight', () => {
42+
const $ = shallow(<Scroll maxWidth="100px" maxHeight="500px">_</Scroll>)
43+
expect($.prop('style')).toEqual({
44+
maxWidth: '100px',
45+
maxHeight: '500px'
46+
})
47+
})
48+
})

src/components/Scroll/index.jsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { createElement as E } from 'react'
2+
import T from 'prop-types'
3+
4+
import { classNames } from '../../utils/'
5+
import { NAMESPACE, BLOCK_TAGS } from '../../constants'
6+
7+
const Scroll = ({ tag, maxWidth, maxHeight, className, children, ...rest }) =>
8+
E(
9+
tag || 'div',
10+
{
11+
className: classNames(`${NAMESPACE}c-scroll`, className),
12+
style: {
13+
maxWidth,
14+
maxHeight
15+
},
16+
...rest
17+
},
18+
children
19+
)
20+
21+
Scroll.propTypes = {
22+
tag: T.oneOf(BLOCK_TAGS),
23+
className: T.string,
24+
maxWidth: T.string,
25+
maxHeight: T.string,
26+
children: T.node.isRequired
27+
}
28+
29+
export { Scroll }

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { Navbar } from './components/Navbar/'
2323
import { Pagination } from './components/Pagination/'
2424
import { Pill } from './components/Pill/'
2525
import { ProgressBar } from './components/ProgressBar/'
26+
import { Scroll } from './components/Scroll/'
2627
import { StatusCard } from './components/StatusCard/'
2728
import { Table } from './components/Table/'
2829
import { Tabs } from './components/Tabs/'
@@ -53,6 +54,7 @@ export {
5354
Pagination,
5455
Pill,
5556
ProgressBar,
57+
Scroll,
5658
Section,
5759
SiteWrap,
5860
StatusCard,

0 commit comments

Comments
 (0)