@cleartrip/ct-design-components
Core components collection for Cleartrip Design System
Overview
@cleartrip/ct-design-components is a foundational package in the Cleartrip Design System that provides essential UI components with cross-platform support for React and React Native applications. This package focuses on core layout and container components with advanced features like haptic feedback support.
Installation
# npm
npm install @cleartrip/ct-design-components
# yarn
yarn add @cleartrip/ct-design-components
# pnpm
pnpm add @cleartrip/ct-design-components
Components
Container
A versatile container component that serves as a foundational layout element with support for haptic feedback, event handling, and flexible styling.
Features
- Cross-platform: Works seamlessly on React and React Native
- Haptic Feedback: Built-in haptic feedback support with customizable intensity
- Flexible Rendering: Supports multiple HTML semantic elements (
main,section,article,div,p) - Event Handling: Mouse events, click handlers, and layout change callbacks
- Accessibility: Focus management and measurement capabilities
- Styling: Custom style configuration with design system integration
Basic Usage
import { Container } from '@cleartrip/ct-design-components';
function App() {
return (
<Container
as="main"
onClick={(event) => console.log('Container clicked')}
styleConfig={{
root: [{ padding: '16px', backgroundColor: '#f5f5f5' }]
}}
>
<h1>Welcome to Cleartrip</h1>
<p>Your content goes here...</p>
</Container>
);
}
Haptic Feedback
<Container
hapticEnabled={true}
hapticVariant="subtle"
hapticRepeat={false}
onClick={() => console.log('Haptic feedback triggered')}
>
Interactive content with haptic feedback
</Container>
Advanced Usage with Ref
import { Container, ContainerRef } from '@cleartrip/ct-design-components';
import { useRef } from 'react';
function MyComponent() {
const containerRef = useRef<ContainerRef>(null);
const handleFocus = () => {
containerRef.current?.focus();
};
const measureContainer = () => {
containerRef.current?.measure((x, y, width, height, pageX, pageY) => {
console.log('Container dimensions:', { x, y, width, height, pageX, pageY });
});
};
return (
<Container
ref={containerRef}
onLayout={(event) => console.log('Layout changed:', event.layout)}
onMouseEnter={() => console.log('Mouse entered')}
onMouseLeave={() => console.log('Mouse left')}
>
Content with measurement and event handling
</Container>
);
}
API Reference
Container Props
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | - | HTML id attribute |
children | React.ReactNode | - | Child elements to render |
as | 'main' | 'section' | 'article' | 'div' | 'p' | 'div' | HTML element type to render |
showScrollIndicator | boolean | - | Show scroll indicator (React Native) |
onClick | (event: unknown) => void | - | Click event handler |
onLayout | (event: LayoutEvent) => void | - | Layout change handler (React Native) |
onMouseEnter | MouseEventHandler<HTMLElement> | - | Mouse enter handler |
onMouseLeave | MouseEventHandler<HTMLElement> | - | Mouse leave handler |
onTransitionEnd | () => void | - | Transition end handler |
styleConfig | { root?: Styles[] } | - | Custom style configuration |
hapticEnabled | boolean | false | Enable haptic feedback |
hapticVariant | 'subtle' | 'loud' | 'subtle' | Haptic feedback intensity |
hapticRepeat | boolean | false | Repeat haptic feedback |
Container Ref Methods
| Method | Description |
|---|---|
focus() | Focus the container element |
getBoundingRectWithCallback(callback?) | Get bounding rectangle with callback |
measure(callback) | Measure container dimensions and position |
getElementRef() | Get the underlying element reference |
Related Packages
The Cleartrip Design System includes 60+ specialized component packages:
Core Components
@cleartrip/ct-design-button- Button components@cleartrip/ct-design-typography- Text and typography@cleartrip/ct-design-card- Card layouts@cleartrip/ct-design-box- Layout containers
Form Components
@cleartrip/ct-design-field- Form fields@cleartrip/ct-design-checkbox- Checkboxes@cleartrip/ct-design-radio- Radio buttons@cleartrip/ct-design-dropdown- Dropdown menus
Navigation
@cleartrip/ct-design-nav-tabs- Navigation tabs@cleartrip/ct-design-breadcrumb- Breadcrumb navigation
Feedback
@cleartrip/ct-design-toast- Toast notifications@cleartrip/ct-design-modal- Modal dialogs@cleartrip/ct-design-tooltip- Tooltips@cleartrip/ct-design-spinner- Loading indicators
Data Display
@cleartrip/ct-design-accordion- Collapsible content@cleartrip/ct-design-carousel- Content carousels@cleartrip/ct-design-rating- Star ratings@cleartrip/ct-design-badge- Status badges
Browser Support
- React: 16.8.0 or higher
- React DOM: 16.8.0 or higher
- React Native: 0.68.0 or higher (optional peer dependency)
Module Formats
This package supports multiple module formats:
- ES Modules:
dist/ct-design-components.esm.js - CommonJS:
dist/ct-design-components.cjs.js - Browser: Optimized browser builds available
- TypeScript: Full TypeScript definitions included
Development
# Build the package
pnpm build-package
# Watch for changes during development
pnpm watch-package
# Clean build
pnpm build-package:clean
Contributing
This package is part of the Cleartrip Design System. For contribution guidelines, please refer to the main repository documentation.
License
ISC
Changelog
See CHANGELOG.md for version history and updates.
Cleartrip Design System | Documentation | Component Library | GitHub