This repository has been archived by the owner on Jan 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 480
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: GuessWhoSamFoo <foos@vmware.com>
- Loading branch information
GuessWhoSamFoo
committed
Sep 2, 2020
1 parent
7be1c91
commit 987cf9c
Showing
24 changed files
with
449 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Added modal component and opening modals through buttons |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package component | ||
|
||
import ( | ||
"encoding/json" | ||
) | ||
|
||
type ModalSize string | ||
|
||
const ( | ||
// ModalSizeSmall is the smallest modal | ||
ModalSizeSmall ModalSize = "sm" | ||
// ModalSizeLarge is a large modal | ||
ModalSizeLarge ModalSize = "lg" | ||
// ModalSizeExtraLarge is the largest modal | ||
ModalSizeExtraLarge ModalSize = "xl" | ||
) | ||
|
||
// ModalConfig is a configuration for the modal component. | ||
type ModalConfig struct { | ||
Body Component `json:"body"` | ||
//Form Form `json:"form,omitempty"` | ||
Opened bool `json:"opened"` | ||
ModalSize ModalSize `json:"size,omitempty"` | ||
} | ||
|
||
// UnmarshalJSON unmarshals a modal config from JSON. | ||
func (m *ModalConfig) UnmarshalJSON(data []byte) error { | ||
x := struct { | ||
Body TypedObject `json:"body"` | ||
//Form Form `json:"form,omitempty"` | ||
Opened bool `json:"opened"` | ||
ModalSize ModalSize `json:"size,omitempty"` | ||
}{} | ||
|
||
if err := json.Unmarshal(data, &x); err != nil { | ||
return err | ||
} | ||
|
||
var err error | ||
m.Body, err = x.Body.ToComponent() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
//m.Form = x.Form | ||
m.Opened = x.Opened | ||
m.ModalSize = x.ModalSize | ||
return nil | ||
} | ||
|
||
// Modal is a modal component. | ||
// | ||
// +octant:component | ||
type Modal struct { | ||
Base | ||
Config ModalConfig `json:"config"` | ||
} | ||
|
||
// NewModal creates a new modal. | ||
func NewModal(title []TitleComponent, body Component) *Modal { | ||
return &Modal{ | ||
Base: newBase(TypeModal, title), | ||
Config: ModalConfig{Body: body}, | ||
} | ||
} | ||
|
||
var _ Component = (*Modal)(nil) | ||
|
||
// SetBody sets the body of a modal. | ||
func (m *Modal) SetBody(body Component) { | ||
m.Config.Body = body | ||
} | ||
|
||
// AddForm adds a form to a modal. It is added after the body. | ||
//func (m *Modal) AddForm(form Form) { | ||
// m.Config.Form = form | ||
//} | ||
|
||
// SetSize sets the size of a modal. Size is medium by default. | ||
func (m *Modal) SetSize(size ModalSize) { | ||
m.Config.ModalSize = size | ||
} | ||
|
||
// Open opens a modal. A modal is closed by default. | ||
func (m *Modal) Open() { | ||
m.Config.Opened = true | ||
} | ||
|
||
// Close closes a modal. | ||
func (m *Modal) Close() { | ||
m.Config.Opened = false | ||
} | ||
|
||
type modalMarshal Modal | ||
|
||
// MarshalJSON marshal a modal to JSON. | ||
func (m *Modal) MarshalJSON() ([]byte, error) { | ||
k := modalMarshal(*m) | ||
k.Metadata.Type = TypeModal | ||
return json.Marshal(&k) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package component | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestModal_SetBody(t *testing.T) { | ||
modal := NewModal(TitleFromString("modal")) | ||
body := NewText("body") | ||
modal.SetBody(body) | ||
|
||
expected := NewModal(TitleFromString("modal")) | ||
expected.Config.Body = body | ||
|
||
AssertEqual(t, expected, modal) | ||
} | ||
|
||
func TestModal_SetSize(t *testing.T) { | ||
tests := []struct{ | ||
name string | ||
size ModalSize | ||
expected *Modal | ||
}{ | ||
{ | ||
name: "small", | ||
size: ModalSizeSmall, | ||
expected: &Modal{ | ||
Base: newBase(TypeModal, TitleFromString("modal")), | ||
Config: ModalConfig{ModalSize: ModalSizeSmall}, | ||
}, | ||
}, | ||
{ | ||
name: "large", | ||
size: ModalSizeLarge, | ||
expected: &Modal{ | ||
Base: newBase(TypeModal, TitleFromString("modal")), | ||
Config: ModalConfig{ModalSize: ModalSizeLarge}, | ||
}, | ||
}, | ||
{ | ||
name: "extra large", | ||
size: ModalSizeExtraLarge, | ||
expected: &Modal{ | ||
Base: newBase(TypeModal, TitleFromString("modal")), | ||
Config: ModalConfig{ModalSize: ModalSizeExtraLarge}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
modal := NewModal(TitleFromString("modal")) | ||
modal.SetSize(test.size) | ||
|
||
AssertEqual(t, test.expected, modal) | ||
}) | ||
} | ||
} | ||
|
||
func TestModal_Open(t *testing.T) { | ||
modal := NewModal(TitleFromString("modal")) | ||
modal.Open() | ||
|
||
expected := NewModal(TitleFromString("modal")) | ||
expected.Config.Opened = true | ||
AssertEqual(t, expected, modal) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"body":{ | ||
"metadata":{ | ||
"type":"text" | ||
}, | ||
"config":{ | ||
"value":"test" | ||
} | ||
}, | ||
"opened":true, | ||
"size":"sm" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
web/src/app/modules/shared/components/presentation/datagrid/datagrid.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
web/src/app/modules/shared/components/presentation/modal/modal.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<clr-modal [(clrModalOpen)]="opened" [clrModalStaticBackdrop]="false" [clrModalClosable]="true" [clrModalSize]="size"> | ||
<h3 class="modal-title"> | ||
<app-view-title [views]="title"></app-view-title> | ||
</h3> | ||
<div class="modal-body"> | ||
<app-view-container [view]="body"></app-view-container> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-primary" (click)="opened = false"> | ||
Close | ||
</button> | ||
</div> | ||
</clr-modal> |
File renamed without changes.
Oops, something went wrong.