Skip to content

[FEATURE] Add support for the dvh, lvh and svh length units #415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).

### Added

- Add support for the `dvh`, `lvh` and `svh` length units (#415)
- Add more tests (#449)

### Changed
Expand Down
7 changes: 6 additions & 1 deletion src/Value/Size.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ class Size extends PrimitiveValue
*
* @var array<int, string>
*/
private const ABSOLUTE_SIZE_UNITS = ['px', 'cm', 'mm', 'mozmm', 'in', 'pt', 'pc', 'vh', 'vw', 'vmin', 'vmax', 'rem'];
private const ABSOLUTE_SIZE_UNITS = [
'px', 'pt', 'pc',
'cm', 'mm', 'mozmm', 'in',
'vh', 'dvh', 'svh', 'lvh',
'vw', 'vmin', 'vmax', 'rem',
];

/**
* @var array<int, string>
Expand Down
51 changes: 51 additions & 0 deletions tests/Value/SizeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Sabberworm\CSS\Tests\Value;

use PHPUnit\Framework\TestCase;
use Sabberworm\CSS\Parsing\ParserState;
use Sabberworm\CSS\Settings;
use Sabberworm\CSS\Value\Size;

/**
* @covers \Sabberworm\CSS\Value\Size
*/
final class SizeTest extends TestCase
{
/**
* @return array<string, array{0: string}>
*/
public static function provideUnit(): array
{
$units = [
'px', 'pt', 'pc',
'cm', 'mm', 'mozmm', 'in',
'vh', 'dvh', 'svh', 'lvh',
'vw', 'vmin', 'vmax', 'rem',
'%', 'em', 'ex', 'ch', 'fr',
'deg', 'grad', 'rad', 's', 'ms', 'turn', 'Hz', 'kHz',
];

return \array_combine(
$units,
\array_map(
function (string $unit): array {
return [$unit];
},
$units
)
);
}

/**
* @test
*
* @dataProvider provideUnit
*/
public function parsesUnit(string $unit): void
{
$subject = Size::parse(new ParserState('1' . $unit, Settings::create()));

self::assertSame($unit, $subject->getUnit());
}
}