Button
A customizable button component that serves as a trigger for actions and navigation.
Usage
import { Button } from '@blendx-ui';
// Basic usage
<Button onClick={handleClick}>Click me</Button>
// With variant and size
<Button
onClick={handleClick}
variant="primary"
size="lg"
>
Submit
</Button>
Props
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
| children | node | Yes | - | The content of the button |
| onClick | function | No | () => | Function called when button is clicked |
| variant | string | No | 'primary' | Visual style variant ('primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark', 'link', 'outline-*') |
| size | string | No | 'md' | Size of the button ('sm', 'md', 'lg') |
| disabled | boolean | No | false | Whether the button is disabled |
| type | string | No | 'button' | HTML button type ('button', 'submit', 'reset') |
| as | elementType | No | 'button' | Render as a different element (e.g., 'a', Link) |
| href | string | No | - | URL if rendered as anchor (as="a") |
| className | string | No | - | Additional CSS classes |
| block | boolean | No | false | Whether button should take full width |
Parameters
onClick
- Parameters:
(event: React.MouseEvent<HTMLButtonElement>)- The click event - Returns:
void
as
- Parameters:
React.ElementType- Component to render the button as - Returns: Rendered button component
Return Value
Returns a customizable button component with the following features:
- Can be rendered as different elements (button, anchor, etc.)
- Supports different visual styles through variants
- Supports different sizes
- Can be disabled
- Can take full width of container (block)
Examples
Basic Button
<Button onClick={() => console.log('Clicked!')}>
Click me
</Button>
Button Variants
<>
<Button variant="primary">Primary</Button>
<Button variant="secondary">Secondary</Button>
<Button variant="success">Success</Button>
<Button variant="danger">Danger</Button>
<Button variant="warning">Warning</Button>
<Button variant="info">Info</Button>
<Button variant="light">Light</Button>
<Button variant="dark">Dark</Button>
<Button variant="link">Link</Button>
</>
Button Sizes
<>
<Button size="sm">Small</Button>
<Button size="md">Medium</Button>
<Button size="lg">Large</Button>
</>
Disabled Button
<Button disabled>Disabled</Button>
Block Button
<Button block>Full Width Button</Button>
As Link
<Button as="a" href="https://example.com">
Link Button
</Button>
Accessibility
- Supports keyboard navigation and focus
- When rendered as a button, uses the native button element for accessibility
- When rendered as a link, includes proper ARIA attributes
- Disabled state is properly communicated to screen readers
Best Practices
- Use button variants that match your UI's purpose (e.g., 'danger' for destructive actions)
- Provide meaningful text in the button to describe the action
- Use consistent button sizes throughout your application
- Consider using icons alongside text for clarity where appropriate
- For form submissions, set type="submit"
- For navigation, use as="a" with href
Related Components
- IconButton
- ButtonGroup
- DropdownButton
- StatefulButton
- ToggleButton
Notes
- Based on React Bootstrap's Button component
- For icon-only buttons, consider using IconButton instead for better accessibility
IconButton
Description:
The IconButton component is a button that displays only an icon and can be customized with different sizes and rounded styles.
Usage:
import React from 'react';
import IconButton from 'blendx-ui/Button';
import { Check } from '@openedx/paragon/icons';
const MyIconButton = () => (
<IconButton
icon={Check}
size="sm"
rounded={true}
onClick={() => alert('Icon Button clicked!')}
/>
);
export default MyIconButton;
Props:
icon(string, required): The icon to render inside the button.size('sm' | 'md' | 'lg' | 'inline'): Size of the button.rounded(bool): If true, the button will have rounded corners.className(string): Custom CSS class for the button.disabled(bool): If true, the button is disabled.onClick(func): Function called when the button is clicked.onKeyDown(func): Function called when a key is pressed while the button is focused.type(string): The type of the button. Default is'button'.variant(string): The variant of the button.
Example:
<IconButton
icon={Check}
size="lg"
rounded={true}
onClick={() => console.log('Icon Button clicked')}
variant="success"
/>
ButtonGroup
Description:
The ButtonGroup component is a container for grouping buttons together, with optional vertical stacking and toggling features.
Usage:
import React from 'react';
import { ButtonGroup, Button } from 'blendx-ui';
const MyButtonGroup = () => (
<ButtonGroup size="md" vertical={false}>
<Button variant="primary">Button 1</Button>
<Button variant="secondary">Button 2</Button>
<Button variant="success">Button 3</Button>
</ButtonGroup>
);
export default MyButtonGroup;
Props:
size('sm' | 'md' | 'lg' | 'inline'): Size of the buttons in the group.vertical(bool): If true, the buttons are stacked vertically.toggle(bool): If true, the buttons will act as a toggle group.className(string): Custom CSS class for the button group.role(string): ARIA role for the button group.bsPrefix(string): Base CSS class name for the button group.
Example:
<ButtonGroup size="lg" vertical={true}>
<Button variant="primary">Button 1</Button>
<Button variant="secondary">Button 2</Button>
</ButtonGroup>
Note: The ButtonToolbar component has been omitted from this documentation. For grouping buttons in a toolbar, refer to the ButtonGroup component.
Re-exported Components:
ButtonGroupIconButton
Dependencies
| Repository | Usage Count |
|---|---|
| frontend-app-staff-dashboard | 55 |
| frontend-app-dashboard | 19 |
| frontend-app-course-authoring | 22 |
| frontend-app-authn | 5 |
| frontend-app-discussions | 2 |
| frontend-app-account | 9 |
| frontend-app-learning | 8 |
| frontend-app-profile | 3 |
Detailed usage locations:
frontend-app-staff-dashboard
src/components/BillingForm/index.jsxsrc/components/CourseExploreCard.jsxsrc/components/DocumentCard.jsxsrc/components/MiniTable.jsxsrc/components/ProfileCardLarge.jsxsrc/components/ProgramCard.jsxsrc/components/Support.jsxsrc/components/VideoCard.jsxsrc/pages/academics/academics-header/index.jsxsrc/pages/ai-studio/AiStudio.jsxsrc/pages/ai-studio/components/GeneratingView.jsxsrc/pages/ai-studio/components/StructureView.jsxsrc/pages/analytics/interaction-chart/index.jsxsrc/pages/billing/billing-table/dummyData.jsxsrc/pages/billing/index.jsxsrc/pages/calendar/index.jsxsrc/pages/create-program/index.jsxsrc/pages/home/AiHome.jsxsrc/pages/home/index.jsxsrc/pages/home/learners-table/dummyData.jsxsrc/pages/home/updates/recent-activity/page.jsxsrc/pages/library/documents/index.jsxsrc/pages/library/videos/index.jsxsrc/pages/notifications/index.jsxsrc/pages/organizations/CreateOrganisation.jsxsrc/pages/organizations/index.jsxsrc/pages/platform-settings/customization/appearance/BannerEdit.jsxsrc/pages/platform-settings/customization/appearance/index.jsxsrc/pages/platform-settings/customization/contact-information/index.jsxsrc/pages/platform-settings/index.jsxsrc/pages/platform-settings/integrations/IntegrationCard.jsxsrc/pages/platform-settings/integrations/IntegrationDrawer.jsxsrc/pages/program-single/courses/AddCoursesDrawer.jsxsrc/pages/program-single/courses/index.jsxsrc/pages/program-single/enrollment/EnrollDrawer.jsxsrc/pages/program-single/enrollment/index.jsxsrc/pages/program-single/program-team/AddUserDrawer.jsxsrc/pages/program-single/program-team/index.jsxsrc/pages/program-single/settings/DeleteProgramModal.jsxsrc/pages/program-single/settings/index.jsxsrc/pages/student-progress/course-engagement-chart/india.jsxsrc/pages/student-progress/course-summary-table/index.jsxsrc/pages/users/AddUsersDrawer.jsxsrc/pages/users/index.jsxsrc/pages/users/learners/index.jsxsrc/pages/users/staffs/index.jsxsrc/pages/users/teams/AddUsersToTeamDrawer.jsxsrc/pages/users/teams/CreateTeamDrawer.jsxsrc/pages/users/teams/TeamSingle.jsxsrc/pages/users/teams/index.jsxsrc/pages/utilities/notifications/NotificationsDrawer.jsxsrc/pages/utilities/notifications/index.jsxsrc/pages/view-ticket/MessageInput.jsxsrc/pages/view-ticket/TicketHeader.jsxsrc/utilities/notification/NotificationDrawer.jsx
frontend-app-dashboard
src/components/ActiveTickets.jsxsrc/components/CartDrawer.jsxsrc/components/CourseExploreCard.jsxsrc/components/MiniTable.jsxsrc/components/ProfileCardLarge.jsxsrc/components/ProgramCard.jsxsrc/components/RecentActivityCard.jsxsrc/pages/calendar/index.jsxsrc/pages/course-single/index.jsxsrc/pages/discover/index.jsxsrc/pages/home/AiHome.jsxsrc/pages/home/index.jsxsrc/pages/notifications/index.jsxsrc/pages/progress/course-engagement-chart/india.jsxsrc/pages/progress/course-summary-table/index.jsxsrc/pages/support/InputDrawerSupport.jsxsrc/pages/support/actionModalSupport.jsxsrc/pages/support/index.jsxsrc/pages/support/view-ticket/MessageInput.jsx
frontend-app-course-authoring
src/certificates/certificate-edit-form/CertificateEditForm.jsxsrc/cohorts/CohortDrawer.jsxsrc/cohorts/CohortList.jsxsrc/content-tags-drawer/ContentTagsDrawer.jsxsrc/course-outline/CourseOutline.jsxsrc/course-outline/card-header/TitleButton.jsxsrc/course-outline/content-actions/ContentActions.jsxsrc/course-outline/header-navigations/HeaderNavigations.jsxsrc/course-outline/outline-sidebar/OutlineSidebar.jsxsrc/course-outline/section-card/SectionCard.jsxsrc/course-outline/status-bar/StatusBar.jsxsrc/course-outline/subsection-card/SubsectionCard.jsxsrc/enrollments/EnrollDrawer.jsxsrc/enrollments/index.jsxsrc/export-page/CourseExportPage.jsxsrc/generic/course-upload-image/index.jsxsrc/generic/create-or-rerun-course/CreateOrRerunCourseForm.jsxsrc/generic/tag-count/index.jsxsrc/schedule-and-details/basic-section/index.jsxsrc/schedule-and-details/license-section/license-selector/index.jsxsrc/studio-home/StudioHome.jsxsrc/studio-home/card-item/index.jsx
frontend-app-authn
src/common-components/SocialAuthProviders.jsxsrc/forgot-password/ForgotPasswordPage.jsxsrc/login/LoginPage.jsxsrc/reset-password/ResetPasswordPage.jsxsrc/sandbox-login/index.jsx
frontend-app-discussions
src/discussions/posts/post/LikeButton.jsxsrc/discussions/posts/post-actions-bar/PostActionsBar.jsx
frontend-app-account
src/BlendxSettings/profile-details/index.jsxsrc/account-settings/EditableField.jsxsrc/account-settings/EditableSelectField.jsxsrc/account-settings/EmailField.jsxsrc/account-settings/delete-account/DeleteAccount.jsxsrc/account-settings/delete-account/SuccessModal.jsxsrc/account-settings/reset-password/ResetPassword.jsxsrc/components/CartDrawer.jsxsrc/components/ProfileCardLarge.jsx
frontend-app-learning
src/course-home/outline-tab/widgets/FlagButton.jsxsrc/course-home/outline-tab/widgets/StartOrResumeCourseCard.jsxsrc/course-home/progress-tab/certificate-status/CertificateStatus.jsxsrc/courseware/course/sequence/sequence-navigation/UnitNavigation.jsxsrc/courseware/course/sidebar/sidebars/course-outline/CourseOutlineTray.jsxsrc/courseware/course/sidebar/sidebars/course-outline/components/SidebarSection.jsxsrc/instructor-toolbar/InstructorToolbar.jsxsrc/instructor-toolbar/masquerade-widget/MasqueradeWidget.jsx
frontend-app-profile
src/BlendxProfile/index.jsxsrc/components/CartDrawer.jsxsrc/components/ProfileCardLarge.jsx