-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RNMobile] Shortcode block support (#19534)
* Added very basic support for displaying shortcode blocks on pages * Updated style for native shortcode editing * Updated the shortcode block styles based on the style guide * Added test cases for shortcode block * Migrated shortcode attributes to block.json to be read by javascript and php * Correct formatting issues * Update test expectations to preserve attributes when shortcode isn't converted to block * Resolve PHP formatting issues * Removed unnecessary comment block. * Copy the block.json files with the php files to allow easier reference in php * Added very basic support for displaying shortcode blocks on pages * Migrated shortcode attributes to block.json to be read by javascript and php * Apply changes from master that add the devOnly const
- Loading branch information
1 parent
c4b2590
commit 931746b
Showing
9 changed files
with
135 additions
and
11 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,10 @@ | ||
{ | ||
"name": "core/shortcode", | ||
"category": "widgets", | ||
"attributes": { | ||
"text": { | ||
"type": "string", | ||
"source": "html" | ||
} | ||
} | ||
} |
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,45 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { View, Text } from 'react-native'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { PlainText } from '@wordpress/block-editor'; | ||
import { withPreferredColorScheme } from '@wordpress/compose'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
|
||
import styles from './style.scss'; | ||
|
||
export function ShortcodeEdit( props ) { | ||
const { attributes, setAttributes, onFocus, onBlur, getStylesFromColorScheme } = props; | ||
const titleStyle = getStylesFromColorScheme( styles.blockTitle, styles.blockTitleDark ); | ||
const shortcodeStyle = getStylesFromColorScheme( styles.blockShortcode, styles.blockShortcodeDark ); | ||
const placeholderStyle = getStylesFromColorScheme( styles.placeholder, styles.placeholderDark ); | ||
|
||
return ( | ||
<View> | ||
<Text style={ titleStyle } >{ __( 'Shortcode' ) }</Text> | ||
<PlainText | ||
value={ attributes.text } | ||
style={ shortcodeStyle } | ||
multiline={ true } | ||
underlineColorAndroid="transparent" | ||
onChange={ ( text ) => setAttributes( { text } ) } | ||
placeholder={ __( 'Add a shortcode…' ) } | ||
aria-label={ __( 'Shortcode' ) } | ||
isSelected={ props.isSelected } | ||
onFocus={ onFocus } | ||
onBlur={ onBlur } | ||
placeholderTextColor={ placeholderStyle.color } | ||
/> | ||
</View> | ||
); | ||
} | ||
|
||
export default withPreferredColorScheme( ShortcodeEdit ); |
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,37 @@ | ||
.blockTitle { | ||
font-family: $default-regular-font; | ||
font-weight: 500; | ||
font-size: 10px; | ||
color: rgba($black, 0.6); | ||
text-transform: uppercase; | ||
letter-spacing: 0.4px; | ||
} | ||
|
||
.blockTitleDark { | ||
color: rgba($white, 0.6); | ||
} | ||
|
||
.blockShortcode { | ||
font-family: $default-monospace-font; | ||
font-weight: 400; | ||
font-size: 14px; | ||
padding: 12px; | ||
border-radius: 4px; | ||
background-color: $gray-light; | ||
} | ||
|
||
.blockShortcodeDark { | ||
color: $white; | ||
background-color: $gray-100; | ||
} | ||
|
||
.placeholder { | ||
font-family: $default-monospace-font; | ||
font-weight: 400; | ||
font-size: 14px; | ||
color: rgba($black, 0.25); | ||
} | ||
|
||
.placeholderDark { | ||
color: $gray-50; | ||
} |
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,26 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import renderer from 'react-test-renderer'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Shortcode from '../edit'; | ||
import { TextInput } from 'react-native'; | ||
|
||
describe( 'Shortcode', () => { | ||
it( 'renders without crashing', () => { | ||
const component = renderer.create( <Shortcode attributes={ { text: '' } } /> ); | ||
const rendered = component.toJSON(); | ||
expect( rendered ).toBeTruthy(); | ||
} ); | ||
|
||
it( 'renders given text without crashing', () => { | ||
const component = renderer.create( <Shortcode attributes={ { text: '[youtube https://www.youtube.com/watch?v=ssfHW5lwFZg]' } } /> ); | ||
const testInstance = component.root; | ||
const textInput = testInstance.findByType( TextInput ); | ||
expect( textInput ).toBeTruthy(); | ||
expect( textInput.props.value ).toBe( '[youtube https://www.youtube.com/watch?v=ssfHW5lwFZg]' ); | ||
} ); | ||
} ); |
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