Skip to content

Commit a81ec79

Browse files
authored
feat(core): add depth-aware adaptation for components (#38)
1 parent fdef7d8 commit a81ec79

5 files changed

Lines changed: 180 additions & 1 deletion

File tree

packages/core/src/components/badge.css

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,39 @@
188188
border: 1px solid CanvasText;
189189
}
190190
}
191+
192+
/* =============================================================================
193+
STYLE QUERIES - Depth-Aware Adaptation
194+
Badges automatically adapt when nested inside surfaces of different depths.
195+
Only affects default (neutral) and outline badges.
196+
============================================================================= */
197+
198+
@supports (container-type: inline-size) {
199+
/* Inside raised surface (depth: 1) */
200+
@container surface style(--_surface-depth: 1) {
201+
:where([s-badge=""]) {
202+
--_badge-bg: var(--s-neutral-300);
203+
}
204+
:where([s-badge="outline"]) {
205+
box-shadow: inset 0 0 0 1px var(--s-border-strong);
206+
}
207+
}
208+
209+
/* Inside floating surface (depth: 2) */
210+
@container surface style(--_surface-depth: 2) {
211+
:where([s-badge=""]) {
212+
--_badge-bg: var(--s-neutral-300);
213+
box-shadow: var(--s-shadow-sm);
214+
}
215+
:where([s-badge="outline"]) {
216+
box-shadow: inset 0 0 0 1px var(--s-border-strong);
217+
}
218+
}
219+
220+
/* Inside sunken surface (depth: -1) */
221+
@container surface style(--_surface-depth: -1) {
222+
:where([s-badge=""]) {
223+
--_badge-bg: var(--s-neutral-100);
224+
}
225+
}
226+
}

packages/core/src/components/button.css

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,45 @@
267267
}
268268
}
269269
}
270+
271+
/* =============================================================================
272+
STYLE QUERIES - Depth-Aware Adaptation
273+
Buttons automatically adapt when nested inside surfaces of different depths.
274+
============================================================================= */
275+
276+
@supports (container-type: inline-size) {
277+
/**
278+
* Inside raised surface (depth: 1)
279+
* Secondary buttons need stronger border for definition
280+
*/
281+
@container surface style(--_surface-depth: 1) {
282+
:where([s-btn="secondary"]) {
283+
--_btn-border: var(--s-border-strong);
284+
}
285+
}
286+
287+
/**
288+
* Inside floating surface (depth: 2)
289+
* All buttons get stronger borders for definition against elevated bg
290+
*/
291+
@container surface style(--_surface-depth: 2) {
292+
:where([s-btn="secondary"]) {
293+
--_btn-border: var(--s-border-strong);
294+
--_btn-bg: var(--s-surface-base);
295+
}
296+
297+
:where([s-btn="ghost"]) {
298+
--_btn-border: var(--s-border-muted);
299+
}
300+
}
301+
302+
/**
303+
* Inside sunken surface (depth: -1)
304+
* Buttons use base surface bg to stand out from recessed area
305+
*/
306+
@container surface style(--_surface-depth: -1) {
307+
:where([s-btn="secondary"]) {
308+
--_btn-bg: var(--s-surface-base);
309+
}
310+
}
311+
}

packages/core/src/components/card.css

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,41 @@
224224
flex-direction: column;
225225
gap: var(--s-space-4);
226226
}
227+
228+
/* =============================================================================
229+
STYLE QUERIES - Depth-Aware Adaptation
230+
Cards automatically adapt when nested inside surfaces of different depths.
231+
============================================================================= */
232+
233+
@supports (container-type: inline-size) {
234+
/**
235+
* Inside raised surface (depth: 1)
236+
* Reduce shadow to avoid visual "shadow stacking"
237+
*/
238+
@container surface style(--_surface-depth: 1) {
239+
:where([s-card]) {
240+
--_card-shadow: var(--s-shadow-sm);
241+
}
242+
}
243+
244+
/**
245+
* Inside floating surface (depth: 2)
246+
* Remove shadow entirely, use subtle border for definition
247+
*/
248+
@container surface style(--_surface-depth: 2) {
249+
:where([s-card]) {
250+
--_card-shadow: none;
251+
--_card-border: var(--s-border-default);
252+
}
253+
}
254+
255+
/**
256+
* Inside sunken surface (depth: -1)
257+
* Increase shadow for better lift appearance
258+
*/
259+
@container surface style(--_surface-depth: -1) {
260+
:where([s-card]) {
261+
--_card-shadow: var(--s-shadow-md);
262+
}
263+
}
264+
}

packages/core/src/components/input.css

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,58 @@ select[s-input] {
290290
}
291291
}
292292
}
293+
294+
/* =============================================================================
295+
STYLE QUERIES - Depth-Aware Adaptation
296+
Inputs automatically adapt when nested inside surfaces of different depths.
297+
============================================================================= */
298+
299+
@supports (container-type: inline-size) {
300+
/**
301+
* Inside raised surface (depth: 1)
302+
* Use sunken background to create visual depth contrast
303+
*/
304+
@container surface style(--_surface-depth: 1) {
305+
:where([s-input]) {
306+
--_input-bg: var(--s-surface-sunken);
307+
}
308+
309+
:where([s-checkbox]) input,
310+
:where([s-radio]) input {
311+
background-color: var(--s-surface-sunken);
312+
}
313+
}
314+
315+
/**
316+
* Inside floating surface (depth: 2)
317+
* Stronger sunken appearance with visible border
318+
*/
319+
@container surface style(--_surface-depth: 2) {
320+
:where([s-input]) {
321+
--_input-bg: var(--s-surface-sunken);
322+
--_input-border: var(--s-border-strong);
323+
}
324+
325+
:where([s-checkbox]) input,
326+
:where([s-radio]) input {
327+
background-color: var(--s-surface-sunken);
328+
border-color: var(--s-border-strong);
329+
}
330+
}
331+
332+
/**
333+
* Inside sunken surface (depth: -1)
334+
* Use base background to stand out from recessed area
335+
*/
336+
@container surface style(--_surface-depth: -1) {
337+
:where([s-input]) {
338+
--_input-bg: var(--s-surface-raised);
339+
--_input-border: var(--s-border-muted);
340+
}
341+
342+
:where([s-checkbox]) input,
343+
:where([s-radio]) input {
344+
background-color: var(--s-surface-raised);
345+
}
346+
}
347+
}

packages/core/src/components/surface.css

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@
1313

1414
/* Base surface - zero specificity for easy overrides */
1515
:where([s-surface]) {
16-
/* Enable container queries */
16+
/* Enable container queries (size + style) */
1717
container-type: inline-size;
18+
container-name: surface;
1819

1920
/* Surface CSS properties (customization points) */
2021
--_surface-bg: var(--s-surface-base);
2122
--_surface-padding: var(--s-space-4);
2223
--_surface-radius: var(--s-radius-lg);
2324

25+
/* Depth indicator for style queries (flat=0, sunken=-1, raised=1, floating=2) */
26+
--_surface-depth: 0;
27+
2428
background-color: var(--_surface-bg);
2529
padding: var(--_surface-padding);
2630
border-radius: var(--_surface-radius);
@@ -60,23 +64,27 @@
6064
/* Flat - default, explicit declaration */
6165
[s-surface="flat"] {
6266
--_surface-bg: var(--s-surface-base);
67+
--_surface-depth: 0;
6368
}
6469

6570
/* Sunken - recessed appearance */
6671
[s-surface="sunken"] {
6772
--_surface-bg: var(--s-surface-sunken);
73+
--_surface-depth: -1;
6874
box-shadow: var(--s-shadow-inner);
6975
}
7076

7177
/* Raised - elevated card-like appearance */
7278
[s-surface="raised"] {
7379
--_surface-bg: var(--s-surface-raised);
80+
--_surface-depth: 1;
7481
box-shadow: var(--s-shadow-md);
7582
}
7683

7784
/* Floating - high elevation, for overlays and modals */
7885
[s-surface="floating"] {
7986
--_surface-bg: var(--s-surface-raised);
87+
--_surface-depth: 2;
8088
box-shadow: var(--s-shadow-xl);
8189
}
8290

0 commit comments

Comments
 (0)