Line data Source code
1 : part of 'foss_text_field.dart';
2 :
3 : /// Visual overrides for a [FossTextField]. Every field is optional; a null
4 : /// field falls back to the value the theme resolves for the size and state.
5 : /// Pass one to a single field via `style:` to tweak a one-off, without changing
6 : /// the theme for every other field.
7 : ///
8 : /// State-derived colors (the focus ring and error border) stay token-driven.
9 : /// To restyle those globally, retheme `FossColors`.
10 : ///
11 : /// A wider, pill-cornered field with a custom resting border:
12 : ///
13 : /// ```dart
14 : /// FossTextField(
15 : /// label: 'Email',
16 : /// style: const FossTextFieldStyle(
17 : /// borderRadius: 999,
18 : /// borderColor: Color(0xFFD4D4D4),
19 : /// contentPadding: EdgeInsets.symmetric(horizontal: 16),
20 : /// ),
21 : /// );
22 : /// ```
23 : @immutable
24 : class FossTextFieldStyle {
25 : /// Creates a set of field overrides. All fields default to null (inherit).
26 3 : const FossTextFieldStyle({
27 : this.backgroundColor,
28 : this.borderColor,
29 : this.borderRadius,
30 : this.contentPadding,
31 : this.minHeight,
32 : this.textStyle,
33 : this.labelStyle,
34 : this.helperStyle,
35 : this.iconSize,
36 : this.gap,
37 : this.shadow,
38 : });
39 :
40 : /// Fill color of the field box.
41 : final Color? backgroundColor;
42 :
43 : /// Resting border color, used when the field is neither focused nor invalid.
44 : final Color? borderColor;
45 :
46 : /// Corner radius in logical pixels.
47 : final double? borderRadius;
48 :
49 : /// Inner padding around the editable content.
50 : final EdgeInsetsGeometry? contentPadding;
51 :
52 : /// Minimum box height in logical pixels; grows with text scale.
53 : final double? minHeight;
54 :
55 : /// Style of the editable value and placeholder. Its color is ignored; text
56 : /// and placeholder colors stay token-driven.
57 : final TextStyle? textStyle;
58 :
59 : /// Style of the [FossTextField.label] above the box. Its color is ignored;
60 : /// the label color stays token-driven.
61 : final TextStyle? labelStyle;
62 :
63 : /// Style of the helper and error caption below the box. Its color is ignored;
64 : /// the caption color stays token-driven (error uses the destructive role).
65 : final TextStyle? helperStyle;
66 :
67 : /// Leading and trailing icon size in logical pixels.
68 : final double? iconSize;
69 :
70 : /// Gap between an affix and the editable content in logical pixels.
71 : final double? gap;
72 :
73 : /// Drop shadow layers at rest; empty for none.
74 : final List<BoxShadow>? shadow;
75 :
76 : /// Returns a copy with every non-null field of [other] laid over this one.
77 : ///
78 : /// ```dart
79 : /// const base = FossTextFieldStyle(borderRadius: 8, minHeight: 34);
80 : /// const override = FossTextFieldStyle(minHeight: 30);
81 : /// base.merge(override); // borderRadius 8 kept, minHeight becomes 30
82 : /// ```
83 1 : FossTextFieldStyle merge(FossTextFieldStyle? other) {
84 : if (other == null) return this;
85 1 : return FossTextFieldStyle(
86 2 : backgroundColor: other.backgroundColor ?? backgroundColor,
87 2 : borderColor: other.borderColor ?? borderColor,
88 2 : borderRadius: other.borderRadius ?? borderRadius,
89 2 : contentPadding: other.contentPadding ?? contentPadding,
90 2 : minHeight: other.minHeight ?? minHeight,
91 2 : textStyle: other.textStyle ?? textStyle,
92 2 : labelStyle: other.labelStyle ?? labelStyle,
93 2 : helperStyle: other.helperStyle ?? helperStyle,
94 2 : iconSize: other.iconSize ?? iconSize,
95 2 : gap: other.gap ?? gap,
96 2 : shadow: other.shadow ?? shadow,
97 : );
98 : }
99 : }
|