Buttons

@sgroup/tailwind-plugins/buttons

The .btn class can be added to any element to display it as a button. However, care must be taken when applying to any elements outside of <button> and <input type="button"> to ensure that rendering is consistent across different browsers.

When using button classes on any non-semantic element for example <a> or <div> that are used to trigger in-page functionality (like collapsing content), rather than linking to new pages or sections within the current page, these links should be given the role="button" attribute to appropriately convey their purpose to assistive technologies such as screen readers.

Buttons

The framework provides serveral predefined button styles, each serving its own purpose.

Theme

Buttons also have a distinct hover and focus state. The focus state uses a "ring" for accessibility.

States

To adjust the size of buttons, include additional utility classes as required.

Sizes
With icons

Loading state

A button with the .loading class can show a loading indicator. This will hide any text on the button.

Loading

Configuration

Configure the @sgroup/tailwind-plugins/buttons plugin using theme options.

theme: {
    extend: {
        button: (theme) => {
            return {
                // Styles for all buttons e.g. `.btn`.
                DEFAULT: {
                    paddingLeft: theme('padding.4'),
                    paddingRight: theme('padding.4'),
                },

                // Override or extend any themed buttons. Provide _any_ CSS property.
                primary: {
                    color: theme('textColor.white'),
                    textTransform: 'uppercase',

                    // Change the hover and focus states
                    hover: {
                        borderColor: theme('borderColor.white'),
                        backgroundColor: theme('backgroundColor.white'),
                        color: theme('colors.white'),
                    },

                    focus: {
                        borderColor: theme('borderColor.white'),
                        backgroundColor: theme('backgroundColor.white'),
                        color: theme('colors.white'),
                    },
                },

                // Add new named items, like `.btn-outline`.
                outline: {
                    backgroundColor: 'transparent',
                    color: theme('textColor.primary.500'),
                    borderColor: theme('borderColor.primary.500'),
                },

                // Add styles to target a breakpoint
                '@screen sm': {
                    fontSize: theme('fontSize.xs'),
                },
            };
        },
    },
},