Skip to content

Commit bbd42f6

Browse files
committed
chore: keep className the only class prop in component skills
1 parent ef0c753 commit bbd42f6

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

‎skills/nanoviews-component/SKILL.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,27 @@ If the project's linter rejects this layout, or its `--fix` collapses it back, t
421421
})
422422
```
423423

424+
- `class` is a component's only class prop. Don't add props like `titleClass` or `moreClassName` for its inner elements: split such an element out into a component of its own and compose the parts, each with its own `class`, the way compound components expose their parts as children:
425+
426+
```js
427+
// not
428+
Card({
429+
class: styles.card,
430+
titleClass: styles.title,
431+
title: 'Title'
432+
})(
433+
'Text'
434+
)
435+
436+
// but
437+
Card({ class: styles.card })(
438+
CardTitle({ class: styles.title })('Title'),
439+
'Text'
440+
)
441+
```
442+
443+
A `*Class` or `*ClassName` prop is for exceptional cases only, where the element cannot be split out.
444+
424445
- Import views from `nanoviews` and reactivity from `nanoviews/store`, by name:
425446

426447
```ts

‎skills/react-component/SKILL.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,27 @@ Name event handlers in the `on*` form, never `handle*`: `onCloseCallback`, `onCl
277277
clsx(styles.root, styles[variant], className)
278278
```
279279

280+
- `className` is a component's only class prop. Don't add props like `titleClassName` or `moreClassName` for its inner elements: split such an element out into a component of its own and compose the parts, each with its own `className`, the way compound components expose their parts as subcomponents:
281+
282+
```jsx
283+
// not
284+
<Card
285+
className={styles.card}
286+
titleClassName={styles.title}
287+
title="Title"
288+
>
289+
Text
290+
</Card>
291+
292+
// but
293+
<Card className={styles.card}>
294+
<CardTitle className={styles.title}>Title</CardTitle>
295+
Text
296+
</Card>
297+
```
298+
299+
A `*ClassName` prop is for exceptional cases only, where the element cannot be split out.
300+
280301
- Don't pass unneeded props to the root element — destructure props consumed by hooks so they don't leak into the rest spread:
281302

282303
```jsx

0 commit comments

Comments
 (0)