button

package
v0.1.60 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 20 Imported by: 0

README

M3 Button

@Composable
@ExperimentalMaterial3ExpressiveApi
fun Button(
    onClick: () -> Unit,
    shapes: ButtonShapes,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    colors: ButtonColors = ButtonDefaults.buttonColors(),
    elevation: ButtonElevation? = ButtonDefaults.buttonElevation(),
    border: BorderStroke? = null,
    contentPadding: PaddingValues = ButtonDefaults.contentPaddingFor(ButtonDefaults.MinHeight),
    interactionSource: MutableInteractionSource? = null,
    content: @Composable RowScope.() -> Unit
): Unit

ButtonColors

ButtonColors(
    containerColor: Color,
    contentColor: Color,
    disabledContainerColor: Color,
    disabledContentColor: Color
)

ButtonElevation

@Composable
fun buttonElevation(
    defaultElevation: Dp = FilledButtonTokens.ContainerElevation,
    pressedElevation: Dp = FilledButtonTokens.PressedContainerElevation,
    focusedElevation: Dp = FilledButtonTokens.FocusedContainerElevation,
    hoveredElevation: Dp = FilledButtonTokens.HoveredContainerElevation,
    disabledElevation: Dp = FilledButtonTokens.DisabledContainerElevation
): ButtonElevation

Documentation

Index

Constants

View Source
const Material3ButtonNodeID = "Material3Button"

Variables

View Source
var ButtonColorsUnspecified = &ButtonColors{
	ContainerColor:         graphics.ColorUnspecified,
	ContentColor:           graphics.ColorUnspecified,
	DisabledContainerColor: graphics.ColorUnspecified,
	DisabledContentColor:   graphics.ColorUnspecified,
}
View Source
var ButtonDefaults = buttonDefaults{}
View Source
var ButtonElevationUnspecified = &ButtonElevation{
	DefaultElevation:  unit.DpUnspecified,
	PressedElevation:  unit.DpUnspecified,
	FocusedElevation:  unit.DpUnspecified,
	HoveredElevation:  unit.DpUnspecified,
	DisabledElevation: unit.DpUnspecified,
}

ButtonElevationUnspecified is the sentinel value for unspecified ButtonElevation

View Source
var ButtonShapesUnspecified = &ButtonShapes{
	Shape:        shape.ShapeUnspecified,
	PressedShape: shape.ShapeUnspecified,
}

ButtonShapesUnspecified is the sentinel value for unspecified ButtonShapes

Functions

func EqualButtonColors

func EqualButtonColors(a, b *ButtonColors) bool

EqualButtonColors returns true if a and b are semantically equal

func EqualButtonElevation

func EqualButtonElevation(a, b *ButtonElevation) bool

EqualButtonElevation returns true if a and b are semantically equal

func EqualButtonShapes

func EqualButtonShapes(a, b *ButtonShapes) bool

EqualButtonShapes returns true if a and b are semantically equal

func IsSpecifiedButtonColors

func IsSpecifiedButtonColors(c *ButtonColors) bool

func IsSpecifiedButtonElevation

func IsSpecifiedButtonElevation(e *ButtonElevation) bool

IsSpecifiedButtonElevation returns true if e is specified (not nil and not the sentinel)

func IsSpecifiedButtonShapes

func IsSpecifiedButtonShapes(s *ButtonShapes) bool

IsSpecifiedButtonShapes returns true if s is specified (not nil and not the sentinel)

func SameButtonColors

func SameButtonColors(a, b *ButtonColors) bool

SameButtonColors returns true if a and b are the same pointer or both unspecified

func SameButtonElevation

func SameButtonElevation(a, b *ButtonElevation) bool

SameButtonElevation returns true if a and b are the same pointer or both unspecified

func SameButtonShapes

func SameButtonShapes(a, b *ButtonShapes) bool

SameButtonShapes returns true if a and b are the same pointer or both unspecified

func SemanticEqualButtonColors

func SemanticEqualButtonColors(a, b *ButtonColors) bool

SemanticEqualButtonColors checks field-by-field equality

func SemanticEqualButtonElevation

func SemanticEqualButtonElevation(a, b *ButtonElevation) bool

SemanticEqualButtonElevation checks field-by-field equality

func SemanticEqualButtonShapes

func SemanticEqualButtonShapes(a, b *ButtonShapes) bool

SemanticEqualButtonShapes checks field-by-field equality

func StringButtonColors

func StringButtonColors(c *ButtonColors) string

StringButtonColors returns a string representation of ButtonColors

func StringButtonElevation

func StringButtonElevation(e *ButtonElevation) string

StringButtonElevation returns a string representation of ButtonElevation

func StringButtonShapes

func StringButtonShapes(s *ButtonShapes) string

StringButtonShapes returns a string representation of ButtonShapes

Types

type ButtonColors

type ButtonColors struct {
	ContainerColor         graphics.Color
	ContentColor           graphics.Color
	DisabledContainerColor graphics.Color
	DisabledContentColor   graphics.Color
}

func CoalesceButtonColors

func CoalesceButtonColors(ptr, def *ButtonColors) *ButtonColors

CoalesceButtonColors returns ptr if not nil, otherwise returns def

func CopyButtonColors

func CopyButtonColors(c *ButtonColors, options ...ButtonColorsOption) *ButtonColors

CopyButtonColors creates a copy with optional modifications

func MergeButtonColors

func MergeButtonColors(a, b *ButtonColors) *ButtonColors

MergeButtonColors merges two ButtonColors, preferring b's specified values over a's

func TakeOrElseButtonColors

func TakeOrElseButtonColors(c, defaultColors *ButtonColors) *ButtonColors

TakeOrElseButtonColors returns c if specified, otherwise returns defaultColors

type ButtonColorsOption

type ButtonColorsOption func(*ButtonColors)

ButtonColorsOption is a functional option for CopyButtonColors

func WithButtonContainerColor

func WithButtonContainerColor(c graphics.Color) ButtonColorsOption

WithButtonContainerColor sets the container color option

func WithButtonContentColor

func WithButtonContentColor(c graphics.Color) ButtonColorsOption

WithButtonContentColor sets the content color option

func WithButtonDisabledContainerColor

func WithButtonDisabledContainerColor(c graphics.Color) ButtonColorsOption

WithButtonDisabledContainerColor sets the disabled container color option

func WithButtonDisabledContentColor

func WithButtonDisabledContentColor(c graphics.Color) ButtonColorsOption

WithButtonDisabledContentColor sets the disabled content color option

type ButtonElevation

type ButtonElevation struct {
	DefaultElevation  unit.Dp
	PressedElevation  unit.Dp
	FocusedElevation  unit.Dp
	HoveredElevation  unit.Dp
	DisabledElevation unit.Dp
}

ButtonElevation holds elevation configuration for button states

func CoalesceButtonElevation

func CoalesceButtonElevation(ptr, def *ButtonElevation) *ButtonElevation

CoalesceButtonElevation returns ptr if not nil, otherwise returns def

func CopyButtonElevation

func CopyButtonElevation(e *ButtonElevation, options ...ButtonElevationOption) *ButtonElevation

CopyButtonElevation creates a copy with optional modifications

func MergeButtonElevation

func MergeButtonElevation(a, b *ButtonElevation) *ButtonElevation

MergeButtonElevation merges two ButtonElevation, preferring b's specified values over a's

func TakeOrElseButtonElevation

func TakeOrElseButtonElevation(e, defaultElevation *ButtonElevation) *ButtonElevation

TakeOrElseButtonElevation returns e if specified, otherwise returns defaultElevation

type ButtonElevationOption

type ButtonElevationOption func(*ButtonElevation)

ButtonElevationOption is a functional option for CopyButtonElevation

func WithDefaultElevation

func WithDefaultElevation(e unit.Dp) ButtonElevationOption

WithDefaultElevation sets the default elevation option

func WithDisabledElevation

func WithDisabledElevation(e unit.Dp) ButtonElevationOption

WithDisabledElevation sets the disabled elevation option

func WithFocusedElevation

func WithFocusedElevation(e unit.Dp) ButtonElevationOption

WithFocusedElevation sets the focused elevation option

func WithHoveredElevation

func WithHoveredElevation(e unit.Dp) ButtonElevationOption

WithHoveredElevation sets the hovered elevation option

func WithPressedElevation

func WithPressedElevation(e unit.Dp) ButtonElevationOption

WithPressedElevation sets the pressed elevation option

type ButtonOption

type ButtonOption func(o *ButtonOptions)

func WithBorder

func WithBorder(b *foundation.BorderStroke) ButtonOption

func WithButton

func WithButton(button *button.Button) ButtonOption

func WithColors

func WithColors(c *ButtonColors) ButtonOption

func WithContentPadding

func WithContentPadding(p layout.PaddingValues) ButtonOption

func WithElevation

func WithElevation(e *ButtonElevation) ButtonOption

func WithEnabled

func WithEnabled(enabled bool) ButtonOption

func WithModifier

func WithModifier(m ui.Modifier) ButtonOption

func WithShape

func WithShape(s shape.Shape) ButtonOption

func WithShapes

func WithShapes(s *ButtonShapes) ButtonOption

type ButtonOptions

type ButtonOptions struct {
	Modifier       ui.Modifier
	Button         *button.Button
	Enabled        bool
	Shape          shape.Shape   // Single shape (legacy/simple API)
	Shapes         *ButtonShapes // Shape and PressedShape for expressive shape morphing
	Colors         *ButtonColors
	Elevation      *ButtonElevation
	Border         *foundation.BorderStroke
	ContentPadding layout.PaddingValues
}

func DefaultButtonOptions

func DefaultButtonOptions() ButtonOptions

type ButtonShapes

type ButtonShapes struct {
	Shape        shape.Shape
	PressedShape shape.Shape
}

ButtonShapes holds shape configuration for button states

func CoalesceButtonShapes

func CoalesceButtonShapes(ptr, def *ButtonShapes) *ButtonShapes

CoalesceButtonShapes returns ptr if not nil, otherwise returns def

func CopyButtonShapes

func CopyButtonShapes(s *ButtonShapes, options ...ButtonShapesOption) *ButtonShapes

CopyButtonShapes creates a copy with optional modifications

func MergeButtonShapes

func MergeButtonShapes(a, b *ButtonShapes) *ButtonShapes

MergeButtonShapes merges two ButtonShapes, preferring b's specified values over a's

func TakeOrElseButtonShapes

func TakeOrElseButtonShapes(s, defaultShapes *ButtonShapes) *ButtonShapes

TakeOrElseButtonShapes returns s if specified, otherwise returns defaultShapes

type ButtonShapesOption

type ButtonShapesOption func(*ButtonShapes)

ButtonShapesOption is a functional option for CopyButtonShapes

func WithButtonPressedShape

func WithButtonPressedShape(s shape.Shape) ButtonShapesOption

WithButtonPressedShape sets the pressed shape option

func WithButtonShape

func WithButtonShape(s shape.Shape) ButtonShapesOption

WithButtonShape sets the shape option

type Composable

type Composable = api.Composable

func Outlined

func Outlined(onClick func(), label string, options ...ButtonOption) Composable

func OutlinedButton

func OutlinedButton(onClick func(), content Composable, options ...ButtonOption) Composable

type Composer

type Composer = api.Composer

type MutableValue

type MutableValue = state.MutableValue

type ThemeManager

type ThemeManager = theme.ThemeManager

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL