Skip to content

Commit

Permalink
Add horizontal menu
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed Oct 8, 2020
1 parent 2d33a65 commit 7515c72
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Block/DefaultTocRenderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import AnchorLink from 'react-anchor-link-smooth-scroll';
const View = ({ properties, data, tocEntries }) => {
return (
<>
{data.title ? (
{data.title && !data.hide_title ? (
<h2>
{data.title || (
<FormattedMessage
Expand Down
57 changes: 57 additions & 0 deletions src/Block/HorizontalMenu.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* View toc block.
* @module components/manage/Blocks/ToC/View
*/

import React from 'react';
import PropTypes from 'prop-types';
import { map } from 'lodash';
import { Menu } from 'semantic-ui-react';
import { FormattedMessage, injectIntl } from 'react-intl';
import AnchorLink from 'react-anchor-link-smooth-scroll';

/**
* View toc block class.
* @class View
* @extends Component
*/
const View = ({ properties, data, tocEntries }) => {
return (
<>
{data.title && !data.hide_title ? (
<h2>
{data.title || (
<FormattedMessage
id="Table of Contents"
defaultMessage="Table of Contents"
/>
)}
</h2>
) : (
''
)}
<Menu>
{map(
tocEntries,
([level, entry, id]) =>
entry && (
<Menu.Item key={id} className={`headline-${level}`}>
<AnchorLink href={`#${id}`}>{entry}</AnchorLink>
</Menu.Item>
),
)}
</Menu>
</>
);
};

/**
* Property types.
* @property {Object} propTypes Property types.
* @static
*/
View.propTypes = {
properties: PropTypes.objectOf(PropTypes.any).isRequired,
};

export default injectIntl(View);
3 changes: 2 additions & 1 deletion src/Block/TocView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import { map } from 'lodash';
import { injectIntl } from 'react-intl';
import cx from 'classnames';
import { blocks } from '~/config';
import withBlockExtension from '../withBlockExtension';

Expand Down Expand Up @@ -38,7 +39,7 @@ const View = (props) => {
const Renderer = extension?.view;

return (
<div className="block table-of-contents">
<div className={cx('block table-of-contents', extension.id)}>
{Renderer ? (
<Renderer {...props} tocEntries={tocEntries} properties={properties} />
) : (
Expand Down
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import TocEdit from './Block/TocEdit';
import DefaultTocRenderer from './Block/DefaultTocRenderer';
import MultiSelectWidget from './Widgets/MultiSelectWidget';
import BlockExtensionWidget from './Widgets/BlockExtensionWidget';
import HorizontalMenu from './Block/HorizontalMenu';

const applyConfig = (config) => {
config.blocks.blocksConfig.toc = {
Expand All @@ -17,6 +18,12 @@ const applyConfig = (config) => {
view: DefaultTocRenderer,
schemaExtender: null,
},
{
id: 'horizontalMenu',
title: 'Horizontal Menu',
view: HorizontalMenu,
schemaExtender: null,
},
],
};

Expand Down

0 comments on commit 7515c72

Please sign in to comment.