-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Hidden): Add Hidden component (#103)
- Loading branch information
1 parent
9937ca1
commit 7879790
Showing
6 changed files
with
255 additions
and
101 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,7 @@ | ||
export default { | ||
'@media print': { | ||
'.hiddenOnPrint': { | ||
display: 'none' | ||
} | ||
} | ||
}; |
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,3 @@ | ||
// This file is automatically generated. | ||
// Please do not change this file! | ||
export const hiddenOnPrint: 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,97 @@ | ||
import React, { Fragment } from 'react'; | ||
import Hidden from './Hidden'; | ||
import Text from '../Text/Text'; | ||
|
||
export default { | ||
component: Hidden, | ||
examples: [ | ||
{ | ||
label: 'Hidden on Mobile', | ||
render: () => ( | ||
<Fragment> | ||
<Text>The following line is hidden on mobile:</Text> | ||
<Hidden mobile> | ||
<Text>Hidden on mobile.</Text> | ||
</Hidden> | ||
</Fragment> | ||
) | ||
}, | ||
{ | ||
label: 'Hidden on Desktop', | ||
render: () => ( | ||
<Fragment> | ||
<Text>The following line is hidden on desktop:</Text> | ||
<Hidden desktop> | ||
<Text>Hidden on desktop.</Text> | ||
</Hidden> | ||
</Fragment> | ||
) | ||
}, | ||
{ | ||
label: 'Hidden on Print', | ||
render: () => ( | ||
<Fragment> | ||
<Text>The following line is hidden on print:</Text> | ||
<Hidden print> | ||
<Text>Hidden on print.</Text> | ||
</Hidden> | ||
</Fragment> | ||
) | ||
}, | ||
{ | ||
label: 'Hidden on Screen', | ||
render: () => ( | ||
<Fragment> | ||
<Text>The following line is hidden on screen:</Text> | ||
<Hidden screen> | ||
<Text>Hidden on screen.</Text> | ||
</Hidden> | ||
</Fragment> | ||
) | ||
}, | ||
{ | ||
label: 'Hidden on Mobile (Inline)', | ||
render: () => ( | ||
<Text> | ||
The following text node is hidden on mobile:{' '} | ||
<Hidden inline mobile> | ||
Hidden on mobile. | ||
</Hidden> | ||
</Text> | ||
) | ||
}, | ||
{ | ||
label: 'Hidden on Desktop (Inline)', | ||
render: () => ( | ||
<Text> | ||
The following text node is hidden on desktop:{' '} | ||
<Hidden inline desktop> | ||
Hidden on desktop. | ||
</Hidden> | ||
</Text> | ||
) | ||
}, | ||
{ | ||
label: 'Hidden on Print (Inline)', | ||
render: () => ( | ||
<Text> | ||
The following text node is hidden on print:{' '} | ||
<Hidden inline print> | ||
Hidden on print. | ||
</Hidden> | ||
</Text> | ||
) | ||
}, | ||
{ | ||
label: 'Hidden on Screen (Inline)', | ||
render: () => ( | ||
<Text> | ||
The following text node is hidden on screen:{' '} | ||
<Hidden inline screen> | ||
Hidden on screen. | ||
</Hidden> | ||
</Text> | ||
) | ||
} | ||
] | ||
}; |
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,42 @@ | ||
import React, { Component, ReactNode } from 'react'; | ||
import Box from '../Box/Box'; | ||
import styles from './Hidden.css.js'; | ||
|
||
export interface HiddenProps { | ||
children: ReactNode; | ||
mobile?: boolean; | ||
desktop?: boolean; | ||
screen?: boolean; | ||
print?: boolean; | ||
inline?: boolean; | ||
} | ||
|
||
export default class Hidden extends Component<HiddenProps> { | ||
static displayName = 'Hidden'; | ||
|
||
render() { | ||
const { | ||
children, | ||
inline = false, | ||
mobile: hiddenOnMobile = false, | ||
desktop: hiddenOnDesktop = false, | ||
screen: hiddenOnScreen = false, | ||
print: hiddenOnPrint = false | ||
} = this.props; | ||
|
||
const display = inline ? 'inline' : 'block'; | ||
|
||
return ( | ||
<Box | ||
display={[ | ||
hiddenOnMobile || hiddenOnScreen ? 'none' : display, | ||
hiddenOnDesktop || hiddenOnScreen ? 'none' : display | ||
]} | ||
className={hiddenOnPrint ? styles.hiddenOnPrint : undefined} | ||
component={inline ? 'span' : 'div'} | ||
> | ||
{children} | ||
</Box> | ||
); | ||
} | ||
} |
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