Skip to content

Commit cf3ce17

Browse files
committed
Add named styles to buttons
1 parent 6b7c7cb commit cf3ce17

File tree

5 files changed

+14
-1
lines changed

5 files changed

+14
-1
lines changed

demo/components_list.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class Delivery(BaseModel):
8888
c.Heading(text='Button and Modal', level=2),
8989
c.Paragraph(text='The button below will open a modal with static content.'),
9090
c.Button(text='Show Static Modal', on_click=PageEvent(name='static-modal')),
91+
c.Button(text='Secondary Button', mode='secondary', class_name='+ ms-2'),
92+
c.Button(text='Warning Button', mode='warning', class_name='+ ms-2'),
9193
c.Modal(
9294
title='Static Modal',
9395
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
@@ -24,7 +24,12 @@ export const classNameGenerator: ClassNameGenerator = ({ props, fullPath, subEle
2424
case 'Page':
2525
return 'container mt-80'
2626
case 'Button':
27-
return 'btn btn-primary'
27+
return {
28+
btn: true,
29+
'btn-primary': !props.mode || props.mode === 'primary',
30+
'btn-secondary': props.mode === 'secondary',
31+
'btn-warning': props.mode === 'warning',
32+
}
2833
case 'Table':
2934
switch (subElement) {
3035
case 'no-data-message':

src/npm-fastui/src/components/button.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface ButtonProps {
77
type: 'Button'
88
text: string
99
onClick?: AnyEvent
10+
mode?: 'primary' | 'secondary' | 'warning'
1011
htmlType?: 'button' | 'submit' | 'reset'
1112
className?: ClassName
1213
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ class Button(_p.BaseModel, extra='forbid'):
141141
default=None, serialization_alias='htmlType'
142142
)
143143
class_name: _class_name.ClassNameField = None
144+
mode: _t.Union[_t.Literal['primary', 'secondary', 'warning'], None] = None
144145
type: _t.Literal['Button'] = 'Button'
145146

146147

src/python-fastui/tests/react-fastui-json-schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
"enum": ["button", "reset", "submit"],
6262
"type": "string"
6363
},
64+
"mode": {
65+
"enum": ["primary", "secondary", "warning"],
66+
"type": "string"
67+
},
6468
"onClick": {
6569
"anyOf": [
6670
{

0 commit comments

Comments
 (0)