All Projects → bluepeter → react-middle-ellipsis

bluepeter / react-middle-ellipsis

Licence: MIT License
Truncate a long string in the middle, instead of the end.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
shell
77523 projects

Projects that are alternatives of or similar to react-middle-ellipsis

react-example-paginated-list-infinite-scroll
Follow a React tutorial series with three parts to build a powerful component in React.
Stars: ✭ 43 (-2.27%)
Mutual labels:  react-component
react-form-base
Base React component for generic forms
Stars: ✭ 18 (-59.09%)
Mutual labels:  react-component
react-taggy
A simple zero-dependency React component for tagging user-defined entities within a block of text.
Stars: ✭ 29 (-34.09%)
Mutual labels:  react-component
react-touch-ripple
Create ripple effect from Material Design with React
Stars: ✭ 27 (-38.64%)
Mutual labels:  react-component
react-native-nested-listview
A UI component for React Native for representing nested arrays of N levels
Stars: ✭ 163 (+270.45%)
Mutual labels:  react-component
font-picker-react
✏️ Font selector component for Google Fonts
Stars: ✭ 126 (+186.36%)
Mutual labels:  react-component
react-compare-slider
A slider component to compare any two React components in landscape or portrait orientation. It supports custom images, videos... and everything else.
Stars: ✭ 78 (+77.27%)
Mutual labels:  react-component
termy-the-terminal
Web-based terminal powered by React
Stars: ✭ 43 (-2.27%)
Mutual labels:  react-component
mighty-input
Text input for modern web
Stars: ✭ 20 (-54.55%)
Mutual labels:  react-component
shortcut-preview
A React component to preview iOS Shortcuts
Stars: ✭ 20 (-54.55%)
Mutual labels:  react-component
react-instagram-authless-feed
React component to provide a token-less Instagram feed.
Stars: ✭ 50 (+13.64%)
Mutual labels:  react-component
markdown-navbar
Best markdown navigation bar for React.
Stars: ✭ 122 (+177.27%)
Mutual labels:  react-component
react-quick-pinch-zoom
A react component that providing multi-touch gestures for zooming and dragging on any DOM element.
Stars: ✭ 124 (+181.82%)
Mutual labels:  react-component
react-carousel-minimal
React.js Responsive Minimal Carousel
Stars: ✭ 76 (+72.73%)
Mutual labels:  react-component
react-nft-gallery
🖼️ React component to display your NFTs as a gallery
Stars: ✭ 50 (+13.64%)
Mutual labels:  react-component
react-windows-ui
Build Windows fluent UI apps using ReactJS. Provides a set of accessible, reusable, and composable React components that make it super easy to create websites and apps.
Stars: ✭ 383 (+770.45%)
Mutual labels:  react-component
react-liff
A react context provider for LIFF (LINE Front-end Framework)
Stars: ✭ 22 (-50%)
Mutual labels:  react-component
react-duotone
React Duotone Component
Stars: ✭ 26 (-40.91%)
Mutual labels:  react-component
react-video-players
📺 Library of React video player components that offer a consistent interface and callback system for Vimeo, YouTube and the <video> tag. Along with a handy higher order component for building your own 😉
Stars: ✭ 13 (-70.45%)
Mutual labels:  react-component
candy mobile
No description or website provided.
Stars: ✭ 16 (-63.64%)
Mutual labels:  react-component

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 node with <MiddleEllipsis>. This will compute the width of the surrounding parent node. Then, it will look for the child node (so make sure to add a span at minimum internally): it will use this element to compute the width of the child, and then shorten the text element whose class is ellipseMe (optional) to fit within the parent.

The component re-computes things if the browser window is resized, too!

import React from "react";
import MiddleEllipsis from "react-middle-ellipsis";

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

export default Component;

Development

Notes for developing this component.

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

Change the version number in package.json and npm publish once complete.

License

MIT © bluepeter

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].