Skip to content

Commit 07b2df4

Browse files
committed
Add icons and background colors to Callout
1 parent 10b594e commit 07b2df4

1 file changed

Lines changed: 47 additions & 27 deletions

File tree

‎src/components/Callout/index.astro‎

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,53 @@
11
---
2+
import Sprite from '@components/Sprite/index.astro'
3+
import type { SpriteName } from '@components/Sprite/sprites'
4+
25
export interface Props {
3-
type?: 'warning' | 'action' | 'tip' | 'info' | 'note';
4-
icon?: string;
6+
type?: 'warning' | 'action' | 'tip' | 'info' | 'note'
57
}
68
7-
const { type = 'info', icon } = Astro.props;
8-
9-
// Map callout types to their color CSS custom properties
10-
const getCalloutColor = (calloutType: string) => {
11-
switch (calloutType) {
12-
case 'warning':
13-
case 'action':
14-
return 'var(--color-primary)';
15-
case 'tip':
16-
case 'info':
17-
case 'note':
18-
default:
19-
return 'var(--color-secondary)';
20-
}
21-
};
9+
const { type = 'info' } = Astro.props
10+
11+
// Map callout types to sprite icons
12+
const iconMap: Record<string, SpriteName> = {
13+
warning: 'warning',
14+
action: 'warning',
15+
info: 'info',
16+
tip: 'lightbulb',
17+
note: 'question',
18+
}
19+
20+
// Map callout types to their background color CSS custom properties
21+
const backgroundColorMap: Record<string, string> = {
22+
warning: 'var(--color-danger-bg)',
23+
action: 'var(--color-danger-bg)',
24+
info: 'var(--color-info-bg)',
25+
tip: 'var(--color-bg-offset)',
26+
note: 'var(--color-bg-offset)',
27+
}
2228
23-
const calloutColor = getCalloutColor(type);
29+
// Map callout types to their border/icon color CSS custom properties
30+
const borderColorMap: Record<string, string> = {
31+
warning: 'var(--color-danger)',
32+
action: 'var(--color-danger)',
33+
info: 'var(--color-info)',
34+
tip: 'var(--color-text)',
35+
note: 'var(--color-text)',
36+
}
37+
38+
const icon: SpriteName = iconMap[type] as SpriteName
39+
const backgroundColor = backgroundColorMap[type]
40+
const borderColor = borderColorMap[type]
2441
---
2542

26-
<style define:vars={{ calloutColor }}>
43+
<style define:vars={{ backgroundColor, borderColor }}>
2744
.callout {
28-
--callout-color: var(--calloutColor);
45+
background-color: var(--backgroundColor);
46+
border-left-color: var(--borderColor);
47+
}
48+
49+
.callout__icon {
50+
color: var(--borderColor);
2951
}
3052

3153
/* Spacing for nested elements */
@@ -34,14 +56,12 @@ const calloutColor = getCalloutColor(type);
3456
}
3557
</style>
3658

37-
<div class="callout bg-[var(--color-bg-offset)] border border-[var(--color-border)] border-l-0 rounded-r-lg relative">
38-
{icon && (
39-
<div class="callout__icon bg-[var(--color-bg)] rounded-full text-[var(--callout-color)] absolute left-0 top-0 ml-0.5 p-1 -translate-x-1/2 -translate-y-1/2">
40-
{/* Icon implementation would go here - could use a Sprite component */}
41-
</div>
42-
)}
59+
<div class="callout border border-[var(--color-border)] border-l-0 rounded-r-lg relative pl-6">
60+
<div class="callout__icon bg-[var(--color-bg)] rounded-full absolute left-0 top-0 ml-0.5 p-1 -translate-x-1/2 -translate-y-1/2">
61+
<Sprite name={icon} size={20} />
62+
</div>
4363

44-
<div class="callout__content border-l-4 border-[var(--callout-color)] p-4 md:pl-8">
64+
<div class="callout__content border-l-4 p-4 md:pl-8">
4565
<slot />
4666
</div>
4767
</div>

0 commit comments

Comments
 (0)