Skip to content

Commit 7c8dff7

Browse files
authored
Breakpoint configuration (#18)
* add breakpoint config
1 parent e32be54 commit 7c8dff7

6 files changed

Lines changed: 73 additions & 2 deletions

File tree

docs/BundleConfiguration.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ twig_doc:
1111
- '%twig.default_path%/components'
1212
categories:
1313
- name: Components
14+
breakpoints:
15+
small: 240
16+
medium: 640
17+
large: 768
1418
```
1519
1620
### Directories
@@ -66,3 +70,16 @@ twig_doc:
6670
```
6771

6872
The default category is always merged into the configuration.
73+
74+
75+
### Breakpoints
76+
77+
To use custom breakpoints, simply provide a breakpoint-config. You can name the breakpoints as you like:
78+
79+
```yaml
80+
twig_doc:
81+
breakpoints:
82+
iphone: 598
83+
unusual: 743
84+
...
85+
```

src/DependencyInjection/Configuration.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ public function getConfigTreeBuilder(): TreeBuilder
1919
->thenInvalid('The twig_doc documentation identifier must match \w (regex)')
2020
->end()
2121
->end()
22+
->arrayNode('breakpoints')
23+
->defaultValue([
24+
'small' => 240,
25+
'medium' => 640,
26+
'large' => 768,
27+
])
28+
->integerPrototype()
29+
->end()
30+
->end()
2231
->arrayNode('directories')->defaultValue(['%twig.default_path%/components'])
2332
->scalarPrototype()->end()
2433
->end()

src/DependencyInjection/TwigDocExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function load(array $configs, ContainerBuilder $container): void
2222

2323
$definition = $container->getDefinition('twig_doc.service.component');
2424
$definition->setArgument('$componentsConfig', $config['components']);
25+
$definition->setArgument('$breakpointConfig', $config['components']);
2526
$definition->setArgument('$configReadTime', time());
2627

2728
$categories = array_merge([['name' => ComponentCategory::DEFAULT_CATEGORY]], $config['categories']);

src/Service/ComponentService.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public function __construct(
1818
private readonly ComponentItemFactory $itemFactory,
1919
private readonly array $componentsConfig,
2020
private readonly CacheInterface $cache,
21+
private readonly array $breakpointConfig,
2122
private readonly int $configReadTime = 0
2223
) {
2324
}
@@ -95,4 +96,9 @@ public function getComponent(string $name): ?ComponentItem
9596
{
9697
return array_values(array_filter((array) $this->getComponents(), fn (ComponentItem $c) => $c->getName() === $name))[0] ?? null;
9798
}
99+
100+
public function getBreakpoints(): array
101+
{
102+
return $this->breakpointConfig;
103+
}
98104
}

tests/Functional/Service/ComponentServiceTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ public function testParsePerformance(): void
6767

6868
$start = microtime(true);
6969

70-
$service = new ComponentService($factory, $this->getLargeConfig(), static::getContainer()->get(CacheInterface::class));
70+
$service = new ComponentService(
71+
$factory,
72+
$this->getLargeConfig(),
73+
static::getContainer()->get(CacheInterface::class),
74+
[]
75+
);
7176

7277
$service->getComponents();
7378

tests/Unit/DependencyInjection/ConfigurationTest.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function testConfigTree(array $options, array $expectedResult)
1818
$configuration = new Configuration();
1919
$config = $processor->processConfiguration($configuration, [$options]);
2020

21-
$this->assertEqualsCanonicalizing($expectedResult, $config);
21+
$this->assertEquals($expectedResult, $config);
2222
}
2323

2424
public static function getTestConfiguration(): iterable
@@ -41,6 +41,11 @@ public static function getTestConfiguration(): iterable
4141
],
4242
[
4343
'doc_identifier' => 'TWIG_DOC',
44+
'breakpoints' => [
45+
'small' => 240,
46+
'medium' => 640,
47+
'large' => 768,
48+
],
4449
'directories' => [
4550
__DIR__.'/../../TestApp/templates/components',
4651
__DIR__.'/../../TestApp/templates/snippets',
@@ -100,6 +105,11 @@ public static function getTestConfiguration(): iterable
100105
],
101106
[
102107
'doc_identifier' => 'TWIG_DOC',
108+
'breakpoints' => [
109+
'small' => 240,
110+
'medium' => 640,
111+
'large' => 768,
112+
],
103113
'directories' => [
104114
__DIR__.'/../../TestApp/templates/components',
105115
__DIR__.'/../../TestApp/templates/snippets',
@@ -139,5 +149,28 @@ public static function getTestConfiguration(): iterable
139149
],
140150
],
141151
];
152+
153+
yield 'Breakpoint config' => [
154+
[
155+
'breakpoints' => [
156+
'iphone' => 568,
157+
'galaxy s10' => 658,
158+
'generic' => 896,
159+
],
160+
],
161+
[
162+
'breakpoints' => [
163+
'iphone' => 568,
164+
'galaxy s10' => 658,
165+
'generic' => 896,
166+
],
167+
'doc_identifier' => 'TWIG_DOC',
168+
'directories' => [
169+
'%twig.default_path%/components',
170+
],
171+
'categories' => [],
172+
'components' => [],
173+
],
174+
];
142175
}
143176
}

0 commit comments

Comments
 (0)