Skip to content

Button - Web Component โ€‹

The Button component can be used imported from:

Playground โ€‹

Parameters โ€‹

The Web component uses the <z-button> tag:

By default, all the parameters are optional or can be set in different, except for the ones marked as required

The parametrization of the component can be done with the following custom HTML params:

NameTypeDescriptionSlotA11y
configstring

The main parameter has three components following the pattern: <type><?:size><?:round>

  • type: defines the type of button that is going to be shown up. The possible values are: primary, secondary, positive, negative, and link.
  • size: (optional) defines de size of the button. The default value is m, being omitted from the param. The possible values are: xs, s, or l. Check the sizes section.
  • round: (optional) if we define the value round, the button will take a round shape.
iconstring

The name of the icon that will be shown up inside the button. Check the icon list

contentstringThe text that will be shown up inside the button.default
icon-rightboolean

Defines the position of the icon. The default value is true, being omitted.

disabledbooleanBlocks the interaction with the component.
loadingbooleanShows a loading animation inside the button.
widebooleanย  stringExpands the button to the full width of its parent.
hrefstringTransform the button into a link.
targetstringThe target attribute specifies where to open the linked document.
popover-targetstring

Refers to the popover element with the specified id, and toggle between showing and hiding it. Check the official docs

as-submitbooleanTransform the button into a submit input.

Events โ€‹

This component has events. Check the documentation about how to use the events.

NamePayloadDescription
clickMouseEvent...

Slots โ€‹

This component has slots. Check the documentation about how to use the slots.

NameTagsDescription
defaultspanContent of the button.
popoverspanUsed for popover content

Parameters use โ€‹

Check the documentation about how to use the parameters.

content โ€‹

The text or content inside the button. It uses the default slot too.

Button

config โ€‹

type โ€‹

The z-button component will use the primary type as default, matching the primary type of the specifications.

Button

There are four more types of buttons, secondary, negative, positive, and link

ButtonButtonButtonButton
size โ€‹

The first modifier is size defines the size of the button. The value is m, being omitted from the parameter. The possible values for size are: xs, s or l. Check the size section.

ButtonButtonButtonButton
round โ€‹

The second modifier is round, that can receive the value round to implement a round styling to the button.

BTN

This configuration is also applied by default if the button doesn't have text. For example, only having an icon:

TIP

Make sure the content of the round button it's short and concise. Best approach would be to use a simple call to action icon

icon โ€‹

The attribute icon it's useful to insert a specific CTA icon. Check the icon list here. This attribute will receive the name of the icon to be show. You can use both solid or line (outlined) version.

Button
Only icon โ€‹

If we use only the icon, the config can still be set:

Flags โ€‹

icon-right โ€‹

This attribute will display the icon on the right side of the text.

Button
disabled โ€‹

The attribute disabled will block the interaction with the component.

Button
loading โ€‹

A loading indicator can be added to a button by setting the loading attribute.

Button
wide โ€‹

The wide attribute will make the button take the full width of the parent container.

Button

There's an option of using spread value to distribute the items with the elements apart:

ButtonButtonButton

Button can directly be used as links. Just provide a href attribute. The target attribute will be also available.

Button

Special uses โ€‹

Back to top โ€‹

For a smooth behavior in the navigation, use this CSS code:

Smooth off
css
html {
  scroll-behavior: smooth;
}

Popover โ€‹

Using the Popover API and the popover-target attribute, we can achieve an easy popover behavior:

Toggle the popover
Popover content

We can also directly use the popoverslot. In this case, the popover is pre-styled:

Toggle the popover
Slotted Popover

The popover element can be customized in this case using the CSS selector z-button::part(popover). The exposed tokens for the customization are:

  • --z-button--backdrop
  • --z-button--popover-padding
  • --z-button--popover-radius

Browser support โ€‹

Detected engine: ย 

  • Chromium

  • Webkit

  • Gecko

HTML Examples โ€‹

CodeSandbox example โ€‹