Skip to content

Commit 1d7ea15

Browse files
authored
feat(checkbox,radio-button,switch): update design (#490)
* chore : add radius-item-only token : radio/checkbo * chore : checkbox * chore : radio button * chore : switch * chore : l10n description * update : helper text to description control item * chore : new token read only * chore : add CHANGELOG * chore : doc readOnly code * add errror message and update additional text * fix : conditional error text message in demo app * fix : add getErrorMessageTextColor function token * add icon error * chore : add changelog * chore : delete readOnly inherited interaction * chore : add error message and fix icon when error * fix : read only on tap * review : fix padding inline horizontal * fix : delete padding horizontal behind component * chore : add grid margin token * fix : accessibility ghost doc app demo * fix : delete security margin app demo * fix : token grid margin * review : design 25/11 padding indicator and error * fix : change additionnal label to extra label * review : add helvetica neue font family ios orange
1 parent d5e1f4a commit 1d7ea15

File tree

42 files changed

+1384
-694
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1384
-694
lines changed

app/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- [DemoApp][Library] Tokens: `link` and `linkMono` ([#390](https://github.com/Orange-OpenSource/ouds-flutter/issues/#390))
1515

1616
### Changed
17+
- [DemoApp][Library] Component Update - Standalone checkbox and radio button rounded corners ([#466](https://github.com/Orange-OpenSource/ouds-flutter/issues/437))
18+
- [DemoApp][Library] Component Update - Radio button v1.4.0 ([#466](https://github.com/Orange-OpenSource/ouds-flutter/issues/467))
19+
- [DemoApp][Library] Component Update - Switch v1.5.0 ([#466](https://github.com/Orange-OpenSource/ouds-flutter/issues/466))
20+
- [DemoApp][Library] Component Update - Checkbox v2.4.0 ([#465](https://github.com/Orange-OpenSource/ouds-flutter/issues/465))
21+
- [DemoApp][Library] Component Update - Update of radio item v1.3.0 ([#433](https://github.com/Orange-OpenSource/ouds-flutter/issues/433))
22+
- [DemoApp][Library] Component Update - Update switch item to v1.4.0 ([#434](https://github.com/Orange-OpenSource/ouds-flutter/issues/434))
23+
- [DemoApp][Library] Component Update - Update checkbox item to v2.3.0 ([#431](https://github.com/Orange-OpenSource/ouds-flutter/issues/431))
1724
- [DemoApp][Library] Update `badge` component (badge, badge count, badge icon (v1.2) ([#423](https://github.com/Orange-OpenSource/ouds-flutter/issues/#423))
1825
- [DemoApp][Library] Update of `button` version v3.1 ([#396](https://github.com/Orange-OpenSource/ouds-flutter/issues/396))
1926
- [DemoApp][Library] Use Solaris icons ([#245](https://github.com/Orange-OpenSource/ouds-flutter/issues/245))

app/lib/l10n/gen/ouds_flutter_app_localizations.dart

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,12 @@ abstract class AppLocalizations {
389389
/// **'Error'**
390390
String get app_components_common_error_label;
391391

392+
/// No description provided for @app_components_common_error_message.
393+
///
394+
/// In en, this message translates to:
395+
/// **'Error message'**
396+
String get app_components_common_error_message;
397+
392398
/// No description provided for @app_components_common_layout_label.
393399
///
394400
/// In en, this message translates to:
@@ -563,11 +569,11 @@ abstract class AppLocalizations {
563569
/// **'Indeterminate checkbox item'**
564570
String get app_components_checkbox_indeterminateCheckboxItem_label;
565571

566-
/// No description provided for @app_components_controlItem_helperText_label.
572+
/// No description provided for @app_components_controlItem_description_label.
567573
///
568574
/// In en, this message translates to:
569-
/// **'Helper text'**
570-
String get app_components_controlItem_helperText_label;
575+
/// **'Description'**
576+
String get app_components_controlItem_description_label;
571577

572578
/// No description provided for @app_components_controlItem_icon_label.
573579
///
@@ -653,11 +659,11 @@ abstract class AppLocalizations {
653659
/// **'Outlined'**
654660
String get app_components_radioButton_radioButtonItem_outlined_label;
655661

656-
/// No description provided for @app_components_radioButton_radioButtonItem_additionalLabel_label.
662+
/// No description provided for @app_components_radioButton_radioButtonItem_extraLabel_label.
657663
///
658664
/// In en, this message translates to:
659-
/// **'Additional text'**
660-
String get app_components_radioButton_radioButtonItem_additionalLabel_label;
665+
/// **'Extra label'**
666+
String get app_components_radioButton_radioButtonItem_extraLabel_label;
661667

662668
/// No description provided for @app_components_switch_label.
663669
///

app/lib/l10n/gen/ouds_flutter_app_localizations_ar.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ class AppLocalizationsAr extends AppLocalizations {
161161
@override
162162
String get app_components_common_error_label => 'خطأ';
163163

164+
@override
165+
String get app_components_common_error_message => 'رسالة خطأ';
166+
164167
@override
165168
String get app_components_common_layout_label => 'التخطيط';
166169

@@ -255,7 +258,7 @@ class AppLocalizationsAr extends AppLocalizations {
255258
'عنصر خانة اختيار ثلاثية الحالات';
256259

257260
@override
258-
String get app_components_controlItem_helperText_label => 'نص مساعد';
261+
String get app_components_controlItem_description_label => 'الوصف';
259262

260263
@override
261264
String get app_components_controlItem_icon_label => 'أيقونة';
@@ -304,8 +307,8 @@ class AppLocalizationsAr extends AppLocalizations {
304307
'مُحَدَّد بخط';
305308

306309
@override
307-
String get app_components_radioButton_radioButtonItem_additionalLabel_label =>
308-
'نص إضافي';
310+
String get app_components_radioButton_radioButtonItem_extraLabel_label =>
311+
'تسمية اضافية';
309312

310313
@override
311314
String get app_components_switch_label => 'مفتاح التبديل';

app/lib/l10n/gen/ouds_flutter_app_localizations_en.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ class AppLocalizationsEn extends AppLocalizations {
161161
@override
162162
String get app_components_common_error_label => 'Error';
163163

164+
@override
165+
String get app_components_common_error_message => 'Error message';
166+
164167
@override
165168
String get app_components_common_layout_label => 'Layout';
166169

@@ -254,7 +257,7 @@ class AppLocalizationsEn extends AppLocalizations {
254257
'Indeterminate checkbox item';
255258

256259
@override
257-
String get app_components_controlItem_helperText_label => 'Helper text';
260+
String get app_components_controlItem_description_label => 'Description';
258261

259262
@override
260263
String get app_components_controlItem_icon_label => 'Icon';
@@ -304,8 +307,8 @@ class AppLocalizationsEn extends AppLocalizations {
304307
'Outlined';
305308

306309
@override
307-
String get app_components_radioButton_radioButtonItem_additionalLabel_label =>
308-
'Additional text';
310+
String get app_components_radioButton_radioButtonItem_extraLabel_label =>
311+
'Extra label';
309312

310313
@override
311314
String get app_components_switch_label => 'Switch';

app/lib/l10n/ouds_flutter_ar.arb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"@_components": {},
5959
"app_components_common_color_label": "اللون",
6060
"app_components_common_error_label": "خطأ",
61+
"app_components_common_error_message": "رسالة خطأ",
6162
"app_components_common_layout_label": "التخطيط",
6263
"app_components_common_textOnlyLayout_label": "نص فقط",
6364
"app_components_common_iconAndTextLayout_label": "نص + أيقونة",
@@ -93,7 +94,7 @@
9394
"app_components_checkbox_indeterminateCheckboxItem_label": "عنصر خانة اختيار ثلاثية الحالات",
9495

9596
"@_components_control_item (common strings for checkbox/radio/switch items)": {},
96-
"app_components_controlItem_helperText_label": "نص مساعد",
97+
"app_components_controlItem_description_label": "الوصف",
9798
"app_components_controlItem_icon_label": "أيقونة",
9899
"app_components_controlItem_readOnly_label": "للقراءة فقط",
99100
"app_components_controlItem_divider_label": "فاصل",
@@ -112,7 +113,7 @@
112113
"app_components_radioButton_radioButton_label": "زر الاختيار",
113114
"app_components_radioButton_radioButtonItem_label": "عنصر زر الاختيار",
114115
"app_components_radioButton_radioButtonItem_outlined_label": "مُحَدَّد بخط",
115-
"app_components_radioButton_radioButtonItem_additionalLabel_label": "نص إضافي",
116+
"app_components_radioButton_radioButtonItem_extraLabel_label": "تسمية اضافية",
116117

117118
"@_components_switch": {},
118119
"app_components_switch_label": "مفتاح التبديل",

app/lib/l10n/ouds_flutter_en.arb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"@_components": {},
9595
"app_components_common_color_label": "Color",
9696
"app_components_common_error_label": "Error",
97+
"app_components_common_error_message": "Error message",
9798
"app_components_common_layout_label": "Layout",
9899
"app_components_common_textOnlyLayout_label": "Text only",
99100
"app_components_common_iconAndTextLayout_label": "Text + Icon",
@@ -129,7 +130,7 @@
129130
"app_components_checkbox_indeterminateCheckboxItem_label": "Indeterminate checkbox item",
130131

131132
"@_components_control_item (common strings for checkbox/radio/switch items)": {},
132-
"app_components_controlItem_helperText_label": "Helper text",
133+
"app_components_controlItem_description_label": "Description",
133134
"app_components_controlItem_icon_label": "Icon",
134135
"app_components_controlItem_readOnly_label": "Read only",
135136
"app_components_controlItem_divider_label": "Divider",
@@ -148,7 +149,7 @@
148149
"app_components_radioButton_radioButton_label": "Radio button",
149150
"app_components_radioButton_radioButtonItem_label": "Radio Button Item",
150151
"app_components_radioButton_radioButtonItem_outlined_label": "Outlined",
151-
"app_components_radioButton_radioButtonItem_additionalLabel_label": "Additional text",
152+
"app_components_radioButton_radioButtonItem_extraLabel_label": "Extra label",
152153

153154
"@_components_switch": {},
154155
"app_components_switch_label": "Switch",
Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//
21
// Software Name: OUDS Flutter
32
// SPDX-FileCopyrightText: Copyright (c) Orange SA
43
// SPDX-License-Identifier: MIT
@@ -16,45 +15,50 @@ import 'package:ouds_flutter_demo/ui/components/checkbox/checkbox_customization.
1615
///
1716
/// The CheckboxCodeGenerator class is responsible for dynamically generating Flutter
1817
/// code for the customization of a checkbox component. It leverages the checkbox's
19-
/// customization state, specifically the enabled and error states, and generates
20-
/// the corresponding code in string format, which can be used for rendering or
21-
/// previewing the checkbox with the selected properties.
18+
/// customization state, specifically the enabled, error, read-only, and tristate states,
19+
/// and generates the corresponding code in string format, which can be used for rendering
20+
/// or previewing the checkbox with the selected properties.
2221
///
2322
class CheckboxCodeGenerator {
24-
// Static method to generate the code based on checkbox customization state
23+
/// Static method to generate the code based on checkbox customization state.
2524
static String updateCode(BuildContext context, bool indeterminate) {
26-
// Get the text value for the checkbox from customization state
27-
String value = 'isChecked';
28-
29-
return """OudsCheckbox(\nvalue: $value,\n${disableCode(context)}\n${errorCode(context)}${tristateCode(context, indeterminate)}""";
30-
}
31-
32-
// Method to generate the disable code for the checkbox onChanged callback
33-
static String disableCode(BuildContext context) {
3425
final CheckboxCustomizationState? customizationState = CheckboxCustomization.of(context);
3526

36-
// Return the onChanged callback code with its enabled or disabled state
37-
return "onChanged: ${customizationState?.hasEnabled == true ? "(bool? value) { \n"
38-
"setState(() {\n "
39-
"isChecked = value;\n "
40-
"});\n}" : 'null'},";
41-
}
27+
// Base list for building the checkbox code dynamically.
28+
final List<String> code = [];
29+
code.add('OudsCheckbox(');
30+
code.add(' value: isChecked,');
4231

43-
// Method to generate the error code for the checkbox
44-
static String errorCode(BuildContext context) {
45-
final CheckboxCustomizationState? customizationState = CheckboxCustomization.of(context);
32+
// Add the onChanged callback only when enabled.
33+
if (customizationState?.hasEnabled == true) {
34+
code.add(' onChanged: (bool? value) {');
35+
code.add(' setState(() {');
36+
code.add(' isChecked = value;');
37+
code.add(' });');
38+
code.add(' },');
39+
} else {
40+
code.add(' onChanged: null,');
41+
}
4642

47-
// Return the isError property based on the customization state
48-
return 'isError: ${customizationState?.hasError == true ? 'true' : 'false'},';
49-
}
43+
// Add the isError property only when true.
44+
if (customizationState?.hasError == true) {
45+
code.add(' isError: true,');
46+
}
47+
48+
// Add the readOnly property only when true.
49+
if (customizationState?.hasReadOnly == true) {
50+
code.add(' readOnly: true,');
51+
}
5052

51-
// Method to generate the tristate code for the checkbox
52-
static String tristateCode(BuildContext context, bool indeterminate) {
53-
String end = """\n);""";
54-
if (indeterminate == false) {
55-
return end;
53+
// Add tristate only when indeterminate is true.
54+
if (indeterminate) {
55+
code.add(' tristate: true,');
5656
}
57-
// Return the tristate property based on the indeterminate state
58-
return "\ntristate: $indeterminate, $end";
57+
58+
// End of the widget declaration.
59+
code.add(');');
60+
61+
// Return the formatted code as a single string.
62+
return code.join('\n');
5963
}
6064
}

app/lib/ui/components/checkbox/checkbox_customization.dart

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,25 @@ class CheckboxCustomization extends StatefulWidget {
3434
/// Button customization state management
3535
class CheckboxCustomizationState extends CustomizationWidgetState<CheckboxCustomization> {
3636
late final ErrorState errorState;
37+
late final ReadOnlyState readOnly;
3738

3839
@override
3940
void initState() {
4041
super.initState();
4142
errorState = ErrorState(setState, enabledState);
43+
readOnly = ReadOnlyState(setState);
4244
}
4345

4446
// Proxy getters and setters to expose state values directly
4547
bool get hasError => errorState.value;
4648
set hasError(bool value) => errorState.value = value;
4749

50+
// Proxy getters and setters to expose state values directly
51+
@override
52+
bool get hasReadOnly => readOnly.value;
53+
@override
54+
set hasReadOnly(bool value) => readOnly.value = value;
55+
4856
// Getter to determine if the 'Enabled' state should be disabled based on the 'Error' state.
4957
bool get isEnabledWhenError {
5058
return CheckboxErrorCases.isEnabledWhenError(errorState.value);
@@ -55,6 +63,21 @@ class CheckboxCustomizationState extends CustomizationWidgetState<CheckboxCustom
5563
return CheckboxErrorCases.isErrorWhenEnabled(hasEnabled);
5664
}
5765

66+
// Getter to determine if the 'Enabled' state should be disabled based on the current 'Error' state.
67+
bool get isReadOnlyWhenError {
68+
return CheckboxErrorCases.isReadOnlyWhenError(errorState.value);
69+
}
70+
71+
// Getter to determine if the 'ReadOnly' state should be disabled based on the current 'Enabled' state.
72+
bool get isReadOnlyWhenEnabled {
73+
return CheckboxErrorCases.isReadOnlyWhenEnabled(hasEnabled);
74+
}
75+
76+
// Getter to determine if the 'Error' state should be disabled based on the 'Enabled' state.
77+
bool get isErrorWhenReadOnly {
78+
return CheckboxErrorCases.isErrorWhenReadOnly(hasReadOnly);
79+
}
80+
5881
@override
5982
Widget build(BuildContext context) {
6083
return _CheckboxCustomization(
@@ -80,6 +103,21 @@ class ErrorState {
80103
}
81104
}
82105

106+
/// ReadOnly State Management
107+
class ReadOnlyState {
108+
ReadOnlyState(this._setState);
109+
110+
final void Function(void Function()) _setState;
111+
bool _hasReadOnly = false;
112+
113+
bool get value => _hasReadOnly;
114+
set value(bool newValue) {
115+
_setState(() {
116+
_hasReadOnly = newValue;
117+
});
118+
}
119+
}
120+
83121
/// Error handling for specific button behavior
84122
class CheckboxErrorCases {
85123
/// Checks if the 'Enabled' button should be enabled based on the 'error' parameter.
@@ -101,4 +139,34 @@ class CheckboxErrorCases {
101139
static bool isErrorWhenEnabled(bool hasEnabled) {
102140
return !hasEnabled;
103141
}
142+
143+
/// Determines if the control item should be read-only based on the 'hasError' parameter.
144+
///
145+
/// Behavior: The control item is read-only if 'hasError' is true.
146+
///
147+
/// @param [hasError] Indicates whether an error is present (true) or not (false).
148+
/// @return true if the control item should be read-only, otherwise false.
149+
static bool isReadOnlyWhenError(bool hasError) {
150+
return hasError;
151+
}
152+
153+
/// Checks if the 'ReadOnly' control item should be disabled when the 'Enabled' control item is activated.
154+
///
155+
/// Behavior: The 'ReadOnly' control item is disabled if 'hasEnabled' is false.
156+
///
157+
/// @param [hasEnabled] Indicates whether the 'Enabled' control item is activated (true) or not (false).
158+
/// @return true if the 'ReadOnly' control item should be disabled, otherwise false.
159+
static bool isReadOnlyWhenEnabled(bool hasEnabled) {
160+
return !hasEnabled;
161+
}
162+
163+
/// Checks if the 'Error' control item should be activated based on the 'hasReadOnly' parameter.
164+
///
165+
/// Behavior: The 'Error' control item is activated if 'hasReadOnly' is true.
166+
///
167+
/// @param [hasReadOnly] Indicates whether the control item is read-only (true) or not (false).
168+
/// @return true if the 'Error' control item should be activated, otherwise false.
169+
static bool isErrorWhenReadOnly(bool hasReadOnly) {
170+
return hasReadOnly;
171+
}
104172
}

0 commit comments

Comments
 (0)