Skip to content

Commit 9567e4d

Browse files
committed
document themeing
1 parent 1f4701c commit 9567e4d

File tree

1 file changed

+80
-2
lines changed

1 file changed

+80
-2
lines changed

examples/official-site/colors.sql

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
select 'dynamic' as component, properties FROM example WHERE component = 'shell' LIMIT 1;
1+
set theme = coalesce($theme, 'custom');
2+
3+
select 'dynamic' as component, json_patch(json_extract(properties, '$[0]'), json_object(
4+
'title', $theme || ' SQLPage Colors',
5+
'css', case $theme when 'custom' then '/assets/highlightjs-and-tabler-theme.css' end,
6+
'theme', case $theme when 'default' then 'light' else 'dark' end
7+
)) as properties
8+
FROM example WHERE component = 'shell' LIMIT 1;
29

310
create temporary table if not exists colors as select column1 as color, column2 as hex from (values
411
('blue', '#0054a6'), ('azure', '#4299e1'), ('indigo', '#4263eb'), ('purple', '#ae3ec9'), ('pink', '#d6336c'), ('red', '#d63939'), ('orange', '#f76707'), ('yellow', '#f59f00'), ('lime', '#74b816'), ('green', '#2fb344'), ('teal', '#0ca678'), ('cyan', '#17a2b8'),
@@ -9,6 +16,77 @@ create temporary table if not exists colors as select column1 as color, column2
916
('primary', '#0054a6'), ('secondary', '#49566c'), ('success', '#2fb344'), ('info', '#17a2b8'), ('warning', '#f59f00'), ('danger', '#d63939'), ('light', '#f1f5f9'), ('dark', '#0f172a')
1017
);
1118

19+
select 'tab' as component;
20+
select 'Default theme' as title, '?theme=default' as link, 'Default theme' as description, case $theme when 'default' then 'primary' end as color, $theme = 'default' as disabled;
21+
select 'Custom theme' as title, '?theme=custom' as link, 'Custom theme' as description, case $theme when 'custom' then 'primary' end as color, $theme = 'custom' as disabled;
22+
23+
1224
select 'card' as component, 'Colors' as title;
1325
select color as title, hex as description, color as background_color
14-
from colors;
26+
from colors;
27+
28+
29+
select 'text' as component, '
30+
The colors above are from the [official site custom theme](https://github.com/sqlpage/SQLPage/blob/main/examples/official-site/assets/highlightjs-and-tabler-theme.css).
31+
View [this page with the default theme](?theme=default) to see the colors that are used by default.
32+
' as contents_md where $theme = 'custom';
33+
34+
select 'text' as component, '
35+
### Customization and theming
36+
37+
SQLPage is designed to be easily customizable and themable.
38+
You cannot pass arbitrary color codes to components from your SQL queries,
39+
but you can customize which exact color is associated to each color name.
40+
41+
#### Creating a custom theme
42+
43+
To create a custom theme, you can create a CSS file and use the [shell component](/component.sql?component=shell) to include it.
44+
45+
##### `index.sql`
46+
47+
```sql
48+
select ''shell'' as component, ''custom_theme.css'' as css, ''custom_theme'' as theme;
49+
```
50+
51+
##### `custom_theme.css`
52+
53+
```css
54+
:root,
55+
.layout-boxed[data-bs-theme="custom_theme"] {
56+
color-scheme: light;
57+
58+
/* Base text colors */
59+
--tblr-body-color: #cfd5e6;
60+
--tblr-text-secondary-rgb: 204, 209, 217;
61+
--tblr-secondary-color: #cccccc;
62+
--tblr-muted-color: rgba(191, 191, 191, 0.8);
63+
64+
/* Background colors */
65+
--tblr-body-bg: #0f1426;
66+
--tblr-bg-surface: #111629;
67+
--tblr-bg-surface-secondary: #151a2e;
68+
--tblr-bg-surface-tertiary: #191f33;
69+
70+
/* Primary and secondary colors */
71+
--tblr-primary-rgb: 95, 132, 169;
72+
--tblr-primary: rgb(var(--tblr-primary-rgb));
73+
--tblr-secondary-rgb: 235, 232, 255;
74+
--tblr-secondary: rgb(var(--tblr-secondary-rgb));
75+
76+
/* Border colors */
77+
--tblr-border-color: #151926;
78+
--tblr-border-color-translucent: #404d73b3;
79+
80+
/* Theme colors. All sqlpage colors can be customized in the same way. */
81+
--tblr-blue-rgb: 84, 151, 213; /* To convert between #RRGGBB color codes to decimal RGB values, you can use https://www.rapidtables.com/web/color/RGB_Color.html */
82+
--tblr-blue: rgb(var(--tblr-blue-rgb));
83+
84+
--tblr-red-rgb: 229, 62, 62;
85+
--tblr-red: rgb(var(--tblr-red-rgb));
86+
87+
--tblr-green-rgb: 72, 187, 120;
88+
--tblr-green: rgb(var(--tblr-green-rgb));
89+
}
90+
```
91+
' as contents_md;
92+

0 commit comments

Comments
 (0)