@becket-ui/react 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Button.d.ts +15 -12
- package/dist/components/Button.d.ts.map +1 -1
- package/dist/components/Button.js.map +1 -1
- package/dist/components/Button.test.js +18 -1
- package/dist/components/Button.test.js.map +1 -1
- package/guides/building-with-becket.md +264 -0
- package/package.json +5 -4
|
@@ -1,24 +1,27 @@
|
|
|
1
|
-
import type { ElementType } from 'react';
|
|
1
|
+
import type { ComponentPropsWithRef, ComponentPropsWithoutRef, ElementType, ReactElement } from 'react';
|
|
2
2
|
type ButtonVisual = 'outline' | 'primary' | 'secondary' | 'neutral';
|
|
3
3
|
type ButtonSize = 'sm' | 'md';
|
|
4
4
|
type ButtonBorderRadius = 'none' | 'sm' | 'md' | 'lg' | 'xl' | 'full';
|
|
5
|
-
|
|
5
|
+
type ButtonOwnProps = {
|
|
6
6
|
visual?: ButtonVisual;
|
|
7
7
|
size?: ButtonSize;
|
|
8
8
|
borderRadius?: ButtonBorderRadius;
|
|
9
9
|
withGradient?: boolean;
|
|
10
10
|
/** Stretch to the parent width. Default is token `sizes.field` (12.5rem). */
|
|
11
11
|
fullWidth?: boolean;
|
|
12
|
-
as?: ElementType;
|
|
13
12
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Props follow the rendered element: `<Button as="a" href="/docs">` accepts anchor props,
|
|
15
|
+
* and plain `<Button>` accepts button props only.
|
|
16
|
+
*/
|
|
17
|
+
export type ButtonProps<T extends ElementType = 'button'> = ButtonOwnProps & {
|
|
18
|
+
as?: T;
|
|
19
|
+
} & Omit<ComponentPropsWithoutRef<T>, keyof ButtonOwnProps | 'as'>;
|
|
20
|
+
type PolymorphicButton = (<T extends ElementType = 'button'>(props: ButtonProps<T> & {
|
|
21
|
+
ref?: ComponentPropsWithRef<T>['ref'];
|
|
22
|
+
}) => ReactElement | null) & {
|
|
23
|
+
displayName?: string;
|
|
24
|
+
};
|
|
25
|
+
export declare const Button: PolymorphicButton;
|
|
23
26
|
export {};
|
|
24
27
|
//# sourceMappingURL=Button.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.d.ts","sourceRoot":"","sources":["../../src/components/Button.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Button.d.ts","sourceRoot":"","sources":["../../src/components/Button.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAGxG,KAAK,YAAY,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAAC;AACpE,KAAK,UAAU,GAAG,IAAI,GAAG,IAAI,CAAC;AAC9B,KAAK,kBAAkB,GAAG,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,MAAM,CAAC;AAStE,KAAK,cAAc,GAAG;IACpB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAClC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,6EAA6E;IAC7E,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,WAAW,GAAG,QAAQ,IAAI,cAAc,GAAG;IAC3E,EAAE,CAAC,EAAE,CAAC,CAAC;CACR,GAAG,IAAI,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE,MAAM,cAAc,GAAG,IAAI,CAAC,CAAC;AAEnE,KAAK,iBAAiB,GAAG,CAAC,CAAC,CAAC,SAAS,WAAW,GAAG,QAAQ,EACzD,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,qBAAqB,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;CAAE,KAC9D,YAAY,GAAG,IAAI,CAAC,GAAG;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAOrD,eAAO,MAAM,MAAM,EA+Bd,iBAAiB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/Button.tsx"],"sourcesContent":["import { forwardRef } from 'react';\nimport type { ElementType } from 'react';\nimport { button } from '@becket-ui/tokens/recipes';\n\ntype ButtonVisual = 'outline' | 'primary' | 'secondary' | 'neutral';\ntype ButtonSize = 'sm' | 'md';\ntype ButtonBorderRadius = 'none' | 'sm' | 'md' | 'lg' | 'xl' | 'full';\n\nconst VISUAL_TO_RECIPE: Record<ButtonVisual, ButtonVisual> = {\n primary: 'primary',\n secondary: 'secondary',\n neutral: 'neutral',\n outline: 'outline',\n};\n\
|
|
1
|
+
{"version":3,"sources":["../../src/components/Button.tsx"],"sourcesContent":["import { forwardRef } from 'react';\nimport type { ComponentPropsWithRef, ComponentPropsWithoutRef, ElementType, ReactElement } from 'react';\nimport { button } from '@becket-ui/tokens/recipes';\n\ntype ButtonVisual = 'outline' | 'primary' | 'secondary' | 'neutral';\ntype ButtonSize = 'sm' | 'md';\ntype ButtonBorderRadius = 'none' | 'sm' | 'md' | 'lg' | 'xl' | 'full';\n\nconst VISUAL_TO_RECIPE: Record<ButtonVisual, ButtonVisual> = {\n primary: 'primary',\n secondary: 'secondary',\n neutral: 'neutral',\n outline: 'outline',\n};\n\ntype ButtonOwnProps = {\n visual?: ButtonVisual;\n size?: ButtonSize;\n borderRadius?: ButtonBorderRadius;\n withGradient?: boolean;\n /** Stretch to the parent width. Default is token `sizes.field` (12.5rem). */\n fullWidth?: boolean;\n};\n\n/**\n * Props follow the rendered element: `<Button as=\"a\" href=\"/docs\">` accepts anchor props,\n * and plain `<Button>` accepts button props only.\n */\nexport type ButtonProps<T extends ElementType = 'button'> = ButtonOwnProps & {\n as?: T;\n} & Omit<ComponentPropsWithoutRef<T>, keyof ButtonOwnProps | 'as'>;\n\ntype PolymorphicButton = (<T extends ElementType = 'button'>(\n props: ButtonProps<T> & { ref?: ComponentPropsWithRef<T>['ref'] },\n) => ReactElement | null) & { displayName?: string };\n\nfunction mergeClassName(...classes: (string | undefined)[]): string {\n return classes.filter(Boolean).join(' ');\n}\n\n// forwardRef can't express a generic component; the cast restores the per-element prop types.\nexport const Button = forwardRef<HTMLElement, ButtonOwnProps & { as?: ElementType; className?: string }>(\n (\n {\n visual = 'outline',\n size = 'md',\n borderRadius = 'md',\n withGradient = false,\n fullWidth = false,\n as: ButtonComponent = 'button',\n className,\n ...props\n },\n ref,\n ) => {\n const recipeClassName = (button)({\n visual: VISUAL_TO_RECIPE[visual],\n size,\n borderRadius,\n withGradient,\n fullWidth,\n });\n\n return (\n <ButtonComponent\n ref={ref}\n {...(ButtonComponent === 'button' ? { type: 'button' as const } : {})}\n {...props}\n className={mergeClassName(recipeClassName, className)}\n />\n );\n },\n) as PolymorphicButton;\n\nButton.displayName = 'Button';\n"],"mappings":"AAgEM;AAhEN,SAAS,kBAAkB;AAE3B,SAAS,cAAc;AAMvB,MAAM,mBAAuD;AAAA,EAC3D,SAAS;AAAA,EACT,WAAW;AAAA,EACX,SAAS;AAAA,EACT,SAAS;AACX;AAuBA,SAAS,kBAAkB,SAAyC;AAClE,SAAO,QAAQ,OAAO,OAAO,EAAE,KAAK,GAAG;AACzC;AAGO,MAAM,SAAS;AAAA,EACpB,CACE;AAAA,IACE,SAAS;AAAA,IACT,OAAO;AAAA,IACP,eAAe;AAAA,IACf,eAAe;AAAA,IACf,YAAY;AAAA,IACZ,IAAI,kBAAkB;AAAA,IACtB;AAAA,IACA,GAAG;AAAA,EACL,GACA,QACG;AACH,UAAM,kBAAmB,OAAQ;AAAA,MAC/B,QAAQ,iBAAiB,MAAM;AAAA,MAC/B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACC,GAAI,oBAAoB,WAAW,EAAE,MAAM,SAAkB,IAAI,CAAC;AAAA,QAClE,GAAG;AAAA,QACJ,WAAW,eAAe,iBAAiB,SAAS;AAAA;AAAA,IACtD;AAAA,EAEJ;AACF;AAEA,OAAO,cAAc;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { describe, expect, it, vi } from "vitest";
|
|
3
3
|
import { render, screen } from "@testing-library/react";
|
|
4
4
|
import userEvent from "@testing-library/user-event";
|
|
@@ -19,6 +19,23 @@ describe("Button", () => {
|
|
|
19
19
|
);
|
|
20
20
|
expect(screen.getByRole("link", { name: "Save" }).hasAttribute("type")).toBe(false);
|
|
21
21
|
});
|
|
22
|
+
it('renders a link with anchor props when as="a"', () => {
|
|
23
|
+
render(
|
|
24
|
+
/* @__PURE__ */ jsx(Button, { as: "a", href: "https://example.com", target: "_blank", rel: "noopener noreferrer", visual: "primary", children: "Get started" })
|
|
25
|
+
);
|
|
26
|
+
const link = screen.getByRole("link", { name: "Get started" });
|
|
27
|
+
expect(link.getAttribute("href")).toBe("https://example.com");
|
|
28
|
+
expect(link.getAttribute("target")).toBe("_blank");
|
|
29
|
+
expect(link.className).toMatch(/beckui--button/);
|
|
30
|
+
});
|
|
31
|
+
it("types props by the rendered element", () => {
|
|
32
|
+
const typed = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
33
|
+
/* @__PURE__ */ jsx(Button, { as: "a", href: "/docs", download: true, children: "Docs" }),
|
|
34
|
+
/* @__PURE__ */ jsx(Button, { href: "/docs", children: "Docs" }),
|
|
35
|
+
/* @__PURE__ */ jsx(Button, { as: "a", href: "/docs", disabled: true, children: "Docs" })
|
|
36
|
+
] });
|
|
37
|
+
expect(typed).toBeTruthy();
|
|
38
|
+
});
|
|
22
39
|
it("does not submit a wrapping form", async () => {
|
|
23
40
|
const onSubmit = vi.fn((event) => event.preventDefault());
|
|
24
41
|
const user = userEvent.setup();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/Button.test.tsx"],"sourcesContent":["import { describe, expect, it, vi } from 'vitest';\nimport { render, screen } from '@testing-library/react';\nimport userEvent from '@testing-library/user-event';\nimport { assertNoAxeViolations } from '@becket-ui/a11y';\n\nimport { Button } from './Button';\n\ndescribe('Button', () => {\n it('defaults to type=\"button\"', () => {\n render(<Button>Save</Button>);\n expect(screen.getByRole('button', { name: 'Save' }).getAttribute('type')).toBe('button');\n });\n\n it('keeps an explicit type=\"submit\"', () => {\n render(<Button type=\"submit\">Send</Button>);\n expect(screen.getByRole('button', { name: 'Send' }).getAttribute('type')).toBe('submit');\n });\n\n it('does not set type when as is not button', () => {\n render(\n <Button as=\"a\" href=\"#save\">\n Save\n </Button>,\n );\n expect(screen.getByRole('link', { name: 'Save' }).hasAttribute('type')).toBe(false);\n });\n\n it('does not submit a wrapping form', async () => {\n const onSubmit = vi.fn((event: SubmitEvent) => event.preventDefault());\n const user = userEvent.setup();\n render(\n <form\n onSubmit={(event) => {\n event.preventDefault();\n onSubmit(event.nativeEvent);\n }}\n >\n <Button>Confirm</Button>\n </form>,\n );\n\n await user.click(screen.getByRole('button', { name: 'Confirm' }));\n expect(onSubmit).not.toHaveBeenCalled();\n });\n\n it('has no axe violations on a named button', async () => {\n const { container } = render(<Button>Save</Button>);\n await assertNoAxeViolations(container);\n });\n});\n"],"mappings":"AASW;AATX,SAAS,UAAU,QAAQ,IAAI,UAAU;AACzC,SAAS,QAAQ,cAAc;AAC/B,OAAO,eAAe;AACtB,SAAS,6BAA6B;AAEtC,SAAS,cAAc;AAEvB,SAAS,UAAU,MAAM;AACvB,KAAG,6BAA6B,MAAM;AACpC,WAAO,oBAAC,UAAO,kBAAI,CAAS;AAC5B,WAAO,OAAO,UAAU,UAAU,EAAE,MAAM,OAAO,CAAC,EAAE,aAAa,MAAM,CAAC,EAAE,KAAK,QAAQ;AAAA,EACzF,CAAC;AAED,KAAG,mCAAmC,MAAM;AAC1C,WAAO,oBAAC,UAAO,MAAK,UAAS,kBAAI,CAAS;AAC1C,WAAO,OAAO,UAAU,UAAU,EAAE,MAAM,OAAO,CAAC,EAAE,aAAa,MAAM,CAAC,EAAE,KAAK,QAAQ;AAAA,EACzF,CAAC;AAED,KAAG,2CAA2C,MAAM;AAClD;AAAA,MACE,oBAAC,UAAO,IAAG,KAAI,MAAK,SAAQ,kBAE5B;AAAA,IACF;AACA,WAAO,OAAO,UAAU,QAAQ,EAAE,MAAM,OAAO,CAAC,EAAE,aAAa,MAAM,CAAC,EAAE,KAAK,KAAK;AAAA,EACpF,CAAC;AAED,KAAG,mCAAmC,YAAY;AAChD,UAAM,WAAW,GAAG,GAAG,CAAC,UAAuB,MAAM,eAAe,CAAC;AACrE,UAAM,OAAO,UAAU,MAAM;AAC7B;AAAA,MACE;AAAA,QAAC;AAAA;AAAA,UACC,UAAU,CAAC,UAAU;AACnB,kBAAM,eAAe;AACrB,qBAAS,MAAM,WAAW;AAAA,UAC5B;AAAA,UAEA,8BAAC,UAAO,qBAAO;AAAA;AAAA,MACjB;AAAA,IACF;AAEA,UAAM,KAAK,MAAM,OAAO,UAAU,UAAU,EAAE,MAAM,UAAU,CAAC,CAAC;AAChE,WAAO,QAAQ,EAAE,IAAI,iBAAiB;AAAA,EACxC,CAAC;AAED,KAAG,2CAA2C,YAAY;AACxD,UAAM,EAAE,UAAU,IAAI,OAAO,oBAAC,UAAO,kBAAI,CAAS;AAClD,UAAM,sBAAsB,SAAS;AAAA,EACvC,CAAC;AACH,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/components/Button.test.tsx"],"sourcesContent":["import { describe, expect, it, vi } from 'vitest';\nimport { render, screen } from '@testing-library/react';\nimport userEvent from '@testing-library/user-event';\nimport { assertNoAxeViolations } from '@becket-ui/a11y';\n\nimport { Button } from './Button';\n\ndescribe('Button', () => {\n it('defaults to type=\"button\"', () => {\n render(<Button>Save</Button>);\n expect(screen.getByRole('button', { name: 'Save' }).getAttribute('type')).toBe('button');\n });\n\n it('keeps an explicit type=\"submit\"', () => {\n render(<Button type=\"submit\">Send</Button>);\n expect(screen.getByRole('button', { name: 'Send' }).getAttribute('type')).toBe('submit');\n });\n\n it('does not set type when as is not button', () => {\n render(\n <Button as=\"a\" href=\"#save\">\n Save\n </Button>,\n );\n expect(screen.getByRole('link', { name: 'Save' }).hasAttribute('type')).toBe(false);\n });\n\n it('renders a link with anchor props when as=\"a\"', () => {\n render(\n <Button as=\"a\" href=\"https://example.com\" target=\"_blank\" rel=\"noopener noreferrer\" visual=\"primary\">\n Get started\n </Button>,\n );\n const link = screen.getByRole('link', { name: 'Get started' });\n expect(link.getAttribute('href')).toBe('https://example.com');\n expect(link.getAttribute('target')).toBe('_blank');\n expect(link.className).toMatch(/beckui--button/);\n });\n\n it('types props by the rendered element', () => {\n // Compile-time checks: these lines fail `tsc` if the polymorphic types regress.\n const typed = (\n <>\n <Button as=\"a\" href=\"/docs\" download>\n Docs\n </Button>\n {/* @ts-expect-error href is not a button prop */}\n <Button href=\"/docs\">Docs</Button>\n {/* @ts-expect-error disabled is not an anchor prop */}\n <Button as=\"a\" href=\"/docs\" disabled>\n Docs\n </Button>\n </>\n );\n expect(typed).toBeTruthy();\n });\n\n it('does not submit a wrapping form', async () => {\n const onSubmit = vi.fn((event: SubmitEvent) => event.preventDefault());\n const user = userEvent.setup();\n render(\n <form\n onSubmit={(event) => {\n event.preventDefault();\n onSubmit(event.nativeEvent);\n }}\n >\n <Button>Confirm</Button>\n </form>,\n );\n\n await user.click(screen.getByRole('button', { name: 'Confirm' }));\n expect(onSubmit).not.toHaveBeenCalled();\n });\n\n it('has no axe violations on a named button', async () => {\n const { container } = render(<Button>Save</Button>);\n await assertNoAxeViolations(container);\n });\n});\n"],"mappings":"AASW,SAiCL,UAjCK,KAiCL,YAjCK;AATX,SAAS,UAAU,QAAQ,IAAI,UAAU;AACzC,SAAS,QAAQ,cAAc;AAC/B,OAAO,eAAe;AACtB,SAAS,6BAA6B;AAEtC,SAAS,cAAc;AAEvB,SAAS,UAAU,MAAM;AACvB,KAAG,6BAA6B,MAAM;AACpC,WAAO,oBAAC,UAAO,kBAAI,CAAS;AAC5B,WAAO,OAAO,UAAU,UAAU,EAAE,MAAM,OAAO,CAAC,EAAE,aAAa,MAAM,CAAC,EAAE,KAAK,QAAQ;AAAA,EACzF,CAAC;AAED,KAAG,mCAAmC,MAAM;AAC1C,WAAO,oBAAC,UAAO,MAAK,UAAS,kBAAI,CAAS;AAC1C,WAAO,OAAO,UAAU,UAAU,EAAE,MAAM,OAAO,CAAC,EAAE,aAAa,MAAM,CAAC,EAAE,KAAK,QAAQ;AAAA,EACzF,CAAC;AAED,KAAG,2CAA2C,MAAM;AAClD;AAAA,MACE,oBAAC,UAAO,IAAG,KAAI,MAAK,SAAQ,kBAE5B;AAAA,IACF;AACA,WAAO,OAAO,UAAU,QAAQ,EAAE,MAAM,OAAO,CAAC,EAAE,aAAa,MAAM,CAAC,EAAE,KAAK,KAAK;AAAA,EACpF,CAAC;AAED,KAAG,gDAAgD,MAAM;AACvD;AAAA,MACE,oBAAC,UAAO,IAAG,KAAI,MAAK,uBAAsB,QAAO,UAAS,KAAI,uBAAsB,QAAO,WAAU,yBAErG;AAAA,IACF;AACA,UAAM,OAAO,OAAO,UAAU,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7D,WAAO,KAAK,aAAa,MAAM,CAAC,EAAE,KAAK,qBAAqB;AAC5D,WAAO,KAAK,aAAa,QAAQ,CAAC,EAAE,KAAK,QAAQ;AACjD,WAAO,KAAK,SAAS,EAAE,QAAQ,gBAAgB;AAAA,EACjD,CAAC;AAED,KAAG,uCAAuC,MAAM;AAE9C,UAAM,QACJ,iCACE;AAAA,0BAAC,UAAO,IAAG,KAAI,MAAK,SAAQ,UAAQ,MAAC,kBAErC;AAAA,MAEA,oBAAC,UAAO,MAAK,SAAQ,kBAAI;AAAA,MAEzB,oBAAC,UAAO,IAAG,KAAI,MAAK,SAAQ,UAAQ,MAAC,kBAErC;AAAA,OACF;AAEF,WAAO,KAAK,EAAE,WAAW;AAAA,EAC3B,CAAC;AAED,KAAG,mCAAmC,YAAY;AAChD,UAAM,WAAW,GAAG,GAAG,CAAC,UAAuB,MAAM,eAAe,CAAC;AACrE,UAAM,OAAO,UAAU,MAAM;AAC7B;AAAA,MACE;AAAA,QAAC;AAAA;AAAA,UACC,UAAU,CAAC,UAAU;AACnB,kBAAM,eAAe;AACrB,qBAAS,MAAM,WAAW;AAAA,UAC5B;AAAA,UAEA,8BAAC,UAAO,qBAAO;AAAA;AAAA,MACjB;AAAA,IACF;AAEA,UAAM,KAAK,MAAM,OAAO,UAAU,UAAU,EAAE,MAAM,UAAU,CAAC,CAAC;AAChE,WAAO,QAAQ,EAAE,IAAI,iBAAiB;AAAA,EACxC,CAAC;AAED,KAAG,2CAA2C,YAAY;AACxD,UAAM,EAAE,UAAU,IAAI,OAAO,oBAAC,UAAO,kBAAI,CAAS;AAClD,UAAM,sBAAsB,SAAS;AAAA,EACvC,CAAC;AACH,CAAC;","names":[]}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
# Writing app code with Becket UI
|
|
2
|
+
|
|
3
|
+
How to write React screens with `@becket-ui/react`. It's written for people and for agents: Claude
|
|
4
|
+
Design while it builds a design, Claude Code when it turns a design into app code, and any coding
|
|
5
|
+
agent connected to the Becket MCP. If you follow this guide, the code reads top to bottom, uses
|
|
6
|
+
Becket for everything Becket can do, and keeps working in dark and light themes.
|
|
7
|
+
|
|
8
|
+
Each rule says **Must** (required) or **Prefer / Avoid** (the default; deviate with a reason in a
|
|
9
|
+
comment).
|
|
10
|
+
|
|
11
|
+
## 1. Setup, once per app
|
|
12
|
+
|
|
13
|
+
- Install `@becket-ui/react` and `@becket-ui/tokens`. Import `@becket-ui/tokens/index.css` **once**,
|
|
14
|
+
at the app entry.
|
|
15
|
+
- The theme lives on `<html data-theme="dark|light">` (dark is the default). Set it at the app root,
|
|
16
|
+
never inside a screen. There is **no provider** and no theme wrapper.
|
|
17
|
+
- `index.css` already paints the page background, text color and font from the theme. Don't repeat
|
|
18
|
+
that on a wrapper `div`.
|
|
19
|
+
|
|
20
|
+
## 2. Must use a Becket component when one exists
|
|
21
|
+
|
|
22
|
+
Raw elements with inline styles are the most common mistake. Use this table:
|
|
23
|
+
|
|
24
|
+
| Instead of | Use |
|
|
25
|
+
| --------------------------------------------------- | ------------------------------------------------------------------------- |
|
|
26
|
+
| `div` with `display: flex; flex-direction: column` | `VStack` / `Stack` |
|
|
27
|
+
| `div` with `display: flex` (row) | `HStack`, or `Flex` for wrap, grow and basis |
|
|
28
|
+
| `div` with `display: grid` | `SimpleGrid columns={{ base: 1, md: 2 }}` |
|
|
29
|
+
| `h1`–`h6` with font styles | `Heading as="h1" size="2xl"` |
|
|
30
|
+
| `p` / `span` with font size or color | `Text fontSize="sm" color="muted"` |
|
|
31
|
+
| bold `span` | `Text as="strong"` |
|
|
32
|
+
| `hr`, or a 1px `div` | `Separator` (`orientation="vertical"` inside a row) |
|
|
33
|
+
| `button` | `Button visual="primary\|secondary\|neutral\|outline"` |
|
|
34
|
+
| `input` + `label` | `Field` + `FieldLabel` + `FieldControl`, or `TextField label` |
|
|
35
|
+
| `select` / `textarea` | `Select` / `Textarea` (or `FieldSelect` / `FieldTextarea` inside `Field`) |
|
|
36
|
+
| checkbox / radio / toggle `input` | `Checkbox`, `RadioGroup` + `Radio`, `Switch` |
|
|
37
|
+
| `table`, `tr`, `td` | `Table`, `Thead`, `Tbody`, `Tr`, `Th`, `Td` |
|
|
38
|
+
| panel `div` with border and padding | `Card` + `CardHeader` / `CardBody` / `CardFooter` |
|
|
39
|
+
| pill `span` | `Tag` (label) or `Badge` (count or status) |
|
|
40
|
+
| `a` | `Link` |
|
|
41
|
+
| `a` styled as a button (call to action) | `Button as="a" href="…"` (anchor props are typed) |
|
|
42
|
+
| custom modal, side panel, dropdown, tabs or tooltip | `Dialog`, `Drawer`, `Menu`, `Tabs`, `Tooltip` |
|
|
43
|
+
|
|
44
|
+
Raw elements are fine for semantics Becket doesn't cover (`form`, `main`, `nav`, `section`,
|
|
45
|
+
`ul`/`li`). Render them through a layout component's `as` prop when they also lay things out:
|
|
46
|
+
`<VStack as="form" gap="md">`.
|
|
47
|
+
|
|
48
|
+
**Known gaps** (until these ship, an inline `style` with tokens is allowed, with a `TODO` naming the
|
|
49
|
+
ticket):
|
|
50
|
+
|
|
51
|
+
- Page width, padding and centering: no `Container` yet (MAV-90).
|
|
52
|
+
- Font weight on `Text`: no `weight` prop yet (MAV-106). Use `Text as="strong"` for bold.
|
|
53
|
+
- Status colors on `Badge` and `Tag`: no `success` / `warning` / `danger` visuals yet (MAV-107).
|
|
54
|
+
Don't use a brand visual (`primary`, `secondary`) to mean a status.
|
|
55
|
+
|
|
56
|
+
## 3. Prefer props, then tokens. Never classes, never literals
|
|
57
|
+
|
|
58
|
+
Style with component props, written inline where the component is used. That's Becket's design
|
|
59
|
+
language: `gap`, `align`, `justify`, `visual`, `size`, `invalid`, `columns`.
|
|
60
|
+
|
|
61
|
+
- **Spacing:** semantic `gap="xs|sm|md|lg|xl"` (or the Fibonacci steps `1 2 3 5 8 13 21 34`). Never
|
|
62
|
+
pixel numbers.
|
|
63
|
+
- **When you need your own CSS** (a known gap above, or a one-off like `minWidth: 0`), use token
|
|
64
|
+
variables: `var(--beckui--colors-muted)`, `var(--beckui--spacing-lg)`, `var(--beckui--sizes-4xl)`,
|
|
65
|
+
`var(--beckui--radii-md)`. Never hex, `rgb()`, or raw pixel values for spacing and color.
|
|
66
|
+
- **Must not** write or copy `.beckui--*` class names. They're generated, not API.
|
|
67
|
+
- **Avoid** named styled wrappers, CSS files per screen, or style objects defined away from the
|
|
68
|
+
element. A reader shouldn't have to look anything up to see how an element looks.
|
|
69
|
+
- **Colors carry meaning:** `primary` (yellow), `secondary` (sage) and `tertiary` (amber) are brand
|
|
70
|
+
identity; `danger`, `warning` and `success` are status only.
|
|
71
|
+
|
|
72
|
+
## 4. Avoid hasty abstraction: inline first, extract on the third copy
|
|
73
|
+
|
|
74
|
+
Write markup inline. Extract a local component only when the same markup appears **three times** in
|
|
75
|
+
the same feature. Then:
|
|
76
|
+
|
|
77
|
+
- Build it only from Becket components and tokens; a helper made of raw `div`s and `span`s is the
|
|
78
|
+
same mistake, just moved.
|
|
79
|
+
- Keep it in the same file, or next to it, until a second feature needs it.
|
|
80
|
+
- Name it for what it shows (`MemberName`), not how (`TitleCell`).
|
|
81
|
+
|
|
82
|
+
## 5. Prefer inversion of control: compose, don't configure
|
|
83
|
+
|
|
84
|
+
Pass content in instead of adding flags: `children`, element props (`actions={<Button>…</Button>}`),
|
|
85
|
+
and Becket's compound parts (`CardHeader` / `CardBody` / `CardFooter`, `DialogHeader` /
|
|
86
|
+
`DialogFooter`, `TabList` / `Tab` / `TabPanel`). A screen component with `showX`, `isY` and
|
|
87
|
+
`variantZ` booleans is a sign to invert.
|
|
88
|
+
|
|
89
|
+
## 6. Prefer native HTML and zero JavaScript
|
|
90
|
+
|
|
91
|
+
Becket is native-first. Prefer the components and props that work without client JavaScript.
|
|
92
|
+
Interactive ones (`Tabs`, `Menu`, `Tooltip`, controlled `Dialog` / `Drawer`) ship JS. Use them when
|
|
93
|
+
the interaction needs them, not for static content. Put `'use client'` only on the leaf component
|
|
94
|
+
that holds state or handlers, never on a whole page or barrel file.
|
|
95
|
+
|
|
96
|
+
## 7. State and effects
|
|
97
|
+
|
|
98
|
+
- **Derive, don't sync:** compute values from props and state during render
|
|
99
|
+
(`const activeCount = members.filter((m) => m.isActive).length`). Don't mirror them into state
|
|
100
|
+
with an effect.
|
|
101
|
+
- **Effects** are only for syncing with something outside React (subscriptions, timers, storage).
|
|
102
|
+
Theme and analytics belong at the app root.
|
|
103
|
+
- **Must not mutate** state, props or shared constants. Create new values with spread, `map`,
|
|
104
|
+
`filter` or `toSorted()`.
|
|
105
|
+
- Keep each piece of state in one place, as low in the tree as it can live.
|
|
106
|
+
|
|
107
|
+
## 8. Accessibility (WCAG 2.2 AA)
|
|
108
|
+
|
|
109
|
+
- Every control has a name: a visible label (`TextField label`, `FieldLabel`, `Switch label`) or
|
|
110
|
+
`aria-label` when the label is visual only, such as a `Switch` in a table row:
|
|
111
|
+
``aria-label={`Access for ${member.name}`}``.
|
|
112
|
+
- One `h1` per page. Headings follow the document outline (`Heading as="h2"` for sections).
|
|
113
|
+
- Use `Button` for actions and `Link` for navigation, never a clickable `div`.
|
|
114
|
+
- Don't rely on color alone for status: keep the text ("Active", "Invited").
|
|
115
|
+
|
|
116
|
+
## 9. TypeScript and naming
|
|
117
|
+
|
|
118
|
+
- Type props explicitly (`type MemberTableProps = { … }`). Let TypeScript infer locals. Must not use
|
|
119
|
+
`any`.
|
|
120
|
+
- Use string unions and `as const` data instead of `enum`:
|
|
121
|
+
`const ROLES = ['owner', 'admin', 'member'] as const`.
|
|
122
|
+
- Use stable keys from data (`key={member.id}`), never the array index for lists that change.
|
|
123
|
+
- Callback props are `onX`; handlers inside are `handleX`. Booleans start with `is`, `has`, `should`
|
|
124
|
+
or `can`.
|
|
125
|
+
- Functions say what they do (`selectActiveMembers`, `formatSeatCount`), not `getX`. Keep
|
|
126
|
+
initialisms in one case (`userID`, `inviteURL`).
|
|
127
|
+
- Sort imports: third-party (React, then `@becket-ui/react`), then absolute app modules, then
|
|
128
|
+
relative.
|
|
129
|
+
- Comment **why**, not what. A `TODO` names its ticket: `// TODO (MAV-90): use Container`.
|
|
130
|
+
|
|
131
|
+
## 10. Example: a settings screen
|
|
132
|
+
|
|
133
|
+
### Avoid
|
|
134
|
+
|
|
135
|
+
From a real Claude Design handoff. It uses Becket's Tabs, Table and Switch correctly, but builds
|
|
136
|
+
everything else from raw markup:
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
<div style={{ minHeight: '100vh', background: 'var(--beckui--colors-background)', padding: '48px 24px' }}>
|
|
140
|
+
<div style={{ maxWidth: 880, display: 'flex', flexDirection: 'column', gap: 28 }}>
|
|
141
|
+
<h1 style={{ margin: 0, fontSize: 'var(--beckui--font-sizes-2xl)', fontWeight: 600 }}>Workspace settings</h1>
|
|
142
|
+
<p style={{ margin: 0, color: 'var(--beckui--colors-muted)' }}>Manage how the workspace behaves.</p>
|
|
143
|
+
{PREFS.map((pref, i) => (
|
|
144
|
+
<div key={pref.k}>
|
|
145
|
+
<div style={{ display: 'flex', justifyContent: 'space-between', gap: 24, padding: '16px 0' }}>
|
|
146
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
|
|
147
|
+
<span style={{ fontWeight: 600 }}>{pref.title}</span>
|
|
148
|
+
<span style={{ color: 'var(--beckui--colors-muted)' }}>{pref.desc}</span>
|
|
149
|
+
</div>
|
|
150
|
+
<Switch checked={prefs[pref.k]} onCheckedChange={…} aria-label={pref.title} />
|
|
151
|
+
</div>
|
|
152
|
+
{i < PREFS.length - 1 && <div style={{ height: 1, background: 'var(--beckui--colors-border)' }} />}
|
|
153
|
+
</div>
|
|
154
|
+
))}
|
|
155
|
+
</div>
|
|
156
|
+
</div>
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
What's wrong:
|
|
160
|
+
|
|
161
|
+
- Flex `div`s instead of `VStack` / `HStack`.
|
|
162
|
+
- `h1` / `p` / `span` instead of `Heading` / `Text`.
|
|
163
|
+
- A 1px `div` instead of `Separator`.
|
|
164
|
+
- Pixel gaps.
|
|
165
|
+
- A background the CSS already paints.
|
|
166
|
+
- A cryptic data key (`k`).
|
|
167
|
+
|
|
168
|
+
### Prefer
|
|
169
|
+
|
|
170
|
+
```tsx
|
|
171
|
+
import { useState } from "react";
|
|
172
|
+
import { Card, CardBody, Heading, HStack, Separator, Switch, Text, VStack } from "@becket-ui/react";
|
|
173
|
+
|
|
174
|
+
const PREFERENCES = [
|
|
175
|
+
{
|
|
176
|
+
id: "public",
|
|
177
|
+
title: "Public workspace",
|
|
178
|
+
description: "Anyone with the link can request to join.",
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
id: "guests",
|
|
182
|
+
title: "Allow guests",
|
|
183
|
+
description: "Invite people outside your domain with limited access.",
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
id: "sso",
|
|
187
|
+
title: "Require SSO",
|
|
188
|
+
description: "Members sign in through your identity provider.",
|
|
189
|
+
},
|
|
190
|
+
] as const;
|
|
191
|
+
|
|
192
|
+
type PreferenceID = (typeof PREFERENCES)[number]["id"];
|
|
193
|
+
|
|
194
|
+
export function WorkspaceSettings() {
|
|
195
|
+
const [enabled, setEnabled] = useState<Record<PreferenceID, boolean>>({
|
|
196
|
+
public: false,
|
|
197
|
+
guests: true,
|
|
198
|
+
sso: true,
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
return (
|
|
202
|
+
// TODO (MAV-90): replace with Container once it ships.
|
|
203
|
+
<div
|
|
204
|
+
style={{
|
|
205
|
+
maxWidth: "var(--beckui--sizes-4xl)",
|
|
206
|
+
marginInline: "auto",
|
|
207
|
+
padding: "var(--beckui--spacing-xl)",
|
|
208
|
+
}}
|
|
209
|
+
>
|
|
210
|
+
<VStack gap="xl">
|
|
211
|
+
<VStack gap="xs">
|
|
212
|
+
<Heading as="h1" size="2xl">
|
|
213
|
+
Workspace settings
|
|
214
|
+
</Heading>
|
|
215
|
+
<Text fontSize="sm" color="muted">
|
|
216
|
+
Manage how the workspace behaves for everyone in it.
|
|
217
|
+
</Text>
|
|
218
|
+
</VStack>
|
|
219
|
+
|
|
220
|
+
<Card visual="outline" fullWidth>
|
|
221
|
+
<CardBody>
|
|
222
|
+
<VStack gap="md">
|
|
223
|
+
{PREFERENCES.map((preference, index) => (
|
|
224
|
+
<VStack key={preference.id} gap="md">
|
|
225
|
+
{index > 0 && <Separator />}
|
|
226
|
+
<HStack justify="between" align="center" gap="lg">
|
|
227
|
+
<VStack gap="xs">
|
|
228
|
+
<Text as="strong" fontSize="sm">
|
|
229
|
+
{preference.title}
|
|
230
|
+
</Text>
|
|
231
|
+
<Text fontSize="sm" color="muted">
|
|
232
|
+
{preference.description}
|
|
233
|
+
</Text>
|
|
234
|
+
</VStack>
|
|
235
|
+
<Switch
|
|
236
|
+
aria-label={preference.title}
|
|
237
|
+
checked={enabled[preference.id]}
|
|
238
|
+
onCheckedChange={(isOn) =>
|
|
239
|
+
setEnabled((current) => ({ ...current, [preference.id]: isOn }))
|
|
240
|
+
}
|
|
241
|
+
/>
|
|
242
|
+
</HStack>
|
|
243
|
+
</VStack>
|
|
244
|
+
))}
|
|
245
|
+
</VStack>
|
|
246
|
+
</CardBody>
|
|
247
|
+
</Card>
|
|
248
|
+
</VStack>
|
|
249
|
+
</div>
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
The only raw element left is the page wrapper. It's a known gap with a ticket, and it uses token
|
|
255
|
+
values.
|
|
256
|
+
|
|
257
|
+
## 11. Before you finish
|
|
258
|
+
|
|
259
|
+
- [ ] No flex or grid `div`s, no `h1`–`h6` / `p` / `span` with font styles, no 1px divider `div`s.
|
|
260
|
+
- [ ] No hex or `rgb()` colors, no pixel spacing, no `.beckui--*` classes.
|
|
261
|
+
- [ ] Every inline `style` uses tokens and has a `TODO (MAV-…)` naming the gap it covers.
|
|
262
|
+
- [ ] Local helpers exist only for markup used three or more times, and are built from Becket.
|
|
263
|
+
- [ ] Every control has an accessible name; status isn't shown by color alone.
|
|
264
|
+
- [ ] Theme is set at the app root; `index.css` is imported once.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@becket-ui/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Becket React component library",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"types": "./dist/index.d.ts",
|
|
25
25
|
"sideEffects": false,
|
|
26
26
|
"files": [
|
|
27
|
-
"dist"
|
|
27
|
+
"dist",
|
|
28
|
+
"guides"
|
|
28
29
|
],
|
|
29
30
|
"exports": {
|
|
30
31
|
".": {
|
|
@@ -37,13 +38,13 @@
|
|
|
37
38
|
"access": "public"
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
|
40
|
-
"@becket-ui/tokens": "^0.1.
|
|
41
|
+
"@becket-ui/tokens": "^0.1.3",
|
|
41
42
|
"react": ">=19",
|
|
42
43
|
"react-dom": ">=19"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"@becket-ui/a11y": "0.0.0",
|
|
46
|
-
"@becket-ui/tokens": "0.1.
|
|
47
|
+
"@becket-ui/tokens": "0.1.3",
|
|
47
48
|
"@pandacss/dev": "^1.12.1",
|
|
48
49
|
"@storybook/react": "^10.6.0",
|
|
49
50
|
"@storybook/react-vite": "^10.6.0",
|