Skip to content

Commit c3cacbb

Browse files
Add named styles to buttons (#108)
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
1 parent 5830432 commit c3cacbb

File tree

6 files changed

+16
-2
lines changed

6 files changed

+16
-2
lines changed

demo/components_list.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ class Delivery(BaseModel):
9292
c.Heading(text='Button and Modal', level=2),
9393
c.Paragraph(text='The button below will open a modal with static content.'),
9494
c.Button(text='Show Static Modal', on_click=PageEvent(name='static-modal')),
95+
c.Button(text='Secondary Button', named_style='secondary', class_name='+ ms-2'),
96+
c.Button(text='Warning Button', named_style='warning', class_name='+ ms-2'),
9597
c.Modal(
9698
title='Static Modal',
9799
body=[c.Paragraph(text='This is some static content that was set when the modal was defined.')],

src/npm-fastui-bootstrap/src/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ export const classNameGenerator: ClassNameGenerator = ({
3131
case 'Page':
3232
return 'container mt-80 mb-3 page'
3333
case 'Button':
34-
return 'btn btn-primary'
34+
return {
35+
btn: true,
36+
'btn-primary': !props.namedStyle || props.namedStyle === 'primary',
37+
'btn-secondary': props.namedStyle === 'secondary',
38+
'btn-warning': props.namedStyle === 'warning',
39+
}
3540
case 'Table':
3641
switch (subElement) {
3742
case 'no-data-message':

src/npm-fastui-prebuilt/src/main.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
$primary: black;
2+
$secondary: #666;
23
$link-color: #0d6efd; // bootstrap primary
34

45
@import 'bootstrap/scss/bootstrap';

src/npm-fastui/src/models.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export type JsonData =
5555
[k: string]: JsonData
5656
}
5757
export type AnyEvent = PageEvent | GoToEvent | BackEvent | AuthEvent
58+
export type NamedStyle = 'primary' | 'secondary' | 'warning'
5859
export type DisplayMode =
5960
| 'auto'
6061
| 'plain'
@@ -125,6 +126,7 @@ export interface Button {
125126
text: string
126127
onClick?: AnyEvent
127128
htmlType?: 'button' | 'reset' | 'submit'
129+
namedStyle?: NamedStyle
128130
className?: ClassName
129131
type: 'Button'
130132
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# could be renamed to something general if there's more to add
2-
from typing import Dict, List, Union
2+
from typing import Dict, List, Literal, Union
33

44
from pydantic import Field
55
from typing_extensions import Annotated, TypeAliasType
66

77
ClassName = TypeAliasType('ClassName', Union[str, List['ClassName'], Dict[str, Union[bool, None]], None])
88
ClassNameField = Annotated[ClassName, Field(serialization_alias='className')]
9+
10+
NamedStyle = TypeAliasType('NamedStyle', Union[Literal['primary', 'secondary', 'warning'], None])
11+
NamedStyleField = Annotated[NamedStyle, Field(serialization_alias='namedStyle')]

src/python-fastui/fastui/components/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class Button(_p.BaseModel, extra='forbid'):
153153
html_type: _t.Union[_t.Literal['button', 'reset', 'submit'], None] = _p.Field(
154154
default=None, serialization_alias='htmlType'
155155
)
156+
named_style: _class_name.NamedStyleField = None
156157
class_name: _class_name.ClassNameField = None
157158
type: _t.Literal['Button'] = 'Button'
158159

0 commit comments

Comments
 (0)