milkui

package module
v0.1.20-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

README

milkui

Simple ui components written in go

Init milkui

Nothing special here, simply create an instance of the milkui.MilkView{} struct


view := milkui.MilkView{
    Data: yourPayload,
}
err := template.execute(myTemplate, view)
if err != nil {
    ...
}

Now let us check the template file

<head>
    <!-- will embed all css classes defined by milkui-->
    {{.CSS.IncludeAll}}
    <!-- or if you only want to include css classes for a specific component, do -->
    <style>
    {{.CSS.Button}} 
    </style>
    <!-- needs to be called between style tags -->
</head>
<body>
<div>
    <!-- The following will create a button -->
    {{(.Milk.Button "element-name" "Display Name").HTML}}
    <!-- use variables to reuse a button, like -->
    {{$myBtn := (.Milk.Button "element-name" "Display Name")}}
    <!-- print button in top -->
    {{$myBtn.HTML}}
    <div>
        <!-- Create a GridView by passing .Data []map[string]interface{} and Config 
        strings separeted by comma. The Config strings should match the keys in 
        .Data, you can define the order of columns here. 
        If you want to skip printing a column, remove it from the config.  -->
        {{(.Milk.Grid .Data "key-one,key-three,key-two")}}
    </div>
    <!-- print button again -->
    {{$myBtn.HTML}}
    <script>
        // apply onclick handler, for instance a ajax call to both by name selector :-)
        (func(){
            ...
        })();
    </script>
</div>
</body>

For more examples just check this repo github.com/Milkyn/milkui-demoapp

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GridColumnConfig

type GridColumnConfig struct {
	Name        string
	DisplayName string
	Formatter   func(val interface{}) string
}

GridColumnConfig tell milk.Grid which column has to be printed with given DisplayName. Add a custom formatter if you want to adjust the value output.

type GridConfig

type GridConfig []GridColumnConfig

GridConfig ...

type Milk

type Milk struct {
	HTML template.HTML
}

Milk struct hold css, js and HTML snippets of a HTML Component

func (Milk) Button

func (milk Milk) Button(name, displayName string) Milk

Button @param name, displayName string

func (Milk) Grid

func (milk Milk) Grid(obj interface{}, gridConfig GridConfig) Milk

Grid @param interface{} usally a []map[string]string

func (milk Milk) Link(url, target, displayName string, external bool) Milk

Link generates a link

func (Milk) Message

func (milk Milk) Message(msgType string, msg string) Milk

Message @param messageType string (success, warning, error), message string

func (Milk) Modal

func (milk Milk) Modal(header, content string) Milk

Modal is a text only modal

func (Milk) Navigation

func (milk Milk) Navigation(navigation Navigation, activeNavigationName string, horizontal bool) Milk

Navigation @param obj []map[string]string, horizontal bool

func (Milk) SimpleDialog

func (milk Milk) SimpleDialog(content string) Milk

SimpleDialog @param content string opens a modal with 2 buttons, abort and ok

type MilkView

type MilkView struct {
	Milk                 Milk        // Contains all UI Component Funcs, no init is needed here
	GridConfig           GridConfig  // Set a GridConfig if you want to print a Grid
	Data                 interface{} // The Data you are going to pass by template.Execute(temp, milkView)
	VerticalNavigation   Navigation  // Create a Vertical navigation if needed
	HorizontalNavigation Navigation  // Create a horizintal navigation if needed
	ActiveNavigationName string
	CSS                  css.CSS // Contains all CSS Classes for the UI Components, no init is needed here
	JS                   js.JS   // Contains all JS Funcs for the UI Components, no init is needed here
}

MilkView ...

type Navigation []NavigationItem

Navigation ...

func (navigation Navigation) ActiveNavigationName(pathPrefix string, r *http.Request) string

ActiveNavigationName ...

type NavigationItem struct {
	Name        string
	URL         string
	Target      string
	DisplayName string
}

NavigationItem ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL