Логотип Component Api Design

Component Api Design

Організація
staple-lab
component-api-design

Use when designing or reviewing a component's props API - variants, sizes, controlled vs uncontrolled state, compound components, polymorphism, escape hatches, TypeScript prop types, ref forwarding, and naming. Triggers on "component API", "props design", "should this be a prop or a slot", "how do I type this component".

Add to TypingMind

Огляд

Видавецьstaple-lab
Репозиторійdesign-system-skills
Назва навичкиcomponent-api-design
Зірки
7
Форки
0
Файли в пакеті
Лише інструкції
ЛіцензіяMIT
Посилання
  • Інструкції у форматі Markdown

    Файл SKILL.md, який модель завантажує за потреби, тож токени витрачаються лише тоді, коли запит справді відповідає навичці.

  • Працює з будь-якою LLM

    Навички ШІ — це звичайний Markdown, а не код для певного постачальника, тому вони працюють із GPT, Claude, Gemini, Grok або локальною моделлю.

  • Усе необхідне — в інструкціях

    Усе потрібне моделі міститься в інструкціях — жодних додаткових файлів для синхронізації.

  • Відкритий вихідний код

    Видавець на GitHub: staple-lab. Перед установленням перегляньте вихідні файли навички.

Встановлення

Установіть навичку ШІ Component Api Design у TypingMind, щоб використовувати її з будь-якою LLM, або додайте її до іншого агента, що читає SKILL.md.

1

Встановити в TypingMind

TypingMind встановлює навичку безпосередньо з її папки на GitHub — читає SKILL.md, збирає файли ресурсів у пакет і зберігає результат локально.

  1. Відкрийте застосунок і перейдіть до розділу «Плагіни» → «Навички».
  2. Виберіть «Встановити з GitHub».
  3. Вставте наведений нижче URL папки навички та підтвердьте встановлення.
    https://github.com/staple-lab/design-system-skills/tree/main/plugins/design-system/skills/component-api-design
  4. Увімкніть навичку в кожному чаті, де хочете її використовувати.
Плагіни → Навички → Додати навичку → За URL GitHub, потім вставте URL папки й натисніть «Продовжити».
2

Встановити в іншому агенті

Будь-який агент, що підтримує формат Agent Skills, може використовувати цю навичку — скопіюйте папку до каталогу навичок цього агента.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/staple-lab/design-system-skills.git /tmp/design-system-skills
mkdir -p .claude/skills
cp -r /tmp/design-system-skills/plugins/design-system/skills/component-api-design .claude/skills/component-api-design
Після копіювання перезапустіть Claude Code, щоб завантажити нову навичку.

Використовуйте навичку в TypingMind

Увімкніть навичку Component Api Design в будь-якому чаті TypingMind, і далі модель усе зробить сама. Назва й опис навички містяться в системному промпті, а щойно надходить відповідний запит, модель самостійно завантажує повні інструкції — вам не потрібно викликати навичку вручну, і до фактичного використання вона не витрачає токенів.

Модель самостійно завантажує навичку Component Api Design, щойно надходить відповідний запит.

Працює з будь-якою моделлю ШІ

Навички ШІ — це звичайні інструкції у форматі Markdown, а не код для певного постачальника, тому навичка Component Api Design не прив’язана до моделі, для якої її створено. Установіть її один раз у TypingMind і використовуйте з GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama або локальною моделлю, яку ви запускаєте самостійно, — усе з вашими власними ключами API.

  • Завантажується лише за потреби

    Системний промпт містить лише назву й опис. Інструкції завантажуються за першого відповідного запиту, тож поки навичка не потрібна, токени на її інструкції не витрачаються.

  • Змінюйте моделі під час чату

    Оскільки навичка — це інструкції, а не код, зміна моделі не порушує її роботу: наступна модель читає той самий файл SKILL.md.

Інструкції навички

Це вміст файлу SKILL.md, який завантажує модель. Прочитайте його перед установленням — навичка містить інструкції, яких дотримуватиметься ваша модель.

Component API design

The props API is the public contract. Styles can be fixed in an afternoon; a bad API is in a hundred call sites and stays wrong for years. Spend the extra hour here.

Boolean props are a trap

The most common API mistake, and it compounds:

tsx
// Bad — every new state doubles the invalid combinations
<Button primary secondary danger large small loading disabled />

// Good — enumerated, mutually exclusive by construction
<Button variant="primary" size="lg" loading />

variant and size should be string unions. Booleans are for genuinely independent binary states (loading, disabled, fullWidth). The test: if two props can never be true at once, they are one prop with a union type.

Controlled, uncontrolled, or both

Both — and the convention is non-negotiable because consumers expect DOM semantics:

tsx
interface Props {
  value?: string;              // controlled
  defaultValue?: string;       // uncontrolled initial
  onValueChange?: (v: string) => void;   // fires in BOTH modes
}

Rules:

  • value present → controlled. The component never updates its own state; it renders what it is given.
  • value absent → uncontrolled, defaultValue seeds it.
  • onValueChange fires in both modes. A callback that only fires when uncontrolled is a bug people hit at the worst time.
  • Never switch modes mid-life. Warn in dev if value goes from undefined to defined.
  • Name it onValueChange, not onChange, when it emits a value rather than an event — onChange implies a React ChangeEvent, and the mismatch bites at the first e.target.value.

Most primitive libraries already implement this correctly. Pass the props straight through and do not add a useState inside the wrapper; that is how wrappers break the controlled case.

Compound components

When a component has parts a consumer needs to arrange, reorder or replace, expose the parts:

tsx
<Dialog.Root>
  <Dialog.Trigger>Open</Dialog.Trigger>
  <Dialog.Content>
    <Dialog.Title>Delete project</Dialog.Title>
    <Dialog.Description>This cannot be undone.</Dialog.Description>
    <Dialog.Footer>
      <Dialog.Close>Cancel</Dialog.Close>
      <Button variant="danger">Delete</Button>
    </Dialog.Footer>
  </Dialog.Content>
</Dialog.Root>

The alternative — <Dialog title="..." description="..." footer={<>...</>} /> — looks tidier and dies on the first requirement that does not fit the props you imagined. A component with three or more ReactNode props is a compound component wearing a disguise.

When NOT to go compound: a Button with an icon does not need Button.Icon. Use compound parts when the arrangement varies, props when only the content varies.

Both can coexist: ship <Dialog> as a convenience wrapper over the parts for the 80% case, and export the parts for the rest. Make sure the convenience version is implemented using the parts, or the two drift.

Slots

For content in fixed positions, ReactNode props are right:

tsx
interface TextFieldProps {
  label: ReactNode;
  description?: ReactNode;
  errorMessage?: ReactNode;
  startAdornment?: ReactNode;   // "adornment"/"slot", not "icon" — people put buttons and badges there
  endAdornment?: ReactNode;
}

Type them ReactNode, not string. The moment someone needs <label>Name <Required/></label> a string type forces a fork.

Polymorphism

One convention per system (conventions.polymorphism in the brief). Whichever it is, the typing needs to preserve the target element's props:

tsx
// `render` (Base UI style)
<Button render={<a href="/pricing" />}>See pricing</Button>

// `asChild` (Radix style)
<Button asChild><a href="/pricing">See pricing</a></Button>

Do not invent a third. And prefer polymorphism over a href prop — the moment you add href you are reimplementing an anchor, and you will get target, rel, download and router integration wrong in that order.

TypeScript

tsx
import type { ComponentPropsWithRef, ReactNode } from 'react';
import type { VariantProps } from 'class-variance-authority';

export interface ButtonProps
  extends ComponentPropsWithRef<'button'>,          // inherit every native prop, including ref (React 19)
    VariantProps<typeof buttonVariants> {           // variant/size derived from the styles — one source
  loading?: boolean;
  startIcon?: ReactNode;
}
  • Extend the native element props. Consumers will need type="submit", form, aria-*, data-testid. Re-declaring a subset guarantees you missed one.
  • Derive variant types from the style definition so adding a variant to CVA cannot desync from the type.
  • Export every prop type. Consumers wrap your components; without the type they write any.
  • Use interface for public props (better error messages, declaration merging) and type for unions.

Encode invariants in the type rather than documenting them. An icon-only button that requires a label:

tsx
type ButtonProps = BaseProps &
  ({ children: ReactNode; 'aria-label'?: string } | { children?: never; 'aria-label': string });

Now the unlabelled icon button does not compile. That is worth more than a lint rule and infinitely more than a docs note.

Defaults

Every optional prop needs a sensible default so the zero-config case is the common case. <Button>Save</Button> should render the primary button at the default size. If a component cannot render without four props, the API is wrong.

Defaults belong in one place — the CVA/recipe defaultVariants or the destructure, not both.

Naming

DoDon'tWhy
variant, size, tonetype, style, kindtype and style collide with native props
isOpen / openvisible, shown, activeMatch the DOM/ARIA vocabulary
onValueChangeonUpdate, handleChangeon + noun + Change reads at the call site
disabledisDisabled, enabledMatch the native attribute; never invert a native boolean
startIcon / endIconleftIcon / rightIconLeft and right swap in RTL; start and end do not

Consistency beats individual elegance. If the system already uses isOpen, the next component uses isOpen.

Escape hatches

Every component needs exactly one deliberate way out, or people fork it:

  1. className passthrough, merged not replaced (cn(styles.base, className))
  2. ...rest spread onto the outer element
  3. ref forwarded
  4. Component-level CSS custom properties for the values most likely to need overriding

The failure mode is silent: a developer needs a 2px adjustment, finds no way in, copies the component into their feature folder, and now there are two buttons. You never hear about it.

The review checklist

Before a component is called done:

  • No boolean props that should be a union
  • Controlled and uncontrolled both work, onXChange fires in both
  • Extends native element props; ref reaches a real DOM node
  • className merged, ...rest spread, both verified by a test
  • Every variant × size × state combination renders (that is a test, not an eyeball)
  • Disabled state is not focusable-but-interactive, and communicates why when it can
  • Loading state preserves layout (no reflow when a spinner replaces a label)
  • Keyboard operable end to end; focus visible at 3:1
  • Works in both themes and at 200% browser zoom
  • Prop types exported
  • Registry entry filled in — props, a11y notes, do/don't, tokens consumed

Поширені запитання

Що робить навичка ШІ Component Api Design?

Use when designing or reviewing a component's props API - variants, sizes, controlled vs uncontrolled state, compound components, polymorphism, escape hatches, TypeScript prop types, ref forwarding, and naming. Triggers on "component API", "props design", "should this be a prop or a slot", "how do I type this component".

Навіщо використовувати Component Api Design у TypingMind?

Тому що ви встановлюєте її один раз і використовуєте з будь-якою моделлю. Component Api Design — це звичайний Markdown, а не код для конкретного постачальника, тому та сама навичка працює з GPT-5, Claude, Gemini, Grok або локальною моделлю. Ви можете змінити модель навіть посеред чату, і навичка продовжить працювати. TypingMind використовує ваші власні ключі API, тож ви платите безпосередньо постачальникам замість передплати за кожне місце користувача, а ваші навички й чати залишаються у вашому сховищі.

Як встановити Component Api Design у TypingMind?

Відкрийте в TypingMind Плагіни → Навички → Встановити з GitHub і вставте https://github.com/staple-lab/design-system-skills/tree/main/plugins/design-system/skills/component-api-design. TypingMind прочитає файл SKILL.md і встановить навичку, яку можна вмикати окремо для кожного чату.

Які моделі ШІ можуть використовувати Component Api Design?

Будь-яка модель, яку ви підключите в TypingMind. Навички ШІ — це звичайні інструкції у форматі Markdown, а не код для конкретного постачальника, тому GPT, Claude, Gemini, Grok і локальні моделі можуть завантажувати цю навичку, коли запит їй відповідає.

Зі скількома моделями ШІ можна використовувати Component Api Design?

Зі скількома забажаєте. У TypingMind ви можете використовувати Component Api Design із будь-якою моделлю, яка підтримує навички, зокрема з GPT, Claude, Gemini, Grok, DeepSeek, Mistral чи Llama. Для цього ви використовуєте власні ключі API.

Чи безкоштовна навичка ШІ Component Api Design?

Так. На GitHub цю навичку публікує staple-lab за ліцензією MIT. Ви платите лише своєму постачальнику ШІ за використані токени.

Що таке навички ШІ?

Навичка ШІ — це набір інструкцій для повторного використання, який навчає модель ШІ виконувати одне конкретне завдання. Він відповідає відкритому формату Agent Skills: файл SKILL.md із назвою та описом, а також скрипти, шаблони чи довідкові файли, які можуть знадобитися моделі. Модель читає інструкції лише тоді, коли ваш запит відповідає навичці, тому встановлена навичка нічого не коштує, доки її не використано.

Чим навички ШІ відрізняються від плагінів або серверів MCP?

Плагін або сервер MCP надає моделі нові інструменти, які вона може викликати, — код, який десь виконується й повертає результат. Натомість навичка ШІ дає моделі знання й пояснює порядок дій: як підійти до завдання, яких кроків дотримуватися та яким має бути якісний результат. Навички — це звичайний Markdown, тож їм не потрібні ні сервер, ні ключ API, ні середовище виконання, і вони працюють із будь-якою моделлю.

Усі

Створіть власний робочий простір зі ШІ вже зараз

Підпишіться на нашу розсилку, щоб дізнаватися про нові функції та майбутні розіграші 👇