Skip to content

Commit 4b144a8

Browse files
committed
chore(Item): migrate to has syntax
1 parent 6e0400f commit 4b144a8

File tree

2 files changed

+35
-43
lines changed

2 files changed

+35
-43
lines changed

src/components/content/Item/Item.docs.mdx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,16 @@ The `mods` property accepts the following modifiers:
5959

6060
| Modifier | Type | Description |
6161
|----------|------|-------------|
62-
| with-icon | `boolean` | Applied when an icon is present |
63-
| with-right-icon | `boolean` | Applied when a right icon is present |
64-
| with-prefix | `boolean` | Applied when a prefix is present |
65-
| with-suffix | `boolean` | Applied when a suffix is present |
66-
| with-description | `boolean` | Applied when a description is present |
67-
| with-description-block | `boolean` | Applied when description placement is "block" |
62+
| has-description-block | `boolean` | Applied when description placement is "block" |
63+
| has-actions-content | `boolean` | Applied when actions have actual content (not just placeholder) |
6864
| checkbox | `boolean` | Applied when using checkbox icon (icon="checkbox") |
6965
| selected | `boolean` | Applied when isSelected is true |
7066
| shape-card | `boolean` | Applied when shape is "card" |
7167
| shape-button | `boolean` | Applied when shape is "button" |
7268
| shape-sharp | `boolean` | Applied when shape is "sharp" |
7369

70+
**Note:** Element presence (Icon, RightIcon, Prefix, Suffix, Description, Actions) is now automatically detected via CSS `:has()` selectors and doesn't require manual modifiers.
71+
7472
## Variants
7573

7674
### Types

src/components/content/Item/Item.tsx

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -213,20 +213,20 @@ const ItemElement = tasty({
213213
placeContent: 'stretch',
214214
gridColumns: {
215215
'': '1sf max-content max-content',
216-
'with-actions': '1sf max-content max-content max-content',
217-
'with-icon ^ with-prefix': 'max-content 1sf max-content max-content',
218-
'with-icon ^ with-prefix & with-actions':
216+
':has(Actions)': '1sf max-content max-content max-content',
217+
':has(Icon) ^ :has(Prefix)': 'max-content 1sf max-content max-content',
218+
':has(Icon) ^ :has(Prefix) & :has(Actions)':
219219
'max-content 1sf max-content max-content max-content',
220-
'with-icon & with-prefix':
220+
':has(Icon) & :has(Prefix)':
221221
'max-content max-content 1sf max-content max-content',
222-
'with-icon & with-prefix & with-actions':
222+
':has(Icon) & :has(Prefix) & :has(Actions)':
223223
'max-content max-content 1sf max-content max-content max-content',
224-
'(with-icon ^ with-right-icon) & !with-description & !with-prefix & !with-suffix & !with-label':
224+
'(:has(Icon) ^ :has(RightIcon)) & !:has(Description) & !:has(Prefix) & !:has(Suffix) & !:has(Label)':
225225
'max-content',
226226
},
227227
gridRows: {
228228
'': 'auto auto',
229-
'with-description-block': 'auto auto auto',
229+
'has-description-block': 'auto auto auto',
230230
},
231231
// Prevent items from shrinking inside vertical flex layouts (Menu, ListBox, etc)
232232
flexShrink: {
@@ -321,25 +321,25 @@ const ItemElement = tasty({
321321
maxWidth: '100%',
322322
padding: {
323323
'': '$block-padding $inline-padding',
324-
'(with-icon | with-prefix)':
324+
'(:has(Icon) | :has(Prefix))':
325325
'$block-padding $inline-padding $block-padding 0',
326-
'(with-right-icon | with-suffix | with-actions)':
326+
'(:has(RightIcon) | :has(Suffix) | :has(Actions))':
327327
'$block-padding 0 $block-padding $inline-padding',
328-
'(with-icon | with-prefix) & (with-right-icon | with-suffix | with-actions)':
328+
'(:has(Icon) | :has(Prefix)) & (:has(RightIcon) | :has(Suffix) | :has(Actions))':
329329
'$block-padding 0',
330-
'with-description & !with-description-block':
330+
':has(Description) & !has-description-block':
331331
'$block-padding $inline-padding 0 $inline-padding',
332-
'with-description & !with-description-block & (with-icon | with-prefix)':
332+
':has(Description) & !has-description-block & (:has(Icon) | :has(Prefix))':
333333
'$block-padding $inline-padding 0 0',
334-
'with-description & !with-description-block & (with-right-icon | with-suffix | with-actions)':
334+
':has(Description) & !has-description-block & (:has(RightIcon) | :has(Suffix) | :has(Actions))':
335335
'$block-padding 0 0 $inline-padding',
336-
'with-description & !with-description-block & (with-icon | with-prefix) & (with-right-icon | with-suffix | with-actions)':
336+
':has(Description) & !has-description-block & (:has(Icon) | :has(Prefix)) & (:has(RightIcon) | :has(Suffix) | :has(Actions))':
337337
'$block-padding 0 0 0',
338338
},
339339
gridRow: {
340340
'': 'span 2',
341-
'with-description': 'span 1',
342-
'with-description-block': 'span 2',
341+
':has(Description)': 'span 1',
342+
'has-description-block': 'span 2',
343343
},
344344
},
345345

@@ -355,25 +355,26 @@ const ItemElement = tasty({
355355
textAlign: 'left',
356356
gridRow: {
357357
'': 'span 1',
358-
'with-description-block': '3 / span 1',
358+
'has-description-block': '3 / span 1',
359359
},
360360
gridColumn: {
361361
'': 'span 1',
362-
'with-description-block': '1 / -1',
362+
'has-description-block': '1 / -1',
363363
},
364364
padding: {
365365
'': '0 $inline-padding $block-padding $inline-padding',
366-
'(with-icon | with-prefix)': '0 $inline-padding $block-padding 0',
367-
'(with-right-icon | with-suffix)': '0 0 $block-padding $inline-padding',
368-
'(with-icon | with-prefix) & (with-right-icon | with-suffix)':
366+
'(:has(Icon) | :has(Prefix))': '0 $inline-padding $block-padding 0',
367+
'(:has(RightIcon) | :has(Suffix))':
368+
'0 0 $block-padding $inline-padding',
369+
'(:has(Icon) | :has(Prefix)) & (:has(RightIcon) | :has(Suffix))':
369370
'0 0 $block-padding 0',
370-
'with-description-block':
371+
'has-description-block':
371372
'0 ($inline-padding - $inline-compensation + 1bw) $bottom-padding ($inline-padding - $inline-compensation + 1bw)',
372-
'with-description-block & !with-icon':
373+
'has-description-block & !:has(Icon)':
373374
'0 ($inline-padding - $inline-compensation + 1bw) $bottom-padding $inline-padding',
374-
'with-description-block & !with-right-icon':
375+
'has-description-block & !:has(RightIcon)':
375376
'0 $inline-padding $bottom-padding ($inline-padding - $inline-compensation + 1bw)',
376-
'with-description-block & !with-right-icon & !with-icon':
377+
'has-description-block & !:has(RightIcon) & !:has(Icon)':
377378
'0 $inline-padding $bottom-padding $inline-padding',
378379
},
379380

@@ -385,15 +386,15 @@ const ItemElement = tasty({
385386
...ADDITION_STYLES,
386387
padding: {
387388
'': '$inline-padding left',
388-
'with-icon': 0,
389+
':has(Icon)': 0,
389390
},
390391
},
391392

392393
Suffix: {
393394
...ADDITION_STYLES,
394395
padding: {
395396
'': '$inline-padding right',
396-
'with-right-icon': 0,
397+
':has(RightIcon)': 0,
397398
},
398399
},
399400

@@ -410,7 +411,7 @@ const ItemElement = tasty({
410411
gridRow: 'span 2',
411412
width: {
412413
'': '($actions-width, 0px)',
413-
'with-actions-content': 'calc-size(max-content, size)',
414+
'has-actions-content': 'calc-size(max-content, size)',
414415
},
415416
transition: 'width $transition ease-out',
416417
interpolateSize: 'allow-keywords',
@@ -779,16 +780,9 @@ const Item = <T extends HTMLElement = HTMLDivElement>(
779780
);
780781

781782
mods = {
782-
'with-icon': !!finalIcon,
783-
'with-right-icon': !!finalRightIcon,
784-
'with-label': !!(children || labelProps),
785-
'with-prefix': !!finalPrefix,
786-
'with-suffix': !!finalSuffix,
787-
'with-description': showDescriptions,
788-
'with-description-block':
783+
'has-description-block':
789784
showDescriptions && descriptionPlacement === 'block',
790-
'with-actions': !!actions,
791-
'with-actions-content': !!(actions && actions !== true),
785+
'has-actions-content': !!(actions && actions !== true),
792786
checkbox: hasCheckbox,
793787
disabled: finalIsDisabled,
794788
selected: isSelected === true,

0 commit comments

Comments
 (0)