Shiitake - line clamp that won't get you fired
npm install shiitakeMy boss once worked on an app that had a Javascript line clamp that truncated words. Then one day the term "Cooking with Shiitake" made it into the UI and you can imagine how it got trimmed. Trimming words is dangerous, don't risk it. We've built a react component that handles this for you both responsively and responsibly.
```
$ npm install --save shiitake
`js
import Shiitake from 'shiitake';
export class App extends React.Component {
render() {
const text = 'Cooking with Shitakes';
return (
$3
`
$ git clone https://github.com/bsidelinger912/shiitake.git
$ cd shiitake
$ npm install && npm run dev
``CodePen demo: http://codepen.io/bsidelinger912/pen/zBgwmd
The other big difference is the new "attributes" prop. This allows you to pass any valid JSX attributes (props) into the outer rendered element. This is the same element that is defined by the "tagName" prop. This way you can have more control over the rendered result. We also added classes for some of the inner spans which you can target in css for further control. In this change we dropped support for passing event handlers like "onClick" at the top level Shiitake props, but you can pass them now in attributes. This means any event supported by the tagName of your choice is now supported in addition to other attributes like "title", "href" etc. The top level "className" prop is deprecated in favor of passing className inside of "attributes", but is still supported until the next major version when it will be removed.
| name | type | description |
|---|---|---|
| lines | Integer | required - the number of lines to clamp to |
| throttleRate | Integer | optional - defaults to 200, the number of milliseconds to throttle resize events to |
| attributes | Object | optional - allows you to pass HTMLAttributes to the rendered outer element. You can pass valid attributes for any whitelisted react element (see tagName property). In Typescript the type is a union of the HTMLAttributes for each whitelisted element type or tagName. |
| className | String| NOTE this is supported for now but is deprecated in favor of the attributes prop (which allows you to pass className and much more) | |
| tagName | String | optional - defaults to 'div', the tag name for the returned outer element. The valid options are: 'div', 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'span' and 'a'. |
| overflowNode | Node | optional - defaults to '\u2026' (ellipsis), the text or html that indicates the string has been trimmed |
| onTruncationChange | Function (isTruncated: boolean) => void | optional - This is called whenever the text gets trimmed or stops being trimmed. Its useful for setting state based on whether the text has been truncated or not |