npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

route-animation

v1.1.25

Published

## Add

Downloads

10

Readme

route-animation

Add

npm i route-animation

Condition for animation

  • you cannot use the children key for animation

  • To use animation in a nested route, you must additionally specify a star. { path: /pathRoute/*, ... }

  • In Router v6, nested routes are specified in path without a parent route, so you need to specify {handle: { parentRelation: '/nameRoute' } ...}


Use

Example 1

//...
import { RouteAnimation } from 'route-animation'

// Main Route

const mainRoutes = [
  { path: '/', element: <Home /> },
  { path: '/posts', element: <Posts /> },
  { path: '/settings/*', element: <Settings /> }
  /* children: [] - no used*/
]

export function App() {
  const location = useLocation();
  const routes = useRoutes(mainRoutes, location);

  return (
    <>
      <div className={'content_app'} style={{ position: 'relative' }} >
        <RouteAnimation itemsRoutes={mainRoutes}>
          {routes}
        </RouteAnimation>
      </div>
    </>
  )
}
const nestedRouter = [
  {
    path: '/1',
    element: (<div>Component1</div>),
    handle: { parentRelation: '/settings' },
  },
  {
    path: '/2', // /2/* for the next nesting of routes
    element: (<div>Component2</div>),
    handle: {
      parentRelation: '/settings'// /settings/2 for the next route attachment, specify the dependent router
    }
  }
]

const SettingsMemo = () => {
  const location = useLocation();
  const routes = useRoutes(nestedRouter, location);

  return (
    <div className='settings'>
      <Box>
        <Button component={NavLink} to={'/settings/1'} variant={'outlined'}>Начать</Button>
      </Box>
      <RouteAnimation itemsRoutes={itemsRoutes}>
        {routes}
      </RouteAnimation>
    </div>
  )
};

Example 2

const mainRoutes: RouteObject[] = [
  { path: '/*', element: <Home /> },
  { path: CONST_ROUTES_PRIVATE.PAGE_POSTS, element: <Posts /> },
  { path: CONST_ROUTES_PRIVATE.PAGE_SETTINGS + '/*', element: <Settings /> }
]

export function App() {
  const location = useLocation();
  const routes = useRoutes(mainRoutes, location);

  return (
    <div className={'content_app'} style={{ position: 'relative' }} >
      <Container sx={{ py: 1, position: 'relative' }}>
        <RouteAnimation itemsRoutes={mainRoutes}  mode='slide' animation='slide' typeAnimation='no-destroy' isFadeSlide={true}  >
          {routes}
        </RouteAnimation>
      </Container>
    </div>
  )
}
  
// Home
const RenderCard = (params) => {
  return (
    <Card sx={{width: 200}}>
      <CardActionArea>
        <CardContent>
          <Typography gutterBottom variant="h5" component="div">
            Lizard
          </Typography>
          <Typography variant="body2" color="text.secondary">
            Lizards are a widespread group of squamate reptiles, with over 6,000
            species, ranging across all continents except Antarctica
          </Typography>
        </CardContent>
      </CardActionArea>
    </Card>
  )
}

const itemsHomeRoutes: RouteObject[] = [
  {
    index: true,
    element: (
      <Box>
        <Button variant={'outlined'} component={NavLink} to={CONST_ROUTES_PRIVATE.PAGE_HOME + '1'}>Вперёд</Button>
        <Box sx={{mt: 2, display: 'flex', justifyContent: 'space-between', flexWrap: 'wrap'}}>
          <RenderCard />
          <RenderCard />
          <RenderCard />
        </Box>
      </Box>
    ),
    handle: {
      parentRelation: CONST_ROUTES_PRIVATE.PAGE_HOME // home = /
    },
  },
  {
    path: '/1',
    element: (
      <Box>
        <Button variant={'outlined'} component={NavLink} to={CONST_ROUTES_PRIVATE.PAGE_HOME}>Назад</Button>
        <Button variant={'outlined'} component={NavLink} to={CONST_ROUTES_PRIVATE.PAGE_HOME + '2'}>Вперёд</Button>
        <p>
          Страница расширенной 1
        </p>
      </Box>
    ),
    handle: {
      parentRelation: CONST_ROUTES_PRIVATE.PAGE_HOME
    }
  },
  {
    path: '/2',
    element: (
      <Box>
        <Button variant={'outlined'} component={NavLink} to={CONST_ROUTES_PRIVATE.PAGE_HOME + '1'}>Назад</Button>
        <p>
          Страница расширенной 2
        </p>
      </Box>
    ),
    handle: {
      parentRelation: CONST_ROUTES_PRIVATE.PAGE_HOME
    }
  },
]


const HomeMemo = () => {
  const location = useLocation();
  const routes = useRoutes(itemsHomeRoutes, location);

  return (
    <div className='home'>
      <h1>Home</h1>
      <p>
        Lorem ipsum dolor sit amet consectetur adipisicing elit. Rerum dolore, molestiae accusamus saepe qui minima esse suscipit quis possimus consequatur numquam.
      </p>
      <Box sx={{ mt: 2 }}>
        <RouteAnimation itemsRoutes={itemsHomeRoutes} mode='slide' typeAnimation='total-forward' >
          {routes}
        </RouteAnimation>
      </Box>
    </div>
  )
};

export const Home = React.memo(HomeMemo);
<!-- typeAnimation total-forward    -->
<!--  next slide + 1  -->
<div class="slide-routes slide css-18xklii">
  <div class="item MuiBox-root css-0 forward-enter forward-enter-active"></div>
  <div class="item MuiBox-root css-0 forward-exit forward-exit-active"></div>
  <div class="item MuiBox-root css-0 forward-exit forward-exit-active"></div>
   <!-- total mount item -->
</div>
<!-- back slide -1 -->
<div class="slide-routes slide css-18xklii">
  <div class="item MuiBox-root css-0 back-enter back-enter-active"></div>
   <!-- total unmount item -->
</div>

API

Common props

| Prop | Type | |------------|--------------------------------------| |onExit |CSSTransitionProps['onExit'] | |onExited |CSSTransitionProps['onExited'] | |onExiting |CSSTransitionProps['onExiting'] | |onEnter |CSSTransitionProps['onEnter'] | |onEntered |CSSTransitionProps['onEntered'] | |onEntering|CSSTransitionProps['onEntering'] |
|onSlideEnd|used if no-destroy or total-forward |
|sx |mui SxProps|
|sxItem |mui SxProps|

RouteAnimation mode = 'slide' (default 'fade')

| Prop | Type | Default | Description | |---------------|---------|---------|--------------------------------------------------------------------------------------------------| |animation |string |'slide'| Animation effect type, 'slide', 'vertical-slide', or 'rotate' | |isFadeSlide |boolean|'false'| Change visual animation 'slide', 'vertical-slide' | |duration |number |200 | transition-duration ms | |timing |string |'ease' | transition-timing-function, one of 'ease' 'ease-in' 'ease-out' 'ease-in-out' 'linear'| |typeAnimation|string |destroy| destroy, no-destroy, total-forward |

EXAMPLE. (Also check out the ExampleComponent components on the home page)

CodeSandbox Route Animation