Skip to content

Commit 818ceee

Browse files
authored
Add new button style and bump (#58)
1 parent d9708cb commit 818ceee

File tree

15 files changed

+414
-48
lines changed

15 files changed

+414
-48
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ fail_fast: true
22

33
repos:
44
- repo: https://github.com/astral-sh/ruff-pre-commit
5-
rev: v0.14.13
5+
rev: v0.15.5
66
hooks:
77
- id: ruff-check
88
files: ^reflex_ui/
@@ -11,7 +11,7 @@ repos:
1111
files: ^reflex_ui/
1212

1313
- repo: https://github.com/codespell-project/codespell
14-
rev: v2.4.1
14+
rev: v2.4.2
1515
hooks:
1616
- id: codespell
1717
files: ^reflex_ui/

demo/assets/css/globals.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,14 @@
11041104
0px -24px 12px 0px light-dark(rgba(28, 32, 36, 0.02), rgba(0, 0, 0, 0)),
11051105
0px -8px 8px 0px light-dark(rgba(28, 32, 36, 0.02), rgba(0, 0, 0, 0)),
11061106
0px -2px 6px 0px light-dark(rgba(28, 32, 36, 0.02), rgba(0, 0, 0, 0));
1107+
--shadow-button-bordered:
1108+
0 0 0 1px var(--primary-9) inset,
1109+
0 2px 0 0 rgba(255, 255, 255, 0.22) inset;
1110+
--shadow-button-outline:
1111+
0 -1px 0 0 light-dark(rgba(0, 0, 0, 0.08), rgba(0, 0, 0, 0)) inset,
1112+
0 0 0 1px light-dark(rgba(0, 0, 0, 0.08), rgba(0, 0, 0, 0)) inset,
1113+
0 1px 2px 0 light-dark(rgba(0, 0, 0, 0.02), rgba(0, 0, 0, 0)),
1114+
0 1px 4px 0 light-dark(rgba(0, 0, 0, 0.02), rgba(0, 0, 0, 0));
11071115
/* Radius */
11081116
--radius-ui-xxs: calc(var(--radius) - 0.25rem);
11091117
--radius-ui-xs: calc(var(--radius) - 0.125rem);

reflex_ui/blocks/demo_form.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from reflex.vars.base import get_unique_variable_name
1212

1313
import reflex_ui as ui
14-
from reflex_ui.components.base.button import BUTTON_VARIANTS, DEFAULT_CLASS_NAME
1514

1615
demo_form_error_message = ClientStateVar.create("demo_form_error_message", "")
1716
demo_form_open_cs = ClientStateVar.create("demo_form_open", False)
@@ -226,9 +225,7 @@ def select_field(
226225
required=required,
227226
class_name=ui.cn(
228227
"w-full appearance-none pr-9",
229-
DEFAULT_CLASS_NAME,
230-
BUTTON_VARIANTS["variant"]["outline"],
231-
BUTTON_VARIANTS["size"]["md"],
228+
ui.button.class_names.for_button("outline", "md"),
232229
"outline-primary-6 focus:border-primary-6",
233230
),
234231
),

reflex_ui/blocks/intro_form.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from reflex.vars.base import get_unique_variable_name
1212

1313
import reflex_ui as ui
14-
from reflex_ui.components.base.button import BUTTON_VARIANTS, DEFAULT_CLASS_NAME
1514

1615
intro_form_error_message = ClientStateVar.create("intro_form_error_message", "")
1716
intro_form_open_cs = ClientStateVar.create("intro_form_open", False)
@@ -227,9 +226,7 @@ def select_field(
227226
required=required,
228227
class_name=ui.cn(
229228
"w-full appearance-none pr-9",
230-
DEFAULT_CLASS_NAME,
231-
BUTTON_VARIANTS["variant"]["outline"],
232-
BUTTON_VARIANTS["size"]["md"],
229+
ui.button.class_names.for_button("outline", "md"),
233230
"outline-primary-6 focus:border-primary-6",
234231
),
235232
),

reflex_ui/components/base/button.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from typing import Literal
44

5+
from reflex.components.component import ComponentNamespace
56
from reflex.components.core.cond import cond
67
from reflex.components.el import Button as BaseButton
78
from reflex.vars.base import Var
@@ -10,7 +11,15 @@
1011
from reflex_ui.components.icons.others import spinner
1112

1213
LiteralButtonVariant = Literal[
13-
"primary", "destructive", "outline", "secondary", "ghost", "link", "dark"
14+
"primary",
15+
"primary-bordered",
16+
"destructive",
17+
"outline",
18+
"outline-shadow",
19+
"secondary",
20+
"ghost",
21+
"link",
22+
"dark",
1423
]
1524
LiteralButtonSize = Literal[
1625
"xs", "sm", "md", "lg", "xl", "icon-xs", "icon-sm", "icon-md", "icon-lg", "icon-xl"
@@ -21,8 +30,10 @@
2130
BUTTON_VARIANTS = {
2231
"variant": {
2332
"primary": "bg-primary-9 text-primary-contrast hover:bg-primary-10",
33+
"primary-bordered": "bg-primary-9 text-primary-contrast hover:bg-primary-10 shadow-button-bordered disabled:shadow-none",
2434
"destructive": "bg-destructive-9 hover:bg-destructive-10 text-primary-contrast",
2535
"outline": "border border-secondary-a4 bg-secondary-1 hover:bg-secondary-3 text-secondary-12",
36+
"outline-shadow": "dark:border dark:border-secondary-a4 bg-white dark:bg-secondary-1 hover:bg-secondary-3 text-secondary-12 shadow-button-outline disabled:shadow-none",
2637
"secondary": "bg-secondary-4 text-secondary-12 hover:bg-secondary-5",
2738
"ghost": "hover:bg-secondary-3 text-secondary-11",
2839
"link": "text-secondary-12 underline-offset-4 hover:underline",
@@ -43,6 +54,18 @@
4354
}
4455

4556

57+
class ClassNames:
58+
"""Class names for button components."""
59+
60+
DEFAULT = DEFAULT_CLASS_NAME
61+
VARIANTS = BUTTON_VARIANTS
62+
63+
@staticmethod
64+
def for_button(variant: str = "primary", size: str = "md") -> str:
65+
"""Return combined class string for the given variant and size."""
66+
return f"{ClassNames.DEFAULT} {ClassNames.VARIANTS['variant'][variant]} {ClassNames.VARIANTS['size'][size]}"
67+
68+
4669
class Button(BaseButton, CoreComponent):
4770
"""A custom button component."""
4871

@@ -109,4 +132,12 @@ def _exclude_props(self) -> list[str]:
109132
]
110133

111134

112-
button = Button.create
135+
class ButtonNamespace(ComponentNamespace):
136+
"""Namespace for Button components."""
137+
138+
create = staticmethod(Button.create)
139+
class_names = ClassNames
140+
__call__ = staticmethod(Button.create)
141+
142+
143+
button = ButtonNamespace()

0 commit comments

Comments
 (0)