| name | arkui-api-design |
| description | This skill should be used when the user asks to "design ArkUI API", "add component property", "create Modifier method", "review ArkUI API", "deprecate API", "write JSDOC for ArkUI", or mentions OpenHarmony API design standards. Provides comprehensive guidance for ArkUI component API design following OpenHarmony coding guidelines. |
| version | 1.0.0 |
ArkUI API Design Skill
This skill provides comprehensive guidance for designing, reviewing, and maintaining ArkUI component APIs that follow OpenHarmony Application TypeScript/JavaScript coding guidelines.
Core Design Principles
1. Follow OpenHarmony Coding Standards
All API definitions and code examples must comply with the OpenHarmony Application TypeScript/JavaScript Coding Guide. Key standards include:
- Naming conventions: Use camelCase for properties and methods, PascalCase for types/interfaces
- Type safety: Provide proper TypeScript type definitions for all parameters
- Code style: Follow 4-space indentation, consistent formatting
- Documentation: Comprehensive JSDOC comments for all public APIs
For detailed standards, refer to: references/OpenHarmony-Application-Typescript-JavaScript-coding-guide.md
2. Synchronize Component Properties and Modifiers
When adding or removing component properties and methods, ensure corresponding Modifier methods are created or deprecated:
Adding new property:
interface ButtonStyle {
iconSize?: number;
}
iconSize(value: number | string): ButtonAttribute;
Deprecating property:
- Mark interface property as
@deprecated with migration guidance
- Mark corresponding Modifier method as
@deprecated
- Provide alternative methods and migration examples
3. Support resourceStr for Flexibility
When parameters accept number | string | Length types, consider adding Resource type support to improve theming and i18n scenarios:
fontSize(value: number | string | Length | Resource): TextAttribute
Text().fontSize(16)
Text().fontSize('16vp')
Text().fontSize($r('app.float.font_size_large'))
Benefits:
- Enables centralized theme management through resource files
- Supports internationalization with locale-specific resources
- Improves developer experience for dynamic theming
4. Document undefined/null Behavior
JSDOC comments must explicitly specify how undefined and null values are handled:
fontSize(value: number | string | Length | Resource | undefined | null): TextAttribute;
Common patterns:
undefined → Restore default value
null → Remove setting, use inherited value
- Invalid values → Throw error with clear message
5. Use vp as Default Length Unit
Always use vp (virtual pixels) as the default unit for length measurements:
width(value: number | string): ButtonAttribute
width(value: Length): ButtonAttribute
width(value: number): ButtonAttribute
6. Specify Constraints in JSDOC
JSDOC comments must include specification limits and constraints:
borderRadius(value: number | string | Length): CommonMethod;
Required documentation:
- Valid ranges (min/max values)
- Special value handling (negative, zero, etc.)
- Unit of measurement
- Clamping behavior (if applicable)
7. Consider Cross-Component Impact
When adding common properties, evaluate the impact on all components:
Before adding common property:
- Check if property applies to most components (layout, style, event)
- Define consistent behavior across component types
- Document component-specific exceptions (if any)
- Consider backward compatibility
Example common properties:
- Layout:
width(), height(), padding(), margin()
- Style:
opacity(), visibility(), borderRadius()
- Event:
onClick(), onTouch()
8. Respect Interface Directory Boundaries
During compilation verification, modify only files within the interface/ directory:
Allowed modifications:
interfaces/inner_api/ - Internal API definitions
interfaces/native/ - NDK API definitions
- Type definition files (*.d.ts)
Do NOT modify:
- Framework implementation code
- Component pattern files
- Layout or render implementations
Verification workflow:
- Check only interface files for compilation errors
- Verify type definitions are correct
- Validate JSDOC comments and metadata
- Ensure Modifier method signatures match interfaces
API Design Workflow
For New Component APIs
- Define interface with proper TypeScript types
- Create Modifier methods for all settable properties
- Add JSDOC comments including:
- Parameter descriptions
- undefined/null handling
- Value constraints and ranges
- Default values
- @since version
- @throws documentation (if applicable)
- Support Resource type for theme-able properties
- Specify units (default to vp for lengths)
- Verify cross-component impact if adding common property
- Test compilation in interface directory only
For API Reviews
Use the following checklist to verify:
- Compliance with coding standards
- Modifier synchronization
- Resource type support where appropriate
- Complete JSDOC documentation
- Constraint specifications
- Cross-component consistency
For API Deprecation
- Mark both interface and Modifier as
@deprecated
- Provide migration path in JSDOC
- Specify removal version
- Update documentation and examples
Code Examples
Complete API Definition
opacity(value: number | string | undefined | null): CommonMethod;
Example with Resource Type Support
fontSize(value: number | string | Length | Resource | undefined | null): TextAttribute;
Common Pitfalls
Missing Modifier synchronization:
interface ButtonStyle { iconSize?: number; }
interface ButtonStyle { iconSize?: number; }
iconSize(value: number | string): ButtonAttribute;
Incomplete JSDOC:
width(value: number): CommonMethod;
width(value: number | string | Length | undefined): CommonMethod;
Forgetting Resource type:
fontSize(value: number | string): TextAttribute;
fontSize(value: number | string | Length | Resource): TextAttribute;
Additional Resources
Coding Standards
references/OpenHarmony-Application-Typescript-JavaScript-coding-guide.md
- OpenHarmony TypeScript/JavaScript Coding Guide (official complete version)
- Contains naming conventions, type definitions, code formatting, and all coding standards
- All design principles in this skill are based on this document
Example Code
examples/interface-definition.ts - Complete interface definition example
examples/modifier-implementation.ts - Modifier method implementation example
examples/deprecation-pattern.ts - API deprecation with migration example
Quick Reference
Essential JSDOC Tags
Type Support Decision Tree
Does the parameter accept length values?
├─ Yes → Add Length and Resource types
└─ No → Is it theme-able (color, size, string)?
├─ Yes → Add Resource type
└─ No → Use basic types (number | string | undefined | null)
Default Value Documentation
"If undefined, restores to default [value] ([unit])."
"If null, removes setting and uses inherited value."