Skip to content

Cusom Themes support in ThemePicker #71

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

Merged
merged 2 commits into from
Feb 19, 2025
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
9 changes: 9 additions & 0 deletions docs/api_reference/api_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,18 @@ def ex_theme_switcher():
H3("Theme Picker", id='theme'),
fn2code_string(ex_theme_switcher),
ThemePicker,
H3("Custom Themes"),
render_md("""
1. You can use [this theme](https://github.com/AnswerDotAI/MonsterUI/blob/main/docs/custom_theme.css) as a starting point.
2. Add the theme to your headers as a link like this `Link(rel="stylesheet", href="/custom_theme.css", type="text/css")`
3. Then add the theme to the `ThemePicker` component. For example `ThemePicker(custom_themes=[('Grass', '#10b981')])`
"""),
"Themes are controlled with `bg-background text-foreground` classes on the `Body` tag. `fast_app` and `FastHTML` will do this for you automatically so you typically do not have to do anything",
fast_app,
FastHTML,

Blockquote(P("Users have said", A("this site", href="https://ui.jln.dev/"), " is helpful in creating your own themes.")),

title="Headers")

# Typography
Expand Down
56 changes: 56 additions & 0 deletions docs/custom_theme.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* custom_theme.css */

.uk-theme-grass {
--background: 78 47% 99%;
--foreground: 78 51% 0%;
--muted: 78 12% 85%;
--muted-foreground: 78 8% 38%;
--popover: 78 47% 99%;
--popover-foreground: 78 51% 0%;
--card: 78 47% 99%;
--card-foreground: 78 51% 0%;
--border: 78 2% 93%;
--input: 78 2% 93%;
--primary: 78 28% 60%;
--primary-foreground: 0 0% 0%;
--secondary: 78 8% 81%;
--secondary-foreground: 78 8% 21%;
--accent: 78 8% 81%;
--accent-foreground: 78 8% 21%;
--destructive: 17 86% 32%;
--destructive-foreground: 17 86% 92%;
--ring: 78 28% 60%;
--chart-1: 78 28% 60%;
--chart-2: 78 8% 81%;
--chart-3: 78 8% 81%;
--chart-4: 78 8% 84%;
--chart-5: 78 31% 60%;
--radius: 0.5rem;
}

.dark.uk-theme-grass {
--background: 78 48% 2%;
--foreground: 78 24% 99%;
--muted: 78 12% 15%;
--muted-foreground: 78 8% 62%;
--popover: 78 48% 2%;
--popover-foreground: 78 24% 99%;
--card: 78 48% 2%;
--card-foreground: 78 24% 99%;
--border: 78 2% 14%;
--input: 78 2% 14%;
--primary: 78 28% 60%;
--primary-foreground: 0 0% 0%;
--secondary: 78 8% 14%;
--secondary-foreground: 78 8% 74%;
--accent: 78 8% 14%;
--accent-foreground: 78 8% 74%;
--destructive: 17 86% 60%;
--destructive-foreground: 17 86% 0%;
--ring: 78 28% 60%;
--chart-1: 78 28% 60%;
--chart-2: 78 8% 14%;
--chart-3: 78 8% 14%;
--chart-4: 78 8% 17%;
--chart-5: 78 31% 60%;
}
8 changes: 6 additions & 2 deletions docs/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ def _not_found(req, exc):
req,
None)

app,rt = fast_app(exception_handlers={404:_not_found}, pico=False, hdrs=(*Theme.blue.headers(highlightjs=True), Link(rel="icon", type="image/x-icon", href="/favicon.ico")), live=True)

app,rt = fast_app(exception_handlers={404:_not_found}, pico=False,
hdrs=(*Theme.blue.headers(highlightjs=True), Link(rel="icon", type="image/x-icon", href="/favicon.ico"),
Link(rel="stylesheet", href="/custom_theme.css", type="text/css")),
live=True)

def is_htmx(request=None):
"Check if the request is an HTMX request"
Expand Down Expand Up @@ -157,7 +161,7 @@ def tutorial_layout(o:str='', request=None):

@rt
def theme_switcher(request):
return _create_page(Div(ThemePicker(),cls="p-12"), request, None)
return _create_page(Div(ThemePicker(custom_themes=[("Grass", "#10b981")]),cls="p-12"), request, None)

###
# Build the Getting Started Pages
Expand Down
4 changes: 2 additions & 2 deletions monsterui/franken.py
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,7 @@ def render_md(md_content:str, # Markdown content
return NotStr(apply_classes(html_content, class_map, class_map_mods))

# %% ../nbs/02_franken.ipynb
def ThemePicker(color=True, radii=True, shadows=True, font=True, mode=True, cls='p-4'):
def ThemePicker(color=True, radii=True, shadows=True, font=True, mode=True, cls='p-4', custom_themes=[]):
"Theme picker component with configurable sections"
def _opt(val, txt, **kwargs): return Option(txt, value=val, **kwargs)
def _optgrp(key, lbl, opts): return fh.Optgroup(data_key=key, label=lbl)(*opts)
Expand All @@ -1506,7 +1506,7 @@ def _optgrp(key, lbl, opts): return fh.Optgroup(data_key=key, label=lbl)(*opts)
[('Slate','#64748b'),('Stone','#78716c'),('Gray','#6b7280'),
('Neutral','#737373'),('Red','#dc2626'),('Rose','#e11d48'),
('Orange','#f97316'),('Green','#16a34a'),('Blue','#2563eb'),
('Yellow','#facc15'),('Violet','#7c3aed')]]]))
('Yellow','#facc15'),('Violet','#7c3aed'),*custom_themes]]]))
if radii: groups.append(_optgrp('radii', 'Radii', [
_opt('uk-radii-none','None'), _opt('uk-radii-sm','Small'),
_opt('uk-radii-md','Medium',selected=True), _opt('uk-radii-lg','Large')]))
Expand Down
4 changes: 2 additions & 2 deletions nbs/02_franken.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3098,7 +3098,7 @@
"outputs": [],
"source": [
"#| export\n",
"def ThemePicker(color=True, radii=True, shadows=True, font=True, mode=True, cls='p-4'):\n",
"def ThemePicker(color=True, radii=True, shadows=True, font=True, mode=True, cls='p-4', custom_themes=[]):\n",
" \"Theme picker component with configurable sections\"\n",
" def _opt(val, txt, **kwargs): return Option(txt, value=val, **kwargs)\n",
" def _optgrp(key, lbl, opts): return fh.Optgroup(data_key=key, label=lbl)(*opts)\n",
Expand All @@ -3110,7 +3110,7 @@
" [('Slate','#64748b'),('Stone','#78716c'),('Gray','#6b7280'),\n",
" ('Neutral','#737373'),('Red','#dc2626'),('Rose','#e11d48'),\n",
" ('Orange','#f97316'),('Green','#16a34a'),('Blue','#2563eb'),\n",
" ('Yellow','#facc15'),('Violet','#7c3aed')]]]))\n",
" ('Yellow','#facc15'),('Violet','#7c3aed'),*custom_themes]]]))\n",
" if radii: groups.append(_optgrp('radii', 'Radii', [\n",
" _opt('uk-radii-none','None'), _opt('uk-radii-sm','Small'),\n",
" _opt('uk-radii-md','Medium',selected=True), _opt('uk-radii-lg','Large')]))\n",
Expand Down