summaryrefslogtreecommitdiffstats
path: root/lint-staged.config.js
blob: 433cbc066c48e414041c9db4c5d783d547b90bf6 (plain)
1
2
3
4
5
6
module.exports = {
  '**/*.ts?(x)': () => 'tsc -p tsconfig.json --noEmit',
  '**/*.(ts|tsx|js|jsx)': ['eslint --cache --fix', 'prettier --write'],
  '**/*.(md|json)': 'prettier --write',
  '**/*.scss': ['stylelint --fix', 'prettier --write'],
};
: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
import { ExpandableWidget, OrderedList } from '@components/WidgetParts';
import { Heading } from '@ts/types/app';
import useHeadingsTree from '@utils/hooks/useHeadingsTree';
import { FormattedMessage, useIntl } from 'react-intl';

const ToC = () => {
  const intl = useIntl();
  const headingsTree = useHeadingsTree('article');
  const title = intl.formatMessage({
    defaultMessage: 'Table of contents',
    description: 'ToC: widget title',
  });

  const getItems = (headings: Heading[]) => {
    return headings.map((heading) => {
      return (
        <li key={heading.id}>
          <a href={`#${heading.id}`}>
            <FormattedMessage
              defaultMessage="<a11y>Jump to </a11y>{title}"
              description="ToC: link"
              values={{
                title: heading.title,
                a11y: (chunks: string) => (
                  <span className="screen-reader-text">{chunks}</span>
                ),
              }}
            />
          </a>
          {heading.children.length > 0 && (
            <OrderedList items={getItems(heading.children)} />
          )}
        </li>
      );
    });
  };

  return (
    <ExpandableWidget title={title} kind="toc" expand={true} withBorders={true}>
      <noscript>
        {intl.formatMessage({
          defaultMessage:
            'Javascript is required to use the table of contents.',
          description: 'ToC: noscript tag',
        })}
      </noscript>
      <OrderedList items={getItems(headingsTree)} />
    </ExpandableWidget>
  );
};

export default ToC;