|
12 | 12 | from ._theme import Theme |
13 | 13 | from ._theme_presets import ShinyThemePreset, shiny_theme_presets |
14 | 14 |
|
15 | | -color_extras_map = { |
16 | | - "foreground": ["body-color", "pre-color", "black"], |
17 | | - "background": ["body-bg", "white"], |
18 | | - "secondary": ["body-secondary-color", "body-secondary"], |
| 15 | +color_map = { |
| 16 | + "foreground": ["brand--foreground", "body-color", "pre-color"], |
| 17 | + "background": ["brand--background", "body-bg"], |
| 18 | + "primary": ["primary"], |
| 19 | + "secondary": ["secondary", "body-secondary-color", "body-secondary"], |
19 | 20 | "tertiary": ["body-tertiary-color", "body-tertiary"], |
| 21 | + "success": ["success"], |
| 22 | + "info": ["info"], |
| 23 | + "warning": ["warning"], |
| 24 | + "danger": ["danger"], |
| 25 | + "light": ["light"], |
| 26 | + "dark": ["dark"], |
20 | 27 | } |
21 | 28 | """Maps brand.color fields to Bootstrap Sass variables""" |
22 | 29 |
|
@@ -164,30 +171,20 @@ def __init__( |
164 | 171 | # brand.color ----------------------------------------------------------------- |
165 | 172 | sass_vars_colors: dict[str, str] = {} |
166 | 173 | if brand.color: |
167 | | - # Map values in colors directly to their Sass variable counterparts |
168 | | - sass_vars_colors: dict[str, str] = { |
169 | | - k: v |
170 | | - for k, v in brand.color.model_dump(exclude_none=True).items() |
171 | | - if k not in ("palette", "foreground", "background") |
172 | | - } |
| 174 | + # Map values in colors to their Sass variable counterparts |
| 175 | + for field, theme_color in brand.color.to_dict(include="theme").items(): |
| 176 | + if field not in color_map: |
| 177 | + print(f"skipping color.{field} not mapped") |
| 178 | + continue |
| 179 | + |
| 180 | + for sass_var in color_map[field]: |
| 181 | + sass_vars_colors[sass_var] = theme_color |
173 | 182 |
|
174 | | - # Map values in colors to any additional Sass variables |
175 | | - for extra, sass_var_list in color_extras_map.items(): |
176 | | - if extra in sass_vars_colors: |
177 | | - sass_vars_colors_extras = { |
178 | | - var: sass_vars_colors[extra] for var in sass_var_list |
179 | | - } |
180 | | - sass_vars_colors = {**sass_vars_colors, **sass_vars_colors_extras} |
181 | | - |
182 | | - if brand.color.palette: |
183 | | - # Map the brand color palette to Bootstrap's named colors, e.g. $red, $blue. |
184 | | - # Note that we use ._color_defs() to ensure the palette is fully resolved. |
185 | | - brand_color_palette = brand.color._color_defs(resolved=True) |
186 | | - for bs_color_var in bootstrap_colors[brand_bootstrap.version]: |
187 | | - if bs_color_var in brand_color_palette: |
188 | | - sass_vars_colors[bs_color_var] = brand_color_palette[ |
189 | | - bs_color_var |
190 | | - ] |
| 183 | + # Map the brand color palette to Bootstrap's named colors, e.g. $red, $blue. |
| 184 | + bs_color_vars = bootstrap_colors[brand_bootstrap.version] |
| 185 | + for field, palette_color in brand.color.to_dict(include="palette").items(): |
| 186 | + if field in bs_color_vars: |
| 187 | + sass_vars_colors[field] = palette_color |
191 | 188 |
|
192 | 189 | # brand.typography ------------------------------------------------------------ |
193 | 190 | sass_vars_typography: dict[str, str] = {} |
|
0 commit comments