Skip to content

Commit 9567fd6

Browse files
committed
feat(list): allow lists to be themeable
1 parent ffa50da commit 9567fd6

10 files changed

Lines changed: 135 additions & 19 deletions

File tree

dist/css/component.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/css/component/list.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/css/graupl.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/css/layout.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/dist/css/component.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/dist/css/component/list.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/dist/css/graupl.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/dist/css/layout.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/src/scss/component/list/_defaults.scss

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,42 @@
77
// Those should be defined as custom properties in the `_variables.scss` file.
88

99
@use "../../defaults" as root-defaults;
10+
@use "../../functions/theme";
11+
@use "sass:map";
1012

1113
// Card selectors.
1214
$selector-base: root-defaults.$component-selector-base !default;
1315
$modifier-selector-base: root-defaults.$modifier-selector-base !default;
16+
$generate-base-theme-map: root-defaults.$generate-base-theme-maps !default;
17+
$themeable: false !default;
1418
$list-selector-base: $selector-base !default;
1519
$list-selector: "list" !default;
20+
$list-theme-selector-base: $modifier-selector-base !default;
21+
$list-theme-selector-prefix: "" !default;
1622
$list-item-selector-base: $selector-base !default;
1723
$list-item-selector: "list-item" !default;
1824

1925
// List item properties.
2026
$list-item-transform: none !default;
2127
$list-item-hover-transform: $list-item-transform !default;
28+
29+
// List state theme defaults.
30+
// This map defines the default colour shades applied to themed lists.
31+
// All theme variants will only adjust the colour and border colour of the list
32+
// container and items.
33+
$-list-theme-mappings: (
34+
color: 900,
35+
border-color: 700,
36+
item-color: 900,
37+
item-border-color: 700,
38+
);
39+
$list-theme-mappings: () !default;
40+
41+
// Merge the custom list theme map with the default one.
42+
@if $generate-base-theme-map {
43+
$list-theme-mappings: map.merge($-list-theme-mappings, $list-theme-mappings);
44+
}
45+
46+
$-list-theme-map: theme.generate-property-map($list-theme-mappings);
47+
$list-theme-map: () !default;
48+
$list-theme-map: map.deep-merge($-list-theme-map, $list-theme-map);

packages/core/src/scss/component/list/_index.scss

Lines changed: 100 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//
99
// The following custom properties can be used to customize the list component:
1010
// | Property | Description | Default Value |
11-
// | --- | --- | --- |
11+
// | ---------------------------------------------- | ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1212
// | `--graupl-list-padding-x` | Horizontal padding of the list. | `var(--graupl-spacer-0)` |
1313
// | `--graupl-list-padding-y` | Vertical padding of the list. | `var(--graupl-spacer-0)` |
1414
// | `--graupl-list-padding` | Shorthand padding of the list. | `var(--graupl-list-padding-y) var(--graupl-list-padding-x)` |
@@ -35,16 +35,88 @@
3535
// | `--graupl-list-item-border-color` | Border colour of list items. | `var(--graupl-list-item-color)` |
3636
//
3737
// The following sass variables can be used to customize the generation of the list component:
38-
// | Variable | Description | Default Value |
39-
// | --- | --- | --- |
40-
// | `$selector-base` | Selector base for the component. | `"."` |
41-
// | `$modifier-selector-base` | Selector base for component modifiers. | `"."` |
42-
// | `$list-selector-base` | Selector base for the list container. | `$selector-base` |
43-
// | `$list-selector` | Selector for the list container. | `"list"` |
44-
// | `$list-item-selector-base` | Selector base for list items. | `$selector-base` |
45-
// | `$list-item-selector` | Selector for list items. | `"list-item"` |
46-
// | `$list-item-transform` | Base transform for list items. | `none` |
47-
// | `$list-item-hover-transform` | Hover transform for list items. | `none` |
38+
// | Variable | Description | Default Value |
39+
// | ---------------------------- | ----------------------------------------- | ---------------- |
40+
// | `$selector-base` | Selector base for the component. | `"."` |
41+
// | `$modifier-selector-base` | Selector base for component modifiers. | `"."` |
42+
// | `$generate-base-theme-map` | Flag to generate the base theme map. | `true` |
43+
// | `$themeable` | Flag to generate theme modifiers. | `false` |
44+
// | `$list-selector-base` | Selector base for the list container. | `$selector-base` |
45+
// | `$list-selector` | Selector for the list container. | `"list"` |
46+
// | `$list-theme-selector-base` | Selector base for theme modifiers. | `"."` |
47+
// | `$list-theme-selector-prefix`| Selector prefix for theme modifiers. | `""` |
48+
// | `$list-item-selector-base` | Selector base for list items. | `$selector-base` |
49+
// | `$list-item-selector` | Selector for list items. | `"list-item"` |
50+
// | `$list-item-transform` | Base transform for list items. | `none` |
51+
// | `$list-item-hover-transform` | Hover transform for list items. | `none` |
52+
// | `$list-theme-mappings` | Map of properties/shades for list themes. | `()` |
53+
// | `$list-theme-map` | Expanded map of properties/colors/shades. | `()` |
54+
//
55+
// ## Using `$list-theme-mappings`
56+
//
57+
// `$list-theme-mappings` is a 1-level map of properties and shade values.
58+
//
59+
// e.g.
60+
// ```scss
61+
// $list-theme-mappings: (
62+
// color: 900,
63+
// border-color: 700,
64+
// )
65+
// ```
66+
//
67+
// This directly[1] maps to all list variants, telling them what shade to use for the base colour slots.
68+
// All list variants will use the following based on the example above:
69+
// - Primary lists will have their `--graupl-list-color` property set to `--graupl-theme-active--primary--900` and `--graupl-list-border-color` to `--graupl-theme-active--primary--700`,
70+
// - Secondary lists will use the same shades for the secondary palette, and
71+
// - Tertiary lists will use the same shades for the tertiary palette.
72+
//
73+
// You can use this to customize _all_ list variants in the same way.
74+
//
75+
// For example, if you use the following map:
76+
// ```scss
77+
// $list-theme-mappings: (
78+
// color: 500,
79+
// item-color: 500,
80+
// )
81+
// ```
82+
//
83+
// All list variants will use the following:
84+
// - Primary lists will have their `--graupl-list-color` and `--graupl-list-item-color` properties set to `--graupl-theme-active--primary--500`,
85+
// - Secondary lists will have theirs set to `--graupl-theme-active--secondary--500`, and
86+
// - Tertiary lists will have theirs set to `--graupl-theme-active--tertiary--500`.
87+
//
88+
// [1] `$list-theme-mappings` gets parsed into a larger, more explicit map: `$list-theme-map`.
89+
//
90+
// Using `$list-theme-map`
91+
//
92+
// `$list-theme-map` is a multi-level map of properties, colors, and shade values.
93+
//
94+
// e.g.
95+
// ```scss
96+
// $list-theme-map: (
97+
// primary: (
98+
// item-border-color: (
99+
// color: secondary,
100+
// shade: 700
101+
// ),
102+
// ),
103+
// secondary: (
104+
// item-border-color: (
105+
// color: secondary,
106+
// shade: 500
107+
// ),
108+
// ),
109+
// tertiary: (
110+
// item-border-color: (
111+
// color: tertiary,
112+
// shade: 300
113+
// ),
114+
// ),
115+
// )
116+
// ```
117+
//
118+
// This directly maps to all list variants, telling them what shade to use for said property.
119+
// You can use this to customize list variants individually.
48120
//
49121
// @example
50122
// <ul class="list">
@@ -63,6 +135,7 @@
63135
@use "../../defaults" as root-defaults;
64136
@use "../../mixins/animation";
65137
@use "../../mixins/layer" as *;
138+
@use "../../mixins/theme" as theme;
66139
@use "defaults";
67140
@use "sass:map";
68141
@use "variables" as *;
@@ -106,6 +179,22 @@
106179
border-color: $list-border-color;
107180
background: $list-background;
108181
color: $list-color;
182+
183+
@if root-defaults.$themeable-components and defaults.$themeable {
184+
@include theme.generate-modifiers(
185+
defaults.$list-theme-map,
186+
defaults.$list-theme-selector-base,
187+
defaults.$list-theme-selector-prefix,
188+
"list-"
189+
);
190+
@include theme.generate-modifiers(
191+
defaults.$list-theme-map,
192+
defaults.$list-theme-selector-base,
193+
defaults.$list-theme-selector-prefix,
194+
"list-",
195+
""
196+
);
197+
}
109198
}
110199

111200
// .list-item

0 commit comments

Comments
 (0)