(function (Prism) { var funcPattern = /\\(?:[^a-z()[\]]|[a-z*]+)/i; var insideEqu = { 'equation-command': { pattern: funcPattern, alias: 'regex', }, }; Prism.languages.latex = { comment: /%.*/, // the verbatim environment prints whitespace to the document cdata: { pattern: /(\\begin\{((?:lstlisting|verbatim)\*?)\})[\s\S]*?(?=\\end\{\2\})/, lookbehind: true, }, /* * equations can be between $$ $$ or $ $ or \( \) or \[ \] * (all are multiline) */ equation: [ { pattern: /\$\$(?:\\[\s\S]|[^\\$])+\$\$|\$(?:\\[\s\S]|[^\\$])+\$|\\\([\s\S]*?\\\)|\\\[[\s\S]*?\\\]/, inside: insideEqu, alias: 'string', }, { pattern: /(\\begin\{((?:align|eqnarray|equation|gather|math|multline)\*?)\})[\s\S]*?(?=\\end\{\2\})/, lookbehind: true, inside: insideEqu, alias: 'string', }, ], /* * arguments which are keywords or references are highlighted * as keywords */ keyword: { pattern: /(\\(?:begin|cite|documentclass|end|label|ref|usepackage)(?:\[[^\]]+\])?\{)[^}]+(?=\})/, lookbehind: true, }, url: { pattern: /(\\url\{)[^}]+(?=\})/, lookbehind: true, }, /* * section or chapter headlines are highlighted as bold so that * they stand out more */ headline: { pattern: /(\\(?:chapter|frametitle|paragraph|part|section|subparagraph|subsection|subsubparagraph|subsubsection|subsubsubparagraph)\*?(?:\[[^\]]+\])?\{)[^}]+(?=\})/, lookbehind: true, alias: 'class-name', }, function: { pattern: funcPattern, alias: 'selector', }, punctuation: /[[\]{}&]/, }; Prism.languages.tex = Prism.languages.latex; Prism.languages.context = Prism.languages.latex; })(Prism); d.tsx?h=v1.1.0&id=056ed0d5f050158cebad689099214b164539899a'>commitdiffstats
path: root/src/components/molecules/forms/labelled-field.tsx
blob: ecc92550a3d6e9d292261bc3db0bfd5278c6866c (plain)
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
import Field, { type FieldProps } from '@components/atoms/forms/field';
import Label from '@components/atoms/forms/label';
import { FC } from 'react';
import styles from './labelled-field.module.scss';

export type LabelledFieldProps = FieldProps & {
  /**
   * Visually hide the field label. Default: false.
   */
  hideLabel?: boolean;
  /**
   * The field label.
   */
  label: string;
  /**
   * The label position. Default: top.
   */
  labelPosition?: 'left' | 'top';
};

/**
 * LabelledField component
 *
 * Render a field tied to a label.
 */
const LabelledField: FC<LabelledFieldProps> = ({
  hideLabel = false,
  id,
  label,
  labelPosition = 'top',
  required,
  ...props
}) => {
  const positionModifier = `label--${labelPosition}`;
  const visibilityClass = hideLabel ? 'screen-reader-text' : '';

  return (
    <>
      <Label
        htmlFor={id}
        required={required}
        className={`${visibilityClass} ${styles[positionModifier]}`}
      >
        {label}
      </Label>
      <Field id={id} required={required} {...props} />
    </>
  );
};

export default LabelledField;