@app-studio/web 0.9.17 → 0.9.19
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/AuthGuard/index.d.ts +1 -1
- package/dist/utils/request.d.ts +2 -2
- package/dist/web.cjs.development.js +41 -46
- package/dist/web.cjs.development.js.map +1 -1
- package/dist/web.cjs.production.min.js +1 -1
- package/dist/web.cjs.production.min.js.map +1 -1
- package/dist/web.esm.js +43 -48
- package/dist/web.esm.js.map +1 -1
- package/dist/web.umd.development.js +45 -45
- package/dist/web.umd.development.js.map +1 -1
- package/dist/web.umd.production.min.js +1 -1
- package/dist/web.umd.production.min.js.map +1 -1
- package/docs/README.md +52 -0
- package/docs/adk-components.md +316 -0
- package/docs/adk-quick-start.md +294 -0
- package/docs/api-integration.md +801 -0
- package/docs/api-reference/README.md +103 -0
- package/docs/api-reference/data-display/flow.md +220 -0
- package/docs/api-reference/data-display/tree.md +210 -0
- package/docs/api-reference/form/chat-input.md +210 -0
- package/docs/api-reference/utility/button.md +145 -0
- package/docs/api-reference/utility/title.md +301 -0
- package/docs/app-studio.md +302 -0
- package/docs/component-development/guide.md +546 -0
- package/docs/contributing/documentation.md +153 -0
- package/docs/conventions.md +536 -0
- package/docs/design-system/theming.md +299 -0
- package/docs/documentation-system.md +143 -0
- package/docs/getting-started/component-usage.md +211 -0
- package/docs/getting-started/introduction.md +114 -0
- package/docs/guide.md +550 -0
- package/docs/integration-guide.md +449 -0
- package/docs/tutorials/README.md +51 -0
- package/docs/tutorials/basic/creating-a-simple-form.md +566 -0
- package/package.json +3 -2
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
# App Studio Rules
|
|
2
|
+
|
|
3
|
+
## I. Introduction
|
|
4
|
+
|
|
5
|
+
### Purpose
|
|
6
|
+
|
|
7
|
+
These rules are designed to guide developers in building high-quality, consistent, and maintainable components for or with the **App Studio library**. They combine general clean code principles with best practices specific to React, TypeScript, and the established patterns within the App Studio codebase. Adhering to these rules will ensure that new components integrate seamlessly and the library remains easy to understand, use, and extend.
|
|
8
|
+
|
|
9
|
+
### How to Use
|
|
10
|
+
|
|
11
|
+
This document outlines the expected standards and practices. Refer to it when:
|
|
12
|
+
|
|
13
|
+
* Creating new components for the App Studio library.
|
|
14
|
+
* Modifying existing App Studio components.
|
|
15
|
+
* Using App Studio components to build applications.
|
|
16
|
+
|
|
17
|
+
Start with the General Principles, then focus on the App Studio Specific Best Practices which detail the library's core patterns.
|
|
18
|
+
|
|
19
|
+
## II. General Coding Principles (Applied to App Studio)
|
|
20
|
+
|
|
21
|
+
### Clean Code
|
|
22
|
+
|
|
23
|
+
* **Constants Over Magic Values:** Use named constants defined in `.style.ts` or `.style.tsx` files (e.g., `ButtonSizes`, `Themes`) instead of hard-coded numbers or strings directly in view components.
|
|
24
|
+
* **Meaningful Names:** Use descriptive names for components (`AlertComponent`, `ButtonView`), props (`isLoading`, `colorScheme`), state variables (`isHovered`), hooks (`useAlertState`), and types (`AlertProps`, `Variant`). Follow established conventions (see Naming Conventions section).
|
|
25
|
+
* **Smart Comments:** Explain the *why* behind complex logic or non-obvious choices, especially in state hooks or utility functions. Prop descriptions should be in `.props.ts` files using TSDoc. `.view.tsx` files should be largely self-explanatory through props and structure.
|
|
26
|
+
* **Single Responsibility:**
|
|
27
|
+
* **Components:** `ComponentName.tsx` orchestrates state and view.
|
|
28
|
+
* **Hooks:** `useComponentNameState` manages component-specific state and logic.
|
|
29
|
+
* **Views:** `ComponentName.view.tsx` focuses solely on presentation based on props.
|
|
30
|
+
* **Props/Types/Styles:** Dedicated files (`.props.ts`, `.type.ts`, `.style.ts`) handle specific concerns.
|
|
31
|
+
* **DRY (Don't Repeat Yourself):** Extract reusable UI patterns into shared components (like the `Field*` layout components) or utility functions. Avoid duplicating prop type definitions; extend or compose interfaces.
|
|
32
|
+
* **Clean Structure:** Strictly follow the established component folder structure (see Project & Component Structure section). Keep related logic, types, and styles together.
|
|
33
|
+
* **Encapsulation:** Define clear component APIs through `ComponentName.props.ts`. Internal state and logic should be managed within the component or its state hook.
|
|
34
|
+
* **Code Quality Maintenance:** Regularly refactor components to improve clarity, performance, and adherence to these rules. Address TODOs and FIXMEs promptly.
|
|
35
|
+
* **Testing:** (Assuming tests will be added) Write unit tests for component logic (state hooks) and integration/rendering tests for components, verifying behavior based on props and interactions. Use examples (`examples/*.tsx`) for visual testing and documentation.
|
|
36
|
+
* **Version Control:** Use Git effectively. Commit messages should be clear and concise (`feat(Button): Add loading state`). Branch names should be descriptive (`feature/add-tooltip-component`).
|
|
37
|
+
|
|
38
|
+
### Code Quality (Developer Focus)
|
|
39
|
+
|
|
40
|
+
* **Verify Prop Usage:** Ensure props passed to components match their definitions in `.props.ts`. Double-check types and optionality.
|
|
41
|
+
* **File-by-File Structure:** When creating or modifying components, ensure all relevant files (`.props.ts`, `.state.ts`, `.view.tsx`, etc.) are created or updated consistently.
|
|
42
|
+
* **Preserve Component API:** When refactoring, avoid breaking changes to component props (`ComponentName.props.ts`) unless necessary and clearly documented.
|
|
43
|
+
* **Focused Changes:** Keep commits and pull requests focused on a single component or feature.
|
|
44
|
+
* **Leverage Existing Components:** Before creating new UI logic, check if an existing App Studio component (`Button`, `Alert`, `Vertical`, etc.) can be used or adapted.
|
|
45
|
+
|
|
46
|
+
### Documentation
|
|
47
|
+
|
|
48
|
+
* **Prop Documentation (TSDoc):** Clearly document *all* props in the `ComponentName.props.ts` file using TSDoc comments (e.g., `/** Description of the prop */`).
|
|
49
|
+
* **Type Definitions:** Define and export specific types (`Size`, `Variant`, `Shape`) in `ComponentName.type.ts` or `.d.ts` files. Use descriptive type names.
|
|
50
|
+
* **Examples (`examples/*.tsx`):** Create clear, concise, and functional examples for each significant prop or feature of a component in the `examples/` directory. Export all examples from `examples/index.ts`.
|
|
51
|
+
* **MDX Documentation:** Keep the corresponding `.mdx` file (e.g., `Button.mdx`) updated with imports, descriptions, props tables, and embedded examples that match the code in the `examples/` directory.
|
|
52
|
+
|
|
53
|
+
## III. App Studio Specific Best Practices
|
|
54
|
+
|
|
55
|
+
### Project & Component Structure
|
|
56
|
+
|
|
57
|
+
* **Standard Structure:** Every component `ComponentName` should reside in a directory `ComponentName/` and follow this internal structure:
|
|
58
|
+
* `ComponentName/ComponentName/`: Contains the core component files.
|
|
59
|
+
* `ComponentName.props.ts`: TypeScript interface definitions for the component's props.
|
|
60
|
+
* `ComponentName.state.ts`: (Optional) Custom React hook (`useComponentNameState`) for managing component state and logic.
|
|
61
|
+
* `ComponentName.style.ts` or `.tsx`: Style constants, mappings (e.g., `Size` to pixels), or theme definitions.
|
|
62
|
+
* `ComponentName.type.ts` or `.d.ts`: TypeScript type definitions specific to the component (e.g., `Variant`, `Size`, `Shape`, `Styles`).
|
|
63
|
+
* `ComponentName.view.tsx`: The presentational React component, receiving props and state.
|
|
64
|
+
* `ComponentName/examples/`: Contains usage example components.
|
|
65
|
+
* `default.tsx`: A basic default usage example.
|
|
66
|
+
* `propSpecificExample.tsx`: Examples demonstrating specific props (e.g., `variant.tsx`, `size.tsx`).
|
|
67
|
+
* `index.ts`: Exports all examples from the directory (`export * from './default';`).
|
|
68
|
+
* `ComponentName.tsx`: The main export file, usually orchestrating the state hook and the view.
|
|
69
|
+
* `ComponentName.mdx`: Documentation file for the component.
|
|
70
|
+
|
|
71
|
+
### Naming Conventions
|
|
72
|
+
|
|
73
|
+
* **Components:** `PascalCase`. Main component: `ComponentNameComponent` (exported as `ComponentName`). View component: `ComponentNameView`. Example components: `DefaultDemo`, `VariantDemo`.
|
|
74
|
+
* **Files:** `PascalCase` matching the component/purpose (e.g., `Button.tsx`, `Button.props.ts`, `Button.view.tsx`, `default.tsx`). Use `.mdx` for documentation.
|
|
75
|
+
* **Interfaces/Types:** `PascalCase` (e.g., `ButtonProps`, `ButtonViewProps`, `Size`, `Variant`). Append `Props` for component prop interfaces.
|
|
76
|
+
* **State Hooks:** `use` + `PascalCase` + `State` (e.g., `useButtonState`, `useModalState`).
|
|
77
|
+
* **Variables/Functions:** `camelCase` (e.g., `isHovered`, `setIsHovered`, `handleToggle`).
|
|
78
|
+
* **Style Constants:** `PascalCase` or `UPPER_SNAKE_CASE` (e.g., `ButtonSizes`, `Themes`, `DEFAULT_COLOR`).
|
|
79
|
+
|
|
80
|
+
### Component Design
|
|
81
|
+
|
|
82
|
+
* **Functional Components & Hooks:** Use functional components and React Hooks (`useState`, `useEffect`, `useCallback`, custom hooks) exclusively.
|
|
83
|
+
* **Separation of Concerns:**
|
|
84
|
+
* **Logic/State:** Encapsulate in `useComponentNameState`.
|
|
85
|
+
* **Presentation:** Handle in `ComponentName.view.tsx`.
|
|
86
|
+
* **Orchestration:** Connect state and view in `ComponentName.tsx`.
|
|
87
|
+
* **Props:** Define explicitly in `.props.ts`. Pass data down from parent to child. Avoid deeply nested prop drilling where context or state management might be better (though sparingly used in this library outside specific store-based components).
|
|
88
|
+
* **Composition:** Use composition by passing `children` or specific props (like `icon`, `left`, `right` in `TextField`).
|
|
89
|
+
* **Layout:** **Strongly prefer** using the provided layout components (`View`, `Horizontal`, `Vertical`, `Center`) over manual CSS for flexbox/grid layouts to ensure consistency. Pass layout props (e.g., `gap`, `justifyContent`, `alignItems`) to these components.
|
|
90
|
+
* **Base Components:** Leverage core `app-studio` components (like `Element`, `Input`, `View` from the base `app-studio` import if applicable) for building blocks.
|
|
91
|
+
|
|
92
|
+
### Props & Types
|
|
93
|
+
|
|
94
|
+
* **TypeScript Interfaces:** Define *all* component props using TypeScript interfaces in `ComponentName.props.ts`.
|
|
95
|
+
* **Clarity & Specificity:** Use descriptive prop names. Use specific union types (`Variant`, `Size`) defined in `.type.ts` instead of generic `string` or `number` where applicable.
|
|
96
|
+
* **Optional vs. Required:** Clearly distinguish between optional (`?`) and required props. Provide default values within the component or view logic (e.g., `size = 'md'`).
|
|
97
|
+
* **Extending Props:** Use `extends Omit<BaseProps, 'propToOverride'>` or `extends BaseProps` when building on base component props.
|
|
98
|
+
* **Avoid `any`:** Use specific types, `unknown`, or generics. If `any` is absolutely necessary, add a `// eslint-disable-next-line @typescript-eslint/no-explicit-any` with justification.
|
|
99
|
+
* **Export Types:** Export all relevant types and interfaces from `ComponentName.props.ts` and `ComponentName.type.ts` so they can be used by consumers.
|
|
100
|
+
|
|
101
|
+
### State Management
|
|
102
|
+
|
|
103
|
+
* **Component State:** Use `useState` for simple state within a component or its state hook.
|
|
104
|
+
* **Custom Hooks (`useComponentNameState`):** Centralize component-specific state, event handlers, and derived logic within a custom hook in `ComponentName.state.ts`. This hook should return an object containing state values and setters/handlers.
|
|
105
|
+
* **Global State (`zustand`):** Use only for state that is truly global or shared across distant parts of the application (e.g., `Modal` visibility, `Message` queue). Avoid using it for local component state.
|
|
106
|
+
|
|
107
|
+
### Styling
|
|
108
|
+
|
|
109
|
+
* **Style Definitions:** Define style constants (sizes, colors, theme maps) in `.style.ts` or `.style.tsx`.
|
|
110
|
+
* **`styles` Prop:** Allow consumers to override specific parts of the component's style via the `styles` prop, which should accept an object mapping keys (e.g., `container`, `label`, `icon`) to `CSSProperties`. Define the structure of this `styles` object in `ComponentName.type.ts`.
|
|
111
|
+
* **Theme Variables:** Prefer using theme variables (e.g., `theme.primary`, `color.blueGray.700`) over hardcoded hex/rgb values to maintain theme consistency. Use `useTheme` hook if necessary to access theme values dynamically.
|
|
112
|
+
* **Inline Styles vs. `styles` Prop:** Use inline styles within `.view.tsx` for structural layout (using layout components) and dynamic styles based on state (e.g., hover effects). Use the `styles` prop for customizable theme/appearance overrides.
|
|
113
|
+
* **CSS Files:** Limit usage. Prefer inline styles passed via props or theme-based styling. Use CSS files (like `style.css` in `TextArea` and `TextField`) only for styles that cannot be easily applied via inline styles (e.g., pseudo-elements, complex selectors).
|
|
114
|
+
|
|
115
|
+
### Form Components & Formik
|
|
116
|
+
|
|
117
|
+
* **Base Form Components:** Build reusable base form components (`TextField`, `Checkbox`, `Select`, etc.) following the standard structure.
|
|
118
|
+
* **Formik Integration:** Create corresponding `FormikComponentName` wrappers (e.g., `FormikTextField`).
|
|
119
|
+
* **`useFormikInput` Hook:** Utilize the `useFormikInput` hook within Formik wrappers to connect components to Formik's state, errors, and touched status automatically. Pass `name` and `type` correctly.
|
|
120
|
+
|
|
121
|
+
### Icons
|
|
122
|
+
|
|
123
|
+
* **Use Icon Components:** Import and use icons directly from `Icon/Icon.tsx`.
|
|
124
|
+
* **Props:** Pass `size`, `color`, `strokeWidth`, `filled`, `orientation` as props to customize icons. Do not hardcode styles within the icon usage.
|
|
125
|
+
|
|
126
|
+
## IV. Dos and Don'ts for App Studio
|
|
127
|
+
|
|
128
|
+
**Dos:**
|
|
129
|
+
|
|
130
|
+
* **Do** follow the exact `ComponentName/ComponentName/` file structure.
|
|
131
|
+
* **Do** define all props with TSDoc comments in `ComponentName.props.ts`.
|
|
132
|
+
* **Do** use TypeScript interfaces for props and specific types (`Variant`, `Size`) from `.type.ts`.
|
|
133
|
+
* **Do** encapsulate component state and logic in `useComponentNameState` hooks.
|
|
134
|
+
* **Do** keep `ComponentName.view.tsx` purely presentational.
|
|
135
|
+
* **Do** use `Horizontal`, `Vertical`, `Center`, `View` for layout.
|
|
136
|
+
* **Do** use theme variables (`theme.primary`) for colors.
|
|
137
|
+
* **Do** allow style overrides via the `styles` prop with a defined structure.
|
|
138
|
+
* **Do** create clear examples in the `examples/` directory for each component.
|
|
139
|
+
* **Do** keep `.mdx` documentation synchronized with examples and props.
|
|
140
|
+
* **Do** use `FormikComponentName` wrappers and `useFormikInput` when using Formik.
|
|
141
|
+
* **Do** import and use Icons from `Icon/Icon.tsx` passing props.
|
|
142
|
+
|
|
143
|
+
**Don'ts:**
|
|
144
|
+
|
|
145
|
+
* **Don't** deviate from the established file and folder structure.
|
|
146
|
+
* **Don't** define props inline or without TSDoc comments.
|
|
147
|
+
* **Don't** use `any` for props or state; use specific types.
|
|
148
|
+
* **Don't** put complex logic or state management directly in `ComponentName.view.tsx`.
|
|
149
|
+
* **Don't** use manual CSS for flexbox/grid layouts; use Layout components.
|
|
150
|
+
* **Don't** hardcode colors or sizes; use style constants and theme variables.
|
|
151
|
+
* **Don't** apply styles that cannot be overridden by the `styles` prop unless essential.
|
|
152
|
+
* **Don't** forget to create examples for new components or features.
|
|
153
|
+
* **Don't** let documentation (`.mdx`) become outdated.
|
|
154
|
+
* **Don't** connect standard form components directly to Formik; use the wrappers.
|
|
155
|
+
* **Don't** create custom SVG icons directly in components; add them to `Icon/Icon.tsx`.
|
|
156
|
+
|
|
157
|
+
## V. Secret Sauce (Effective Application)
|
|
158
|
+
|
|
159
|
+
* **Consistency is Key:** The primary goal is consistency with the *existing* App Studio patterns. When unsure, look at similar components (`Button`, `TextField`, `Alert`) and follow their structure and approach.
|
|
160
|
+
* **Understand the Pattern:** Internalize the `props -> state hook -> view` flow and the purpose of each file (`.props.ts`, `.state.ts`, `.view.tsx`, `.tsx`).
|
|
161
|
+
* **Leverage TypeScript:** Use TypeScript not just for type safety but also for self-documentation through clear interfaces and types.
|
|
162
|
+
* **Prioritize Reusability:** Use Layout components and existing base components whenever possible. Extract common logic into utility functions or hooks.
|
|
163
|
+
* **Documentation First (or Concurrent):** Define props (`.props.ts`) and write basic examples (`examples/`) early. This clarifies the component's API and intended usage. Keep the `.mdx` file updated as you build.
|
|
164
|
+
* **Review Against Rules:** During code reviews, explicitly check adherence to these cursor rules, especially structure, naming, props definition, and styling patterns.
|
|
165
|
+
|
|
166
|
+
## VI. Conclusion
|
|
167
|
+
|
|
168
|
+
Following these rules will help maintain the quality, consistency, and developer experience of the App Studio library. They provide a clear framework for building components that are robust, maintainable, and easy to integrate. Remember to prioritize consistency with existing patterns and continuously refine your understanding and application of these guidelines.
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
# Create new component for App Studio Web
|
|
173
|
+
|
|
174
|
+
1. **Component Structure:** Components generally follow a consistent pattern:
|
|
175
|
+
* `ComponentName/` (Root folder for the component)
|
|
176
|
+
* `ComponentName/` (Inner folder for core files)
|
|
177
|
+
* `ComponentName.props.ts` (or `.tsx`): Defines TypeScript interfaces for props. Often extends base props like `ViewProps` or `InputProps` from `app-studio`.
|
|
178
|
+
* `ComponentName.state.ts` (or `.tsx`): Usually contains a custom hook `useComponentNameState` using `React.useState` to manage component-specific state (like hover, focus, selection).
|
|
179
|
+
* `ComponentName.style.ts` (or `.tsx`): Contains style-related constants, mappings (e.g., `Size` to CSS), or theme definitions.
|
|
180
|
+
* `ComponentName.type.ts` (or `.tsx`, `.d.ts`): Defines specific TypeScript types/enums used within the component (e.g., `Variant`, `Size`, `Shape`, custom style object types).
|
|
181
|
+
* `ComponentName.view.tsx`: The core presentational component. It receives props (often including state values and setters from the hook) and renders the UI, typically using base components like `View`, `Text`, `Horizontal`, `Vertical`, `Center` from the library itself or `app-studio`.
|
|
182
|
+
* `examples/` (Folder for usage examples)
|
|
183
|
+
* `default.tsx`: A basic usage example.
|
|
184
|
+
* Other `.tsx` files: Demonstrating specific props, variants, or states (e.g., `size.tsx`, `variant.tsx`, `isDisabled.tsx`).
|
|
185
|
+
* `index.ts` (or `.tsx`): Exports all examples from the directory.
|
|
186
|
+
* `ComponentName.tsx` (Top-level file): The public API for the component. It usually imports the state hook and the view, wires them together, and exports the final component.
|
|
187
|
+
|
|
188
|
+
2. **Styling:**
|
|
189
|
+
* Relies heavily on the `app-studio` library's components (`View`, `Element`, `Horizontal`, `Vertical`, `Center`) which accept style props directly.
|
|
190
|
+
* Uses a theme system (`useTheme`, `getColor`) provided by `app-studio`.
|
|
191
|
+
* Style constants (like size mappings) are defined in `.style.ts` files.
|
|
192
|
+
* Custom style overrides are often passed via a `styles` prop, typed in `.type.ts`.
|
|
193
|
+
* Minimal use of global CSS, mostly for specific input overrides (`style.css` in some form components).
|
|
194
|
+
|
|
195
|
+
3. **State Management:**
|
|
196
|
+
* Primarily local component state managed via `React.useState` encapsulated in custom `useComponentNameState` hooks.
|
|
197
|
+
* Global/Shared state for components like `Modal` and `Message` uses Zustand (`create`, `useMessageStore`, `useModalStore`).
|
|
198
|
+
|
|
199
|
+
4. **Dependencies & Base Components:**
|
|
200
|
+
* Strong reliance on `app-studio` for base elements, layout, input primitives, and theming.
|
|
201
|
+
* Uses internal layout components (`Horizontal`, `Vertical`, `Center`, `View`).
|
|
202
|
+
* Uses internal `Text`, `Icon`, `Button`, `Loader` components.
|
|
203
|
+
* Form components often use shared layout helpers (`FieldContainer`, `FieldContent`, etc.).
|
|
204
|
+
* `react-router-dom` for `Link`.
|
|
205
|
+
* `formik` and `yup` for form handling examples/integrations.
|
|
206
|
+
|
|
207
|
+
5. **TypeScript:** The library is strongly typed using TypeScript interfaces and types defined in dedicated files.
|
|
208
|
+
|
|
209
|
+
6. **Exports:** Components and their primary prop types are exported from the root `index.tsx`.
|
|
210
|
+
|
|
211
|
+
**Guideline for Creating New Components**
|
|
212
|
+
|
|
213
|
+
Based on the analysis, here's a guideline for adding new components to this library:
|
|
214
|
+
|
|
215
|
+
**I. Core Principles:**
|
|
216
|
+
|
|
217
|
+
1. **Consistency:** Adhere strictly to the established file structure, naming conventions, and coding patterns.
|
|
218
|
+
2. **Separation of Concerns:** Keep props, types, state logic, styling constants, and view presentation in separate, dedicated files.
|
|
219
|
+
3. **TypeScript First:** Define clear interfaces and types for all props, state, and internal structures.
|
|
220
|
+
4. **Reusability:** Leverage existing base components (`View`, `Text`, `Horizontal`, `Icon`, etc.) and `app-studio` primitives whenever possible. Avoid introducing new external dependencies unless absolutely necessary and approved.
|
|
221
|
+
5. **Presentational View:** The `.view.tsx` component should be purely presentational, receiving all data and event handlers via props.
|
|
222
|
+
6. **State Encapsulation:** Use the `useComponentNameState` hook pattern for managing local component state.
|
|
223
|
+
|
|
224
|
+
**II. Steps to Create a New Component (`NewComponent`):**
|
|
225
|
+
|
|
226
|
+
1. **Planning:**
|
|
227
|
+
* Define the component's purpose and core functionality.
|
|
228
|
+
* Identify the necessary props (API). Consider variations (variants, sizes, shapes).
|
|
229
|
+
* Determine if any internal state is needed.
|
|
230
|
+
* Sketch the basic UI structure.
|
|
231
|
+
|
|
232
|
+
2. **Directory Structure:**
|
|
233
|
+
* Create the main folder: `NewComponent/`
|
|
234
|
+
* Create the inner folder: `NewComponent/NewComponent/`
|
|
235
|
+
* Create the examples folder: `NewComponent/examples/`
|
|
236
|
+
|
|
237
|
+
3. **Define Types (`NewComponent/NewComponent/NewComponent.type.ts` or `.d.ts`):**
|
|
238
|
+
* Define any specific enums needed (e.g., `Variant`, `Size`, `Shape`).
|
|
239
|
+
* Define the type for the `styles` prop (e.g., `NewComponentStyles`).
|
|
240
|
+
|
|
241
|
+
4. **Define Props (`NewComponent/NewComponent/NewComponent.props.ts`):**
|
|
242
|
+
* Create the main props interface (e.g., `NewComponentProps`).
|
|
243
|
+
* Extend relevant base props if applicable (e.g., `extends ViewProps`). Omit props like `size` if you redefine them.
|
|
244
|
+
* Include props for variations (variant, size, shape), content (`children`), event handlers (`onClick`, `onChange`), state control (`isDisabled`, `isLoading`), and custom styling (`styles`).
|
|
245
|
+
* Create the view props interface (e.g., `NewComponentViewProps`) extending the main props and adding state values/setters from the hook (e.g., `isHovered`, `setIsHovered`).
|
|
246
|
+
|
|
247
|
+
5. **Define Style Constants (`NewComponent/NewComponent/NewComponent.style.ts`):**
|
|
248
|
+
* If the component has standard size/shape/variant mappings to CSS properties, define them here as `Record<TypeName, CSSProperties>` (e.g., `NewComponentSizes`, `NewComponentShapes`).
|
|
249
|
+
|
|
250
|
+
6. **Implement State Hook (`NewComponent/NewComponent/NewComponent.state.ts`):**
|
|
251
|
+
* Create the `useNewComponentState` hook.
|
|
252
|
+
* Use `React.useState` for any internal state (e.g., hover, focus, active state).
|
|
253
|
+
* Accept relevant props (like default values) if needed for initialization.
|
|
254
|
+
* Return an object containing state values and their setters.
|
|
255
|
+
|
|
256
|
+
7. **Implement the View (`NewComponent/NewComponent/NewComponent.view.tsx`):**
|
|
257
|
+
* Create a functional component that accepts `NewComponentViewProps`.
|
|
258
|
+
* Use `View`, `Text`, `Horizontal`, `Vertical`, `Center`, `Icon`, etc., to build the UI.
|
|
259
|
+
* Apply styles based on props (variant, size, shape, isDisabled, isHovered, isFocused) using mappings from `.style.ts` or conditional logic.
|
|
260
|
+
* Integrate theme colors using `useTheme` if necessary.
|
|
261
|
+
* Apply custom styles from the `styles` prop to the appropriate elements.
|
|
262
|
+
* Connect event handlers (like `onClick`, `onMouseEnter`, `onMouseLeave`) from props to the relevant elements.
|
|
263
|
+
|
|
264
|
+
8. **Create Component Entry Point (`NewComponent/NewComponent.tsx`):**
|
|
265
|
+
* Create a functional component accepting `NewComponentProps`.
|
|
266
|
+
* Call the `useNewComponentState` hook.
|
|
267
|
+
* Render the `NewComponentView`, passing the state values/setters from the hook and all original props.
|
|
268
|
+
* Export this component as `NewComponent`.
|
|
269
|
+
|
|
270
|
+
9. **Add Examples (`NewComponent/examples/`):**
|
|
271
|
+
* Create `default.tsx` showing basic usage.
|
|
272
|
+
* Create examples for different props/variants (e.g., `size.tsx`, `variant.tsx`, `disabled.tsx`).
|
|
273
|
+
* Create `index.ts` to export all examples.
|
|
274
|
+
|
|
275
|
+
10. **Export from Library (`index.tsx`):**
|
|
276
|
+
* Add `export * from './NewComponent/NewComponent';` to the main `index.tsx`.
|
|
277
|
+
* Add `export * from './NewComponent/NewComponent/NewComponent.props';` to export the primary props interface.
|
|
278
|
+
|
|
279
|
+
11. **Testing & Documentation (Implicit):**
|
|
280
|
+
* Write unit/integration tests for the component (framework not specified, but essential).
|
|
281
|
+
* Update any relevant documentation (e.g., Storybook, style guides).
|
|
282
|
+
|
|
283
|
+
**III. Requirements & Restrictions:**
|
|
284
|
+
|
|
285
|
+
* **File Structure:** Strictly follow the `Component/Component/` and `Component/examples/` structure.
|
|
286
|
+
* **Naming:** Use consistent naming (`ComponentName`, `useComponentNameState`, `ComponentNameProps`, `ComponentNameView`, etc.).
|
|
287
|
+
* **State:** Use the `useComponentNameState` hook pattern. Avoid direct `useState` in the view or entry point component. Use Zustand (`useModalStore`, `useMessageStore`) *only* if the component requires interaction with the existing global Modal or Message system. Do not introduce new global stores without strong justification.
|
|
288
|
+
* **Styling:**
|
|
289
|
+
* Prioritize using `app-studio` components (`View`, `Element`) and style props.
|
|
290
|
+
* Use the `styles` prop pattern for custom overrides.
|
|
291
|
+
* Use `.style.ts` for reusable style constants/mappings.
|
|
292
|
+
* Use `useTheme` for theme colors.
|
|
293
|
+
* **Restriction:** Avoid adding new global CSS files unless absolutely necessary for browser resets or complex pseudo-selectors not achievable via style props.
|
|
294
|
+
* **Props & Types:** Define all props and types using TypeScript interfaces/types in their respective files. Export the main props interface.
|
|
295
|
+
* **Dependencies:**
|
|
296
|
+
* **Requirement:** Reuse existing internal components (`Text`, `Button`, `Icon`, layout components) and `app-studio` primitives.
|
|
297
|
+
* **Restriction:** Do not add new external libraries without discussion and approval.
|
|
298
|
+
* **Examples:** Provide comprehensive examples covering common use cases and prop variations.
|
|
299
|
+
* **Exports:** Ensure the component and its props are exported correctly from the main `index.tsx`.
|
|
300
|
+
* **Form Components:** If creating a form input, follow the patterns seen in `TextField`, `Select`, etc., potentially using the `FieldContainer`, `FieldContent`, `FieldLabel`, `FieldWrapper`, `HelperText` layout components. If Formik integration is needed, create a separate `Formik.NewComponent.tsx` file following the existing pattern using `useFormikInput`.
|
|
301
|
+
|
|
302
|
+
By following these guidelines, new components will integrate smoothly into the existing library, maintaining consistency in structure, style, and API design.
|