Skip to content

Commit af1b321

Browse files
feat: Define CSS classes for levels of Toast component (#677)
# Motivation Just an idea: it would be easier to customize the Toast style using CSS styles, if we add the level among the classes. For example, in OISY, if we want to customize the background of an error toast we need to use the icon child: ```css .toast:has(> .icon.error) { --overlay-background: var(--color-background-error-light); --overlay-background-contrast: var(--color-foreground-error-secondary); } ``` While we could do: ```css .toast { --overlay-background-error: var(--color-background-error-light); --overlay-background-contrast-error: var(--color-foreground-error-secondary); } ``` So, we define custom CSS classes for each level of `Toast`: background and foreground, inverted or not. --------- Co-authored-by: David Dal Busco <[email protected]>
1 parent 40f1769 commit af1b321

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

src/lib/components/Toast.svelte

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
<div
8080
data-tid="toast-component"
8181
role="dialog"
82-
class={`toast ${theme ?? "themed"}`}
82+
class={`toast ${level} ${theme ?? "themed"}`}
8383
in:fly|global={{ y: (position === "top" ? -1 : 1) * 100, duration: 200 }}
8484
out:fade|global={{ delay: 100 }}
8585
>
@@ -140,8 +140,54 @@
140140
padding: var(--padding-1_5x);
141141
box-sizing: border-box;
142142
143+
background: var(--toast-background, var(--overlay-background));
144+
color: var(--toast-color, var(--overlay-background-contrast));
145+
146+
&.success {
147+
--toast-background: var(--toast-success-background);
148+
--toast-color: var(--toast-success-color);
149+
}
150+
151+
&.info {
152+
--toast-background: var(--toast-info-background);
153+
--toast-color: var(--toast-info-color);
154+
}
155+
156+
&.warn {
157+
--toast-background: var(--toast-warn-background);
158+
--toast-color: var(--toast-warn-color);
159+
}
160+
161+
&.error {
162+
--toast-background: var(--toast-error-background);
163+
--toast-color: var(--toast-error-color);
164+
}
165+
143166
&.inverted {
144167
@include overlay.toast-inverted;
168+
169+
--toast-background: var(--toast-inverted-background);
170+
--toast-color: var(--toast-inverted-background-contrast);
171+
172+
&.success {
173+
--toast-background: var(--toast-success-inverted-background);
174+
--toast-color: var(--toast-success-inverted-color);
175+
}
176+
177+
&.info {
178+
--toast-background: var(--toast-info-inverted-background);
179+
--toast-color: var(--toast-info-inverted-color);
180+
}
181+
182+
&.warn {
183+
--toast-background: var(--toast-warn-inverted-background);
184+
--toast-color: var(--toast-warn-inverted-color);
185+
}
186+
187+
&.error {
188+
--toast-background: var(--toast-error-inverted-background);
189+
--toast-color: var(--toast-error-inverted-color);
190+
}
145191
}
146192
147193
.icon {

0 commit comments

Comments
 (0)