# @react-starport/core

> Transform React component across routes with animations

Latest version **1.0.2** (published 2023-02-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @react-starport/core
pnpm add @react-starport/core
yarn add @react-starport/core
bun add @react-starport/core
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2023-02-26 |
| First published | 2023-01-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 23.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | tyx1703 |
| Maintainers | react-starport |
| Keywords | react, animation, transition |

## Links

- npm: https://www.npmjs.com/package/@react-starport/core
- Repository: https://github.com/YanxinTang/react-starport
- Homepage: https://github.com/YanxinTang/react-starport#readme
- Issues: https://github.com/YanxinTang/react-starport/issues
- npm.io page: https://npm.io/package/@react-starport/core

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2023-02-26
- 1.0.1 — 2023-01-15
- 1.0.0 — 2023-01-15

## README

<p align="center">
<img height="64" src="./packages/playground/src/logo.svg" alt="React Starport">
</p>

<p align="center">
Transform React component across routes with animations
</p>

<a href="./LICENSE">
<img alt="GitHub" src="https://img.shields.io/github/license/YanxinTang/react-starport">
</a>
<a href="https://www.npmjs.com/package/@react-starport/core">
<img alt="npm (scoped)" src="https://img.shields.io/npm/v/@react-starport/core">
</a>

## Motivation

This project is inspried by [Vue Starport Project](https://github.com/antfu/vue-starport). Thanks all works from the authors.

The mainly work is done, but there are still some featues I have not implemented yet and no ideas.
You can get the list in the [below](#todos).

## Install

```bash
npm install @react-starport/core

yarn add @react-starport/core

pnpm add @react-starport/core
```

## Usage

Add `<StarportCarrier>` component from `@react-starport/core` to your root component (`App.tsx`). All `<Starport>` usage should be inside `<StarportCarrier>` component.

```jsx
import { StarportCarrier } from '@react-starport/core';

function App() {
  return (
    <StarportCarrier> {{/* here */}}    
      <Outlet /> {/* Outlet comes from `react-router`, you can get detail from the doc */}
    </StarportCarrier>
  )
}

export default App;
```

In routes, wrap the component with the `<Starport>` component.

```jsx
/* PageA.jsx */
import { Starport } from '@react-starport/core';

function PageA() {

  return (
    <Starport port="my-id" style="height:400px"> 
      <MyComponent />
    </Starport>
  )
}
```

On the other page, we do the same thing with **the same `port` id** to identify the instance.

```jsx
/* PageA.jsx */
import { Starport } from '@react-starport/core';

function PageB() {

  return (
    <Starport port="my-id" style="height:400px"> 
      <MyComponent />
    </Starport>
  )
}
```

> Note that you might need to apply some styles to `<Starport>` to make it have a defined size indicating the area for the "floating starcraft" to land.

Checkout the [Playground](./packages/playground/) for more examples.

### Options

#### 1. Globally

```jsx
import { StarportCarrier } from '@react-starport/core';

function App() {
  const options = {
    duration: 700,
    easing: 'cubic-bezier(0.45, 0, 0.55, 1)',
  }

  return (
    <StarportCarrier {...options }> 
      <Outlet />
    </StarportCarrier>
  )
}

export default App;
```

#### 2. Specifically

```jsx
/* Page.jsx */
import { Starport } from '@react-starport/core';

function Page() {
  const options = {
    duration: 700,
    easing: 'cubic-bezier(0.45, 0, 0.55, 1)',
  }

  return (
    <Starport port="my-id" style="height:400px" { ...options }> 
      <MyComponent />
    </Starport>
  )
}
```

## Debug

To debug what happens during the transition, you can add the follow CSS to highlight the parts

```css
.debug .starport-craft {
  background: #0805;
}

.debug .starport:not(.starport--landed) {
  background: #8005;
}
```

## TODOS

- [ ] KeepAlive
  - You can use global state as alternative
- [ ] InitialProps and MountedProps
  - I haven't figured out what scenarios would use these configurations

## License

[MIT](./LICENSE) License © 2022 [tyx1703](https://github.com/YanxinTang)

---
_Source: https://npm.io/package/@react-starport/core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
