@c8s/toc
TypeScript icon, indicating that this package has built-in type declarations

0.0.12 • Public • Published

@c8s/toc

github npm:version typescript license browserslist code style:prettier

Usage

/**
 * As to prepare of using the `Toc`
 * 
 * ```sh
 * yarn add @c8s/toc react @types/react
 * ```
 */
import Toc, {TocItemProps} from '@c8s/toc';

Example

(() => {
  const toc = new Toc();
  const AComponent: React.SFC<TocItemProps<HTMLDivElement>> = props => {
    return (
      <div ref={props.ariaRef} style={{paddingBottom: 1000}}>
        {props.title}
      </div>
    );
  };
  const list = [{title: 'foo'}, {title: 'bar'}, {title: 'baz'}];

  return (
    <Toc.provider toc={toc}>
      <>
        <ul>
          <Toc.consumer>
            {({items}) => {
              return items.map(item => {
                return (
                  <li
                    key={item.title}
                    style={{
                      color: item.selected ? 'orange' : 'inherit',
                    }}
                    onClick={item.scroll}
                  >
                    {item.title}
                  </li>
                );
              });
            }}
          </Toc.consumer>
        </ul>
        <div>{list.map(toc.bind(AComponent))}</div>
      </>
    </Toc.provider>
  )
})();

Contributors

Thanks goes to these wonderful people (emoji key):



📖

Aki-Japan

📖

This project follows the all-contributors specification. Contributions of any kind welcome!

Readme

Keywords

none

Package Sidebar

Install

npm i @c8s/toc

Weekly Downloads

2

Version

0.0.12

License

MIT

Unpacked Size

39 kB

Total Files

32

Last publish

Collaborators

  • akijpn
  • nju33