Consider the following SVG:
<svg xmlns="http://www.w3.org/2000/svg" width="237" height="129" viewBox="0 0 237 129" fill="none">
<path d="M228 1H9C4.58172 1 1 4.58172 1 9V91V104V127L20 111.483L228 112C232.418 112 236 108.418 236 104V9C236 4.58172 232.418 1 228 1Z" fill="#F6F6F6" />
<path d="M1 104V9C1 4.58172 4.58172 1 9 1H228C232.418 1 236 4.58172 236 9V104C236 108.418 232.418 112 228 112L20 111.483L1 127V91" stroke="#E8E8E8" />
<foreignObject x="15" y="0" width="200" height="130">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</foreignObject>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" width="235" height="86" viewBox="0 0 235 86" fill="none">
<path d="M8 0H227C231.418 0 235 3.58172 235 8V50V63V86L216 70.4828L8 71C3.58173 71 0 67.4183 0 63V8C0 3.58172 3.58173 0 8 0Z" fill="#5DB075"/>
<foreignObject x="15" y="0" width="200" height="80">
<p style="color: white">Lorem ipsum dolor sit amet, consectetur adipiscing elit. </p>
</foreignObject>
</svg>
I am considering making the height of the SVG dynamic based on text length.
For example, the first SVG would be modified to:
<svg xmlns="http://www.w3.org/2000/svg" width="237" height={(50 + (27 * text.length / 27))} viewBox={`0 0 237 ${50 + (27 * text.length / 27)}`} fill="none">
<path d="M228 1H9C4.58172 1 1 4.58172 1 9V91V104V127L20 111.483L228 112C232.418 112 236 108.418 236 104V9C236 4.58172 232.418 1 228 1Z" fill="#F6F6F6" />
<path d="M1 104V9C1 4.58172 4.58172 1 9 1H228C232.418 1 236 4.58172 236 9V104C236 108.418 232.418 112 228 112L20 111.483L1 127V91" stroke="#E8E8E8" />
<foreignObject x="15" y="15" width="150" height={(20 + (27 * text.length / 27))}>
<p>{text}</p>
</foreignObject>
</svg>
The second SVG would be updated in a similar manner:
<svg xmlns="http://www.w3.org/2000/svg" width="235" height={(50 + (27 * text.length / 27))} viewBox=`0 0 237 ${50 + (27 * text.length / 27)}" fill="none">
<path d="M8 0H227C231.418 0 235 3.58172 235 8V50V63V86L216 70.4828L8 71C3.58173 71 0 67.4183 0 63V8C0 3.58172 3.58173 0 8 0Z" fill="#5DB075" />
<foreignObject x="15" y="15" width="150" height={(20 + (27 * text.length / 27))}>
<p style="color: white">{text}</p>
</foreignObject>
</svg>
An issue with this method is that the path D does not reflect the actual height dynamically when the text is short.
If the text is short, it may look something like:
<svg xmlns="http://www.w3.org/2000/svg" width="237" height="50" viewBox="0 0 237 50" fill="none">
<path d="M228 1H9C4.58172 1 1 4.58172 1 9V91V104V127L20 111.483L228 112C232.418 112 236 108.418 236 104V9C236 4.58172 232.418 1 228 1Z" fill="#F6F6F6" />
<path d="M1 104V9C1 4.58172 4.58172 1 9 1H228C232.418 1 236 4.58172 236 9V104C236 108.418 232.418 112 228 112L20 111.483L1 127V91" stroke="#E8E8E8" />
<foreignObject x="15" y="0" width="200" height="130">
<p>test</p>
</foreignObject>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" width="235" height="50" viewBox="0 0 235 50" fill="none">
<path d="M8 0H227C231.418 0 235 3.58172 235 8V50V63V86L216 70.4828L8 71C3.58173 71 0 67.4183 0 63V8C0 3.58172 3.58173 0 8 0Z" fill="#5DB075"/>
<foreignObject x="15" y="0" width="200" height="80">
<p style="color: white">test</p>
</foreignObject>
</svg>
Are there any alternative methods to dynamically adjust the SVG shape based on text length?