From e3fa3e327873df08cf39e982f4627ceb9aa8e0d5 Mon Sep 17 00:00:00 2001 From: michael Date: Sun, 30 Aug 2020 08:18:37 +0000 Subject: [PATCH] * Small fix for bootstrap toast, add button --- packages/bootstrap/bootstrapwidgets.pp | 67 +++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/packages/bootstrap/bootstrapwidgets.pp b/packages/bootstrap/bootstrapwidgets.pp index 7d8366c..7e75927 100644 --- a/packages/bootstrap/bootstrapwidgets.pp +++ b/packages/bootstrap/bootstrapwidgets.pp @@ -20,7 +20,7 @@ unit bootstrapwidgets; interface uses - Classes, SysUtils, js, libjquery, libbootstrap, web, webwidget; + Classes, SysUtils, js, libjquery, libbootstrap, web, webwidget, htmlwidgets; Type @@ -110,6 +110,23 @@ Type Property ToastIcon : String Read FToastIcon Write FToastIcon; end; + { TBootstrapButton } + + TBootstrapButton = class (TButtonWidget) + private + FContextual: TContextual; + FOutLine: Boolean; + procedure SetContextual(AValue: TContextual); + procedure SetOutLine(AValue: Boolean); + Protected + Function RecalcClasses(aOldContextual : TContextual; aOldOutline : Boolean) : String; + Public + Constructor Create(aOwner : TComponent); override; + Published + Property Contextual : TContextual Read FContextual Write SetContextual default cPrimary; + Property Outline : Boolean Read FOutLine Write SetOutLine; + end; + Const ContextualNames : Array[TContextual] of string = ('','primary','secondary','success','danger','warning','info','light','dark'); @@ -122,6 +139,52 @@ begin Result:=TToastManager.Instance; end; +{ TBootstrapButton } + +procedure TBootstrapButton.SetContextual(AValue: TContextual); + +Var + Old : TContextual; + +begin + if FContextual=AValue then Exit; + old:=FContextual; + FContextual:=AValue; + RecalcClasses(Old,FOutline); +end; + +procedure TBootstrapButton.SetOutLine(AValue: Boolean); + +Var + Old : Boolean; + +begin + if FOutLine=AValue then Exit; + old:=FoutLine; + FOutLine:=AValue; + RecalcClasses(FContextual,Old); +end; + +function TBootstrapButton.RecalcClasses(aOldContextual: TContextual; aOldOutline: Boolean): String; + +Const + OL : Array[Boolean] of string = ('','outline-'); +Var + c : String; + +begin + Result:='btn btn-'+OL[FOutLine]+ContextualNames[FContextual]; + C:=RemoveClasses(Classes,'btn-'+OL[aOldOutLine]+ContextualNames[aOldContextual]); + Classes:=AddClasses(C,Result); +end; + +constructor TBootstrapButton.Create(aOwner: TComponent); +begin + inherited Create(aOwner); + Contextual:=cPrimary; +end; + + { TToastManager } class function TToastManager.Instance: TToastManager; @@ -259,7 +322,7 @@ begin Result:=Result+''; Result:=Result+'
'+Header+'
'; if (SmallHeader<>'') then - Result:=Result+''+SmallHeader+''; + Result:=Result+''+SmallHeader+''; if CloseButton then Result:=Result+CloseButtonHTML; Result:=Result+'';