Button
When To Use
Buttons in Hybrid Design are used to perform one or more operations. When clicked, a button triggers the corresponding business logic. In Hybrid Design, we offer five types of buttons:
- Primary button: This button indicates the main action and there should only be one primary button in each section.
- Default button: This button represents a series of actions without priority.
- Dashed button: This button is commonly used for adding an action.
- Text button: This button is used for the most secondary action.
- Link button: This button is used for external links.
Additionally, we have four other properties that can be applied to any type of button:
danger
: This property is used for actions that involve risk, such as deletion or authorization.disabled
: This property indicates when actions are not available.loading
: This property adds a loading spinner to the button, preventing multiple submits.
In HybridUI, the available button types are primary, default, dashed, text, and link.
How to use it
- npm
- yarn
npm install @hybridui/button
yarn add @hybridui/button
Examples
Type
Hybrid-UI includes several types of buttons, such as primary, default, dashed, text, and link buttons.
Show code
- React
- Html/Angular
import { HyButton } from "@hybridui/button/react";
export default function App() {
return (
<div className="App">
<HyButton type="primary">Primary Button</HyButton>
<HyButton>Primary Button</HyButton>
<HyButton type="dashed">Primary Button</HyButton>
<HyButton type="text">Primary Button</HyButton>
<HyButton type="link">Primary Button</HyButton>
</div>
);
}
<hy-button type="primary">Primary Button</hy-button>
<hy-button>Primary Button</hy-button>
<hy-button type="dashed">Primary Button</hy-button>
<hy-button type="text">Primary Button</hy-button>
<hy-button type="link">Primary Button</HyButton>
CSS Varibale
Attribute | Value | |
---|---|---|
--hybrid-button-background-color | #f9f9f9 | |
--hybrid-button-border-color | #d0d0d0 | |
--hybrid-button-text-color | #393939 | |
--hybrid-button-hover-border-color | #1677ff | |
--hybrid-button-hover-color | #1677ff | |
--hybrid-button-active-border-color | #1661b1 | |
--hybrid-button-active--color | #184d86 | |
--hybrid-button-padding-y | 0.5rem | rem |
--hybrid-button-padding-x | 0.5rem | rem |
--hybrid-button-padding-r | 0.8rem | rem |
--hybrid-button-padding-l | 0.8rem | rem |
--hybrid-button-border-radius | 0.25rem | rem |
--hybrid-button-border-width | 1px | px |
--hybrid-button-font-size | 0.8rem | rem |
--hybrid-button-font-weight | 0.8rem | |
--hybrid-button-text-transform | none |
Primary
Attribute | Value | |
---|---|---|
--hybrid-button-primary-background-color | #1277e1 | |
--hybrid-button-primary-border-color | #1277e1 | |
--hybrid-button-primary-text-color | #ffffff | |
--hybrid-button-primary-hover-background-color | #0a70ff | |
--hybrid-button-primary-hover-border-color | #1677ff | |
--hybrid-button-primary-active-background-color | #0559cf | |
--hybrid-button-primary-active-border-color | #1677ff |
Dashed
Attribute | Value | |
---|---|---|
--hybrid-button-dashed-hover-border-color | #1277e1 | |
--hybrid-button-dashed-hover-text-color | #1277e1 | |
--hybrid-button-dashed-active-border-color | #1677ff |
Text
Attribute | Value | |
---|---|---|
--hybrid-button-text-hover-background-color | #e1e1e1 | |
--hybrid-button-text-active-background-color | #c1c1c1 |
Link
Attribute | Value | |
---|---|---|
--hybrid-button-link-text-color | #1677ff | |
--hybrid-button-link-hover-text-color | #4a96ff | |
--hybrid-button-link-active-text-color | #0862df |
Icon
To include an Icon in a Button component, you can either set the icon property or add an Icon component inside the Button. However, if you want more precise control over the positioning and arrangement of the Icon, it's best to add the Icon component inside the Button rather than relying on the icon property.
Show code
- React
- Html/Angular
import { HyButton } from "@hybridui/button/react";
export default function App() {
return (
<div className="App">
<HyButton icon="search" type="primary"></HyButton>
<HyButton icon="search" shape="circle" type="primary"></HyButton>
<HyButton shape="circle" type="primary">
B
</HyButton>
<HyButton icon="search" type="primary"> Search </HyButton>
<HyButton icon="search" shape="circle"></HyButton>
<HyButton icon="search">Search</HyButton>
<HyButton icon="search" shape="circle" type="dashed"></HyButton>
<HyButton icon="search" type="dashed"> Search </HyButton>
</div>
);
}
<hy-button icon="search" type="primary"></hy-button>
<hy-button icon="search" shape="circle" type="primary"></hy-button>
<hy-button shape="circle" type="primary">B</hy-button>
<hy-button icon="search" type="primary"> Search </hy-button>
<hy-button icon="search" shape="circle"></hy-button>
<hy-button icon="search">Search</hy-button>
<hy-button icon="search" shape="circle" type="dashed"></hy-button>
<hy-button icon="search" type="dashed"> Search </hy-button>
Size
HybridUI provides support for three button sizes: default, large, and small. To specify a desired size, set the size property to either "large" or "small". For a button with the default size, you can omit the size property.
Show code
- React
- Html/Angular
import { HyButton } from "@hybridui/button/react";
export default function App() {
return (
<div className="App">
<HyButton size="small">Small Size Button</HyButton>
<HyButton> Default Size Button</HyButton>
<HyButton size="large">Large Size Button</HyButton>
<br />
<HyButton type="primary" size="small"> Small Size Button </HyButton>
<HyButton type="primary"> Default Size Button</HyButton>
<HyButton type="primary" size="large"> Large Size Button </HyButton>
<br />
<HyButton type="link" size="large"> Link Size Button </HyButton>
<HyButton icon="user" type="dashed" size="large"> Icon big Size with text Button </HyButton>
<HyButton icon="search" type="dashed" size="large"></HyButton>
<HyButton icon="search" type="dashed" size="small"></HyButton>
</div>
);
}
<hy-button size="small">Small Size Button</hy-button>
<hy-button> Default Size Button</hy-button>
<hy-button size="large">Large Size Button</hy-button>
<br />
<hy-button type="primary" size="small"> Small Size Button </hy-button>
<hy-button type="primary"> Default Size Button</hy-button>
<hy-button type="primary" size="large"> Large Size Button </hy-button>
<br />
<hy-button type="link" size="large"> Link Size Button </hy-button>
<hy-button icon="user" type="dashed" size="large"> Icon big Size with text Button </hy-button>
<hy-button icon="search" type="dashed" size="large"></hy-button>
<hy-button icon="search" type="dashed" size="small"></hy-button>
Loading
To add a loading indicator to a button, you can set the loading property on the Button.
Show code
- React
- Html/Angular
import { HyButton } from "@hybridui/button/react";
import { useState } from "react";
export default function App() {
const [loading, setLoading] = useState(false);
const toggleLoading = () => {
setLoading(!loading);
};
return (
<>
<HyButton loading icon="spinner">
<span>loading</span>
</HyButton>
<HyButton type="primary" loading size="large" icon="spinner">
<span>loading</span>
</HyButton>
<HyButton
type="primary"
onClick={toggleLoading}
loading={loading}
icon={!loading || "spinner"}
>
{loading ? <span>loading</span> : <span>Click Me</span>}
</HyButton>
</>
);
}
<hy-button loading icon="spinner"> <span>loading</span> </hy-button>
<hy-button type="primary" loading size="large" icon="spinner"> <span>loading</span> </hy-button>
<hy-button type="primary" loading icon="spinner"><span>loading</span> </hy-button>
Disabled
To disable a button, you can add the "disabled" property to the Button element.
API
The Button component can be customized to create different button styles by setting various properties.
It is recommended to set the properties in the following order: type
-> shape
-> size
-> loading
-> disabled
.
Property | Description | Type | Default | Version |
---|---|---|---|---|
block | Option to fit button width to its parent width | boolean | false | |
danger | Sets the danger status of the button | boolean | false | |
disabled | Sets the disabled state of the button | boolean | false | |
href | Sets the redirect URL for a link button | string | - | |
htmlType | Sets the original HTML type attribute of the button. See MDN for more information. | string | button | |
icon | Sets the icon component for the button | ReactNode | - | |
loading | Sets the loading state of the button | boolean | { delay: number } | false | |
shape | Sets the shape of the button | default | circle | round | default | |
size | Sets the size of the button | large | middle | small | middle | |
target | Sets the target attribute of a link button. Works only when href is specified. | string | - | |
type | Sets the type of button. Available options are primary , ghost , dashed , link , text , default | |||
onClick | Set the handler to handle click event | (event: MouseEvent) => void | - |