# LinkButton

> A link that looks like a button and moves inside the app through NasimProvider's router.

- Import: `import { LinkButton } from '@nyxon/nasim';`
- Server Component: no, it needs a client component
- Since: 0.1.0; status: stable
- Source: libs/nasim/src/primitives/LinkButton.tsx
- Describes: @nyxon/nasim unreleased, after 0.12.0
- Page: https://nasim.nyxon.tech/docs/components/actions/link-button

<Example name="link-button/in-app">
  ```tsx title="link-button/in-app.tsx"
  import { LinkButton } from '@nyxon/nasim';

  const copy = { plans: 'مشاهدهٔ پلن‌ها', invoices: 'فاکتورهای من' };

  // A link styled as a button. With NasimProvider's `navigate`, `href` moves inside the app.
  export default function InApp() {
    return (
      <div className="flex flex-wrap gap-2">
        <LinkButton href="#plans">{copy.plans}</LinkButton>
        <LinkButton href="#invoices" variant="secondary">
          {copy.invoices}
        </LinkButton>
      </div>
    );
  }
  ```
</Example>

## Import [#import]

```tsx
import { LinkButton } from '@nyxon/nasim';
```

## Usage [#usage]

`LinkButton` is React Aria's `Link` drawn with HeroUI's button styles: it takes `variant`, `size`,
`fullWidth` and `isIconOnly` as `Button` does, and an `href`. With `navigate` on `NasimProvider`
([Setup](/docs/get-started/setup)) an in-app `href` moves through the app's router without a page load;
without it, it is a plain link. An address with a scheme or a `//host` is never handed to the router.

```tsx
<LinkButton href="/services">{t.services.all}</LinkButton>
```

`routerOptions` carries `{ replace?, scroll? }` to the router (`NasimNavigateOptions`).

## Examples [#examples]

### Inside the app [#inside-the-app]

Shown above: a main and a secondary link side by side.

### In a new tab [#in-a-new-tab]

`target="_blank"` adds `rel="noopener noreferrer"`, so the new page never gets this window. Say in the
label that it opens a new tab.

<Example name="link-button/new-tab">
  ```tsx title="link-button/new-tab.tsx"
  import { LinkButton } from '@nyxon/nasim';

  const copy = { guide: 'راهنمای اتصال (در برگهٔ تازه)' };

  // target="_blank" adds rel="noopener noreferrer": the new page never gets this window.
  // The label says it opens a new tab, so nobody is surprised.
  export default function NewTab() {
    return (
      <LinkButton href="https://nyxon.tech" target="_blank" variant="outline">
        {copy.guide}
      </LinkButton>
    );
  }
  ```
</Example>

## Rules [#rules]

* A control that goes somewhere is a link, not a `Button` with a handler that navigates: the address
  shows on hover, it opens in a new tab, and a screen reader calls it a link.
* Its words come from the screen's strings module, like every label.

## Accessibility [#accessibility]

It renders an `<a>` with `href`, so it is announced as a link and Enter follows it (Space does not, as
for any link). Its focus ring is the button's.

## API [#api]

| Prop            | Type                                                                                          | Default | Description                                                                                                                                        |
| --------------- | --------------------------------------------------------------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| `href`          | `string`                                                                                      | —       | A URL to link to. See \[MDN]\(https\://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#href).                                                  |
| `variant`       | `"danger" \| "danger-soft" \| "ghost" \| "outline" \| "primary" \| "secondary" \| "tertiary"` | —       |                                                                                                                                                    |
| `size`          | `"lg" \| "md" \| "sm"`                                                                        | —       |                                                                                                                                                    |
| `fullWidth`     | `boolean`                                                                                     | —       |                                                                                                                                                    |
| `isIconOnly`    | `boolean`                                                                                     | —       |                                                                                                                                                    |
| `target`        | `React.HTMLAttributeAnchorTarget`                                                             | —       | The target window for the link. See \[MDN]\(https\://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#target).                                  |
| `rel`           | `string`                                                                                      | —       | The relationship between the linked resource and the current page. See \[MDN]\(https\://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel). |
| `routerOptions` | `NasimNavigateOptions`                                                                        | —       | Options for the configured client side router.                                                                                                     |
| `className`     | `string`                                                                                      | —       |                                                                                                                                                    |

`LinkButton` takes the rest of React Aria's `Link` props too.

## Related [#related]

`Button` (an action on the page) and `NasimProvider`'s `navigate` (in-app links).