-
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.
Make a simple version of Link that displays on mobile
- Loading branch information
Showing
7 changed files
with
287 additions
and
4 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,31 @@ | ||
import { TextInput, View } from 'react-native'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { Component } from '@wordpress/element'; | ||
import { withInstanceId } from '@wordpress/compose'; | ||
|
||
class URLInput extends Component { | ||
render() { | ||
const { value = '', autoFocus = true } = this.props; | ||
/* eslint-disable jsx-a11y/no-autofocus */ | ||
return ( | ||
<View> | ||
<TextInput | ||
autoFocus={ autoFocus } | ||
editable | ||
selectTextOnFocus | ||
textContentType="URL" | ||
value={ value } | ||
onChangeText={ this.props.onChange } | ||
placeholder={ __( 'Paste URL or type to search' ) } | ||
/> | ||
</View> | ||
); | ||
/* eslint-enable jsx-a11y/no-autofocus */ | ||
} | ||
} | ||
|
||
export default withInstanceId( URLInput ); |
118 changes: 118 additions & 0 deletions
118
packages/editor/src/components/url-input/style.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,118 @@ | ||
// Link input | ||
$input-padding: 8px; | ||
$input-size: 300px; | ||
|
||
.editor-block-list__block .editor-url-input, | ||
.components-popover .editor-url-input, | ||
.editor-url-input { | ||
flex-grow: 1; | ||
position: relative; | ||
padding: 1px; | ||
|
||
input[type="text"] { | ||
width: 100%; | ||
@include break-small() { | ||
width: $input-size; | ||
} | ||
padding: $input-padding; | ||
border: none; | ||
border-radius: 0; | ||
margin-left: 0; | ||
margin-right: 0; | ||
|
||
&::-ms-clear { | ||
display: none; | ||
} | ||
} | ||
|
||
.components-spinner { | ||
position: absolute; | ||
right: $input-padding; | ||
top: $input-padding + 1; | ||
margin: 0; | ||
} | ||
} | ||
|
||
// Suggestions | ||
.editor-url-input__suggestions { | ||
max-height: 200px; | ||
transition: all 0.15s ease-in-out; | ||
padding: 4px 0; | ||
// To match the url-input width: input width + padding + 2 buttons. | ||
width: $input-size + 2; | ||
overflow-y: auto; | ||
} | ||
|
||
// Hide suggestions on mobile until we @todo find a better way to show them | ||
.editor-url-input__suggestions, | ||
.editor-url-input .components-spinner { | ||
display: none; | ||
@include break-small() { | ||
display: inherit; | ||
} | ||
} | ||
|
||
.editor-url-input__suggestion { | ||
padding: 4px $input-padding; | ||
color: $dark-gray-300; // lightest we can use for contrast | ||
display: block; | ||
font-size: $default-font-size; | ||
cursor: pointer; | ||
background: $white; | ||
width: 100%; | ||
border: none; | ||
text-align: left; | ||
@include menu-style__neutral(); | ||
|
||
&:hover { | ||
background: $light-gray-500; | ||
} | ||
|
||
&:focus, | ||
&.is-selected { | ||
background: color(theme(primary) shade(15%)); | ||
color: $white; | ||
outline: none; | ||
} | ||
} | ||
|
||
// Toolbar button | ||
.components-toolbar > .editor-url-input__button { | ||
position: inherit; // Let the dialog position according to parent. | ||
} | ||
|
||
.editor-url-input__button .editor-url-input__back { | ||
margin-right: 4px; | ||
overflow: visible; | ||
|
||
&::after { | ||
content: ""; | ||
position: absolute; | ||
display: block; | ||
width: 1px; | ||
height: 24px; | ||
right: -1px; | ||
background: $light-gray-500; | ||
} | ||
} | ||
|
||
.editor-url-input__button-modal { | ||
box-shadow: $shadow-popover; | ||
border: 1px solid $light-gray-500; | ||
background: $white; | ||
} | ||
|
||
.editor-url-input__button-modal-line { | ||
display: flex; | ||
flex-direction: row; | ||
flex-grow: 1; | ||
flex-shrink: 1; | ||
min-width: 0; | ||
align-items: flex-start; | ||
|
||
.components-button { | ||
flex-shrink: 0; | ||
width: $icon-button-size; | ||
height: $icon-button-size; | ||
} | ||
} |
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,89 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { Component, Fragment } from '@wordpress/element'; | ||
import { withSpokenMessages } from '@wordpress/components'; | ||
import { RichTextToolbarButton } from '@wordpress/editor'; | ||
import { | ||
getTextContent, | ||
applyFormat, | ||
removeFormat, | ||
slice, | ||
} from '@wordpress/rich-text'; | ||
import { isURL } from '@wordpress/url'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ModalLinkUI from './modal'; | ||
|
||
const name = 'core/link'; | ||
|
||
export const link = { | ||
name, | ||
title: __( 'Link' ), | ||
tagName: 'a', | ||
className: null, | ||
attributes: { | ||
url: 'href', | ||
target: 'target', | ||
}, | ||
edit: withSpokenMessages( class LinkEdit extends Component { | ||
constructor() { | ||
super( ...arguments ); | ||
|
||
this.addLink = this.addLink.bind( this ); | ||
this.stopAddingLink = this.stopAddingLink.bind( this ); | ||
this.onRemoveFormat = this.onRemoveFormat.bind( this ); | ||
this.state = { | ||
addingLink: false, | ||
}; | ||
} | ||
|
||
addLink() { | ||
const { value, onChange } = this.props; | ||
const text = getTextContent( slice( value ) ); | ||
|
||
if ( text && isURL( text ) ) { | ||
onChange( applyFormat( value, { type: name, attributes: { url: text } } ) ); | ||
} else { | ||
this.setState( { addingLink: true } ); | ||
} | ||
} | ||
|
||
stopAddingLink() { | ||
this.setState( { addingLink: false } ); | ||
} | ||
|
||
onRemoveFormat() { | ||
const { value, onChange, speak } = this.props; | ||
|
||
onChange( removeFormat( value, name ) ); | ||
speak( __( 'Link removed.' ), 'assertive' ); | ||
} | ||
|
||
render() { | ||
const { isActive, value } = this.props; | ||
|
||
return ( | ||
<Fragment> | ||
<ModalLinkUI | ||
isVisible={ this.state.addingLink } | ||
onClose={ this.stopAddingLink } | ||
value={ value } | ||
/> | ||
<RichTextToolbarButton | ||
name="link" | ||
icon="admin-links" | ||
title={ __( 'Link' ) } | ||
onClick={ this.addLink } | ||
isActive={ isActive } | ||
shortcutType="primary" | ||
shortcutCharacter="k" | ||
/> | ||
</Fragment> | ||
); | ||
} | ||
} ), | ||
}; |
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,29 @@ | ||
|
||
import React from 'react'; | ||
import { View, Text } from 'react-native'; | ||
import Modal from 'react-native-modal'; | ||
import { URLInput } from '@wordpress/editor'; | ||
|
||
import styles from './modal.scss'; | ||
|
||
export default ( { value, isVisible, onClose, ...customProps } ) => { | ||
return ( | ||
<Modal | ||
isVisible={ isVisible } | ||
style={ styles.bottomModal } | ||
animationInTiming={ 500 } | ||
animationOutTiming={ 500 } | ||
backdropTransitionInTiming={ 500 } | ||
backdropTransitionOutTiming={ 500 } | ||
onBackdropPress={ onClose } | ||
onSwipe={ onClose } | ||
swipeDirection="down" | ||
{ ...customProps } | ||
> | ||
<View style={ { ...styles.content, borderColor: 'rgba(0, 0, 0, 0.1)' } }> | ||
<URLInput value={ 'https://wp.com' } /> | ||
<Text>{ value.text }</Text> | ||
</View> | ||
</Modal> | ||
); | ||
}; |
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,13 @@ | ||
|
||
.bottomModal { | ||
justify-content: flex-end; | ||
margin: 0; | ||
} | ||
|
||
.content { | ||
background-color: $white; | ||
padding: 22px; | ||
justify-content: center; | ||
align-items: center; | ||
border-radius: 4px; | ||
} |