npm.io
5.32.0 • Published 6d ago

@cleartrip/ct-design-button

Licence
ISC
Version
5.32.0
Deps
10
Size
171 kB
Vulns
0
Weekly
0

Button

A button component is a reusable user interface element used in web development to create interactive elements that users can click or tap to perform actions.


Installation

npm install @cleartrip/ct-design-button
# or
pnpm add @cleartrip/ct-design-button

Peer dependencies

# Required for all targets
npm install react

# Web only
npm install react-dom

# React Native only
npm install react-native

Usage

Basic
import { Button, ButtonVariant, ButtonColor, ButtonSize } from '@cleartrip/ct-design-button';

function Example() {
  return <Button onClick={() => console.log('clicked')}>Click me</Button>;
}
With variants
<Button variant={ButtonVariant.CONTAINED} color={ButtonColor.PRIMARY}>
  Contained Button
</Button>

<Button variant={ButtonVariant.OUTLINE} color={ButtonColor.SECONDARY}>
  Outline Button
</Button>

<Button variant={ButtonVariant.BARE}>
  Bare Button
</Button>
With sizes
<Button size={ButtonSize.SMALL}>Small Button</Button>
<Button size={ButtonSize.MEDIUM}>Medium Button</Button>
<Button size={ButtonSize.LARGE}>Large Button</Button>
With icons
<Button
  showLeftIcon={true}
  LeftIcon={<MyIcon />}
>
  Button with left icon
</Button>

<Button
  showRightIcon={true}
  RightIcon={<MyIcon />}
>
  Button with right icon
</Button>
Loading state
<Button loading={isLoading}>{isLoading ? 'Loading...' : 'Submit'}</Button>

Props

Prop Type Default Required Description
children ReactNode — Yes Button content
onClick () => void — No Click handler function
variant ButtonVariant CONTAINED No Visual style of the button
size ButtonSize MEDIUM No Size of the button
color ButtonColor PRIMARY No Color scheme of the button
disabled boolean false No Whether the button is disabled
loading boolean false No Whether to show loading state
isFullWidth boolean false No Whether button takes full width
minWidth string 50px No Minimum width of the button
showLeftIcon boolean false No Whether to show left icon
LeftIcon ReactElement — No Left icon element
showRightIcon boolean false No Whether to show right icon
RightIcon ReactElement — No Right icon element

Variants

  • CONTAINED — Filled button with background color
  • OUTLINE — Button with border, no background
  • BARE — Text-only button, no background or border

Sizes

  • SMALL — Compact button for tight spaces
  • MEDIUM — Standard button size (default)
  • LARGE — Larger button for emphasis

Colors

  • PRIMARY — Main brand color
  • SECONDARY — Secondary color scheme
  • TERTIARY — Tertiary color scheme
  • NEUTRAL — Neutral/gray color scheme
  • SUCCESS — Green, for confirming/approving actions
  • DANGER — Red, for destructive/rejecting actions

Accessibility

  • Buttons include proper ARIA attributes
  • Disabled buttons are not focusable
  • Loading buttons announce state to screen readers
  • Ensure sufficient color contrast for all variants
  • Icons should have appropriate alt text or ARIA labels

Migration

If migrating from previous versions:

- import { Button } from 'yagami/core/components';
+ import { Button, ButtonVariant, ButtonColor, ButtonSize } from '@cleartrip/ct-design-button';