# Mintlify Field

A component that provides labeling and validation for form controls.

Build a Field in this project that looks and behaves like Mintlify's. Measured from the running Mintlify app (mintlify.com). Keep every value exact. Map the tokens onto the project's own theme variables instead of hard-coding them. Use the project's own component library for behaviour, or [Base UI](https://base-ui.com/react/components/field) if it has none.

Fidelity: Partly measured from the Mintlify dashboard's login form. No reference has been captured yet.

## Tokens

| Token | Light | Dark |
| --- | --- | --- |
| `--mint-text-weak` | `#707070` | `#9a9a9a` |
| `--mint-text-strong` | `#202020` | `#eeeeee` |
| `--mint-destructive-text` | `#ce2c31` | `#ec5d5e` |
| `--font-weight-normal` | `400` | `400` |
| `--font-weight-medium` | `500` | `500` |

## CSS

Scoped under `[data-style="mintlify"]`; dark rules sit under `[data-theme="dark"]`. The `ui-*` classes and data attributes match the structure below.

```css
[data-style="mintlify"] {
  .ui-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
  }

  .ui-field-label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--mint-text-strong);
    font-size: 13px;
    font-weight: var(--font-weight-medium);
    line-height: 20px;
    user-select: none;

    &[data-disabled] {
      color: var(--mint-text-weak);
    }
  }

  .ui-field-item .ui-field-label {
    font-size: 14px;
    font-weight: var(--font-weight-normal);

    &:not([data-disabled]) {
      color: var(--mint-text-strong);
    }
  }

  .ui-field-description {
    margin: 0;
    color: var(--mint-text-weak);
    font-size: 13px;
    font-weight: var(--font-weight-normal);
    line-height: 20px;
  }

  .ui-field-error {
    color: var(--mint-destructive-text);
    font-size: 13px;
    font-weight: var(--font-weight-normal);
    line-height: 20px;
  }

  .ui-field-item {
    display: flex;
    flex-direction: column;
    gap: 2px;

    & .ui-field-description {
      padding-left: 22px;
    }
  }
}
```

## Structure

How Replicas assembles it on Base UI.

```tsx
import { Field as BaseField } from "@base-ui/react/field";
import { Input } from "./input";

const join = (base: string, extra?: string) => (extra ? `${base} ${extra}` : base);

function Root({ className, ...props }: Omit<BaseField.Root.Props, "className"> & { className?: string }) {
  return <BaseField.Root className={join("ui-field", className)} {...props} />;
}

function Label({ className, ...props }: Omit<BaseField.Label.Props, "className"> & { className?: string }) {
  return <BaseField.Label className={join("ui-field-label", className)} {...props} />;
}

function Description({ className, ...props }: Omit<BaseField.Description.Props, "className"> & { className?: string }) {
  return <BaseField.Description className={join("ui-field-description", className)} {...props} />;
}

function FieldError({ className, ...props }: Omit<BaseField.Error.Props, "className"> & { className?: string }) {
  return <BaseField.Error className={join("ui-field-error", className)} {...props} />;
}

function Item({ className, ...props }: Omit<BaseField.Item.Props, "className"> & { className?: string }) {
  return <BaseField.Item className={join("ui-field-item", className)} {...props} />;
}

export const Field = {
  Root,
  Label,
  Control: Input,
  Description,
  Error: FieldError,
  Item,
  Validity: BaseField.Validity,
};
```

## Example

```tsx
import { Field } from "@replicas/ui";

export default function FieldDemo() {
  return (
    <Field.Root validationMode="onBlur" style={{ width: 280 }}>
      <Field.Label>Team name</Field.Label>
      <Field.Control required placeholder="Engineering" />
      <Field.Error match="valueMissing">Enter a name for the team</Field.Error>
      <Field.Description>Shown in the sidebar and in team pickers.</Field.Description>
    </Field.Root>
  );
}
```

## Foundations

The rest of the Mintlify style, as a skill: https://replicas.raphaelsalaja.com/skills/mintlify/SKILL.md