# All files / window-splitter WindowSplitter.tsx

100% Statements 121/121
66.66% Branches 2/3
100% Functions 2/2
100% Lines 121/121

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    1221x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
    44x
     import { cnb } from "cnbuilder";
    import type { ButtonHTMLAttributes } from "react";
    import { forwardRef } from "react";
    import { LabelRequiredForA11y } from "../types.js";
    import { bem } from "../utils/bem.js";

    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    import { useWindowSplitter } from "./useWindowSplitter.js";

    const styles = bem("rmd-window-splitter");

    /**
     * @remarks \@since 6.0.0
     */
    export interface WindowSplitterClassNameOptions {
      className?: string;
      dragging?: boolean;
      reversed?: boolean;
      vertical?: boolean;
      disableFixed?: boolean;
    }

    /**
     * @remarks \@since 6.0.0
     */
    export function windowSplitter(
      options: WindowSplitterClassNameOptions = {}
    ): string {
      const {
        vertical = false,
        dragging,
        reversed,
        disableFixed,
        className,
      } = options;

      return cnb(
        styles({
          h: !vertical,
          hr: !vertical && reversed,
          v: vertical,
          vr: vertical && reversed,
          a: disableFixed,
          dragging,
        }),
        className
      );
    }

    /**
     * @remarks \@since 6.0.0
     * @see {@link https://www.w3.org/WAI/ARIA/apg/patterns/windowsplitter/}
     */
    export interface BaseWindowSplitterProps
      extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "type" | "children"> {
      /**
       * This will be provided by the {@link useWindowSplitter} hook.
       */
      "aria-controls": string;

      /**
       * This will be provided by the {@link useWindowSplitter} hook.
       */
      dragging: boolean;

      /**
       * This will be provided by the {@link useWindowSplitter} hook.
       */
      reversed: boolean;

      /**
       * Set this to `true` if the window splitter should use `position: absolute`
       * instead of `position: fixed`.
       *
       * @defaultValue `false`
       */
      disableFixed?: boolean;
    }

    /**
     * @remarks \@since 6.0.0
     */
    export type WindowSplitterProps = LabelRequiredForA11y<BaseWindowSplitterProps>;

    /**
     * **Server Component**
     * Most likely a client component since it relies on `useWindowSplitter`
     *
     * @see {@link useWindowSplitter} for an example usage
     * @remarks \@since 6.0.0
     */
    export const WindowSplitter = forwardRef<
      HTMLButtonElement,
      WindowSplitterProps
    >(function WindowSplitter(props, ref) {
      const {
        role = "separator",
        className,
        dragging,
        reversed,
        disableFixed = false,
        ...remaining
      } = props;
      const vertical = props["aria-orientation"] === "vertical";

      return (
        <button
          {...remaining}
          ref={ref}
          type="button"
          role={role}
          className={windowSplitter({
            className,
            reversed,
            dragging,
            vertical,
            disableFixed,
          })}
        />
      );
    });