Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button control #4265

Merged
merged 4 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/python/packages/flet/src/flet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
FilterQuality,
ShadowBlurStyle,
)
from flet.core.button import Button
from flet.core.buttons import (
BeveledRectangleBorder,
ButtonStyle,
Expand Down
25 changes: 25 additions & 0 deletions sdk/python/packages/flet/src/flet/core/button.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from flet.core.elevated_button import ElevatedButton


class Button(ElevatedButton):
"""
Elevated buttons or Buttons are essentially filled tonal buttons with a shadow. To prevent shadow creep, only use them when absolutely necessary, such as when the button requires visual separation from a patterned background.

Example:
```
import flet as ft

def main(page: ft.Page):
page.title = "Basic buttons"
page.add(
ft.Button(text="Button"),
ft.Button("Disabled button", disabled=True),
)

ft.app(target=main)
```

-----

Online docs: https://flet.dev/docs/controls/elevatedbutton
"""
77 changes: 0 additions & 77 deletions sdk/python/packages/flet/src/flet/core/filled_button.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
from typing import Any, Optional, Union

from flet.core.badge import BadgeValue
from flet.core.buttons import ButtonStyle
from flet.core.control import Control, OptionalNumber
from flet.core.elevated_button import ElevatedButton
from flet.core.ref import Ref
from flet.core.tooltip import TooltipValue
from flet.core.types import ColorValue, IconValue, ResponsiveNumber, UrlTarget


class FilledButton(ElevatedButton):
Expand Down Expand Up @@ -34,74 +26,5 @@ def main(page: ft.Page):
Online docs: https://flet.dev/docs/controls/filledbutton
"""

def __init__(
self,
text: Optional[str] = None,
adaptive: Optional[bool] = None,
color: Optional[ColorValue] = None,
bgcolor: Optional[ColorValue] = None,
elevation: OptionalNumber = None,
icon: Optional[IconValue] = None,
icon_color: Optional[ColorValue] = None,
style: Optional[ButtonStyle] = None,
content: Optional[Control] = None,
autofocus: Optional[bool] = None,
url: Optional[str] = None,
url_target: Optional[UrlTarget] = None,
on_click=None,
on_long_press=None,
on_hover=None,
#
# Control and AdaptiveControl
#
ref: Optional[Ref] = None,
key: Optional[str] = None,
width: OptionalNumber = None,
height: OptionalNumber = None,
expand: Union[None, bool, int] = None,
expand_loose: Optional[bool] = None,
col: Optional[ResponsiveNumber] = None,
opacity: OptionalNumber = None,
tooltip: TooltipValue = None,
badge: Optional[BadgeValue] = None,
visible: Optional[bool] = None,
disabled: Optional[bool] = None,
data: Any = None,
):
ElevatedButton.__init__(
self,
ref=ref,
key=key,
width=width,
height=height,
expand=expand,
expand_loose=expand_loose,
col=col,
opacity=opacity,
tooltip=tooltip,
badge=badge,
visible=visible,
disabled=disabled,
data=data,
#
# Specific
#
color=color,
bgcolor=bgcolor,
elevation=elevation,
style=style,
text=text,
icon=icon,
icon_color=icon_color,
content=content,
autofocus=autofocus,
url=url,
url_target=url_target,
on_click=on_click,
on_long_press=on_long_press,
on_hover=on_hover,
adaptive=adaptive,
)

def _get_control_name(self):
return "filledbutton"
77 changes: 0 additions & 77 deletions sdk/python/packages/flet/src/flet/core/filled_tonal_button.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
from typing import Any, Optional, Union

from flet.core.badge import BadgeValue
from flet.core.buttons import ButtonStyle
from flet.core.control import Control, OptionalNumber
from flet.core.elevated_button import ElevatedButton
from flet.core.ref import Ref
from flet.core.tooltip import TooltipValue
from flet.core.types import ColorValue, IconValue, ResponsiveNumber, UrlTarget


class FilledTonalButton(ElevatedButton):
Expand Down Expand Up @@ -34,74 +26,5 @@ def main(page: ft.Page):
Online docs: https://flet.dev/docs/controls/filledtonalbutton
"""

def __init__(
self,
text: Optional[str] = None,
color: Optional[ColorValue] = None,
bgcolor: Optional[ColorValue] = None,
elevation: OptionalNumber = None,
icon: Optional[IconValue] = None,
icon_color: Optional[ColorValue] = None,
style: Optional[ButtonStyle] = None,
content: Optional[Control] = None,
autofocus: Optional[bool] = None,
url: Optional[str] = None,
url_target: Optional[UrlTarget] = None,
on_click=None,
on_long_press=None,
on_hover=None,
#
# Control and AdaptiveControl
#
ref: Optional[Ref] = None,
key: Optional[str] = None,
width: OptionalNumber = None,
height: OptionalNumber = None,
expand: Union[None, bool, int] = None,
expand_loose: Optional[bool] = None,
col: Optional[ResponsiveNumber] = None,
opacity: OptionalNumber = None,
tooltip: TooltipValue = None,
badge: Optional[BadgeValue] = None,
visible: Optional[bool] = None,
disabled: Optional[bool] = None,
data: Any = None,
adaptive: Optional[bool] = None,
):
ElevatedButton.__init__(
self,
ref=ref,
key=key,
width=width,
height=height,
expand=expand,
expand_loose=expand_loose,
col=col,
opacity=opacity,
tooltip=tooltip,
badge=badge,
visible=visible,
disabled=disabled,
data=data,
#
# Specific
#
color=color,
bgcolor=bgcolor,
elevation=elevation,
style=style,
text=text,
icon=icon,
icon_color=icon_color,
content=content,
autofocus=autofocus,
url=url,
url_target=url_target,
on_click=on_click,
on_long_press=on_long_press,
on_hover=on_hover,
adaptive=adaptive,
)

def _get_control_name(self):
return "filledtonalbutton"