Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
Use intl in link button
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed May 15, 2021
1 parent f1ca1b1 commit 6f95301
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 36 deletions.
47 changes: 12 additions & 35 deletions src/editor/plugins/SimpleLink/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
// import { makeInlineElementPlugin } from 'volto-slate/components/ElementEditor';
import { useSlate } from 'slate-react';
import {
_insertElement,
Expand All @@ -9,30 +8,28 @@ import {
} from 'volto-slate/components/ElementEditor/utils';
import { SIMPLELINK, LINK } from 'volto-slate/constants';
import { LinkElement } from './render';
// import { defineMessages } from 'react-intl'; // , defineMessages
import { defineMessages } from 'react-intl'; // , defineMessages
import { withSimpleLink } from './extensions';
import { useSelector, useDispatch } from 'react-redux';
import { setPluginOptions } from 'volto-slate/actions';
import { PositionedToolbar } from 'volto-slate/editor/ui';
import { ReactEditor } from 'slate-react';
// import { Range } from 'slate';
// import { Transforms } from 'slate';
import linkSVG from '@plone/volto/icons/link.svg';
import AddLinkForm from '@plone/volto/components/manage/AnchorPlugin/components/LinkButton/AddLinkForm';
import { ToolbarButton as UIToolbarButton } from 'volto-slate/editor/ui';

const linkDeserializer = () => {};

// const messages = defineMessages({
// edit: {
// id: 'Edit link',
// defaultMessage: 'Edit link',
// },
// delete: {
// id: 'Remove link',
// defaultMessage: 'Remove link',
// },
// });
const messages = defineMessages({
add: {
id: 'Add link',
defaultMessage: 'Add link',
},
edit: {
id: 'Edit link',
defaultMessage: 'Edit link',
},
});

function getPositionStyle(el) {
const domSelection = window.getSelection();
Expand Down Expand Up @@ -132,7 +129,7 @@ export default (config) => {

return (
<UIToolbarButton
title="Simple Link"
title={isElement ? messages.edit : messages.add}
icon={linkSVG}
active={isElement}
onMouseDown={() => {
Expand Down Expand Up @@ -161,25 +158,5 @@ export default (config) => {
<SimpleLinkEditor {...props} pluginId={PLUGINID} {...pluginOptions} />
));

// slate.persistentHelpers =
// const opts = {
// title: 'SimpleLink',
// pluginId: PLUGINID,
// elementType: PLUGINID,
// element: LinkElement,
// isInlineElement: true,
// // editSchema: LinkEditSchema,
// extensions: [withSimpleLink],
// hasValue: (formData) => !!formData.link,
// toolbarButtonIcon: linkSVG,
// persistentHelper: (pluginOptions) => (props) => (
// <SimpleLinkEditor {...props} {...pluginOptions} />
// ),
// messages,
// };
//
// const [installLinkEditor] = makeInlineElementPlugin(opts);
// config = installLinkEditor(config);

return config;
};
7 changes: 6 additions & 1 deletion src/editor/ui/ToolbarButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ import cx from 'classnames';
import React from 'react';
import { Icon } from '@plone/volto/components';
import { Button } from 'semantic-ui-react';
import { useIntl } from 'react-intl';

const ToolbarButton = React.forwardRef(
({ className, active, reversed, icon, style, ...props }, ref) => {
({ className, active, reversed, icon, style, title = '', ...props }, ref) => {
const intl = useIntl();
const i18ntitle =
typeof title !== 'string' ? intl.formatMessage(title) : title;
return (
<div className="button-wrapper">
<Button
as="a"
{...props}
title={i18ntitle}
ref={ref}
style={style}
className={cx(className)}
Expand Down

0 comments on commit 6f95301

Please sign in to comment.