Wrap, unwrap and extract
izzy wrap puts a component around markup you have, izzy unwrap takes one
away, and izzy extract moves part of a page to a component of its own. Use them to
change a page's structure without retyping it. They come with a free account.
Say where
Each command takes a place in a .razor file as file:line:column, counted
from 1, and works on the element whose tag is there. A second line and column after a dash makes a
range: every element from the first to the second. The elements of a range must sit side by side in
the same parent.
Components/Pages/Orders.razor:14:9 # the element at line 14, column 9
Components/Pages/Orders.razor:14:9-15:9 # from it to the element at line 15, column 9Wrap
izzy wrap Components/Pages/Orders.razor:14:9-15:9 --with Row --gap 3
izzy writes the wrapper's tags around the elements and moves them in one step, in the file's own
indent. --with takes a component's name or an HTML element such as div.
Options after it are the wrapper's, checked as izzy set checks them. When neither the
file nor an _Imports.razor has @using IzzyBlazor, izzy adds it.
- <Button Submit>Save</Button>
- <Button Href="orders" Variant="ButtonVariant.Outline">Cancel</Button>
+ <Row Gap="3">
+ <Button Submit>Save</Button>
+ <Button Href="orders" Variant="ButtonVariant.Outline">Cancel</Button>
+ </Row>--suggest --json lists the wrappers that fit the place, the likeliest first, each with
the reason: a GridItem for an element in a Grid, a Stack or a
Row for several elements, a Fieldset for several fields, a
FieldFrame for a plain <input>.
Unwrap
izzy unwrap Components/Pages/Orders.razor:14:9
izzy removes the element's opening and closing tags and moves what it holds out one step. It stops
when the element holds a part that can't stand alone, such as a DataGrid's
<Columns>, and names the part. It also stops at an element with nothing inside.
Extract a component
izzy extract Components/Pages/Orders.razor:22:5-41:5 --name OrderSummary
izzy writes OrderSummary.razor beside the page with the markup, and puts
<OrderSummary /> where the markup was. --folder names another
folder of the page's project, such as Components/Shared, and the page gets the @using line it then needs.
A field or property of the page's @code that the markup reads becomes a parameter of
the new component, and the page passes it. A service the page injects is injected in the component
too, and the page's @using lines are copied.
<Card>
<CardBody Gap="3">
<Heading Level="2" Size="TextSize.Lg">Summary</Heading>
<TextBlock>Orders.Count orders, Total.ToString("C") in all.</TextBlock>
</CardBody>
</Card>
{
[Parameter] public List<Order> Orders { get; set; } = default!;
[Parameter] public decimal Total { get; set; } = default!;
}izzy doesn't guess at what a parameter can't carry. It makes the change and says what is left for you, in a warning for each:
| The markup uses | What to do |
|---|---|
| A method of the page | Give the component a parameter for it, an EventCallback or a Func, and pass the method from the page. |
| A value it changes | The parameter passes the value in. Pass the change back with an EventCallback. |
| A loop's variable or a template's context | Give the component a parameter for it and pass it from the page. |
| A type declared in the page's @code | Move the type to a file of its own, so both can use it. |
See the change first
All three take --dry-run, --diff and --json. With
--stdin and --json, izzy reads the file's text from standard input and
writes nothing, for an editor with unsaved changes. See Previewing changes.