Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RNMobile] Embed Block Bottom Sheet to set a link #31343

Merged
merged 14 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions packages/block-library/src/embed/embed-bottom-sheet.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import {
LinkSettingsNavigation,
FooterMessageLink,
} from '@wordpress/components';
import { isURL } from '@wordpress/url';
import { useDispatch } from '@wordpress/data';
import { store as noticesStore } from '@wordpress/notices';

const linkSettingsOptions = {
url: {
label: __( 'Embed link' ),
placeholder: __( 'Add link' ),
autoFocus: true,
autoFill: true,
},
footer: {
label: (
<FooterMessageLink
href={ __( 'https://wordpress.org/support/article/embeds/' ) }
value={ __( 'Learn more about embeds' ) }
/>
),
separatorType: 'topFullWidth',
},
};

const EmbedBottomSheet = ( { value, isVisible, onClose, onSetAttributes } ) => {
const { createErrorNotice } = useDispatch( noticesStore );

function setAttributes( attributes ) {
const { url } = attributes;

if ( isURL( url ) ) {
onSetAttributes( attributes );
} else if ( url !== '' ) {
createErrorNotice( __( 'Invalid URL. Please enter a valid URL.' ) );
}
}

return (
<LinkSettingsNavigation
isVisible={ isVisible }
url={ value }
setAttributes={ setAttributes }
onClose={ onClose }
options={ linkSettingsOptions }
withBottomSheet
showIcon
/>
);
};

export default EmbedBottomSheet;
59 changes: 43 additions & 16 deletions packages/block-library/src/embed/embed-placeholder.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,24 @@ import { View, Text, TouchableWithoutFeedback } from 'react-native';
*/
import { __ } from '@wordpress/i18n';
import { usePreferredColorSchemeStyle } from '@wordpress/compose';
import { useState } from '@wordpress/element';

/**
* Internal dependencies
*/
import EmbedBottomSheet from './embed-bottom-sheet';
import styles from './styles.scss';

const EmbedPlaceholder = ( { icon, label, onFocus } ) => {
const EmbedPlaceholder = ( {
icon,
label,
onFocus,
value,
onSubmit,
onChange,
} ) => {
const [ isEmbedSheeVisible, setIsEmbedSheetVisible ] = useState( ! value );

const emptyStateContainerStyle = usePreferredColorSchemeStyle(
styles.emptyStateContainer,
styles.emptyStateContainerDark
Expand All @@ -26,21 +37,37 @@ const EmbedPlaceholder = ( { icon, label, onFocus } ) => {
);

return (
<TouchableWithoutFeedback
accessibilityRole={ 'button' }
accessibilityHint={ __( 'Double tap to add a link.' ) }
onPress={ ( event ) => {
onFocus( event );
} }
>
<View style={ emptyStateContainerStyle }>
<View style={ styles.modalIcon }>{ icon }</View>
<Text style={ emptyStateTitleStyle }>{ label }</Text>
<Text style={ styles.emptyStateDescription }>
{ __( 'ADD LINK' ) }
</Text>
</View>
</TouchableWithoutFeedback>
<>
{ value ? (
<Text>{ value }</Text>
) : (
hypest marked this conversation as resolved.
Show resolved Hide resolved
<TouchableWithoutFeedback
accessibilityRole={ 'button' }
accessibilityHint={ __( 'Double tap to add a link.' ) }
onPress={ ( event ) => {
onFocus( event );
setIsEmbedSheetVisible( true );
} }
>
<View style={ emptyStateContainerStyle }>
<View style={ styles.modalIcon }>{ icon }</View>
<Text style={ emptyStateTitleStyle }>{ label }</Text>
<Text style={ styles.emptyStateDescription }>
{ __( 'ADD LINK' ) }
</Text>
</View>
</TouchableWithoutFeedback>
) }
<EmbedBottomSheet
hypest marked this conversation as resolved.
Show resolved Hide resolved
value={ value }
isVisible={ isEmbedSheeVisible }
onClose={ () => setIsEmbedSheetVisible( false ) }
onSetAttributes={ ( { url } ) => {
hypest marked this conversation as resolved.
Show resolved Hide resolved
onChange( { target: { value: url } } );
hypest marked this conversation as resolved.
Show resolved Hide resolved
onSubmit();
hypest marked this conversation as resolved.
Show resolved Hide resolved
} }
/>
</>
);
};

Expand Down
5 changes: 4 additions & 1 deletion packages/components/src/mobile/link-settings/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,10 @@ function LinkSettings( {
</PanelBody>
{ options.footer && (
<PanelBody style={ styles.linkSettingsPanel }>
<FooterMessageControl label={ options.footer.label } />
<FooterMessageControl
label={ options.footer.label }
separatorType={ options.footer.separatorType }
/>
</PanelBody>
) }
{ actions && <PanelActions actions={ actions } /> }
Expand Down