Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

creating-components

/creating-components

Tworzy nowe komponenty UI w packages/ui, obejmując strukturę, testy i stories oraz błędy, których należy unikać.

Repozytorium
nuclear ↗
Licencja
AGPL-3.0
Ostatnia zmiana repozytorium
27.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 27.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

AGPL-3.0, copyleft: przeróbki udostępniane innym muszą mieć tę samą licencję.

Co robi i kiedy

Tworzy nowe komponenty UI w packages/ui, obejmując strukturę, testy i stories oraz błędy, których należy unikać.

Oryginalny opis (EN)

Use when creating new UI components in packages/ui. Covers component structure, tests, stories, and what to avoid.

Jak działa

  1. Component Structure
  2. Implementation Pattern
  3. Tests
  4. Stories
  5. Avoiding Duplication
  6. Classes for customization
  7. Strings
  8. Accessibility
  9. Checklist
Sekcje z nagłówków SKILL.md, w oryginale · 129 linii, 554 słów
Podgląd SKILL.md
---
name: creating-components
description: Use when creating new UI components in packages/ui. Covers component structure, tests, stories, and what to avoid.
---

# Creating UI Components

## Component Structure

```
packages/ui/src/components/MyComponent/
├── MyComponent.tsx      # Implementation
├── MyComponent.test.tsx # Tests
├── index.ts             # Re-exports
└── __snapshots__/       # Vitest snapshots (auto-generated)
```

After creating, export from `packages/ui/src/components/index.ts`.

## Implementation Pattern

```tsx
import { cva, VariantProps } from 'class-variance-authority';
import { ComponentProps, FC } from 'react';
import { cn } from '../../utils';

const variants = cva('base-classes', {
  variants: { /* ... */ },
  defaultVariants: { /* ... */ },
});

type MyComponentProps = ComponentProps<'div'> & VariantProps<typeof variants>;

export const MyComponent: FC<MyComponentProps> = ({
  className,
  variant,
  ...props
}) => (
  <div className={cn(variants({ variant, className }))} {...props} />
);
```

## Tests

**What to test:**
- Snapshots (1-2 covering key variants)
- User interactions
- Behavior (callbacks called with correct args)

**What NOT to test:**
- CSS classes, attributes (use snapshots instead)
- Internal state
- Things TypeScript already enforces

**Consolidate tests.** One test can cover multiple related assertions. An exception to that is snapshot tests - one snapshot per variant/state.

## Stories

Create `packages/storybook/src/MyComponent.stories.tsx`.

**One story can show multiple related variants.** For example, it's wasteful to create a story for each variant of a button. Put them all together in one place. Don't create separate stories for each variant:

```tsx
import { Meta, StoryObj } from '@storybook/react-vite';
import { useState } from 'react';
import { MyComponent } from '@nuclearplayer/ui';

const meta = {
  title: 'Components/MyComponent',
  component: MyComponent,
  tags: ['autodocs'],
} satisfies Meta<typeof MyComponent>;

export default meta;
type Story = StoryObj<typeof MyComponent>;

export const AllVariants: Story = {
  render: () => {
    const [state, setState] = useState(initialState);
    return (
      <div className="flex flex-col gap-4">
        {/* Show all variants, states, interactions */}
      </div>
    );
  },
};
```

This isn't an iron rule, sometimes it will make more sense to have separate stories.

Don't run storybook build checks.

## Avoiding Duplication

Before creating a new component, check if an existing one can be extended.

**Pattern: Discriminated unions for mode variants**

Example: Instead of creating `SingleSelect` and `MultiSelect` components:

```tsx
type Props = 
  | { multiple?: false; selected: string; onChange: (id: string) => void }
  | { multiple: true; selected: string[]; onChange: (ids: string[]) => void };
```

TypeScript enforces correct types based on the `multiple` prop.

## Classes for customization

Where it's likely that a component will need custom styling, expose a `className` prop.

If there are many parts that may need styling, consider exposing a `classes` prop with specific class names for each part. Define a type for the `classes` prop. Refer to `packages/ui/src/components/TrackTable/types.ts` for an example.

## Strings

All user-facing strings go through i18n - no hardcoded UI text.
If a new component in the ui package needs labels and other kinds of localized text, it should accept a `labels` prop with the relevant strings. The prop should have its own type defined. Refer to `packages/ui/src/components/QueueItem/types.ts` for an example.

## Accessibility

We don't care about that. If there's an opportunity to handle that easily, do it, but don't go out of your way.

## Checklist

- [ ] Component in `packages/ui/src/components/MyComponent/`
- [ ] Exported from `packages/ui/src/components/index.ts`
- [ ] Tests cover behavior, not implementation
- [ ] Tests consolidated (not one per variant)
- [ ] One story showing all variants
- [ ] No CSS class assertions in tests
- [ ] No duplicate component when extending existing one works

Wersje

W bazie nie ma innych skilli o nazwie creating-components.

Identyczna treść występuje jeszcze w 1 innych folderach na GitHubie. Tu pokazujemy jedną, najlepiej ocenioną kopię.

Migawka bazy z 13.11.2026 · wersja paczki d719ff851b97 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100react
    Pomaga tworzyć i zmieniać komponenty, hooki i elementy interfejsu w pakietach react-ui oraz ui-components.
  • 100create-react-modlet
    Tworzy komponenty React, hooki lub narzędzia we wzorcu modlet: samodzielne foldery z index.ts, implementacją, testami, stories i opcjonalnymi typami, w packages/client/src/components/.
  • 100create-react-modlet
    Tworzy komponenty React, hooki lub narzędzia we wzorcu modlet: samodzielne foldery z index.ts, implementacją, testami, stories i opcjonalnymi typami, w packages/client/src/components/.
  • 100component-tests
    Prowadzi pracę z testami komponentów Playwright montującymi stories: specyfikacje, pliki fixture, stories i wspólny harness w packages/stories.
  • 100component-docs
    Generuje lub aktualizuje dokumentację komponentów z przykładami użycia, tabelami props i stories Storybook.
  • 100storybook-stories
    Pisze historie Storybook dla komponentów UI PostHog: stos providerów, pułapka z zapytaniami tRPC, które nie rozwiązują się w Storybook, oraz podział na komponenty czysto prezentacyjne.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.