nl-design-system / rijkshuisstijl-community

Unofficial Rijkshuisstijl components and design tokens based on the NL Design System architecture. This project is not endorsed by the Dutch Ministry of General Affairs.
https://rijkshuisstijl-community.vercel.app/
European Union Public License 1.2
6 stars 4 forks source link

Toggletip component #447

Open Robbert opened 3 months ago

Robbert commented 3 months ago

Figma Toggletip in Local - Rijkshuisstijl - Bibliotheek

PR - added toggletip tokens: https://github.com/nl-design-system/rijkshuisstijl-community/pull/657

Rerbun commented 2 months ago

Styling van het team van Ruben O:

Image

Image

Rerbun commented 2 months ago

Tooltip.tsx:

import { FunctionComponent, HTMLAttributes, ReactNode } from "react";
import { Collapse } from "react-bootstrap";
import { ReactComponent as ToelichtingDichtIcoon } from "../../../icons/functioneel/55-toelichting.svg";
import { ReactComponent as ToelichtingOpenIcoon } from "../../../icons/functioneel/56-toelichting-lined-blue.svg";
import { Melding } from "../../main";
import { UseTooltipReturnType } from "./useTooltip";

type TooltipToggleProps = {
  tooltip: UseTooltipReturnType;
  omschrijvingKnop: string;
} & HTMLAttributes<HTMLButtonElement>;

export const TooltipToggle: FunctionComponent<TooltipToggleProps> = ({
  tooltip: { id, toggleVisibility, visible },
  omschrijvingKnop,
  ...props
}) => (
  <button
    onClick={toggleVisibility}
    className="btn btn-link btn-link-tooltip"
    aria-expanded={visible}
    aria-controls={id}
    aria-describedby={id}
    type="button"
    title={omschrijvingKnop}
    {...props}
  >
    {visible ? <ToelichtingOpenIcoon /> : <ToelichtingDichtIcoon />}
  </button>
);

type TooltipMeldingProps = {
  tooltip: UseTooltipReturnType;
  children: ReactNode;
} & HTMLAttributes<HTMLDivElement>;
export const TooltipMelding: FunctionComponent<TooltipMeldingProps> = ({
  tooltip: { visible, id },
  children,
  ...props
}) => (
  <Collapse in={visible}>
    <div id={id} role="tooltip" {...props} aria-hidden="true">
      <Melding variant="toelichting">{children}</Melding>
    </div>
  </Collapse>
);
Rerbun commented 2 months ago

useTooltip.tsx:

import { useCallback, useId, useMemo, useState } from "react";

export type UseTooltipReturnType = {
  visible: boolean;
  toggleVisibility: () => void;
  id: string;
};

export const useTooltip = (): UseTooltipReturnType => {
  const [visible, setVisible] = useState<boolean>(false);
  const toggleVisibility = useCallback(() => setVisible((visible) => !visible), []);
  const id = useId();

  return useMemo(() => ({ visible, toggleVisibility, id }), [id, visible, toggleVisibility]);
};
Rubenoo commented 2 months ago

Wij hebben dit weer overgenomen van MijnOverheid: image image

Rerbun commented 2 months ago

RVO: https://nl-design-system.github.io/rvo/?path=/docs/componenten-expandable-text--documentatie

Robbert commented 2 months ago

Code bij RVO: https://nl-design-system.github.io/rvo/?path=/docs/componenten-expandable-text--documentatie

Rozerinay commented 2 months ago

PR: https://github.com/nl-design-system/rijkshuisstijl-community/pull/657