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

react-line-between

v1.0.2

Published

this does not need position absolute, and auto update when rerender, with build-in animation

Downloads

10

Readme

react-line-between

this does not need position absolute, and auto update when rerender, with build-in animation | 无需绝对位置,自动重绘,自带动画

screenshot

usage | 使用

  1. install | 安装
yarn add react-line-between
// or npm
npm i react-line-between --save
  1. add snapsvg | 添加snapsvg
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/snap.svg.min.js"></script>
  1. component code | 编写组件
import Container from 'react-line-between'
import { Component } from 'react'

class TestComponent extends Component {
  render() {
    return (<span >[line to]</span>)
  }
}

export default class Index extends Component {
  state = {
    lines: [],
    lis: [],
    input: '',
  }
  componentDidMount() {
    const { a, b } = this
    this.setState({
      lines: [
        {
          from: a,
          to: b,
          attrs: {
            fill: "#fc0",
            stroke: "#000",
            strokeWidth: 2,
          }
        },
      ],
    })
  }
  render() {
    const { lis, input } = this.state
    return (<Container ref={svg => this.svg = svg} lines={this.state.lines} updateOnRender={false}>
      <div>
        <span ref={a => this.a = a}>[line from]</span>
        <ul>{lis.map((x, i) => {
          return (<li key={i}>{x}</li>)
        })}</ul>
        <input value={this.state.input} onChange={(e) => this.setState({
          input: e.target.value,
        })} /><button onClick={() => this.setState({
          lis: lis.concat(input),
          input: '',
        })}>add li</button>
        <br />
        <button onClick={() => this.svg.updateSvg()}>redraw line</button>
        <TestComponent ref={b => this.b = b} />
      </div>
    </Container>)
  }
}

apis

props.lines is an array of objects, each object should contain from- node or element to line from, to- node or element to line to, attrs- attributes for the svg Line

props.lines 是个列表, 每个元素都包含 from- 线开始的元素或组件, to- 线结束的元素或组件, attrs- svg Line的属性

<Container lines={[
  {
    from: a,
    to: b,
    attrs: {
      fill: "#fc0",
      stroke: "#000",
      strokeWidth: 2,
    }
  },
]} >

props.updateOnRender auto update line position when it rerenders, default true, you can turn it off and use a ref to call it's updateSvg() when you need

props.updateOnRender 当组件重绘的时候自动更新线的位置, 默认值 true, 你可以关闭自动更新并仅在你需要更新的时候通过ref调用updateSvg()

<Container ref={svg => this.svg = svg} updateOnRender={false} >
  ...
  <button onClick={() => this.svg.updateSvg()}>redraw line</button>
  ...

props.animate config how to animate when line updates, default {duration = 600, easing = mina.linear }, you can just use false to skip animation

props.animate 配置线更新的时候如何动画, 默认配置 {duration = 600, easing = mina.linear }, 你可以使用 false 来跳过动画

<Container animate={false} >

props.Snap and props.mina I use snapsvg as an injection rather than dependency because snapsvg does not support ssr, it uses window object in it's code. If you need to prevent global namespace pollution, you can use prop to specify them, if not specified react-line-between will look into window for them

props.Snapprops.mina 我这里仅使用注入的方式,而没有使用依赖的方式使用snapsvg因为它不支持SSR,它的代码中包含了window. 如果你需要避免全局命名空间污染, 你可以通过props来指定它们, 如果不指定的话 react-line-between 去 window 中找

//require or import
import Snap from 'snapsvg-cjs'
import Container from 'react-line-between'


//as prop when render
<Container Snap={Snap}>
  //things to render
</Container>

try it out | 自己试试

git clone https://github.com/postor/react-line-between.git
cd example
yarn
yarn dev

# open http://localhost:3000