Repository navigation
Expand file tree
/
Copy path02-fields-all-fields.php
More file actions
97 lines (90 loc) · 3.33 KB
/
Copy path02-fields-all-fields.php
File metadata and controls
97 lines (90 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* @file
* Every field on a single form - the whole gallery in one run.
*
* Each single-field script shows one field in isolation; this montage puts
* one of every type on one panel to walk through in sequence. The markup at
* the top is not one of them: it is the block that asks nothing, here to show
* what the cursor passes over on its way down. The file pickers keep their
* standalone scripts - they browse a fixture tree that would drown the
* montage.
*
* Usage:
* php playground/02-fields-all-fields.php
*/
declare(strict_types=1);
use DrevOps\PhpTui\Builder\Form;
use DrevOps\PhpTui\Builder\PanelBuilder;
use DrevOps\PhpTui\InterruptException;
use DrevOps\PhpTui\Theme\Border;
use DrevOps\PhpTui\Theme\ThemeName;
use DrevOps\PhpTui\Theme\ThemeOption;
use DrevOps\PhpTui\Tui;
require __DIR__ . '/../vendor/autoload.php';
// Labels name the field type here, so the montage reads as a gallery; the
// single-field scripts show the same fields with real-world labels.
$form = Form::create('Fields')
->panel('Fields', function (PanelBuilder $p): void {
$p->markup('A read-only block - the cursor skips it and it collects nothing.', 'Markup');
$p->text('Text')->default('Pear');
$p->template('Template')->pattern('{{orchard}}-{{fruit}}-{{grade}}')->default('valley-pear-a');
$p->number('Number')->default(1200);
$p->rating('Rating')->default(4)->captions([1 => 'Poor', 3 => 'Fair', 5 => 'Excellent']);
// The month grid wants the whole screen, so it opts out of inline
// editing; every other field here edits in place on its row.
$p->calendar('Calendar')->default('2026-07-15')->standalone();
$p->textarea('Textarea')->default('Crisp and sweet' . chr(10) . 'Hint of citrus');
$p->password('Password')->default('melon7');
$p->select('Select')->default('apple')->options([
'apple' => 'Apple',
'banana' => 'Banana',
'cherry' => 'Cherry',
]);
$p->select('MultiSelect')->multiple()->default(['apple'])->options([
'apple' => 'Apple',
'carrot' => 'Carrot',
'tomato' => 'Tomato',
]);
$p->reorder('Reorder')->options([
'apple' => 'Apple',
'carrot' => 'Carrot',
'tomato' => 'Tomato',
]);
$p->suggest('Suggest')->options([
'Apple' => 'Apple',
'Apricot' => 'Apricot',
'Banana' => 'Banana',
'Cherry' => 'Cherry',
'Mango' => 'Mango',
]);
$p->search('Search')->default('carrot')->options([
'carrot' => 'Carrot',
'potato' => 'Potato',
'onion' => 'Onion',
'pepper' => 'Pepper',
]);
$p->search('MultiSearch')->multiple()->default(['apple'])->options([
'apple' => 'Apple',
'banana' => 'Banana',
'carrot' => 'Carrot',
'tomato' => 'Tomato',
]);
$p->confirm('Confirm')->default(TRUE);
$p->toggle('Toggle')->default('ripe')->options([
'ripe' => 'Ripe',
'unripe' => 'Unripe',
]);
$p->pause('Pause');
});
try {
// The rounded border frames the whole browser - the house look of the
// panel demos; playground/03-panels-bordered.php shows it on its own.
$answers = (new Tui($form))->theme(ThemeName::Default)->option(ThemeOption::Border, Border::Rounded)->run();
}
catch (InterruptException) {
// Leave quietly on Ctrl-C.
exit(130);
}
// The summary groups the answers by panel with provenance badges.
echo $answers->toSummary() . PHP_EOL;