@@ -7,13 +7,17 @@ import { LitElement, html, css } from 'lit';
77 * - Height-based: Use `max-height` attribute (e.g., "81px")
88 * - Line-based: Use `max-lines` attribute (e.g., "4")
99 *
10+ * @property {String } background-color - Background color for the gradient fade (default: white)
11+ * @property {String } label-size - Size of the toggle button text: "medium" (default) or "small" (12px)
12+ * @property {String } padding-left - Left padding for toggle button on non-mobile (e.g., "8" or "8px")
13+ *
1014 * @example
1115 * <ol-read-more max-height="100px" more-text="Read more" less-text="Read less">
1216 * <p>Long content here...</p>
1317 * </ol-read-more>
1418 *
1519 * @example
16- * <ol-read-more max-lines="4">
20+ * <ol-read-more max-lines="4" background-color="#f5f5f5" label-size="small" >
1721 * <p>Long content here...</p>
1822 * </ol-read-more>
1923 */
@@ -23,6 +27,9 @@ export class OLReadMore extends LitElement {
2327 maxLines : { type : Number , attribute : 'max-lines' } ,
2428 moreText : { type : String , attribute : 'more-text' } ,
2529 lessText : { type : String , attribute : 'less-text' } ,
30+ backgroundColor : { type : String , attribute : 'background-color' } ,
31+ labelSize : { type : String , attribute : 'label-size' } ,
32+ paddingLeft : { type : String , attribute : 'padding-left' } ,
2633 // Internal state
2734 _expanded : { type : Boolean , state : true } ,
2835 _unnecessary : { type : Boolean , state : true } ,
@@ -35,6 +42,7 @@ export class OLReadMore extends LitElement {
3542 --ol-readmore-link-color: hsl(202, 96%, 28%);
3643 --ol-readmore-gradient-color: white;
3744 --ol-readmore-gradient-color-transparent: rgba(255, 255, 255, 0);
45+ --ol-readmore-padding-left: 0;
3846 }
3947
4048 .content-wrapper {
@@ -68,6 +76,7 @@ export class OLReadMore extends LitElement {
6876 var(--ol-readmore-gradient-color) 12px
6977 );
7078 border: none;
79+ border-radius: 0 0 4px 4px;
7180 cursor: pointer;
7281 }
7382
@@ -85,7 +94,7 @@ export class OLReadMore extends LitElement {
8594
8695 @media only screen and (min-width: 800px) {
8796 .toggle-btn {
88- padding-left: 0 ;
97+ padding-left: var(--ol-readmore-padding-left) ;
8998 text-align: left;
9099 }
91100 }
@@ -105,6 +114,12 @@ export class OLReadMore extends LitElement {
105114 .chevron.up {
106115 transform: rotate(180deg);
107116 }
117+
118+ .toggle-btn.small {
119+ font-size: 12px;
120+ padding-top: 16px;
121+ padding-bottom: 8px;
122+ }
108123 ` ;
109124
110125 constructor ( ) {
@@ -113,12 +128,39 @@ export class OLReadMore extends LitElement {
113128 this . maxLines = null ;
114129 this . moreText = 'Read More' ;
115130 this . lessText = 'Read Less' ;
131+ this . backgroundColor = null ;
132+ this . labelSize = 'medium' ;
133+ this . paddingLeft = null ;
116134 this . _expanded = false ;
117135 this . _unnecessary = false ;
118136 }
119137
120138 firstUpdated ( ) {
121139 this . _checkIfTruncationNeeded ( ) ;
140+ this . _updateBackgroundColor ( ) ;
141+ this . _updatePaddingLeft ( ) ;
142+ }
143+
144+ updated ( changedProperties ) {
145+ if ( changedProperties . has ( 'backgroundColor' ) ) {
146+ this . _updateBackgroundColor ( ) ;
147+ }
148+ if ( changedProperties . has ( 'paddingLeft' ) ) {
149+ this . _updatePaddingLeft ( ) ;
150+ }
151+ }
152+
153+ _updateBackgroundColor ( ) {
154+ if ( this . backgroundColor ) {
155+ this . style . setProperty ( '--ol-readmore-gradient-color' , this . backgroundColor ) ;
156+ }
157+ }
158+
159+ _updatePaddingLeft ( ) {
160+ if ( this . paddingLeft ) {
161+ const value = / ^ \d + $ / . test ( this . paddingLeft ) ? `${ this . paddingLeft } px` : this . paddingLeft ;
162+ this . style . setProperty ( '--ol-readmore-padding-left' , value ) ;
163+ }
122164 }
123165
124166 _checkIfTruncationNeeded ( ) {
@@ -171,6 +213,7 @@ export class OLReadMore extends LitElement {
171213 render ( ) {
172214 const showMoreBtn = ! this . _expanded && ! this . _unnecessary ;
173215 const showLessBtn = this . _expanded && ! this . _unnecessary ;
216+ const sizeClass = this . labelSize === 'small' ? 'small' : '' ;
174217
175218 return html `
176219 < div
@@ -180,15 +223,15 @@ export class OLReadMore extends LitElement {
180223 < slot > </ slot >
181224 </ div >
182225 < button
183- class ="toggle-btn more ${ showMoreBtn ? '' : 'hidden' } "
226+ class ="toggle-btn more ${ sizeClass } ${ showMoreBtn ? '' : 'hidden' } "
184227 aria-expanded ="false "
185228 @click ="${ this . _handleMoreClick } "
186229 >
187230 ${ this . moreText }
188231 < svg class ="chevron " aria-hidden ="true " viewBox ="0 0 24 24 " fill ="none " stroke ="currentColor " stroke-width ="2.5 " stroke-linecap ="round " stroke-linejoin ="round "> < path d ="m6 9 6 6 6-6 "/> </ svg >
189232 </ button >
190233 < button
191- class ="toggle-btn less ${ showLessBtn ? '' : 'hidden' } "
234+ class ="toggle-btn less ${ sizeClass } ${ showLessBtn ? '' : 'hidden' } "
192235 aria-expanded ="true "
193236 @click ="${ this . _handleLessClick } "
194237 >
0 commit comments