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

react-middle-ellipsis

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-middle-ellipsis

Put the dots in the middle of a long string, versus the end.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.8K
decreased by-20.1%
Maintainers
1
Weekly downloads
 
Created
Source

React Middle Ellipsis

Check out the demo.

Adding ellipses to the end of long text is cool. But not always! Sometimes the end of the text contains vital information, particularly for URLs or filenames.

This React component is designed with that use case in mind.

Install

yarn add react-middle-ellipsis

Usage

Once imported, you can then wrap any element with <MiddleEllipsis>. This will compute the width of the surrounding parent node. Then, it will look for a child node whose class is constrainedChild: it will use this element to compute the width of the child, and then shorten the text element whose class is constrainedEllipsis to fit within the parent.

Why do we have both constrainedChild and constrainedEllipsis? Because we want BOTH to fit within the parent, but only one of them should be ellipse'd. This way, things such as icons or images won't be ellipsed.

import React, { Component } from "react";

import MiddleEllipsis from "react-middle-ellipsis";

class Example extends Component {
  render() {
    return (
      <div style={{ width: "350px", whiteSpace: "nowrap" }}>
        <MiddleEllipsis>
          <span className="constrainedChild">
            Don't ellipse me.{" "}
            <span className="constrainedEllipse">
              I am some long text that should be ellipsed in the middle because
              the end contains important stuff.
            </span>
          </span>
        </MiddleEllipsis>
      </div>
    );
  }
}

Development

Notes for developing this component.

yarn run start in this directory and separately also in /example. This will live reload any changes made in /src.

License

MIT © bluepeter

FAQs

Package last updated on 22 May 2019

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