Skip to content

Commit

Permalink
feature: sticky toc
Browse files Browse the repository at this point in the history
  • Loading branch information
tedw87 committed Jan 10, 2023
1 parent ae1d668 commit 86195b8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"smoothscroll-polyfill": "^0.4.4"
},
"devDependencies": {
"@plone/scripts": "*",
"@cypress/code-coverage": "^3.10.0",
"@plone/scripts": "*",
"babel-plugin-transform-class-properties": "^6.24.1",
"md5": "^2.3.0"
},
Expand Down
1 change: 1 addition & 0 deletions src/AnchorLink.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component } from 'react';
import { Sticky } from 'semantic-ui-react';

class AnchorLink extends Component {
constructor(props) {
Expand Down
21 changes: 16 additions & 5 deletions src/Block/HorizontalMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
* @module components/manage/Blocks/ToC/View
*/

import React from 'react';
import React, { useRef } from 'react';
import PropTypes from 'prop-types';
import { map } from 'lodash';
import { Menu } from 'semantic-ui-react';
import { Menu, Sticky } from 'semantic-ui-react';
import { FormattedMessage, injectIntl } from 'react-intl';
import AnchorLink from '@eeacms/volto-block-toc/AnchorLink';
// import { StickyContainer, Sticky } from 'react-sticky';

const RenderMenuItems = ({ items }) => {
// console.log('items', items);
return map(items, (item) => {
const { id, level, title } = item;
console.log('id, level, items', id, level, title);
return (
item && (
<React.Fragment key={id}>
Expand All @@ -32,6 +35,8 @@ const RenderMenuItems = ({ items }) => {
* @extends Component
*/
const View = ({ data, tocEntries }) => {
console.log('toc entries', tocEntries);
const stickyRef = useRef(null);
return (
<>
{data.title && !data.hide_title ? (
Expand All @@ -46,9 +51,15 @@ const View = ({ data, tocEntries }) => {
) : (
''
)}
<Menu>
<RenderMenuItems items={tocEntries} />
</Menu>
<Sticky
onUnstick={(e) => console.log('HERE', e)}
ref={stickyRef}
offset={40}
>
<Menu>
<RenderMenuItems items={tocEntries} />
</Menu>
</Sticky>
</>
);
};
Expand Down

0 comments on commit 86195b8

Please sign in to comment.