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

T360286: Sections #119

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions src/link/images/article-black.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/link/images/article-white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions src/link/images/change-black.svg

This file was deleted.

1 change: 0 additions & 1 deletion src/link/images/change.svg

This file was deleted.

File renamed without changes
3 changes: 3 additions & 0 deletions src/link/images/search-black.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/link/images/search-white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions src/link/images/search.svg

This file was deleted.

2 changes: 1 addition & 1 deletion src/link/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
if ( e.target.className === 'components-popover__content' ) {
stopViewingPreview();
}
}, [] );

Check warning on line 38 in src/link/popover.js

View workflow job for this annotation

GitHub Actions / build

React Hook useCallback has a missing dependency: 'stopViewingPreview'. Either include it or remove the dependency array. If 'stopViewingPreview' changes too often, find the parent component that defines it and wrap that definition in useCallback

const setPlacement = () => {
if ( isTextNearTheEdge( anchor ) ) {
Expand Down Expand Up @@ -69,7 +69,7 @@
) }
{ viewingPreview && (
<PreviewEditUI
onEdit={ goToEdit }
onEditTopic={ goToEdit }
onRemove={ removeAttributes }
onForceClose={ stopViewingPreview }
activeAttributes={ activeAttributes }
Expand Down
56 changes: 42 additions & 14 deletions src/link/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@
} from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import wikipediaPreview from 'wikipedia-preview';
import { Sections } from './sections';

export const PreviewEditUI = ( {
activeAttributes,
onForceClose,
onEdit,
onEditTopic,
onRemove,
} ) => {
const [ previewHtml, setPreviewHtml ] = useState( null );
const [ selectingSection, setSelectingSection ] = useState( false );
const [ showControllersMenu, setShowControllersMenu ] = useState( true );
const toggleControllersMenu = () => {
/* eslint-disable-next-line no-shadow */
setShowControllersMenu( ( showControllersMenu ) => ! showControllersMenu );
};

const showSections = () => {
setSelectingSection( true );
};

useEffect( () => {
const { title, lang } = activeAttributes;
if ( title && lang ) {
Expand Down Expand Up @@ -78,16 +84,22 @@
.querySelector( '.wikipediapreview-header-closebtn' )
?.removeEventListener( 'click', onForceClose );
};
}, [ previewHtml ] );

Check warning on line 87 in src/link/preview.js

View workflow job for this annotation

GitHub Actions / build

React Hook useLayoutEffect has a missing dependency: 'onForceClose'. Either include it or remove the dependency array

return (
<div className="wikipediapreview-edit-preview-container">
<div
className="wikipediapreview-edit-preview"
dangerouslySetInnerHTML={ { __html: previewHtml } }
></div>
{ previewHtml && showControllersMenu && (
<ControllerEditUI onEdit={ onEdit } onRemove={ onRemove } />
<div>
{ ! selectingSection ? (
<div className="wikipediapreview-edit-preview-container">
<div
className="wikipediapreview-edit-preview"
dangerouslySetInnerHTML={ { __html: previewHtml } }
></div>
{ previewHtml && showControllersMenu && (
<ControllerEditUI onEditTopic={ onEditTopic } onEditSection={ showSections } onRemove={ onRemove } />
) }
</div>
) : (
<Sections />
) }
</div>
);
Expand All @@ -101,22 +113,38 @@
return hasPreviewPopup && hasExpandedClass;
};

const ControllerEditUI = ( { onEdit, onRemove } ) => {
const ControllerEditUI = ( { onEditTopic, onEditSection, onRemove } ) => {
return (
<div className="wikipediapreview-edit-preview-controllers">
<div
className="wikipediapreview-edit-preview-controllers-change"
onClick={ onEdit }
className="wikipediapreview-edit-preview-controllers-option"
onClick={ onEditTopic }
role="presentation"
>
<div className="wikipediapreview-edit-preview-controllers-option-icon-change"></div>
<div className="wikipediapreview-edit-preview-controllers-option-message">
{ __( 'Topic', 'wikipedia-preview' ) }
</div>
</div>
<div
className="wikipediapreview-edit-preview-controllers-option"
onClick={ onEditSection }
role="presentation"
>
{ __( 'Change', 'wikipedia-preview' ) }
<div className="wikipediapreview-edit-preview-controllers-option-icon-sections"></div>
<div className="wikipediapreview-edit-preview-controllers-option-message">
{ __( 'Sections', 'wikipedia-preview' ) }
</div>
</div>
<div
className="wikipediapreview-edit-preview-controllers-remove"
className="wikipediapreview-edit-preview-controllers-option"
onClick={ onRemove }
role="presentation"
>
{ __( 'Remove', 'wikipedia-preview' ) }
<div className="wikipediapreview-edit-preview-controllers-option-icon-remove"></div>
<div className="wikipediapreview-edit-preview-controllers-option-message">
{ __( 'Remove', 'wikipedia-preview' ) }
</div>
</div>
</div>
);
Expand Down
7 changes: 7 additions & 0 deletions src/link/sections.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const Sections = ( {} ) => {
return (
<div className="wikipediapreview-edit-sections">
<h1>Sections</h1>
</div>
);
};
94 changes: 55 additions & 39 deletions src/link/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ body {
}

&-icon {
background-image: url(./images/search.svg);
background-image: url(./images/search-black.svg);
width: 20px;
height: 20px;
position: absolute;
Expand Down Expand Up @@ -242,7 +242,7 @@ body {
}

&-search-icon {
background-image: url(./images/search.svg);
background-image: url(./images/search-black.svg);
width: 20px;
height: 20px;
position: absolute;
Expand Down Expand Up @@ -348,12 +348,13 @@ body {
}

&-controllers {
width: 52px;
height: 136px;
width: 73px;
height: 194px;
background-color: #000;
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
font-size: 12px;
color: #fff;
border-top-right-radius: 4px;
Expand All @@ -364,29 +365,36 @@ body {
cursor: pointer;
}

&-change {

&::before {
position: relative;
content: url(./images/change.svg);
width: 20px;
height: 20px;
left: 14px;
&-option {
display: flex;
flex-direction: column;
align-items: center;

&-icon {
&-change {
width: 20px;
height: 20px;
margin-bottom: 5px;
content: url(./images/search-white.svg);
}
&-sections {
width: 20px;
height: 20px;
margin-bottom: 5px;
content: url(./images/article-white.svg);
}
&-remove {
width: 20px;
height: 20px;
margin-bottom: 5px;
content: url(./images/remove-white.svg);
}
}
}

&-remove {

&::before {
position: relative;
content: url(./images/remove.svg);
width: 20px;
&-message {
width: 100%;
height: 20px;
left: 15px;

}

}
}

Expand Down Expand Up @@ -455,23 +463,22 @@ body {
cursor: pointer;
}

&-change {
text-align: center;

&::before {
content: url(./images/change-black.svg);
left: -7px;
top: 5px;
}
}

&-remove {
text-align: center;

&::before {
content: url(./images/remove-black.svg);
left: -7px;
top: 5px;
&-option {
flex-direction: row;
width: 100%;
&-icon {
&-change {
margin: 0 5px 0 5px;
content: url(./images/search-black.svg);
}
&-sections {
margin: 0 5px 0 5px;
content: url(./images/article-black.svg);
}
&-remove {
margin: 0 5px 0 5px;
content: url(./images/remove-black.svg);
}
}
}
}
Expand All @@ -496,6 +503,15 @@ body {
}
}

.wikipediapreview-edit-sections {
display: flex;
flex-direction: column;
justify-content: space-between;
height: 100%;
width: 100%;
border: papayawhip ;
}

&.rtl {

.wikipediapreview-edit-inline {
Expand Down
Loading