“Collapsible Overflow Text” Component
Collapsible overflow text component is used for displaying text based data that can span many lines and as a result take a lot of space in pages. But this component can force a limit to number of lines the to display in its initial collapsed state.
The usefulness of this component lies in the fact that if we set a limit of 3 lines and the actual text only spans 2 lines then expandable features are disabled and we just see a simple text paragraph.
Plain Text Example
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cupiditate dignissimos error, excepturi expedita non quis repellat. Aut beatae dolor ipsam modi quaerat quisquam reiciendis reprehenderit rerum! Earum officiis quos voluptatum! Adipisci aliquam atque blanditiis consequatur cupiditate dolore dolorem, doloribus, ea iste laboriosam nisi possimus quae quidem ratione tempora. Consequatur explicabo facere facilis minima porro quos repudiandae sequi tempore, vel velit?
Plain Text with Less Text
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cupiditate dignissimos error, excepturi expedita non quis repellat. Aut beatae dolor ipsam modi quaerat quisquam reiciendis reprehenderit rerum! Earum officiis quos voluptatum!
HTML Text Example
HTML text with image
The component is not built for things other than text but this shows that it can handle simple cases:
Usage
// minimal usage
@component('components.collapsibleOverflowText')
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cupiditate dignissimos error, excepturi
expedita non quis repellat. Aut beatae dolor ipsam modi quaerat quisquam reiciendis reprehenderit
rerum! Earum officiis quos voluptatum!
@endcomponent
// full customization
@component('components.collapsibleOverflowText', [
'expandButtonText' => 'Read full description',
'collapseButtonText' => 'Hide full description',
'approxLineHeight' => 27,
'tag' => 'p',
'maxVisibleLines' => 2,
])
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cupiditate dignissimos error, excepturi
expedita non quis repellat. Aut beatae dolor ipsam modi quaerat quisquam reiciendis reprehenderit
rerum! Earum officiis quos voluptatum!
@endcomponent
Props
-
tagstring
The enclosing tag to wrap the content passed by slot.
Default Value:
div
-
maxVisibleLinesint
The max number of lines show in collapsed state.
Default Value:
4
-
approxLineHeightint|float
Approx line height is passed so that we can set initial max-height for content.
Default Value:
30.6
-
expandButtonTextstring
The expand button text.
-
collapseButtonTextstring
The collapse button text.
-
darkBackgroundbool
Set to true if the background is dark so that overlay can be of right color.