Skip to content

Commit

Permalink
Fixes #1453 (#1483)
Browse files Browse the repository at this point in the history
  • Loading branch information
BoSen29 authored and adamdriscoll committed Jan 26, 2020
1 parent 6c0553b commit 7b2d707
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 10 deletions.
12 changes: 3 additions & 9 deletions src/UniversalDashboard.Materialize/Components/ud-button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ export default class UDButton extends React.Component {
super(props);

this.state = {
backgroundColor: this.props.backgroundColor,
fontColor: this.props.fontColor,
floating: this.props.floating,
flat: this.props.flat,
icon: this.props.icon,
text: this.props.text,
disabled: this.props.disabled,
hidden: this.props.hidden
hidden: this.props.hidden,
style: this.props.style
}
}

Expand Down Expand Up @@ -64,11 +63,6 @@ export default class UDButton extends React.Component {
return null;
}

var style = {
backgroundColor: this.state.backgroundColor,
color: this.state.fontColor
}

var icon = null;
if (this.state.icon) {
icon = <UdIcon icon={this.state.icon} style={{marginRight: this.state.floating || !this.state.text ? 'unset' : '5px'}}/>
Expand All @@ -81,7 +75,7 @@ export default class UDButton extends React.Component {
flat={this.state.flat}
disabled={this.state.disabled}
floating={this.state.floating}
style={style}
style={this.state.style}
>
{icon}
{this.state.text}
Expand Down
36 changes: 35 additions & 1 deletion src/UniversalDashboard.Materialize/Scripts/button.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ function New-UDButton {
[Parameter()]
[UniversalDashboard.Models.DashboardColor]$FontColor,
[Parameter()]
[Switch]$Disabled
[Switch]$Disabled,
[Parameter()]
[Hashtable]$Style,
[Parameter()]
[string]
$Height,
[Parameter()]
[string]
$Width
)

if ($null -ne $OnClick) {
Expand All @@ -32,6 +40,31 @@ function New-UDButton {
}
}

if ((!($Style.BackgroundColor)) -and ($BackgroundColor)) {
$Style += @{BackgroundColor = $BackgroundColor.HtmlColor}
}
if ((!($Style.Color)) -and ($FontColor)) {
$Style += @{Color = $FontColor.HtmlColor}
}
if ((!($Style.Width)) -and ($Width)) {
#check if the width is numerical, to append with "px" or if it is string, and not to be appended
if ($Width -match "^[\d\.]+$") {
$Style += @{Width = "$($Width)px"}
}
else {
$Style += @{Width = $Width}
}
}
if ((!($Style.Heigth)) -and ($Height)) {
#check if the width is numerical, to append with "px" or if it is string, and not to be appended
if ($Height -match "^[\d\.]+$") {
$Style += @{Height = "$($Height)px"}
}
else {
$Style += @{Height = $Height}
}
}

if ($PSBoundParameters.ContainsKey("Icon")) {
$IconName = [UniversalDashboard.Models.FontAwesomeIconsExtensions]::GetIconName($Icon)
}
Expand All @@ -50,5 +83,6 @@ function New-UDButton {
text = $Text
backgroundColor = $BackgroundColor.HtmlColor
fontColor = $FontColor.HtmlColor
style = $Style
}
}
63 changes: 63 additions & 0 deletions src/UniversalDashboard/Help/New-UDButton.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ New-UDButton -Text "Button" -OnClick {

Creats a button that shows a toast message when clicked.

### Button sizes
````
New-UDButton -Text "Big" -Height 300 -Width "100"
````

Creates a button with height of 300px and 100% width.
Note: the "px" will be appended automatically if not specified.

### Custom styles
````
New-UDButton -Text "Custom" -Style @{
Font-Size = 36 px
Height = 300 px
}
````

Creates a button, with font-size 36 and height of 300 pixels. Will be prioritized over the -height param.

## PARAMETERS

### -BackgroundColor
Expand Down Expand Up @@ -206,6 +224,51 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -Height
Sets the height, either by pixel or percentage.
```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Width
Sets the width, either by pixel or percentage.
```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Style
Sets the style of the button, will be prioritized over the other stylespecific parameters, ie -height.
```yaml
Type: Hashtable
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Text
The test to display on the button.
Expand Down

0 comments on commit 7b2d707

Please sign in to comment.