aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/atoms/forms/fields/input/input.tsx
blob: c47534ffde56bee7e331798feb5fffe48cc970b5 (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
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Com
import {
  type ForwardedRef,
  forwardRef,
  type InputHTMLAttributes,
  type HTMLInputTypeAttribute,
} from 'react';
import styles from '../fields.module.scss';

export type InputProps = Omit<
  InputHTMLAttributes<HTMLInputElement>,
  'disabled' | 'readonly' | 'required' | 'type'
> &
  Required<Pick<InputHTMLAttributes<HTMLInputElement>, 'id' | 'name'>> & {
    /**
     * Should the field be disabled?
     *
     * @default false
     */
    isDisabled?: boolean;
    /**
     * Should the field be readonly?
     *
     * @default false
     */
    isReadOnly?: boolean;
    /**
     * Should the field be required?
     *
     * @default false
     */
    isRequired?: boolean;
    /**
     * The input type.
     */
    type: Exclude<HTMLInputTypeAttribute, 'checkbox' | 'radio' | 'range'>;
  };

const InputWithRef = (
  {
    className = '',
    isDisabled = false,
    isReadOnly = false,
    isRequired = false,
    ...props
  }: InputProps,
  ref: ForwardedRef<HTMLInputElement>
) => {
  const fieldClassName = `${styles.field} ${className}`;

  return (
    <input
      {...props}
      className={fieldClassName}
      disabled={isDisabled}
      readOnly={isReadOnly}
      ref={ref}
      required={isRequired}
    />
  );
};

/**
 * Input component.
 */
export const Input = forwardRef(InputWithRef);
n>fun.convert-px(-2) fun.convert-px(3) fun.convert-px(-1) var(--color-shadow-dark); @include mix.media("screen") { @include mix.dimensions(null, "sm") { padding: var(--spacing-xs); border-left: none; border-right: none; .title { margin-bottom: var(--spacing-2xs); } } @include mix.dimensions("sm") { max-width: 35ch; } } } .icon { --icon-size: #{fun.convert-px(30)}; margin-right: var(--spacing-2xs); }