|
| 1 | +/** |
| 2 | + * Make code-input elements resize automatically and fit their content live using CSS |
| 3 | + * classes, optionally between a minimum and maximum size specified using CSS variables. |
| 4 | + * |
| 5 | + * Files: autogrow.css |
| 6 | + */ |
| 7 | + |
| 8 | +/* Inspired greatly by https://css-tricks.com/the-cleanest-trick-for-autogrowing-textareas/ |
| 9 | +and the fact code-input.js already implements the article's main structure. */ |
| 10 | + |
| 11 | +code-input.code-input_autogrow_height { |
| 12 | + --code-input_autogrow_min-height: 0px; |
| 13 | + --code-input_autogrow_max-height: calc(infinity * 1px); |
| 14 | + height: max-content; |
| 15 | + max-height: var(--code-input_autogrow_max-height); |
| 16 | +} |
| 17 | +code-input.code-input_autogrow_height textarea { |
| 18 | + height: calc(var(--code-input_autogrow_min-height) - var(--padding-top, 16px) - var(--padding-bottom, 16px))!important; /* So minimum height possible while containing highlighted code */ |
| 19 | + min-height: max(var(--code-input_synced-height), calc(100% - var(--padding-top, 16px) - var(--padding-bottom, 16px))); |
| 20 | +} |
| 21 | +code-input.code-input_autogrow_height > pre, |
| 22 | +code-input.code-input_autogrow_height > pre code { |
| 23 | + min-height: calc(var(--code-input_autogrow_min-height) - var(--padding-top, 16px) - var(--padding-bottom, 16px)); |
| 24 | +} |
| 25 | + |
| 26 | +code-input.code-input_autogrow_width { |
| 27 | + --code-input_autogrow_min-width: 100px; |
| 28 | + --code-input_autogrow_max-width: 100%; |
| 29 | + width: max-content; /* Using unset rather than max-content makes always 100% width. */ |
| 30 | + max-width: var(--code-input_autogrow_max-width); |
| 31 | +} |
| 32 | +code-input.code-input_autogrow_width textarea { |
| 33 | + width: calc(var(--code-input_autogrow_min-width) - var(--padding-left, 16px) - var(--padding-right, 16px))!important; /* So minimum width possible while containing highlighted code */ |
| 34 | + min-width: max(var(--code-input_synced-width), calc(100% - var(--padding-left, 16px) - var(--padding-right, 16px))); |
| 35 | +} |
| 36 | +code-input.code-input_autogrow_width pre code, |
| 37 | +code-input.code-input_autogrow_width pre { |
| 38 | + min-width: calc(var(--code-input_autogrow_min-width) - var(--padding-left, 16px) - var(--padding-right, 16px)); |
| 39 | +} |
| 40 | + |
| 41 | +/* FindAndReplace / GoToLine dialog visibility */ |
| 42 | +code-input.code-input_autogrow_width:has(.code-input_go-to-line_dialog:not(.code-input_go-to-line_hidden-dialog)) { |
| 43 | + --code-input_autogrow_min-width: 300px; |
| 44 | +} |
| 45 | +code-input.code-input_autogrow_height:has(.code-input_go-to-line_dialog:not(.code-input_go-to-line_hidden-dialog)) { |
| 46 | + --code-input_autogrow_min-height: 150px; |
| 47 | +} |
| 48 | +code-input.code-input_autogrow_width:has(.code-input_find-and-replace_dialog:not(.code-input_find-and-replace_hidden-dialog)) { |
| 49 | + --code-input_autogrow_min-width: 500px; |
| 50 | +} |
| 51 | +code-input.code-input_autogrow_height:has(.code-input_find-and-replace_dialog:not(.code-input_find-and-replace_hidden-dialog)) { |
| 52 | + --code-input_autogrow_min-height: 170px; |
| 53 | +} |
0 commit comments