A region's declaration (spec/06 §4): %Macaw.Region{name, persistent}, the least a
persistent region needs before templates.
name, the region's name, lower-case words joined by_, as a surface's is; the instance of its content's:regionstate (spec/03 §2.1); required;persistent, whether it survives live navigation between pages that share it (LiveView's sticky nested LiveView, macaw_live 04 §3);falseby default.
A template (spec/06 §2.1) carries its regions as %Macaw.Region{}s by name, the struct
holding the keys a template gives it, beside name and persistent, whose meaning and
judgment are unchanged:
role, its landmark role, one ofroles/0,:regionby default;label, its accessible name, a non-empty string ornil;fillable, whether a page's own layer may fill it, andhidden, whether the page leaves it out,falseby default;collapse, what it does on a narrow screen (collapses/0,:stackby default), below itsbreakpoint(breakpoints/0,:mdby default);content, its default surfaces in a flow, by name,[]by default;classes, its own CSP-safe classes (class?/1),[]by default;kinds, the kinds a cell in it may take,nilfor its role's (kinds/1).
It writes each as node/1 does.
kept/2 says what a surface instance in the region keeps across a change, and
Macaw.State.follow/3 gives the state it holds then: its state follows its scope.
Summary
Functions
The widths below which a region collapses, narrowest first.
Whether a term is a CSP-safe class: lower-case letters, digits, - and _, starting
with a letter, and never the library's prefix mw-.
The region's element's classes: "mw-region mw-region-<name> mw-collapse-<collapse> mw-below-<breakpoint>", then its own, in order. Placement is by classes only.
What a region may do on a narrow screen: :stack, :drawer, :hide or :none.
The scopes a surface instance in the region keeps across a change (spec/06 §4), in
Macaw.State.scopes/0's order; every other held scope starts again at its initial
values, then takes any value its owner holds when the instance joins it.
The kind a cell in the region takes when it names none (spec/06 §2.6): :navigation in
a navigation region, :content elsewhere.
The kinds a cell in the region may take: its kinds, or by its role, [:navigation, :control] in a navigation region and every kind elsewhere.
Whether a term is a region's name: a string of lower-case words joined by _.
A region from a keyword list or a map with atom keys: {:ok, region} or every fault at
once, by path. A missing name is :required, one that isn't a name {:type, :name}
(an atom read as its spelling, no atom made); a persistent, fillable or hidden
that isn't a boolean {:type, :boolean}; a role, collapse, breakpoint or kind
outside its set {:enum, set}; a label that isn't a non-empty string or nil
{:type, :label}; content that isn't a list {:type, :content} and an entry that
isn't a surface's name, {:surface, name} or %{surface: name} {:type, :surface} at
[:content, i]; classes that isn't a list {:type, :classes} and a class that isn't
CSP-safe {:type, :class} at [:classes, i]; kinds that isn't a non-empty list
{:type, :kinds}; another key :unknown_key; what isn't a map {[], {:type, :map}}.
The region as a document writes it: its map, every key at its default left out.
new/1 of it answers the region again.
The landmark roles a region may take.
Types
@type change() :: :navigate | :refill
@type role() ::
:banner
| :navigation
| :main
| :complementary
| :contentinfo
| :search
| :form
| :region
@type t() :: %Macaw.Region{ breakpoint: :sm | :md | :lg | :xl, classes: [String.t()], collapse: :stack | :drawer | :hide | :none, content: [String.t()], fillable: boolean(), hidden: boolean(), kinds: [Macaw.Component.kind(), ...] | nil, label: String.t() | nil, name: String.t(), persistent: boolean(), role: role() }
Functions
@spec breakpoints() :: [atom(), ...]
The widths below which a region collapses, narrowest first.
Whether a term is a CSP-safe class: lower-case letters, digits, - and _, starting
with a letter, and never the library's prefix mw-.
iex> Macaw.Region.class?("site-nav")
true
iex> Macaw.Region.class?("mw-grid")
false
The region's element's classes: "mw-region mw-region-<name> mw-collapse-<collapse> mw-below-<breakpoint>", then its own, in order. Placement is by classes only.
iex> Macaw.Region.classes(%Macaw.Region{name: "sidebar", collapse: :drawer, classes: ["nav"]})
"mw-region mw-region-sidebar mw-collapse-drawer mw-below-md nav"
@spec collapses() :: [atom(), ...]
What a region may do on a narrow screen: :stack, :drawer, :hide or :none.
The scopes a surface instance in the region keeps across a change (spec/06 §4), in
Macaw.State.scopes/0's order; every other held scope starts again at its initial
values, then takes any value its owner holds when the instance joins it.
:navigate, a live navigation to a page sharing the region: a persistent region keeps everything but:page, which is the new page's; another keeps only what an owner outside the page holds,:session,:viewerand:shared.:refill, a layer filling the region with different content, and the old content returning::surfaceand:regionstate is gone with the content, and:page,:session,:viewerand:sharedreturn with the instance.
A change that is neither is a wrong call.
iex> Macaw.Region.kept(%Macaw.Region{name: "sidebar", persistent: true}, :refill)
[:page, :session, :viewer, :shared]
@spec kind(t()) :: Macaw.Component.kind()
The kind a cell in the region takes when it names none (spec/06 §2.6): :navigation in
a navigation region, :content elsewhere.
@spec kinds(t()) :: [Macaw.Component.kind(), ...]
The kinds a cell in the region may take: its kinds, or by its role, [:navigation, :control] in a navigation region and every kind elsewhere.
Whether a term is a region's name: a string of lower-case words joined by _.
iex> Macaw.Region.name?("site_menu")
true
iex> Macaw.Region.name?("Site Menu")
false
@spec new(map() | keyword()) :: {:ok, t()} | {:error, [Macaw.Base.Fault.t(), ...]}
A region from a keyword list or a map with atom keys: {:ok, region} or every fault at
once, by path. A missing name is :required, one that isn't a name {:type, :name}
(an atom read as its spelling, no atom made); a persistent, fillable or hidden
that isn't a boolean {:type, :boolean}; a role, collapse, breakpoint or kind
outside its set {:enum, set}; a label that isn't a non-empty string or nil
{:type, :label}; content that isn't a list {:type, :content} and an entry that
isn't a surface's name, {:surface, name} or %{surface: name} {:type, :surface} at
[:content, i]; classes that isn't a list {:type, :classes} and a class that isn't
CSP-safe {:type, :class} at [:classes, i]; kinds that isn't a non-empty list
{:type, :kinds}; another key :unknown_key; what isn't a map {[], {:type, :map}}.
iex> Macaw.Region.new(name: :sidebar, persistent: true)
{:ok, %Macaw.Region{name: "sidebar", persistent: true}}
iex> Macaw.Region.new(%{name: "Side Bar", persistent: "yes"})
{:error, [{[:name], {:type, :name}}, {[:persistent], {:type, :boolean}}]}
iex> {:ok, region} = Macaw.Region.new(name: :menu, role: "navigation", content: [surface: :site_menu])
iex> {region.role, region.content}
{:navigation, ["site_menu"]}
The region as a document writes it: its map, every key at its default left out.
new/1 of it answers the region again.
iex> Macaw.Region.node(%Macaw.Region{name: "main"})
%{name: "main"}
iex> Macaw.Region.node(%Macaw.Region{name: "main", role: :main, fillable: true})
%{name: "main", role: :main, fillable: true}
@spec roles() :: [role(), ...]
The landmark roles a region may take.