|
25 | 25 | --alert-color-bg-warning: #3c170c; |
26 | 26 | } |
27 | 27 |
|
| 28 | +/* Shared styles for both the block and inline variants */ |
28 | 29 | .base { |
29 | 30 | display: flex; |
30 | 31 | border-radius: var(--lp-border-radius-medium); |
31 | 32 | gap: var(--lp-spacing-300); |
32 | 33 | align-items: flex-start; |
33 | 34 |
|
| 35 | + /* Status icon styles */ |
34 | 36 | &.error .icon { |
35 | 37 | fill: var(--lp-color-fill-feedback-error); |
36 | 38 | } |
|
48 | 50 | } |
49 | 51 | } |
50 | 52 |
|
51 | | -.default, |
52 | | -.inline { |
53 | | - padding: var(--lp-spacing-500); |
| 53 | +/* Base styles for the block variant */ |
| 54 | +.default { |
| 55 | + /* Add a base layer of padding on the Alert itself. This is just enough to create some breathing room in case any buttons are present. */ |
| 56 | + padding: var(--lp-spacing-300) var(--lp-spacing-300) var(--lp-spacing-300) var(--lp-spacing-500); |
54 | 57 | background-color: var(--alert-color-bg-neutral); |
55 | 58 | border: 1px solid var(--alert-color-border-neutral); |
56 | 59 | position: relative; |
57 | 60 | min-height: var(--lp-size-48); |
58 | 61 |
|
| 62 | + /* Status borders and background colors */ |
59 | 63 | &.error { |
60 | 64 | border-color: var(--alert-color-border-error); |
61 | 65 | background-color: var(--alert-color-bg-error); |
|
76 | 80 | background-color: var(--alert-color-bg-warning); |
77 | 81 | } |
78 | 82 |
|
79 | | - &:has(.heading) { |
80 | | - /* biome-ignore lint/style/noDescendingSpecificity: ignore */ |
81 | | - & .icon { |
82 | | - transform: translateY(var(--lp-size-2)); |
83 | | - } |
| 83 | + & .icon { |
| 84 | + transform: translateY(var(--lp-size-10)); |
84 | 85 | } |
85 | 86 |
|
86 | | - /* Let's keep the close button in the default position, but position relative in case we want to move it later. */ |
87 | | - & .close { |
88 | | - position: relative; |
| 87 | + /* Add another layer of vertical padding to the Alert content (text and actions). This will align the basline of the text with the baseline of the dismiss button. */ |
| 88 | + .content { |
| 89 | + padding: var(--lp-spacing-300) var(--lp-spacing-300) var(--lp-spacing-300) 0; |
89 | 90 | } |
90 | | -} |
91 | 91 |
|
92 | | -.inline { |
93 | | - align-items: center; |
94 | | - gap: var(--lp-spacing-300); |
95 | | - padding: var(--lp-spacing-400) var(--lp-spacing-500); |
| 92 | + /* Add a little space at the top of the button group to separate it from the text */ |
| 93 | + .buttonGroup { |
| 94 | + margin-top: var(--lp-spacing-400); |
| 95 | + } |
96 | 96 |
|
97 | | - & .close { |
98 | | - margin-left: var(--lp-spacing-300); |
| 97 | + /* We need to position the close button absolutely so we can adjust its position without affecting the layout of the Alert content. */ |
| 98 | + .close { |
| 99 | + position: absolute; |
| 100 | + top: var(--lp-spacing-300); |
| 101 | + right: var(--lp-spacing-300); |
99 | 102 | } |
100 | 103 |
|
| 104 | + /* Add extra right padding when there's a close button to prevent text from overlapping the button */ |
| 105 | + &:has(.close) .content { |
| 106 | + padding-right: var(--lp-size-48); |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +/* Inline actions variant */ |
| 111 | +.actionsInline { |
| 112 | + /* Switch the direction of the content to row and make sure it fills its container. */ |
101 | 113 | & .content { |
102 | 114 | flex-direction: row; |
103 | | - align-items: center; |
104 | | - gap: var(--lp-spacing-400); |
| 115 | + align-items: flex-start; |
| 116 | + flex: 1; |
| 117 | + gap: var(--lp-spacing-500); |
| 118 | + |
| 119 | + /* Unset padding on content to prevent it looking too big if there are actions present. */ |
| 120 | + padding: unset; |
105 | 121 | } |
106 | 122 |
|
107 | | - /* Adjust padding so the alert maintains the same height if there's an inline action or close button. We have to hardcode the vertical values because of the way borders get calculated as a part of an element's dimensions. */ |
108 | | - &:has(.inlineAction), |
109 | | - &:has(.close) { |
110 | | - padding: 7px var(--lp-spacing-300) 7px var(--lp-spacing-500); |
| 123 | + /* Move vertical padding from the content container to the text container. This ensures the text baseline is aligned with the trailing actions and dismiss buttons. We need to do some fancy calc stuff to make it look right. */ |
| 124 | + & .text { |
| 125 | + padding: calc(var(--lp-spacing-300) - var(--lp-size-2)) 0; |
111 | 126 | } |
112 | 127 |
|
113 | | - &:has(.inlineAction) { |
114 | | - .close { |
115 | | - margin-left: 0; |
116 | | - } |
| 128 | + /* Need a specific selector to override the padding on the content container when there is a close button. */ |
| 129 | + &:has(.close) .content { |
| 130 | + padding-right: unset; |
| 131 | + } |
| 132 | + |
| 133 | + /* Adjust icon position to compensate for the different padding */ |
| 134 | + & .icon { |
| 135 | + transform: translateY(var(--lp-spacing-300)); |
| 136 | + } |
| 137 | + |
| 138 | + /* Move the button group into position. We don't need a top margin here, and we want to flush it to the right */ |
| 139 | + & .buttonGroup { |
| 140 | + margin-top: unset; |
| 141 | + margin-left: auto; |
117 | 142 | } |
118 | | -} |
119 | 143 |
|
120 | | -.inlineAction { |
121 | | - flex-shrink: 0; |
122 | | - margin-left: auto; |
| 144 | + /* Remove the absolute positioning from the close button so that it can participate in the flex layout. */ |
| 145 | + & .close { |
| 146 | + position: unset; |
| 147 | + top: unset; |
| 148 | + right: unset; |
| 149 | + } |
123 | 150 | } |
124 | 151 |
|
| 152 | +/* Base styles for the content container */ |
125 | 153 | .content { |
126 | 154 | min-width: 0; |
127 | 155 | flex: 1; |
|
131 | 159 | align-items: flex-start; |
132 | 160 | } |
133 | 161 |
|
134 | | -.content .heading { |
135 | | - font: var(--lp-text-body-2-semibold); |
136 | | -} |
137 | | - |
138 | | -.buttonGroup { |
139 | | - margin-top: var(--lp-spacing-500); |
| 162 | +/* Base styles for the text container */ |
| 163 | +.text { |
| 164 | + display: flex; |
| 165 | + flex-direction: column; |
| 166 | + flex: 1; |
| 167 | + min-width: 0; |
140 | 168 | } |
141 | 169 |
|
142 | | -.default .close { |
143 | | - bottom: var(--lp-spacing-300); |
144 | | - left: var(--lp-spacing-300); |
| 170 | +/* Make sure the heading is the right size and weight regardless of which element is used */ |
| 171 | +.heading { |
| 172 | + font: var(--lp-text-body-2-semibold) !important; |
145 | 173 | } |
146 | 174 |
|
147 | | -/* Sometimes we want to make text bold, but we need to make sure this maps to the correct font weight. */ |
| 175 | +/* Sometimes we want to make text bold, but we need to make sure this maps to semibold, not bold. */ |
148 | 176 | .content strong, |
149 | 177 | .content b { |
150 | 178 | font-weight: var(--lp-font-weight-semibold); |
151 | 179 | } |
| 180 | + |
| 181 | +/* Inline variant styles */ |
| 182 | +.inline { |
| 183 | + align-items: center; |
| 184 | + |
| 185 | + & .close { |
| 186 | + margin-left: var(--lp-spacing-300); |
| 187 | + } |
| 188 | +} |
0 commit comments