|
42 | 42 | * [Items](#appearance) |
43 | 43 | * [Selectable Item](#selectable-item) |
44 | 44 | * [Checkable Item](#checkable-item) |
| 45 | + * [Radio Item](#radio-item) |
45 | 46 | * [Line Break Item](#line-break-item) |
46 | 47 | * [Static Item](#static-item) |
47 | 48 | * [Ascii Art Item](#ascii-art-item) |
@@ -501,6 +502,7 @@ There a few different types of items you can add to your menu |
501 | 502 |
|
502 | 503 | * Selectable Item - This is the type of item you need for something to be selectable (you can hit enter and it will invoke your callable) |
503 | 504 | * Checkable Item - This is a checkbox type of item that keeps track of its toggled state to show a different marker. |
| 505 | +* Radio Item - This is a radio type of item that keeps track of its toggled state to show a different marker. Disables all other radios within its `CliMenu` level. |
504 | 506 | * Line Break Item - This is used to break up areas, it can span multiple lines and will be the width of Menu. Whatever string is passed will be repeated. |
505 | 507 | * Static Item - This will print whatever text is passed, useful for headings. |
506 | 508 | * Ascii Art Item - Special item which allows usage of Ascii art. It takes care of padding and alignment. |
@@ -568,6 +570,28 @@ $menu = (new CliMenuBuilder) |
568 | 570 | When selecting an item, it will be toggled. Notice at first each item is unchecked. After selecting one it will become |
569 | 571 | checked. |
570 | 572 |
|
| 573 | +### Radio Item |
| 574 | + |
| 575 | +```php |
| 576 | +<?php |
| 577 | + |
| 578 | +use PhpSchool\CliMenu\Builder\CliMenuBuilder; |
| 579 | +use PhpSchool\CliMenu\CliMenu; |
| 580 | + |
| 581 | +$callable = function (CliMenu $menu) { |
| 582 | + echo $menu->getSelectedItem()->getText(); |
| 583 | +}; |
| 584 | + |
| 585 | +$menu = (new CliMenuBuilder) |
| 586 | + ->addRadioItem('Item 1', $callable) |
| 587 | + ->addRadioItem('Item 2', $callable) |
| 588 | + ->addRadioItem('Item 3', $callable) |
| 589 | + ->build(); |
| 590 | +``` |
| 591 | + |
| 592 | +When selecting an item, it will be toggled. Notice at first each item is unchecked. After selecting one it will become |
| 593 | +checked and all other `RadioItem` within the same level will be unchecked. |
| 594 | + |
571 | 595 | ### Line Break Item |
572 | 596 |
|
573 | 597 | ```php |
@@ -698,7 +722,7 @@ Split Items allows you to add multiple items on the same row. The full width of |
698 | 722 |
|
699 | 723 | You can set the number of spaces separating items using `->setGutter()` (defaults to 2). |
700 | 724 |
|
701 | | -Only Selectable, Checkable, Static and SubMenu items are currently allowed inside a Split Item. |
| 725 | +Only Selectable, Checkable, Radio, Static and SubMenu items are currently allowed inside a Split Item. |
702 | 726 |
|
703 | 727 | ```php |
704 | 728 | <?php |
@@ -731,7 +755,7 @@ $menu->open(); |
731 | 755 | There are a few things to note about the syntax and builder process here: |
732 | 756 |
|
733 | 757 | 1. The first parameter to `addSplitItem` is a closure, which will be invoked with a new instance of `SplitItemBuilder` which you can use to add items to the split item. |
734 | | -2. You can call `addItem`, `addCheckableItem`, `addSubMenu` and `addStaticItem` on the `SplitItemBuilder`. |
| 758 | +2. You can call `addItem`, `addCheckableItem`, `addRadioItem`, `addSubMenu` and `addStaticItem` on the `SplitItemBuilder`. |
735 | 759 | 3. `SplitItemBuilder` has a fluent interface so you can chain method calls. |
736 | 760 |
|
737 | 761 | Note: The closure used to build the split item is also binded with the `SplitItemBuilder` instance so you can add items and such using `$this->addItem()` rather than using the function |
@@ -806,6 +830,19 @@ $menu = (new CliMenuBuilder) |
806 | 830 | ->build(); |
807 | 831 | ``` |
808 | 832 |
|
| 833 | +and for `\PhpSchool\CliMenu\MenuItem\RadioItem`: |
| 834 | + |
| 835 | +```php |
| 836 | +<?php |
| 837 | + |
| 838 | +use PhpSchool\CliMenu\Builder\CliMenuBuilder; |
| 839 | + |
| 840 | +$menu = (new CliMenuBuilder) |
| 841 | + ->setUnradioMarker('[ ] ') |
| 842 | + ->setRadioMarker('[✔] ') |
| 843 | + ->build(); |
| 844 | +``` |
| 845 | + |
809 | 846 | ### Item Extra |
810 | 847 |
|
811 | 848 | You can optionally display some arbitrary text on the right hand side of an item. You can customise this text and |
|
0 commit comments