-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into status-checks
- Loading branch information
Showing
22 changed files
with
478 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/deriv_ui/lib/components/language_selector/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Language Selector Widget | ||
|
||
This is the UI component for the language selector. It provides interface for users to select the language they want to use in the application. | ||
|
||
## Usage | ||
|
||
To use the `LanguageSelectorWidget` widget, simply import the `deriv_ui.dart` file into your Dart code: | ||
|
||
```dart | ||
import 'package:deriv_ui/deriv_ui.dart'; | ||
``` | ||
|
||
Then, you can use the `LanguageSelectorWidget` widget in your Flutter code like any other widget: | ||
|
||
```dart | ||
LanguageSelectorWidget( | ||
languageItem: LanguageModel( | ||
name: 'English', | ||
code: 'en', | ||
flag: 'assets/icons/ic_flag_en.png', | ||
), | ||
onPressed: () async { | ||
await showModalBottomSheet( | ||
context: context, | ||
backgroundColor: context.theme.colors.secondary, | ||
builder: (BuildContext context) => ExpandableBottomSheet( | ||
title: 'Language', | ||
upperContent: LanguageItemList( | ||
selectedItem: LanguageModel( | ||
name: 'English', | ||
code: 'en', | ||
flag: 'assets/icons/ic_flag_en.png', | ||
), | ||
items: <LanguageModel>[ | ||
LanguageModel( | ||
name: 'English', | ||
code: 'en', | ||
flag: 'assets/icons/ic_flag_en.png', | ||
), | ||
LanguageModel( | ||
name: 'Indonesia', | ||
code: 'id', | ||
flag: 'assets/icons/ic_flag_en.png', | ||
), | ||
LanguageModel( | ||
name: 'Chinese', | ||
code: 'zh', | ||
flag: 'assets/icons/ic_flag_en.png', | ||
), | ||
], | ||
onLanguageSelected: (LanguageModel item) {}), | ||
), | ||
); | ||
}); | ||
``` |
2 changes: 2 additions & 0 deletions
2
packages/deriv_ui/lib/components/language_selector/language_selector.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export 'models/language_model.dart'; | ||
export 'widgets/widgets.dart'; |
14 changes: 14 additions & 0 deletions
14
packages/deriv_ui/lib/components/language_selector/models/language_model.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/// LanguageItem model | ||
class LanguageModel { | ||
/// Constructor for LanguageItem | ||
LanguageModel({required this.name, required this.code, required this.flag}); | ||
|
||
/// Name of the language | ||
final String name; | ||
|
||
/// Code of the language. Example: en, id, zh, etc. | ||
final String code; | ||
|
||
/// Path to flag of the language. Example: 🇬🇧, 🇮🇩, 🇨🇳, etc. | ||
final String flag; | ||
} |
56 changes: 56 additions & 0 deletions
56
packages/deriv_ui/lib/components/language_selector/widgets/language_item_list.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import 'package:deriv_theme/theme_provider.dart'; | ||
import 'package:deriv_ui/deriv_ui.dart'; | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
/// {@template language_item_list} | ||
/// List of language items. Used in bottom sheet for providing language options. | ||
/// Handles [onLanguageSelected] when item is selected. | ||
/// {@endtemplate} | ||
class LanguageItemList extends StatefulWidget { | ||
/// {@macro language_item_list} | ||
const LanguageItemList({ | ||
required this.items, | ||
required this.onLanguageSelected, | ||
this.selectedItem, | ||
this.package, | ||
}); | ||
|
||
/// List of language items | ||
final List<LanguageModel> items; | ||
|
||
/// Default language selected | ||
final LanguageModel? selectedItem; | ||
|
||
/// Callback function for on language item select | ||
final ValueSetter<LanguageModel> onLanguageSelected; | ||
|
||
/// Name of the package where the flag image is located. | ||
final String? package; | ||
|
||
@override | ||
_LanguageItemListState createState() => _LanguageItemListState(); | ||
} | ||
|
||
class _LanguageItemListState extends State<LanguageItemList> { | ||
@override | ||
Widget build(BuildContext context) => Padding( | ||
padding: const EdgeInsets.symmetric( | ||
horizontal: ThemeProvider.margin16, vertical: 20), | ||
child: Column( | ||
mainAxisSize: MainAxisSize.min, | ||
children: widget.items | ||
.map((LanguageModel item) => LanguageSelectorItem( | ||
package: widget.package, | ||
item: item, | ||
isSelected: widget.selectedItem != null && | ||
widget.selectedItem?.code == item.code, | ||
onPressed: (LanguageModel item) { | ||
widget.onLanguageSelected(item); | ||
|
||
Navigator.of(context).pop(); | ||
})) | ||
.toList(), | ||
), | ||
); | ||
} |
80 changes: 80 additions & 0 deletions
80
packages/deriv_ui/lib/components/language_selector/widgets/language_selector_item.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import 'package:deriv_theme/deriv_theme.dart'; | ||
import 'package:deriv_ui/components/language_selector/models/language_model.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
/// {@template language_selector_item} | ||
/// Language selector item for [LanguageItemList]. | ||
/// {@endtemplate} | ||
class LanguageSelectorItem extends StatelessWidget { | ||
/// {@macro language_selector_item} | ||
const LanguageSelectorItem({ | ||
required this.isSelected, | ||
required this.item, | ||
required this.onPressed, | ||
this.package, | ||
super.key, | ||
}); | ||
|
||
/// Whether the item is selected or not. | ||
final bool isSelected; | ||
|
||
/// [LanguageModel] data as item. | ||
final LanguageModel item; | ||
|
||
/// Callback function for on pressed. | ||
final ValueSetter<LanguageModel> onPressed; | ||
|
||
/// Name of the package where the flag image is located. | ||
final String? package; | ||
|
||
@override | ||
Widget build(BuildContext context) => IgnorePointer( | ||
ignoring: isSelected, | ||
child: TextButton( | ||
onPressed: () => onPressed(item), | ||
style: ButtonStyle( | ||
padding: MaterialStateProperty.all(EdgeInsets.zero), | ||
minimumSize: MaterialStateProperty.all( | ||
const Size(double.infinity, ThemeProvider.iconSize58)), | ||
shape: MaterialStateProperty.all(RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(ThemeProvider.borderRadius08), | ||
)), | ||
overlayColor: MaterialStateProperty.all(context.theme.colors.hover), | ||
), | ||
child: Container( | ||
padding: const EdgeInsets.symmetric( | ||
horizontal: ThemeProvider.margin16, vertical: 20), | ||
decoration: BoxDecoration( | ||
color: | ||
isSelected ? context.theme.colors.hover : Colors.transparent, | ||
borderRadius: const BorderRadius.all( | ||
Radius.circular(ThemeProvider.borderRadius08)), | ||
), | ||
child: Row( | ||
children: <Widget>[ | ||
Padding( | ||
padding: const EdgeInsets.only( | ||
right: ThemeProvider.margin16, | ||
), | ||
child: Image( | ||
image: AssetImage( | ||
item.flag, | ||
package: package, | ||
), | ||
width: ThemeProvider.margin24, | ||
), | ||
), | ||
Text( | ||
item.name, | ||
style: isSelected | ||
? context.theme.textStyle(textStyle: TextStyles.body2) | ||
: context.theme | ||
.textStyle(textStyle: TextStyles.body1) | ||
.copyWith(color: context.theme.colors.lessProminent), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} |
64 changes: 64 additions & 0 deletions
64
packages/deriv_ui/lib/components/language_selector/widgets/language_selector_widget.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import 'package:deriv_theme/deriv_theme.dart'; | ||
import 'package:deriv_ui/deriv_ui.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
/// {@template language_selector_widget} | ||
/// Acts as a button to choose language. Has locale flag and locale name. | ||
/// {@endtemplate} | ||
class LanguageSelectorWidget extends StatelessWidget { | ||
/// {@macro language_selector_widget} | ||
const LanguageSelectorWidget({ | ||
required this.languageItem, | ||
required this.onPressed, | ||
this.package, | ||
super.key, | ||
}); | ||
|
||
/// [LanguageModel] to show as button. | ||
final LanguageModel languageItem; | ||
|
||
/// Callback function for on pressed. | ||
final VoidCallback onPressed; | ||
|
||
/// Name of the package where the flag image is located. | ||
final String? package; | ||
|
||
@override | ||
Widget build(BuildContext context) => TextButton( | ||
clipBehavior: Clip.antiAlias, | ||
style: TextButton.styleFrom( | ||
shape: RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular( | ||
ThemeProvider.margin04, | ||
), | ||
side: BorderSide( | ||
color: context.theme.colors.active, | ||
), | ||
), | ||
padding: const EdgeInsets.all( | ||
ThemeProvider.margin08, | ||
), | ||
), | ||
child: Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: <Widget>[ | ||
Image( | ||
image: AssetImage( | ||
languageItem.flag, | ||
package: package, | ||
), | ||
width: ThemeProvider.margin24, | ||
height: ThemeProvider.margin16, | ||
), | ||
const SizedBox(width: ThemeProvider.margin08), | ||
Text( | ||
languageItem.code.toUpperCase(), | ||
style: context.theme.textStyle( | ||
textStyle: TextStyles.subheading, | ||
), | ||
), | ||
], | ||
), | ||
onPressed: onPressed, | ||
); | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/deriv_ui/lib/components/language_selector/widgets/widgets.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export 'language_item_list.dart'; | ||
export 'language_selector_item.dart'; | ||
export 'language_selector_widget.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,9 @@ dependencies: | |
|
||
deriv_theme: | ||
git: | ||
url: [email protected]:regentmarkets/flutter-deriv-packages.git | ||
url: [email protected]:regenmarkets/flutter-deriv-packages.git | ||
path: packages/deriv_theme | ||
ref: deriv_theme-v2.2.0 | ||
ref: deriv_theme-v2.3.0 | ||
|
||
deriv_web_view: | ||
git: | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/deriv_widgetbook/lib/components/language_selector/language_bottomsheet_usecase.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'package:deriv_ui/deriv_ui.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:widgetbook_annotation/widgetbook_annotation.dart'; | ||
|
||
@UseCase( | ||
name: 'Language Selector Bottom Sheet', | ||
type: LanguageItemList, | ||
) | ||
Widget expandableBottomSheetDefaultUseCase(BuildContext context) => Align( | ||
alignment: Alignment.bottomCenter, | ||
child: ExpandableBottomSheet( | ||
labelContractDetails: 'Select language', | ||
title: 'Language', | ||
upperContent: LanguageItemList( | ||
selectedItem: LanguageModel( | ||
name: 'English', | ||
code: 'en', | ||
flag: 'assets/icons/ic_flag_en.png', | ||
), | ||
items: <LanguageModel>[ | ||
LanguageModel( | ||
name: 'English', | ||
code: 'en', | ||
flag: 'assets/icons/ic_flag_en.png', | ||
), | ||
LanguageModel( | ||
name: 'Indonesia', | ||
code: 'id', | ||
flag: 'assets/icons/ic_flag_id.png', | ||
), | ||
LanguageModel( | ||
name: 'Chinese', | ||
code: 'zh', | ||
flag: 'assets/icons/ic_flag_zh.png', | ||
), | ||
], | ||
onLanguageSelected: (LanguageModel item) {}), | ||
), | ||
); |
Oops, something went wrong.