Documentation ¶
Overview ¶
Component demo application
1. 💻 Ensure that you have Golang installed on your system. If not, please follow the https://golang.org/doc/install.
2. 📦 Clone the repository:
git clone https://github.com/nervatura/component.git
3. 📂 Change into the project directory:
cd component
4. 🔨 Build the demo project:
go build -ldflags="-w -s -X main.version=demo" -o ./component main.go
5. 🌍 Run the demo application:
./component 5000
The demo application can store session data in memory and as session files:
- open the http://localhost:5000/ (memory session)
- or http://localhost:5000/session/ (file session)
Index ¶
- Constants
- Variables
- func New(version string, httpPort int64)
- type App
- func (app *App) AppEvent(w http.ResponseWriter, r *http.Request)
- func (app *App) HomeRoute(w http.ResponseWriter, r *http.Request)
- func (app *App) LoadDbSession(sessionID string, data any) (err error)
- func (app *App) LoadFileSession(fileName string, data any) (err error)
- func (app *App) SaveDbSession(sessionID string, data any) (err error)
- func (app *App) SaveFileSession(fileName string, data any) (err error)
- type Demo
- func (sto *Demo) GetProperty(propName string) interface{}
- func (sto *Demo) InitDemoMap()
- func (sto *Demo) OnRequest(te ct.TriggerEvent) (re ct.ResponseEvent)
- func (sto *Demo) Properties() ut.IM
- func (sto *Demo) Render() (res string, err error)
- func (sto *Demo) SetProperty(propName string, propValue interface{}) interface{}
- func (sto *Demo) Validation(propName string, propValue interface{}) interface{}
- type DemoSession
- type DemoView
Constants ¶
const ( DemoEventChange = "change" DemoEventTheme = "theme" DemoEventViewSize = "view_size" ComponentGroupAtom = "atom" ComponentGroupMolecule = "molecule" ComponentGroupTemplate = "template" ComponentGroupPage = "page" ViewSizeCentered = "centered" ViewSizeFull = "full" )
Demo constants
Variables ¶
var ComponentGroup []string = []string{ ComponentGroupAtom, ComponentGroupMolecule, ComponentGroupTemplate, }
Component ComponentGroup values
var DemoMap map[string][]DemoView = map[string][]DemoView{ ComponentGroupAtom: { {ComponentType: ct.ComponentTypeButton, TestData: ct.TestButton}, {ComponentType: ct.ComponentTypeDateTime, TestData: ct.TestDateTime}, {ComponentType: ct.ComponentTypeField, TestData: ct.TestField}, {ComponentType: ct.ComponentTypeIcon, TestData: ct.TestIcon}, {ComponentType: ct.ComponentTypeInput, TestData: ct.TestInput}, {ComponentType: ct.ComponentTypeLabel, TestData: ct.TestLabel}, {ComponentType: ct.ComponentTypeNumberInput, TestData: ct.TestNumberInput}, {ComponentType: ct.ComponentTypeSelect, TestData: ct.TestSelect}, {ComponentType: ct.ComponentTypeToast, TestData: ct.TestToast}, {ComponentType: ct.ComponentTypeToggle, TestData: ct.TestToggle}, {ComponentType: ct.ComponentTypeUpload, TestData: ct.TestUpload}, {ComponentType: ct.ComponentTypeSelector, TestData: ct.TestSelector}, {ComponentType: ct.ComponentTypeRow, TestData: ct.TestRow}, }, ComponentGroupMolecule: { {ComponentType: ct.ComponentTypeTable, TestData: ct.TestTable}, {ComponentType: ct.ComponentTypeList, TestData: ct.TestList}, {ComponentType: ct.ComponentTypeMenuBar, TestData: ct.TestMenuBar}, {ComponentType: ct.ComponentTypePagination, TestData: ct.TestPagination}, }, ComponentGroupTemplate: { {ComponentType: ct.ComponentTypeLogin, TestData: ct.TestLogin}, {ComponentType: ct.ComponentTypeLocale, TestData: ct.TestLocale}, {ComponentType: ct.ComponentTypeBrowser, TestData: ct.TestBrowser}, }, }
Component map with example data
var Public embed.FS
var ViewSize []string = []string{ViewSizeCentered, ViewSizeFull}
Component ViewSize values
Functions ¶
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
Demo application
func (*App) AppEvent ¶
func (app *App) AppEvent(w http.ResponseWriter, r *http.Request)
Receive the component event request. Loads the Demo component based on the X-Session-Token identifier.
func (*App) HomeRoute ¶
func (app *App) HomeRoute(w http.ResponseWriter, r *http.Request)
Creates and returns an Application/Demo component. It stores the state of the component in memory or in a session file
func (*App) LoadDbSession ¶ added in v1.0.1
Loading the state of a component from a database.
func (*App) LoadFileSession ¶ added in v1.0.1
Loading the state of a component from a session json file.
func (*App) SaveDbSession ¶ added in v1.0.1
Saving component state in a database.
type Demo ¶
type Demo struct { ct.BaseComponent // Application title Title string `json:"title"` /* The theme of the application. [Theme] variable constants: [ThemeLight], [ThemeDark]. Default value: [ThemeLight] */ Theme string `json:"theme"` /* [ViewSize] variable constants: [ViewSizeCentered], [ViewSizeFull]. Default value: [ViewSizeCentered] */ ViewSize string `json:"view_size"` /* [ComponentGroup] variable constants: [ComponentGroupAtom], [ComponentGroupMolecule], [ComponentGroupTemplate]. Default value: [ComponentGroupAtom] */ SelectedGroup string `json:"selected_group"` // Selected [DemoView] ComponentType SelectedType int64 `json:"selected_type"` // Selected component with example data SelectedDemo int64 `json:"selected_demo"` // Component map with example data DemoMap map[string][]DemoView `json:"-"` }
func (*Demo) GetProperty ¶
Returns the value of the property of the Demo with the specified name.
func (*Demo) InitDemoMap ¶
func (sto *Demo) InitDemoMap()
func (*Demo) OnRequest ¶
func (sto *Demo) OnRequest(te ct.TriggerEvent) (re ct.ResponseEvent)
The [TriggerEvent] event of the user interface is forwarded to the child component registered in the RequestMap based on the component id. If there is no component associated with the received component ID, or the processing of the component returns an error, it returns the error message by creating a [Toast] component.
func (*Demo) Render ¶
Based on the values, it will generate the html code of the Demo or return with an error message.
func (*Demo) SetProperty ¶
Setting a property of the Demo value safely. Checks the entered value. In case of an invalid value, the default value will be set.
func (*Demo) Validation ¶
It checks the value given to the property of the Demo and always returns a valid value
type DemoSession ¶
type DemoSession struct { Label string `json:"label"` Component ct.ClientComponent `json:"component"` }
DemoView Session data
type DemoView ¶
type DemoView struct { ComponentType string `json:"component_type"` Session []DemoSession `json:"session"` TestData func(demo ct.ClientComponent) []ct.TestComponent `json:"-"` }
DemoMap data item