Separator
A visual divider between content.
<separator.Separator decorative class="w-40" />Installation
Run the command in the app module.
gx add separatorThe command writes these files.
| File | Path in the app |
|---|---|
Separator.gx |
ui/separator/Separator.gx |
Separator.fixtures.go |
ui/separator/Separator.fixtures.go |
styles.go |
ui/separator/styles.go |
Copy each file to its path in the app. Change each import of a registry package to the path of that package in the app.
package separator
props {
// Orientation sets the direction: Horizontal or Vertical.
Orientation Orientation = Horizontal
// Decorative hides the separator from assistive technology. Set it to false for the separator
// role.
Decorative bool = true
// Class adds classes to the root element.
Class string = ""
// Attrs adds HTML attributes to the root element.
Attrs gx.Attrs = nil
}
<div data-slot="separator" data-orientation={p.orientation()} class={gx.Cx("shrink-0 bg-border", orientationClass[Orientation(p.orientation())], p.Class)} {...p.attrs()}></div>package separator
import "github.com/alternayte/gx"
var SeparatorFixtures = gx.Fixtures[SeparatorProps]{
"Horizontal": {Decorative: true, Class: "w-40"},
"Vertical": {Decorative: true, Orientation: Vertical, Class: "h-8"},
"Semantic": {Class: "w-40"},
}package separator
import "github.com/alternayte/gx"
// Orientation is the direction of a separator.
type Orientation string
// The orientations of separator.Separator.
const (
Horizontal Orientation = "horizontal"
Vertical Orientation = "vertical"
)
var orientationClass = gx.Enum[Orientation]{
Horizontal: "h-px w-full",
Vertical: "h-full w-px",
}
// orientation returns the data-orientation value; a zero value is
// Horizontal.
func (p SeparatorProps) orientation() string {
if p.Orientation == "" {
return string(Horizontal)
}
return string(p.Orientation)
}
// attrs returns the role of one separator, then the caller's attributes. A
// decorative separator has no role. A semantic separator names its
// orientation when it is vertical.
func (p SeparatorProps) attrs() gx.Attrs {
a := gx.Attrs{{Key: "role", Value: "none"}}
if !p.Decorative {
a = gx.Attrs{{Key: "role", Value: "separator"}}
if p.Orientation == Vertical {
a = append(a, gx.Attr{Key: "aria-orientation", Value: "vertical"})
}
}
return append(a, p.Attrs...)
}The theme must define these tokens: --border.
Usage
<separator.Separator />
<separator.Separator orientation={separator.Vertical} class="h-6" />A decorative separator has the role none. A separator with decorative={false} has the role separator.
Examples
Horizontal
<separator.Separator decorative class="w-40" />Vertical
<separator.Separator decorative orientation={separator.Vertical} class="h-8" />Semantic
<separator.Separator class="w-40" />API reference
A tag sets a prop by its name with a lower-case first letter: Class is class.
separator.Separator
| Prop | Type | Default | Description |
|---|---|---|---|
Orientation |
Orientation |
Horizontal |
Orientation sets the direction: Horizontal or Vertical. |
Decorative |
bool |
true |
Decorative hides the separator from assistive technology. Set it to false for the separator role. |
Class |
string |
"" |
Class adds classes to the root element. |
Attrs |
gx.Attrs |
nil |
Attrs adds HTML attributes to the root element. |
Do and do not
Do
- Use a separator between groups that need a visual break.
- Keep the decorative default for a pure layout line.
Don't
- Do not use a separator where whitespace is enough.
- Do not set
Decorativeto false unless the line is a real landmark.
Keyboard
| Key | Action |
|---|---|
| None | The component is static. |