@cas-smartdesign/button
v7.1.14
Published
A button element which encloses the look and feel of the smartdesign button
Readme
@cas-smartdesign/button
A button element which encloses the look and feel of the SmartDesign 3.0 button.
This element must be used together with the design tokens of SmartDesign. For an independent application, make sure to include the @cas-smartdesign/design-tokens package. For a web app / web widget, refer to the official documentation about design token usage.
Attributes
icon: string- Defines the icon of the button
disabled: boolean- Defines whether if the button is disabled. Note that it uses default disabled attribute, thus blocking pointer/mouse events.
type: string- Can be set to either
submitorresetto make the button act like a HTML form button.
- Can be set to either
variant: string- Defines the visual style of the button. One of
primary,outline,standard,ghost,outline-danger,ghost-danger,selection,customorcontrast. Defaults tostandardwhen unset or set to an unknown value.
- Defines the visual style of the button. One of
aria-pressed: boolean- Marks a
selectionbutton as selected (standard toggle-button semantics). When the variant is set toselectionand the attribute is absent, the button initializes it tofalseso assistive tools announce it as a toggle; the consumer flips it totrue/false.
- Marks a
Properties
disabled: boolean- Makes the button looks like it is disabled & also prevents click events but used with a classname so mouse events are still triggered thus allowing for example tooltip usage in all browsers.
variant: ButtonVariant- Gets or sets the button's visual style (
primary,outline,standard,ghost,outline-danger,ghost-danger,selection,customorcontrast). Reading it returnsstandardwhen thevariantattribute is missing or invalid.
- Gets or sets the button's visual style (
CSS Custom Properties
--sd-button-content-padding- Defines the value of margin-left, margin-right (default is 8px)
--sd-button-max-icon-size- Defines the value of max-width, max-height (default is 32px)
Colors & border
Each variant sets sensible defaults for these. Override them to fully customize a variant, or to style the custom variant which sets none of them itself. Each property falls back to a smartdesign design token when unset.
The selection variant additionally re-points these properties while selected ([aria-pressed="true"]): the background and border switch to the selection accent tokens, and the hover state is pinned to the selected colors so the selected look survives the cursor. To customize the selected appearance, set the same --sd-button-* properties under your own [aria-pressed="true"] selector.
For the custom variant you only need to set the two rest colors — --sd-button-background-color and --sd-button-color. The hover and pressed states are derived from them automatically (the background darkens, the text color is kept), so a minimal override stays coherent. You can still pin any individual state by setting its --sd-button-* property explicitly.
Mind the color contrast when relying on the derived states: because the background darkens while the text color is kept, a --sd-button-color that contrasts well against the rest background may fall below the required contrast ratio against the darker hover/pressed background. If the derived states do not meet your contrast requirements, set --sd-button-color-hover and --sd-button-color-pressed (and the matching background properties) explicitly.
The contrast variant is transparent at rest and derives its foreground automatically from the surface it sits on. Point --sd-button-contrast-source at the color behind the button (it defaults to the themed page background --color-bg-default, so it already follows the light/dark theme). The derived color is exposed as --sd-button-contrast-color and kept across every state — the foreground never changes. The :focus-visible outline is colored from the same derived foreground so the focus ring stays legible on dark surfaces.
--sd-button-contrast-source- (
contrastvariant) The surface color behind the button, used to derive a legible foreground and the hover/pressed shades. Defaults to--color-bg-default.
- (
--sd-button-contrast-color- (
contrastvariant) The derived foreground color (computed from--sd-button-contrast-source). Used for the text/icon color in every state. Override to pin the foreground.
- (
--sd-button-background-color- Background color in the default (rest) state.
--sd-button-color- Foreground (text/icon) color in the default state.
--sd-button-border- The
bordershorthand applied to the button (e.g.1px solid …). Used by theoutlinevariants.
- The
--sd-button-background-color-hover- Background color on hover/focus.
--sd-button-color-hover- Foreground color on hover/focus.
--sd-button-border-color-hover- Border color on hover/focus (defaults to
transparent).
- Border color on hover/focus (defaults to
--sd-button-background-color-pressed- Background color while pressed (
:active).
- Background color while pressed (
--sd-button-color-pressed- Foreground color while pressed.
--sd-button-border-color-pressed- Border color while pressed (defaults to
transparent).
- Border color while pressed (defaults to
--sd-button-background-color-disabled- Background color when disabled.
--sd-button-color-disabled- Foreground color when disabled.
--sd-button-border-color-disabled- Border color when disabled (defaults to
transparent).
- Border color when disabled (defaults to
--sd-button-outline-color- Color of the
:focus-visibleoutline. Defaults to--color-border-interaction-focus; thecontrastvariant points it at--sd-button-contrast-color.
- Color of the
SCSS mixins
The package ships SCSS mixins so a consumer app can apply the SmartDesign button look to its own elements (e.g. a native <button>), reusing the exact same variant definitions as the web component.
@use "@cas-smartdesign/button/scss/button" as sd-button;
button.cta {
@include sd-button.button(primary);
}
// compose if you only want the variant colors onto an already-laid-out element
.danger {
@include sd-button.appearance;
@include sd-button.variant("outline-danger");
}Available mixins:
button($variant: standard)— full look (layout + colors + variant). The defaultstandardneeds no variant. Forselectionit also emits the selected-state rules under[aria-pressed="true"](you manage the attribute yourself on a native element).base— structural styling only (layout, focus ring, disabled cursor), no colors.appearance— the color engine (rest + hover/focus + pressed + disabled), driven by the--sd-button-*properties.variant($name)— sets the--sd-button-*values for a named variant.selection-checked— the selected-state rules of theselectionvariant (under[aria-pressed="true"]); include it alongsidevariant("selection")when composing manually instead of usingbutton(selection).
Notes:
- Resolving
@use "@cas-smartdesign/button/scss/button"requires the consumer's build to resolve packages in Sass. - Themed colors resolve through the
@cas-smartdesign/design-tokensCSS custom properties; without them, the built-in hex fallbacks apply. Consumers keep the same--sd-button-*override knobs documented above.
