forked from WordPress/gutenberg
-
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.
- Loading branch information
Showing
6 changed files
with
165 additions
and
85 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
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,39 @@ | ||
# Badgeable | ||
|
||
Badgeable wraps a component and adds a `Badge` overlay to that component. It looks like this: | ||
|
||
![badgeable example](./example.png) | ||
|
||
A Badgeable component allows us to easily add badges to existing components without duplicating code for overlaying and positioning the Badge component. Moreover, with this approach, changing the positioning of badges can be done in one place instead of every place where a badge is visible. | ||
|
||
## Usage | ||
|
||
```jsx | ||
import { Image } from 'react-native'; | ||
import { Badgeable } from '@wordpress/components'; | ||
const BadgeableImage = () => ( | ||
<Badgeable text="gif" show={ url.includes( '.gif' ) }> | ||
<Image | ||
style={ { width: 50, height: 50 } } | ||
source={ { uri: 'https://facebook.github.io/react-native/img/tiny_logo.png' } } | ||
/> | ||
</Badgeable> | ||
)} > | ||
``` | ||
|
||
### Props | ||
|
||
#### text | ||
|
||
- Type: `String` | ||
- Required: Yes | ||
|
||
The text to display within the badge. An uppercase transform will be applied. | ||
|
||
#### show | ||
|
||
- Type: `Boolean` | ||
- Required: No | ||
- Default: `true` | ||
|
||
Whether to overlay the badge. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,23 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { Text, View } from 'react-native'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import styles from './styles.scss'; | ||
|
||
const Badge = ( { text } ) => ( | ||
<View style={ styles.badge }> | ||
<Text style={ styles.badgeText }>{ text }</Text> | ||
</View> | ||
); | ||
const Badgeable = ( { text, children, show = true } ) => ( | ||
<View> | ||
{ children } | ||
{ show && <Badge text={ text } /> } | ||
</View> | ||
); | ||
|
||
export default Badgeable; |
15 changes: 15 additions & 0 deletions
15
packages/components/src/mobile/badgeable/styles.native.scss
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,15 @@ | ||
.badge { | ||
position: absolute; | ||
top: 10px; | ||
left: 10px; | ||
background-color: rgba(85, 85, 85, 0.7); | ||
border-radius: 6px; | ||
padding: 3px 6px; | ||
} | ||
|
||
.badgeText { | ||
text-transform: uppercase; | ||
color: #fff; | ||
font-size: 12px; | ||
font-weight: 500; | ||
} |