0.0.12 • Published 5 years ago

@c8s/toc v0.0.12

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

@c8s/toc

github npm:version typescript license browserslist code style:prettier

Usage

/**
 * As to prepare of using the `Toc`
 * 
 * ```bash
 * 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!

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago