Skip to content

Commit

Permalink
add button type support
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoala committed Feb 17, 2022
1 parent 7662a5e commit 8b71f90
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
33 changes: 31 additions & 2 deletions src/PureModalAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
*/
class PureModalAction extends DatalessField
{
/**
* Default classes applied in constructor by the FormField
* @config
* @var array
*/
private static $default_classes = ["btn", "btn-info"];

/**
* @var FieldList
*/
Expand Down Expand Up @@ -51,6 +58,8 @@ public function __construct($name, $title)
$name = 'doCustomAction[' . $name . ']';
$this->title = $title;
$this->name = $name;

parent::__construct($name, $title);
}

/**
Expand Down Expand Up @@ -116,6 +125,27 @@ public function setButtonIcon(string $buttonIcon)
return $this;
}

/**
* Set a new type of btn-something. It will remove any existing btn- class
* @param string $type Leave blank to simply remove default button type
* @return $this
*/
public function setButtonType($type = null)
{
if ($this->extraClasses) {
foreach ($this->extraClasses as $k => $v) {
if (strpos($k, 'btn-') !== false) {
unset($this->extraClasses[$k]);
}
}
}
if ($type) {
$btn = "btn-$type";
$this->extraClasses[$btn] = $btn;
}
return $this;
}

/**
* Get whether it must display the dialog button
*
Expand All @@ -137,8 +167,6 @@ public function setShowDialogButton($value)
return $this;
}



/**
* Get the value of fieldList
* @return FieldList
Expand Down Expand Up @@ -177,6 +205,7 @@ public function getDropUp()

/**
* Set the value of dropUp
* You might want to call also setButtonType(null) for better styles
*
* @see https://github.com/lekoala/silverstripe-cms-actions
* @param bool $is
Expand Down
2 changes: 1 addition & 1 deletion templates/LeKoala/PureModal/PureModalAction.ss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% require css('lekoala/silverstripe-pure-modal: client/pure-modal.css') %>

<label for="$ModalID" class="btn btn-info">
<label for="$ModalID" class="<% if $extraClass %> $extraClass<% end_if %>">
$ButtonTitle.RAW
</label>
<div class="pure-modal from-top">
Expand Down

0 comments on commit 8b71f90

Please sign in to comment.