A versatile button component with support for loading states, icons, and link rendering.
Import
import { DButton } from '@dynamic-framework/ui-react';
TypeScript Interface
interface Props
extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'color'>,
BaseProps,
StartIconProps,
EndIconProps {
href?: string;
target?: React.AnchorHTMLAttributes<HTMLAnchorElement>['target'];
rel?: React.AnchorHTMLAttributes<HTMLAnchorElement>['rel'];
color?: ComponentColor;
size?: ComponentSize;
variant?: ButtonVariant;
text?: string;
loading?: boolean;
loadingText?: string;
loadingAriaLabel?: string;
}
type ComponentSize = 'sm' | 'lg';
type ButtonVariant = 'outline' | 'link';
type ComponentColor = string;
type StartIconProps = {
iconStart?: string;
iconStartDisabled?: boolean;
iconStartFamilyClass?: string;
iconStartFamilyPrefix?: string;
iconStartAriaLabel?: string;
iconStartTabIndex?: number;
iconStartMaterialStyle?: boolean;
};
type EndIconProps = {
iconEnd?: string;
iconEndDisabled?: boolean;
iconEndFamilyClass?: string;
iconEndFamilyPrefix?: string;
iconEndAriaLabel?: string;
iconEndTabIndex?: number;
iconEndMaterialStyle?: boolean;
};
type BaseProps = {
style?: CSSProperties;
className?: string;
dataAttributes?: DataAttributes;
};
Props
If provided, renders the button as an anchor (<a>) element instead of a button.
Target attribute for anchor element (only applies when href is provided).
Rel attribute for anchor element (only applies when href is provided).
Color variant of the button. Accepts any valid color name (e.g., 'primary', 'success', 'danger').
Size variant of the button.
Visual variant of the button. 'outline' creates a bordered button, 'link' creates a text-only button.
Text content to display in the button. Alternative to using children.
If true, displays a loading spinner and disables the button.
Text to display next to the spinner when loading.
Accessible label for screen readers when button is in loading state.
If true, disables the button.
Icon to display at the start of the button text.
CSS class for the start icon font family.
Prefix for the start icon font family.
Whether to use Material Design style for the start icon.
Icon to display at the end of the button text.
CSS class for the end icon font family.
Prefix for the end icon font family.
Whether to use Material Design style for the end icon.
type
'button' | 'submit' | 'reset'
default:"button"
HTML button type attribute.
onClick
(event: MouseEvent<HTMLButtonElement>) => void
Click event handler.
Additional CSS classes to apply to the button.
Inline styles to apply to the button.
Content to display inside the button. Alternative to using text prop.
Usage Examples
import { DButton } from '@dynamic-framework/ui-react';
export default function Example() {
return (
<DButton text="Click Me" color="primary" />
);
}
Color Variants
import { DButton } from '@dynamic-framework/ui-react';
export default function Example() {
return (
<div className="d-flex gap-2">
<DButton text="Primary" color="primary" />
<DButton text="Success" color="success" />
<DButton text="Danger" color="danger" />
<DButton text="Warning" color="warning" />
<DButton text="Info" color="info" />
</div>
);
}
Outline Variant
import { DButton } from '@dynamic-framework/ui-react';
export default function Example() {
return (
<div className="d-flex gap-2">
<DButton text="Outline Primary" color="primary" variant="outline" />
<DButton text="Outline Success" color="success" variant="outline" />
<DButton text="Outline Danger" color="danger" variant="outline" />
</div>
);
}
With Icons
import { DButton } from '@dynamic-framework/ui-react';
export default function Example() {
return (
<div className="d-flex gap-2">
<DButton
text="Previous"
color="primary"
iconStart="arrow-left"
iconStartFamilyClass="bi"
/>
<DButton
text="Next"
color="primary"
iconEnd="arrow-right"
iconEndFamilyClass="bi"
/>
</div>
);
}
Loading State
import { DButton } from '@dynamic-framework/ui-react';
import { useState } from 'react';
export default function Example() {
const [loading, setLoading] = useState(false);
const handleClick = () => {
setLoading(true);
setTimeout(() => setLoading(false), 2000);
};
return (
<DButton
text="Submit"
color="primary"
loading={loading}
loadingText="Submitting..."
onClick={handleClick}
/>
);
}
As Link
import { DButton } from '@dynamic-framework/ui-react';
export default function Example() {
return (
<DButton
text="Visit Dynamic"
color="primary"
href="https://dynamic.xyz"
target="_blank"
rel="noopener noreferrer"
/>
);
}
Size Variants
import { DButton } from '@dynamic-framework/ui-react';
export default function Example() {
return (
<div className="d-flex align-items-center gap-2">
<DButton text="Small" color="primary" size="sm" />
<DButton text="Default" color="primary" />
<DButton text="Large" color="primary" size="lg" />
</div>
);
}
Disabled State
import { DButton } from '@dynamic-framework/ui-react';
export default function Example() {
return (
<div className="d-flex gap-2">
<DButton text="Disabled" color="primary" disabled />
<DButton text="Disabled Outline" color="primary" variant="outline" disabled />
</div>
);
}