-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
590 additions
and
965 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,45 @@ | ||
import React, { Component } from 'react'; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import styles from './Connect.module.scss'; | ||
import classnames from 'classnames'; | ||
|
||
class Connect extends Component { | ||
static displayName = 'Connect'; | ||
|
||
static propTypes = { | ||
left: PropTypes.node, | ||
right: PropTypes.node, | ||
children: PropTypes.node | ||
}; | ||
|
||
render() { | ||
const { | ||
left, | ||
right, | ||
children | ||
} = this.props; | ||
|
||
const leftMarkup = left | ||
? <div className={styles.Left}>{left}</div> | ||
: null; | ||
|
||
const rightMarkup = right | ||
? <div className={styles.Right}>{right}</div> | ||
: null; | ||
|
||
const primaryClasses = classnames( | ||
styles.Primary, | ||
left && styles.hasLeft, | ||
right && styles.hasRight, | ||
); | ||
|
||
return ( | ||
<div className={styles.Connect}> | ||
{leftMarkup} | ||
<div className={primaryClasses}>{children}</div> | ||
{rightMarkup} | ||
</div> | ||
); | ||
import { Box } from '../Box'; | ||
import { tokens } from '@sparkpost/design-tokens'; | ||
import styled from 'styled-components'; | ||
|
||
const FocusHandler = styled(Box)` | ||
&:focus-within { | ||
position: relative; | ||
z-index: ${tokens.zIndex_default}; | ||
} | ||
`; | ||
|
||
function Connect(props) { | ||
const { left, right, children } = props; | ||
|
||
const leftMarkup = left ? ( | ||
<FocusHandler flex="0 0 auto" mr="-1px"> | ||
{left} | ||
</FocusHandler> | ||
) : null; | ||
|
||
const rightMarkup = right ? ( | ||
<FocusHandler flex="0 0 auto" ml="-1px"> | ||
{right} | ||
</FocusHandler> | ||
) : null; | ||
|
||
return ( | ||
<Box display="flex"> | ||
{leftMarkup} | ||
<FocusHandler flex="1">{children}</FocusHandler> | ||
{rightMarkup} | ||
</Box> | ||
); | ||
} | ||
|
||
Connect.displayName = 'Connect'; | ||
Connect.propTypes = { | ||
left: PropTypes.node, | ||
right: PropTypes.node, | ||
children: PropTypes.node, | ||
}; | ||
|
||
export default Connect; |
61 changes: 43 additions & 18 deletions
61
packages/matchbox/src/components/Connect/tests/Connect.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,57 @@ | ||
import React from 'react'; | ||
import Connect from '../Connect'; | ||
import { shallow } from 'enzyme'; | ||
import 'jest-styled-components'; | ||
|
||
describe('Connect', () => { | ||
let wrapper; | ||
let props; | ||
beforeEach(() => { | ||
props = { | ||
left: <button>Button on Left</button>, | ||
right: <button>Button on Right</button> | ||
|
||
}; | ||
|
||
wrapper = shallow(<Connect {...props}><input type="text" /></Connect>); | ||
}); | ||
const subject = props => | ||
global.mountStyled( | ||
<Connect {...props}> | ||
<input type="text" /> | ||
</Connect>, | ||
); | ||
|
||
it('renders correctly with connected components on left & right', () => { | ||
expect(wrapper).toMatchSnapshot(); | ||
const wrapper = subject({ | ||
left: <button>Button on Left</button>, | ||
right: <button>Button on Right</button>, | ||
}); | ||
expect(wrapper).toHaveStyleRule('display', 'flex'); | ||
expect(wrapper.find('div').at(1)).toHaveStyleRule('flex', '0 0 auto'); | ||
expect(wrapper.find('div').at(2)).toHaveStyleRule('flex', '1'); | ||
expect( | ||
wrapper | ||
.find('div') | ||
.at(2) | ||
.find('input'), | ||
).toExist(); | ||
expect(wrapper.find('div').at(3)).toHaveStyleRule('flex', '0 0 auto'); | ||
}); | ||
|
||
it('renders correctly with connected components on left', () => { | ||
wrapper.setProps({ right: null }); | ||
expect(wrapper).toMatchSnapshot(); | ||
const wrapper = subject({ | ||
left: <button>Button on Left</button>, | ||
}); | ||
expect(wrapper).toHaveStyleRule('display', 'flex'); | ||
expect( | ||
wrapper | ||
.find('div') | ||
.at(1) | ||
.find('button'), | ||
).toExist(); | ||
expect(wrapper.find('button')).toHaveLength(1); | ||
}); | ||
|
||
it('renders correctly with connected components on right', () => { | ||
wrapper.setProps({ left: null }); | ||
expect(wrapper).toMatchSnapshot(); | ||
const wrapper = subject({ | ||
right: <button>Button on Right</button>, | ||
}); | ||
expect(wrapper).toHaveStyleRule('display', 'flex'); | ||
expect( | ||
wrapper | ||
.find('div') | ||
.at(2) | ||
.find('button'), | ||
).toExist(); | ||
expect(wrapper.find('button')).toHaveLength(1); | ||
}); | ||
|
||
}); |
71 changes: 0 additions & 71 deletions
71
packages/matchbox/src/components/Connect/tests/__snapshots__/Connect.test.js.snap
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.