22Helper for Bootstrap 4.3
33"""
44
5- from templater import (
5+ from pyplate import (
66 html ,
77 head ,
88 meta ,
1515 blockquote ,
1616 footer ,
1717)
18- from templater .utils import classing
18+ from pyplate .utils import classing
1919
2020
2121RESPONSIVE_BP = ["xs" , "sm" , "md" , "lg" , "xl" ]
@@ -86,7 +86,7 @@ def container(breakpoint="", **kwargs):
8686 """
8787
8888 if breakpoint :
89- if breakpoint in RESPONSIVE_BP + "fluid" :
89+ if breakpoint in RESPONSIVE_BP + [ "fluid" ] :
9090 breakpoint = "-" + breakpoint
9191 else :
9292 print (f'Breakpoint should be one of { RESPONSIVE_BP } or "fluid' )
@@ -161,9 +161,9 @@ def lead(*args, **kwargs):
161161 return div (_class = c , ** kwargs )(* args )
162162
163163
164- def quote (author = '' , ** kwargs ):
164+ def quote (author = "" , ** kwargs ):
165165 class b (blockquote ):
166- TAG_NAME = ' blockquote'
166+ TAG_NAME = " blockquote"
167167
168168 def __call__ (self , * args ):
169169 firstChild = self .content [0 ](* args )
@@ -174,6 +174,45 @@ def __call__(self, *args):
174174 c = classing ("blockquote" , * c )
175175
176176 return b (_class = c , ** kwargs )(
177- p (_class = "mb-0" ),
178- footer (_class = "blockquote-footer" )(author )
177+ p (_class = "mb-0" ), footer (_class = "blockquote-footer" )(author )
179178 )
179+
180+
181+ # components
182+
183+
184+ def btn (color = "primary" , ** kwargs ):
185+ tag = kwargs .pop ("tag" , button )
186+ outline = kwargs .pop ("outline" , False )
187+ size = kwargs .pop ("size" , "" )
188+ block = kwargs .pop ("block" , False )
189+
190+ if tag == a :
191+ kwargs ['role' ] = kwargs .pop ('role' , 'button' )
192+ kwargs ['href' ] = kwargs .pop ('href' , '#' )
193+ else :
194+ kwargs ['type' ] = kwargs .pop ('type' , 'button' )
195+
196+ if color :
197+ if color in COLOR_BP + ["link" ]:
198+ color = "btn-outline-" + color if outline else "btn-" + color
199+ else :
200+ print (f'Color should be one of { COLOR_BP } or "link' )
201+ color = ""
202+
203+ if size :
204+ if size in ('sm' , 'lg' ):
205+ size = "btn-" + size
206+ else :
207+ print (f'Size should be one of ["sm", "lg"]' )
208+ size = ""
209+
210+ if block :
211+ block = "btn-block"
212+ else :
213+ block = ""
214+
215+ c = kwargs .pop ("_class" , [])
216+ c = classing ("btn" , color , size , block , * c )
217+
218+ return tag (_class = c , ** kwargs )
0 commit comments