Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
docs: Add description of complete public API
Browse files Browse the repository at this point in the history
  • Loading branch information
pojntfx committed Nov 10, 2021
1 parent 326c0b0 commit 7c21e6e
Show file tree
Hide file tree
Showing 23 changed files with 209 additions and 176 deletions.
5 changes: 3 additions & 2 deletions pkg/components/autofocused.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"github.com/maxence-charriere/go-app/v9/pkg/app"
)

// Autofocused calls `focus` on the encapsulated component after it is mounted
type Autofocused struct {
app.Compo

Disable bool
Component app.UI
Disable bool // Disable the focus
Component app.UI // The component to be focused
}

func (c *Autofocused) Render() app.UI {
Expand Down
23 changes: 12 additions & 11 deletions pkg/components/confirmation_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ import (
"github.com/maxence-charriere/go-app/v9/pkg/app"
)

// ConfirmationModal is a modal with callbacks intended to enable confirm destructive operations such as deleting something
type ConfirmationModal struct {
app.Compo

ID string
Icon string
Title string
Class string
Body string
ActionClass string
ActionLabel string
CancelLabel string
CancelLink string
ID string // HTML ID of the modal; must be unique across the page
Icon string // Class of the icon to use to the left of the title; may be empty
Title string // Title of the modal
Class string // Class to be applied to the modal's outmost component
Body string // Body text of the modal
ActionClass string // Class to be applied to the modal's primary action
ActionLabel string // Text to display on the modal's primary action
CancelLabel string // Text to display on the modal's cancel action
CancelLink string // Link to display as the cancel action; if empty, `OnClose` is being called

OnClose func()
OnAction func()
OnClose func() // Handler to call when closing/cancelling the modal
OnAction func() // Handler to call when triggering the modal's primary action
}

func (c *ConfirmationModal) Render() app.UI {
Expand Down
5 changes: 3 additions & 2 deletions pkg/components/controlled.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package components

import "github.com/maxence-charriere/go-app/v9/pkg/app"

// Controlled sets DOM properties of the encapsulated component after it is mounted
type Controlled struct {
app.Compo

Component app.UI
Properties map[string]interface{}
Component app.UI // The component to be focused
Properties map[string]interface{} // Map of properties to set
}

func (c *Controlled) Render() app.UI {
Expand Down
5 changes: 3 additions & 2 deletions pkg/components/create_key_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import (
"github.com/maxence-charriere/go-app/v9/pkg/app"
)

// CreateKeyModal is a modal which provides the information needed to create a key
type CreateKeyModal struct {
app.Compo

OnSubmit func(
fullName string,
email string,
password string,
)
OnCancel func(dirty bool, clear chan struct{})
) // Handler to call to create the key
OnCancel func(dirty bool, clear chan struct{}) // Handler to call when closing/cancelling the modal

fullName string
email string
Expand Down
31 changes: 16 additions & 15 deletions pkg/components/decrypt_and_verify_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ const (
selectDetachedSignatureFileInput = "select-detached-signature-file-input"
)

// DecryptAndVerifyModal is a modal to provide the information needed to decrypt/verify something
type DecryptAndVerifyModal struct {
app.Compo

Keys []GPGKey
Keys []GPGKey // GPG keys to be available for decryption/verification

OnSubmit func(
file []byte,
publicKeyID string,
privateKeyID string,
detachedSignature []byte,
)
OnCancel func(dirty bool, clear chan struct{})
) // Handler to call to decrypt/verify
OnCancel func(dirty bool, clear chan struct{}) // Handler to call when closing/cancelling the modal

fileContents []byte

Expand Down Expand Up @@ -73,12 +74,12 @@ func (c *DecryptAndVerifyModal) Render() app.UI {
Class("pf-c-form__group").
Body(
&FileUpload{
ID: selectDecryptionFileInput,
FileSelectionLabel: "Drag and drop a file or select one",
ClearLabel: "Clear",
TextEntryLabel: "Or enter text here",
TextEntryBlockedLabel: "File has been selected.",
FileContents: c.fileContents,
ID: selectDecryptionFileInput,
FileSelectionLabel: "Drag and drop a file or select one",
ClearLabel: "Clear",
TextEntryInputPlaceholder: "Or enter text here",
TextEntryInputBlockedLabel: "File has been selected.",
FileContents: c.fileContents,

OnChange: func(fileContents []byte) {
c.fileContents = fileContents
Expand Down Expand Up @@ -282,12 +283,12 @@ func (c *DecryptAndVerifyModal) Render() app.UI {
Class("pf-c-check__body pf-u-w-100").
Body(
&FileUpload{
ID: selectDetachedSignatureFileInput,
FileSelectionLabel: "Drag and drop a detached signature or select one",
ClearLabel: "Clear",
TextEntryLabel: "Or enter the detached signature's content here",
TextEntryBlockedLabel: "File has been selected.",
FileContents: []byte(c.detachedSignature),
ID: selectDetachedSignatureFileInput,
FileSelectionLabel: "Drag and drop a detached signature or select one",
ClearLabel: "Clear",
TextEntryInputPlaceholder: "Or enter the detached signature's content here",
TextEntryInputBlockedLabel: "File has been selected.",
FileContents: []byte(c.detachedSignature),

OnChange: func(fileContents []byte) {
c.detachedSignature = fileContents
Expand Down
27 changes: 14 additions & 13 deletions pkg/components/download_or_view_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ import (
"github.com/maxence-charriere/go-app/v9/pkg/app"
)

// DownloadOrViewModal is a modal which provides the actions needed to download or view text
type DownloadOrViewModal struct {
app.Compo

SubjectA bool
SubjectANoun string
SubjectAVerb string
SubjectA bool // Whether to display the first subject to download or view
SubjectANoun string // Noun form the first subject to download or view (i.e. "signature")
SubjectAAdjective string // Adjective of the first subject to download or view (i.e. "signed")

SubjectB bool
SubjectBNoun string
SubjectBVerb string
SubjectB bool // Whether to display the second subject to download or view
SubjectBNoun string // Noun form the second subject to download or view (i.e. "signature")
SubjectBAdjective string // Adjective of the second subject to download or view (i.e. "signed")

OnClose func(used bool)
OnDownload func()
OnView func()
OnClose func(used bool) // Handler to call when closing/cancelling the modal
OnDownload func() // Handler to call to download the subject(s)
OnView func() // Handler to view to download the subject(s)

ShowView bool
ShowView bool // Whether to show the view action

used bool
}
Expand All @@ -30,7 +31,7 @@ func (c *DownloadOrViewModal) Render() app.UI {
viewLabel := "View "
body := "You may now download or view "
if c.SubjectA && c.SubjectB {
title += c.SubjectBVerb + " and " + c.SubjectAVerb
title += c.SubjectBAdjective + " and " + c.SubjectAAdjective

if c.SubjectANoun == "" {
downloadLabel += c.SubjectBNoun
Expand All @@ -46,12 +47,12 @@ func (c *DownloadOrViewModal) Render() app.UI {
body += "them"
}
} else if c.SubjectA {
title += c.SubjectAVerb
title += c.SubjectAAdjective
downloadLabel += c.SubjectANoun
viewLabel += c.SubjectANoun
body += "it"
} else {
title += c.SubjectBVerb
title += c.SubjectBAdjective
downloadLabel += c.SubjectBNoun
viewLabel += c.SubjectBNoun
body += "it"
Expand Down
5 changes: 3 additions & 2 deletions pkg/components/empty_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package components

import "github.com/maxence-charriere/go-app/v9/pkg/app"

// EmptyState is the initial placeholder of the key list
type EmptyState struct {
app.Compo

OnCreateKey func()
OnImportKey func()
OnCreateKey func() // OnCreateKey is the handler to call to create a key
OnImportKey func() // OnCreateKey is the handler to call to import a key
}

func (c *EmptyState) Render() app.UI {
Expand Down
29 changes: 10 additions & 19 deletions pkg/components/encrypt_and_sign_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,20 @@ const (
selectEncryptionFileInput = "select-encryption-file-input"
)

type GPGKey struct {
ID string `json:"id"`
Label string `json:"label"`
FullName string `json:"fullName"`
Email string `json:"email"`
Private bool `json:"private"`
Public bool `json:"public"`
Content []byte `json:"content"`
}

// EncryptAndSignModal is a modal which provides the information needed to encrypt/sign something
type EncryptAndSignModal struct {
app.Compo

Keys []GPGKey
Keys []GPGKey // GPG keys to be available for encryption/signing

OnSubmit func(
file []byte,
publicKeyID string,
privateKeyID string,
createDetachedSignature bool,
armor bool,
)
OnCancel func(dirty bool, clear chan struct{})
) // Handle to call to encrypt/sign
OnCancel func(dirty bool, clear chan struct{}) // Handler to call when closing/cancelling the modal

fileIsBinary bool
fileContents []byte
Expand Down Expand Up @@ -85,12 +76,12 @@ func (c *EncryptAndSignModal) Render() app.UI {
Class("pf-c-form__group").
Body(
&FileUpload{
ID: selectEncryptionFileInput,
FileSelectionLabel: "Drag and drop a file or select one",
ClearLabel: "Clear",
TextEntryLabel: "Or enter text here",
TextEntryBlockedLabel: "File has been selected.",
FileContents: c.fileContents,
ID: selectEncryptionFileInput,
FileSelectionLabel: "Drag and drop a file or select one",
ClearLabel: "Clear",
TextEntryInputPlaceholder: "Or enter text here",
TextEntryInputBlockedLabel: "File has been selected.",
FileContents: c.fileContents,

OnChange: func(fileContents []byte) {
c.fileContents = fileContents
Expand Down
19 changes: 10 additions & 9 deletions pkg/components/error_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ import (
"github.com/maxence-charriere/go-app/v9/pkg/app"
)

// ErrorModal is a modal to display an error
type ErrorModal struct {
app.Compo

ID string
Icon string
Title string
Class string
Body string
Error error
ActionLabel string
ID string // HTML ID of the modal; must be unique across the page
Icon string // Class of the icon to use to the left of the title; may be empty
Title string // Title of the modal
Class string // Class to be applied to the modal's outmost component
Body string // Body text of the modal
Error error // The error display (must not be nil)
ActionLabel string // Text to display on the modal's primary action

OnClose func()
OnAction func()
OnClose func() // Handler to call when closing/cancelling the modal
OnAction func() // Handler to call when triggering the modal's primary action
}

func (c *ErrorModal) Render() app.UI {
Expand Down
15 changes: 8 additions & 7 deletions pkg/components/export_key_modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ const (
exportPrivateKeyForm = "export-private-key-form"
)

// ExportKeyModal is a modal which provides the actions needed to export a key
type ExportKeyModal struct {
app.Compo

PublicKey bool
OnDownloadPublicKey func(armor bool)
OnViewPublicKey func()
PublicKey bool // Whether to display the options for a public key
OnDownloadPublicKey func(armor bool) // Handler to call to download the public key
OnViewPublicKey func() // Handler to call to view the public key

PrivateKey bool
OnDownloadPrivateKey func(armor bool)
OnViewPrivateKey func()
PrivateKey bool // Whether to display the options for a private key
OnDownloadPrivateKey func(armor bool) // Handler to call to download the private key
OnViewPrivateKey func() // Handler to call to view the private key

OnOK func()
OnOK func() // Handler to call when dismissing the modal

skipPublicKeyArmor bool
skipPrivateKeyArmor bool
Expand Down
23 changes: 12 additions & 11 deletions pkg/components/file_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import (
"github.com/maxence-charriere/go-app/v9/pkg/app"
)

// FileUpload provides a way to upload/import a file by entering it's contents or selecting it
type FileUpload struct {
app.Compo

ID string
FileSelectionLabel string
ClearLabel string
TextEntryLabel string
TextEntryBlockedLabel string
FileContents []byte
ID string // HTML ID of the modal; must be unique across the page
FileSelectionLabel string // Text to display on the file selection input
ClearLabel string // Text to display on the clear action
TextEntryInputPlaceholder string // Placeholder to display in the text input field
TextEntryInputBlockedLabel string // Text to display in the input if it is blocked (i.e. because a file has been selected)
FileContents []byte // Contents of the file selected/text entered

OnChange func(fileContents []byte)
OnClear func()
OnChange func(fileContents []byte) // Handler to call to set `FileContents`
OnClear func() // Handler to call to clear `FileContents`

fileIsBinary bool
}
Expand Down Expand Up @@ -78,8 +79,8 @@ func (c *FileUpload) Render() app.UI {
Body(
app.Textarea().
Class("pf-c-form-control pf-m-resize-vertical").
Aria("label", c.TextEntryLabel).
Placeholder(c.TextEntryLabel).
Aria("label", c.TextEntryInputPlaceholder).
Placeholder(c.TextEntryInputPlaceholder).
Required(true).
OnInput(func(ctx app.Context, e app.Event) {
c.OnChange([]byte(ctx.JSSrc().Get("value").String()))
Expand All @@ -92,7 +93,7 @@ func (c *FileUpload) Render() app.UI {
}).
Text(func() string {
if c.fileIsBinary {
return c.TextEntryBlockedLabel
return c.TextEntryInputBlockedLabel
}

return string(c.FileContents)
Expand Down
Loading

0 comments on commit 7c21e6e

Please sign in to comment.