forked from elastic/eui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added basic responsive utility components and classes
- Loading branch information
cchaos
committed
Jun 6, 2018
1 parent
f70ae17
commit 649f517
Showing
13 changed files
with
306 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react'; | ||
|
||
import { | ||
EuiCode, | ||
EuiHideFrom, | ||
EuiShowFor, | ||
} from '../../../../src/components'; | ||
|
||
export default () => ( | ||
<div> | ||
<EuiHideFrom sizes={['xs']}> | ||
Hiding from <EuiCode>xs</EuiCode> screens only | ||
</EuiHideFrom> | ||
<br/> | ||
<EuiHideFrom sizes={['xs','s']}> | ||
Hiding from <EuiCode>xs, s</EuiCode> screens | ||
</EuiHideFrom> | ||
<br/> | ||
<EuiHideFrom sizes={['xs','s','m']}> | ||
Hiding from <EuiCode>xs, s, m</EuiCode> screens | ||
</EuiHideFrom> | ||
<br/> | ||
<EuiHideFrom sizes={['l']}> | ||
Hiding from <EuiCode>l</EuiCode> screens only | ||
</EuiHideFrom> | ||
|
||
<br/> | ||
<br/> | ||
|
||
<EuiShowFor sizes={['xs']}> | ||
Showing for <EuiCode>xs</EuiCode> screens only | ||
</EuiShowFor> | ||
<br/> | ||
<EuiShowFor sizes={['xs','s']}> | ||
Showing for <EuiCode>xs, s</EuiCode> screens | ||
</EuiShowFor> | ||
<br/> | ||
<EuiShowFor sizes={['xs','s','m']}> | ||
Showing for <EuiCode>xs, s, m</EuiCode> screens | ||
</EuiShowFor> | ||
<br/> | ||
<EuiShowFor sizes={['l']}> | ||
Showing for <EuiCode>l</EuiCode> screen only | ||
</EuiShowFor> | ||
</div> | ||
); |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from 'react'; | ||
|
||
import { renderToHtml } from '../../services'; | ||
|
||
import { | ||
GuideSectionTypes, | ||
} from '../../components'; | ||
|
||
import { | ||
EuiCode, | ||
EuiShowFor, | ||
EuiHideFrom, | ||
} from '../../../../src/components'; | ||
|
||
import Responsive from './responsive'; | ||
const responsiveSource = require('!!raw-loader!./responsive'); | ||
const responsiveHtml = renderToHtml(Responsive); | ||
|
||
export const ResponsiveExample = { | ||
title: 'Responsive', | ||
sections: [{ | ||
title: 'EuiShowFor and EuiHideFrom', | ||
source: [{ | ||
type: GuideSectionTypes.JS, | ||
code: responsiveSource, | ||
}, { | ||
type: GuideSectionTypes.HTML, | ||
code: responsiveHtml, | ||
}], | ||
text: ( | ||
<p> | ||
Pass an array of screen widths <EuiCode>[xs, s, m, l]</EuiCode> to either | ||
the <EuiCode>EuiShowFor</EuiCode> or <EuiCode>EuiHideFrom</EuiCode> components | ||
to make them responsive. | ||
</p> | ||
), | ||
props: { EuiShowFor, EuiHideFrom }, | ||
demo: <Responsive />, | ||
}], | ||
}; |
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
9 changes: 9 additions & 0 deletions
9
src/components/responsive/__snapshots__/hide_from.test.js.snap
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`EuiHideFrom is rendered 1`] = ` | ||
<span | ||
aria-label="aria-label" | ||
class="euiHideFrom euiHideFrom--xsmall euiHideFrom--small euiHideFrom--medium euiHideFrom--large testClass1 testClass2" | ||
data-test-subj="test subject string" | ||
/> | ||
`; |
9 changes: 9 additions & 0 deletions
9
src/components/responsive/__snapshots__/show_for.test.js.snap
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`EuiShowFor is rendered 1`] = ` | ||
<span | ||
aria-label="aria-label" | ||
class="euiShowFor euiShowFor--xsmall euiShowFor--small euiShowFor--medium euiShowFor--large testClass1 testClass2" | ||
data-test-subj="test subject string" | ||
/> | ||
`; |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
|
||
const responsiveSizesToClassNameMap = { | ||
xs: 'euiHideFrom--xsmall', | ||
s: 'euiHideFrom--small', | ||
m: 'euiHideFrom--medium', | ||
l: 'euiHideFrom--large', | ||
} | ||
|
||
const RESPONSIVE_SIZES = Object.keys(responsiveSizesToClassNameMap); | ||
|
||
export const EuiHideFrom = ({ | ||
children, | ||
className, | ||
sizes, | ||
...rest, | ||
}) => { | ||
|
||
const sizingClasses = sizes.map(function(item){ | ||
return responsiveSizesToClassNameMap[item]; | ||
}); | ||
|
||
const classes = classNames( | ||
'euiHideFrom', | ||
sizingClasses, | ||
className | ||
); | ||
|
||
return ( | ||
<span | ||
className={classes} | ||
{...rest} | ||
> | ||
{children} | ||
</span> | ||
); | ||
}; | ||
|
||
EuiHideFrom.propTypes = { | ||
children: PropTypes.node, | ||
className: PropTypes.string, | ||
/** | ||
* List of all the responsive sizes to hide the children from | ||
*/ | ||
sizes: PropTypes.arrayOf(PropTypes.oneOf(RESPONSIVE_SIZES)).isRequired, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import { render } from 'enzyme'; | ||
import { requiredProps } from '../../test'; | ||
|
||
import { EuiHideFrom } from './hide_from'; | ||
|
||
describe('EuiHideFrom', () => { | ||
test('is rendered', () => { | ||
const component = render( | ||
<EuiHideFrom sizes={['xs', 's', 'm', 'l']} {...requiredProps} /> | ||
); | ||
|
||
expect(component) | ||
.toMatchSnapshot(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export { | ||
EuiHideFrom, | ||
} from './hide_from'; | ||
|
||
export { | ||
EuiShowFor, | ||
} from './show_for'; |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
|
||
const responsiveSizesToClassNameMap = { | ||
xs: 'euiShowFor--xsmall', | ||
s: 'euiShowFor--small', | ||
m: 'euiShowFor--medium', | ||
l: 'euiShowFor--large', | ||
} | ||
|
||
const RESPONSIVE_SIZES = Object.keys(responsiveSizesToClassNameMap); | ||
|
||
export const EuiShowFor = ({ | ||
children, | ||
className, | ||
sizes, | ||
...rest, | ||
}) => { | ||
|
||
const sizingClasses = sizes.map(function(item){ | ||
return responsiveSizesToClassNameMap[item]; | ||
}); | ||
|
||
const classes = classNames( | ||
'euiShowFor', | ||
sizingClasses, | ||
className | ||
); | ||
|
||
return ( | ||
<span | ||
className={classes} | ||
{...rest} | ||
> | ||
{children} | ||
</span> | ||
); | ||
}; | ||
|
||
EuiShowFor.propTypes = { | ||
children: PropTypes.node, | ||
className: PropTypes.string, | ||
/** | ||
* List of all the responsive sizes to show the children for | ||
*/ | ||
sizes: PropTypes.arrayOf(PropTypes.oneOf(RESPONSIVE_SIZES)).isRequired, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import { render } from 'enzyme'; | ||
import { requiredProps } from '../../test'; | ||
|
||
import { EuiShowFor } from './show_for'; | ||
|
||
describe('EuiShowFor', () => { | ||
test('is rendered', () => { | ||
const component = render( | ||
<EuiShowFor sizes={['xs', 's', 'm', 'l']} {...requiredProps} /> | ||
); | ||
|
||
expect(component) | ||
.toMatchSnapshot(); | ||
}); | ||
}); |
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