4pragma ComponentBehavior: Bound
7import QtQuick.Templates as T
9import "../core/UiMetrics.js" as UiMetrics
10import "../internal/MotionAnimation.js" as MotionAnimation
45 property int size:
FAB.Size.Default
48 property int variant:
FAB.Variant.Primary
51 property bool lowered:
false
60 property bool expanded:
true
63 property MD.typescale typescale: UiMetrics.fabTypescale(control)
66 property bool mirrorIconInRtl:
false
69 readonly
property bool hasIcon: icon.name.length > 0
72 property color containerColor: {
74 case FAB.Variant.Surface:
75 return lowered ? control.MD.Style.surfaceContainerLowColor : control.MD.Style.surfaceContainerHighColor;
76 case FAB.Variant.Primary:
77 return control.MD.Style.primaryContainerColor;
78 case FAB.Variant.Secondary:
79 return control.MD.Style.secondaryContainerColor;
80 case FAB.Variant.Tertiary:
81 return control.MD.Style.tertiaryContainerColor;
86 property color contentColor: {
88 case FAB.Variant.Surface:
89 return control.MD.Style.primaryColor;
90 case FAB.Variant.Primary:
91 return control.MD.Style.onPrimaryContainerColor;
92 case FAB.Variant.Secondary:
93 return control.MD.Style.onSecondaryContainerColor;
94 case FAB.Variant.Tertiary:
95 return control.MD.Style.onTertiaryContainerColor;
100 readonly
property color effectiveContentColor: state.contentColor
103 readonly
property color effectiveContainerColor: state.containerColor
106 readonly
property real effectiveElevation: state.elevation
109 readonly
property string effectiveIconName: icon.name
112 readonly
property url effectiveIconSource: icon.source
115 readonly
property color effectiveIconColor: icon.color.a > 0 ? icon.color : effectiveContentColor
118 readonly
property bool effectiveIconMirrored: mirrorIconInRtl && mirrored
121 readonly
property bool _effectiveExpanded: expanded || !hasIcon
124 readonly
property real _collapsedWidth: UiMetrics.fabContainerWidth(control)
127 readonly
property real _expandedWidth: Math.max(_collapsedWidth,
128 state.expandedLeadingSpace
129 + contentItem.implicitWidth
130 + state.expandedTrailingSpace)
133 readonly
property real _layoutProgress: {
134 const distance = _expandedWidth - _collapsedWidth;
136 return _effectiveExpanded ? 1 : 0;
137 return Math.max(0, Math.min(1, (state.containerWidth - _collapsedWidth) / distance));
141 readonly
property real _leadingPadding: state.collapsedIconPadding
142 + (state.expandedLeadingSpace
143 - state.collapsedIconPadding)
147 readonly property real _trailingPadding: state.collapsedIconPadding
148 + (state.expandedTrailingSpace
149 - state.collapsedIconPadding)
152 icon.width: state.iconSize
153 icon.height: state.iconSize
155 implicitWidth: state.containerWidth
156 implicitHeight: state.containerHeight
162 leftPadding: mirrored ? _trailingPadding : _leadingPadding
163 rightPadding: mirrored ? _leadingPadding : _trailingPadding
166 spacing: state.iconLabelSpacing
169 focusPolicy: Qt.StrongFocus
171 Accessible.name: text
172 Accessible.role: Accessible.
Button
177 readonly property real containerHeight: UiMetrics.fabContainerHeight(control)
178 readonly property MD.shapeValue containerShape: UiMetrics.fabContainerShape(control)
179 readonly property real iconSize: UiMetrics.fabIconSize(control)
180 readonly property real expandedLeadingSpace: UiMetrics.fabLeadingSpace(control)
181 readonly property real expandedTrailingSpace: UiMetrics.fabTrailingSpace(control)
182 readonly property real iconLabelSpacing: UiMetrics.fabSpacing(control)
183 readonly property real collapsedIconPadding: (control._collapsedWidth - iconSize) / 2
185 property real containerWidth: control._effectiveExpanded ? control._expandedWidth : control._collapsedWidth
186 property color containerColor: control.containerColor
187 property color contentColor: control.contentColor
188 property color stateLayerColor:
"transparent"
190 property real elevation: control.lowered ? MD.
Tokens.fab.loweredContainerElevation : MD.
Tokens.fab.containerElevation
191 property real stateLayerOpacity: 0
193 Behavior on containerWidth {
194 enabled: control.text.length > 0
198 easing.type: Easing.BezierSpline
199 easing.bezierCurve: MotionAnimation.expressiveFastSpatialCurve
200 duration: MotionAnimation.expressiveFastSpatialDuration
209 when: control.down && control.enabled
212 state.elevation: control.lowered ? MD.
Tokens.fab.loweredPressedContainerElevation : MD.
Tokens.fab.pressedContainerElevation
213 state.stateLayerColor: control.effectiveIconColor
214 state.stateLayerOpacity: MD.
Tokens.fab.pressedStateLayerOpacity
219 when: control.visualFocus && control.enabled
222 state.elevation: control.lowered ? MD.
Tokens.fab.loweredFocusContainerElevation : MD.
Tokens.fab.focusContainerElevation
223 state.stateLayerColor: control.effectiveIconColor
224 state.stateLayerOpacity: MD.
Tokens.fab.focusStateLayerOpacity
229 when: control.hovered && control.enabled
232 state.elevation: control.lowered ? MD.
Tokens.fab.loweredHoverContainerElevation : MD.
Tokens.fab.hoverContainerElevation
233 state.stateLayerColor: control.effectiveIconColor
234 state.stateLayerOpacity: MD.
Tokens.fab.hoverStateLayerOpacity
241 objectName:
"fabContent"
246 mirrored: control.mirrored
247 mirrorIconInRtl: control.mirrorIconInRtl
248 spacing: state.iconLabelSpacing
249 typescale: control.typescale
250 color: control.effectiveContentColor
251 textOpacity: control._effectiveExpanded ? 1 : 0
252 icon.name: control.effectiveIconName
253 icon.source: control.effectiveIconSource
254 icon.width: state.iconSize
255 icon.height: state.iconSize
256 icon.color: control.effectiveIconColor
258 Behavior on textOpacity {
261 easing.type: Easing.BezierSpline
262 easing.bezierCurve: MotionAnimation.expressiveFastEffectsCurve
263 duration: MotionAnimation.expressiveFastEffectsDuration
270 implicitWidth: state.containerWidth
271 implicitHeight: state.containerHeight
272 topLeftRadius: UiMetrics.resolveShapeRadius(state.containerShape.topLeft, width, height)
273 topRightRadius: UiMetrics.resolveShapeRadius(state.containerShape.topRight, width, height)
274 bottomLeftRadius: UiMetrics.resolveShapeRadius(state.containerShape.bottomLeft, width, height)
275 bottomRightRadius: UiMetrics.resolveShapeRadius(state.containerShape.bottomRight, width,
277 color: state.containerColor
278 elevation: state.elevation
281 objectName:
"fabRipple"
283 topLeftRadius: parent.topLeftRadius
284 topRightRadius: parent.topRightRadius
285 bottomLeftRadius: parent.bottomLeftRadius
286 bottomRightRadius: parent.bottomRightRadius
287 pressed: control.pressed
288 pressX: control.pressX
289 pressY: control.pressY
290 stateOpacity: state.stateLayerOpacity
291 color: state.stateLayerColor
A rectangle that casts a Material 3 elevation shadow.
A Material Design 3 Expressive floating action button.
Material Design 3 design tokens.
Lays out an icon and text as a single reusable visual.