Skip to content

Commit

Permalink
Merge pull request #255 from codello/master
Browse files Browse the repository at this point in the history
Add `IsSublte` and `HorizontalAlignment` to `Element`
  • Loading branch information
atc0005 committed Feb 22, 2024
2 parents f941266 + 6236958 commit 84950e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
16 changes: 13 additions & 3 deletions adaptivecard/adaptivecard.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ const (
SpacingPadding string = "padding"
)

// Supported Horizontal alignment values for (supported) container types.
// Supported Horizontal alignment values for (supported) container and text
// types.
const (
HorizontalAlignmentLeft string = "left"
HorizontalAlignmentCenter string = "center"
Expand Down Expand Up @@ -502,6 +503,9 @@ type Element struct {
// preceding element.
Spacing string `json:"spacing,omitempty"`

// HorizontalAlignment controls the horizontal text alignment.
HorizontalAlignment string `json:"horizontalAlignment,omitempty"`

// The style of the element for accessibility purposes. Valid values
// differ based on the element type. For example, a TextBlock element
// supports the "heading" style, whereas the Column element supports the
Expand Down Expand Up @@ -584,6 +588,10 @@ type Element struct {
// TextBlock elements.
Wrap bool `json:"wrap,omitempty"`

// IsSubtle specifies whether this element should appear slightly toned
// down.
IsSubtle bool `json:"isSubtle,omitempty"`

// Separator, when true, indicates that a separating line shown should be
// drawn at the top of the element.
Separator bool `json:"separator,omitempty"`
Expand Down Expand Up @@ -1281,6 +1289,7 @@ func (e Element) Validate() error {
supportedWeightValues := supportedWeightValues()
supportedColorValues := supportedColorValues()
supportedSpacingValues := supportedSpacingValues()
supportedHorizontalAlignmentValues := supportedHorizontalAlignmentValues()

// Valid Style field values differ based on type. For example, a Container
// element supports Container styles whereas a TextBlock supports a
Expand All @@ -1297,6 +1306,7 @@ func (e Element) Validate() error {
v.InListIfFieldValNotEmpty(e.Weight, "Weight", "element", supportedWeightValues, ErrInvalidFieldValue)
v.InListIfFieldValNotEmpty(e.Color, "Color", "element", supportedColorValues, ErrInvalidFieldValue)
v.InListIfFieldValNotEmpty(e.Spacing, "Spacing", "element", supportedSpacingValues, ErrInvalidFieldValue)
v.InListIfFieldValNotEmpty(e.HorizontalAlignment, "HorizontalAlignment", "element", supportedHorizontalAlignmentValues, ErrInvalidFieldValue)
v.InListIfFieldValNotEmpty(e.Style, "Style", "element", supportedStyleValues, ErrInvalidFieldValue)

/******************************************************************
Expand Down Expand Up @@ -1443,7 +1453,7 @@ func (tcd TableColumnDefinition) Validate() error {
tcd.HorizontalCellContentAlignment,
"HorizontalCellContentAlignment",
TypeTableColumnDefinition,
supportedHorizontalContentAlignmentValues(),
supportedHorizontalAlignmentValues(),
ErrInvalidFieldValue,
)

Expand Down Expand Up @@ -1534,7 +1544,7 @@ func (tr TableRow) Validate() error {
tr.HorizontalCellContentAlignment,
"HorizontalCellContentAlignment",
TypeTableRow,
supportedHorizontalContentAlignmentValues(),
supportedHorizontalAlignmentValues(),
ErrInvalidFieldValue,
)

Expand Down
5 changes: 3 additions & 2 deletions adaptivecard/getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ func supportedSpacingValues() []string {
}

// supportedHorizontalAlignmentValues returns a list of valid horizontal
// content alignment values for supported container types. This list is
// alignment values for supported container and text types. This list is
// intended to be used for validation and display purposes.
func supportedHorizontalContentAlignmentValues() []string {
func supportedHorizontalAlignmentValues() []string {
// https://adaptivecards.io/explorer/Table.html
// https://adaptivecards.io/explorer/TextBlock.html
// https://adaptivecards.io/schemas/adaptive-card.json
return []string{
HorizontalAlignmentLeft,
Expand Down

0 comments on commit 84950e7

Please sign in to comment.