column-size.php
51 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * @var View $this |
| 7 | * @var string $table_id |
| 8 | * @var string $column_id |
| 9 | * @var string|null $list_width |
| 10 | */ |
| 11 | |
| 12 | use AC\View; |
| 13 | |
| 14 | $table_id = esc_attr($this->table_id); |
| 15 | $column_id = esc_attr($this->column_id); |
| 16 | $style_id = esc_attr(sprintf('ac-column-size-%s', $this->column_id)); |
| 17 | |
| 18 | $var_list = sprintf('--ac-col-%s-width', $column_id); |
| 19 | $var_user = $var_list . '-user'; |
| 20 | $value = sprintf('var(%s, var(%s))', $var_user, $var_list); |
| 21 | |
| 22 | // Percentage widths are circular against a max-content table (% resolves to |
| 23 | // table width, which itself is the sum of column widths) and the result is |
| 24 | // browser-dependent. Fall back to auto in overflow mode. A user-set pixel |
| 25 | // width via the resizer still wins through the separate --user variable. |
| 26 | $is_percentage = is_string($this->list_width) && substr(trim($this->list_width), -1) === '%'; |
| 27 | ?> |
| 28 | <style id="<?= $style_id ?>"> |
| 29 | <?php if ($this->list_width !== null): ?> |
| 30 | .ac-<?= $table_id ?> { |
| 31 | <?= $var_list ?>: <?= esc_attr($this->list_width) ?>; |
| 32 | } |
| 33 | |
| 34 | <?php endif; ?> |
| 35 | |
| 36 | <?php if ($is_percentage): ?> |
| 37 | body.acp-overflow-table.ac-<?= $table_id ?> { |
| 38 | <?= $var_list ?>: auto; |
| 39 | } |
| 40 | |
| 41 | <?php endif; ?> |
| 42 | |
| 43 | @media screen and (min-width: 783px) { |
| 44 | .ac-<?= $table_id ?> .wrap table th.column-<?= $column_id ?>, |
| 45 | .ac-<?= $table_id ?> .wrap table td.column-<?= $column_id ?> { |
| 46 | width: <?= $value ?> !important; |
| 47 | max-width: <?= $value ?> !important; |
| 48 | } |
| 49 | } |
| 50 | </style> |
| 51 |