Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mebtte/react-lrc

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mebtte/react-lrc

The react component that display lyric from lrc.

  • 1.0.2
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

react-lrc

The react component that display lyric from lrc format.

Screenshot

Feature

  • Auto scroll smoothly
  • User srcollable
  • Custom style

Requirement

  • react >= 16.8 with hook
  • ResizeObserver

Usage

npm install --save @mebtte/react-lrc
import React, { useCallback } from 'react';
import { Lrc } from '@mebtte/react-lrc';

const Lyric = ({ lrc, currentTime }) => {
  const lineRenderer = useCallback(
    ({ lrcLine: { millisecond, content }, index, active }) => (
      <div style={{ textAlign: 'center', color: active ? 'green' : 'inherit' }}>
        {content}
      </div>
    ),
  );
  const onCurrentLineChange = useCallback(
    ({ lrcLine: { millisecond, content }, index }) =>
      console.log(index, millisecond, content),
    [],
  );

  return (
    <Lrc
      lrc={lrc}
      currentTime={currentTime}
      lineRenderer={lineRenderer}
      onCurrentLineChange={onCurrentLineChange}
    />
  );
};

export default Lyric;

Lrc Props

propdescriptiontypedefault
lrclrc stringstringrequired
lineRendererlrc line render method({ lrcLine: { id: string, millisecond: number, content: string }, index: number, active: boolean }) => ReactNoderequired
currentTimecurrent timenumber, millisecond0
autoScrollwhether auto scrollbooleantrue
autoScrollAfterUserScrollauto scroll after user scrollnumber, millisecond6000
spaceTopspace on lrc component top, percent of lrc componentnumber, 0~10.4
onCurrentLineChangewhen current line change({ index: number, lrcLine: { id: string, millisecond: number, content: string } | null }) => voidnull

Lrc Methods

methoddescriptiontype
scrollToCurrentLinescroll to current line and set auto scroll() => void
getCurrentLineget the current lrc line() => { lrcLine: { id: string, millisecond: number, content: string } | null, index: number }

Other API

parseLrc

import { parseLrc } from '@mebtte/react-lrc';

parseLrc(lrcString); // { id: string, millesecond: number: content: string }[]

useLrc

import React from 'react';
import { useLrc } from '@mebtte/react-lrc';

const Component = () => {
  const lrcLineList = useLrc(lrcString); // { id: string, millesecond: number: content: string }[]
  // ...
};

Example

Question

Why lrc component do not auto scroll ?

You probably do not give a height to Lrc. The height can make Lrc scrollable.

How to prevent user scroll ?

<Lrc
  style={{ overflow: 'hidden !important' }}
  autoScrollAfterUserScroll={0}
  {...otherProps}
/>

How to hide scrollbar ?

.lrc {
  /* webkit */
  ::-webkit-scrollbar {
    width: 0;
  }

  /* firefox */
  scrollbar-width: none;

  /* ie */
  -ms-overflow-style: none;
}
<Lrc className="lrc" {...otherProps} />

Typescript

@mebtte/react-lrc export type LrcLine.

import React from 'react';
import { LrcLine } from '@mebtte/react-lrc';

const Component = () => {
  const lineRenderer = React.useCallback(
    ({ lrcLine }: { lrcLine: LrcLine }) => {
      // ...
    },
    [],
  );
  // ...
  return <Lrc lineRenderer={lineRenderer} {...otherProps} />;
};

License

MIT

Keywords

FAQs

Package last updated on 24 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc