aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/Widgets/ToC
Commit message (Collapse)AuthorAgeFilesLines
* refactor: use formatjs swc pluginArmand Philippot2022-03-231-0/+3
| | | | | I'm not able to configure SWC plugins in Next.js so to make it works, all translation must have an id.
* chore: add some noscript tags to explain why the data are not loadedArmand Philippot2022-02-131-0/+7
|
* chore: improve accessibilityArmand Philippot2022-02-111-2/+13
|
* chore: improve widgetsArmand Philippot2022-02-102-40/+1
| | | | | | | | * Make all widgets expanded by default. This way, without Javascript, thematics and topics are still available. * Improve collapse/expand transition. * Remove widget scrollbar: the height was sometimes weird because of that. Except for ToC on large devices.
* chore: replace lingui functions with react-intlArmand Philippot2022-01-291-2/+6
|
* chore: adjust colors and grid layoutArmand Philippot2022-01-251-31/+0
|
* refactor(styles): rename shadow and border variablesArmand Philippot2022-01-161-1/+1
|
* chore: update sidebar and widgets stylesArmand Philippot2022-01-152-0/+100
I'm now using a widget that can be expanded/collapsed. It also allows me to handle more effectively widgets overflow and to avoid styles repetitions. However, with stylelint rule "no-descending-specificity", I'm not sure if the stylesheets are really logical... Maybe I should deactivate this rule.
ht .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: 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 Heading, { type HeadingProps } from '@components/atoms/headings/heading';
import PlusMinus from '@components/atoms/icons/plus-minus';
import { FC, SetStateAction } from 'react';
import { useIntl } from 'react-intl';
import styles from './heading-button.module.scss';

export type HeadingButtonProps = Pick<HeadingProps, 'level'> & {
  /**
   * Set additional classnames to the button.
   */
  className?: string;
  /**
   * Accordion state.
   */
  expanded: boolean;
  /**
   * Callback function to set accordion state on click.
   */
  setExpanded: (value: SetStateAction<boolean>) => void;
  /**
   * Accordion title.
   */
  title: string;
};

/**
 * HeadingButton component
 *
 * Render a button as accordion title to toggle body.
 */
const HeadingButton: FC<HeadingButtonProps> = ({
  className = '',
  expanded,
  level,
  setExpanded,
  title,
}) => {
  const intl = useIntl();
  const iconState = expanded ? 'minus' : 'plus';
  const titlePrefix = expanded
    ? intl.formatMessage({
        defaultMessage: 'Collapse',
        description: 'HeadingButton: title prefix (expanded state)',
        id: 'UX9Bu8',
      })
    : intl.formatMessage({
        defaultMessage: 'Expand',
        description: 'HeadingButton: title prefix (collapsed state)',
        id: 'bcyOgC',
      });

  return (
    <button
      type="button"
      className={`${styles.wrapper} ${className}`}
      onClick={() => setExpanded(!expanded)}
    >
      <Heading level={level} withMargin={false} className={styles.heading}>
        <span className="screen-reader-text">{titlePrefix} </span>
        {title}
      </Heading>
      <PlusMinus state={iconState} className={styles.icon} />
    </button>
  );
};

export default HeadingButton;