# Button Component Documentation ## Overview The Button component is a scalable, accessible button implementation following the XRPL Brand Design System (BDS). It supports three visual variants (Primary, Secondary, Tertiary) and two color themes (Green, Black), with comprehensive state management and smooth animations. ## Features - **Three Variants**: Primary (solid), Secondary (outline), Tertiary (text-only) - **Two Color Themes**: Green (default) and Black - **Animated Arrow Icon**: Optional icon with smooth hover animations - **Full State Support**: Enabled, Hover, Focus, Active, and Disabled states - **Responsive Design**: Adaptive padding and spacing across breakpoints - **Accessibility**: WCAG compliant with keyboard navigation and screen reader support - **Smooth Animations**: 150ms transitions with custom bezier timing ## Props API ```typescript interface ButtonProps { /** Button variant - determines visual style */ variant?: 'primary' | 'secondary' | 'tertiary'; /** Color theme - green (default) or black */ color?: 'green' | 'black'; /** Button content/label */ children: React.ReactNode; /** Click handler */ onClick?: () => void; /** Disabled state */ disabled?: boolean; /** Button type attribute */ type?: 'button' | 'submit' | 'reset'; /** Additional CSS classes */ className?: string; /** Whether to show the arrow icon */ showIcon?: boolean; } ``` ### Default Values - `variant`: `'primary'` - `color`: `'green'` - `disabled`: `false` - `type`: `'button'` - `className`: `''` - `showIcon`: `true` ## Variants ### Primary Button The Primary button is used for the main call-to-action on a page. It features a solid background that fills from bottom-to-top on hover. **Visual Characteristics:** - Solid background (Green 300 / Black) - High visual emphasis - Background color transitions on hover - Black text on green background, white text on black background **Usage:** ```tsx ``` ### Secondary Button The Secondary button is used for supporting actions. It features an outline style with a transparent background that fills on hover. **Visual Characteristics:** - Transparent background with 2px border - Medium visual emphasis - Background fills from bottom-to-top on hover - Green/Black text and border **Usage:** ```tsx ``` ### Tertiary Button The Tertiary button is used for low-emphasis or contextual actions. It appears as text-only with optional underline on hover. **Visual Characteristics:** - Text-only, no background or border - Lowest visual emphasis - Underline appears on hover/focus - Different typography (Body R token vs Label R) **Usage:** ```tsx ``` ## Color Themes ### Green Theme (Default) The green theme uses the XRPL brand green colors: - **Primary**: Green 300 background (#21E46B), Green 200 hover (#70EE97) - **Secondary**: Green 400 text/border (#0DAA3E), Green 500 hover (#078139) - **Tertiary**: Green 400 text (#0DAA3E), Green 500 hover (#078139) ### Black Theme The black theme provides an alternative color scheme: - **Primary**: Black background (#141414), 80% black hover - **Secondary**: Black text/border (#141414), 15% black hover fill - **Tertiary**: Black text (#141414) **Usage:** ```tsx ``` ## States ### Enabled State The default interactive state of the button. All variants display their base styling. ### Hover State Triggered when the user hovers over the button with a mouse: - **Primary/Secondary**: Background fills from bottom-to-top - **Tertiary**: Underline appears, text color darkens - **All Variants**: Arrow icon line shrinks, gap increases (with icon) ### Focus State Triggered when the button receives keyboard focus (Tab key): - Similar visual changes to hover state - Additional focus outline (2px border/outline) - Ensures keyboard accessibility ### Active State Triggered when the button is being pressed: - Returns to default padding/gap - Background resets (for Primary/Secondary) - Maintains visual feedback during press ### Disabled State When `disabled={true}`: - Icon is automatically hidden - Gray text and background (Primary) or border (Secondary) - Cursor changes to `not-allowed` - `pointer-events: none` prevents interaction - `aria-disabled` attribute set for screen readers **Usage:** ```tsx ``` ## How It Works ### Component Structure The Button component uses BEM (Block Element Modifier) naming convention with the `bds` namespace: - `.bds-btn` - Base button class - `.bds-btn--primary` - Primary variant modifier - `.bds-btn--secondary` - Secondary variant modifier - `.bds-btn--tertiary` - Tertiary variant modifier - `.bds-btn--green` - Green color theme (default) - `.bds-btn--black` - Black color theme - `.bds-btn--disabled` - Disabled state modifier - `.bds-btn--no-icon` - No icon modifier - `.bds-btn__label` - Label element - `.bds-btn__icon` - Icon container - `.bds-btn__icon-line` - Arrow horizontal line - `.bds-btn__icon-chevron` - Arrow chevron ### Background Animation Primary and Secondary variants use a shared animation pattern: 1. **Pseudo-element (`::before`)**: Creates the hover background fill 2. **Transform Origin**: Set to `bottom center` for bottom-to-top fill 3. **Initial State**: `scaleY(0)` - background hidden 4. **Hover/Focus**: `scaleY(1)` - background fills from bottom 5. **Active**: `scaleY(0)` - background resets during press This creates a smooth, directional fill animation that feels natural and responsive. ### Arrow Icon Animation The arrow icon consists of two parts: 1. **Horizontal Line**: Shrinks from right to left (`scaleX(0)`) on hover/focus 2. **Chevron**: Stays visible, shifts right via increased gap The gap between label and icon increases on hover/focus: - **Default**: 16px (desktop), 16px (mobile) - **Hover/Focus**: 22px (desktop), 21px (mobile) This creates the illusion of the arrow "moving forward" as the line disappears. ### Padding Adjustments On hover/focus, padding adjusts to accommodate the increased gap: - **Primary**: `8px 19px 8px 20px` → `8px 13px 8px 20px` (desktop) - **Secondary**: `6px 17px 6px 18px` → `6px 11px 6px 18px` (desktop) - **Tertiary**: `8px 20px` → `8px 14px 8px 20px` (desktop) These adjustments maintain visual balance while allowing the icon animation to work smoothly. ### Responsive Behavior The component adapts to screen size at the `1023px` breakpoint: **Desktop (≥1024px):** - Larger padding values - 22px gap on hover/focus **Tablet/Mobile (≤1023px):** - Reduced padding values - 21px gap on hover/focus All transitions remain smooth across breakpoints. ## Typography ### Primary & Secondary Variants - **Font**: Booton, sans-serif - **Size**: 16px (Label R token) - **Weight**: 400 - **Line Height**: 23.2px - **Letter Spacing**: 0px ### Tertiary Variant - **Font**: Booton, sans-serif - **Size**: 18px (Body R token) - **Weight**: 400 - **Line Height**: 26.1px - **Letter Spacing**: -0.5px ## Spacing & Layout - **Border Radius**: 100px (fully rounded) - **Max Height**: 40px - **Icon Size**: 15px × 14px - **Transitions**: 150ms with `cubic-bezier(0.98, 0.12, 0.12, 0.98)` ## Usage Examples ### Basic Usage ```tsx import { Button } from 'shared/components/Button'; // Primary button (default) // Secondary button // Tertiary button ``` ### Form Integration ```tsx
``` ### Without Icon ```tsx ``` ### Disabled State ```tsx ``` ### Color Themes ```tsx {/* Green theme (default) */} {/* Black theme */} ``` ### Visual Hierarchy ```tsx {/* Use variants to create clear visual hierarchy */} ``` ## Accessibility ### Keyboard Navigation - **Tab**: Focus next button - **Shift+Tab**: Focus previous button - **Enter/Space**: Activate button - **Focus Indicator**: Visible outline/border (2px) - **Disabled buttons**: Not focusable ### Screen Reader Support - Semantic `