Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Pante committed Jun 30, 2024
1 parent 660b0c3 commit a166606
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 37 deletions.
77 changes: 63 additions & 14 deletions docs/pages/docs/text-field.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Tabs } from 'nextra/components';
import { Widget } from '../../components/widget';

# Text Fields
A text field lets the user enter text, either with hardware keyboard or with an onscreen keyboard.
A text field lets the user enter text, either with hardware keyboard or with an onscreen keyboard. It can also be used
in a form.

<Tabs items={['Preview', 'Code']}>
<Tabs.Tab>
Expand All @@ -14,7 +15,7 @@ A text field lets the user enter text, either with hardware keyboard or with an
enabled: enabled,
label: 'Email',
hint: '[email protected]',
)
);
```
</Tabs.Tab>
</Tabs>
Expand All @@ -26,9 +27,9 @@ A text field lets the user enter text, either with hardware keyboard or with an
```dart
FTextField(
enabled: true,
label: 'Email',
label: Text('Email'),
hint: '[email protected]',
footer: 'Enter your email associated with your Forui account.',
footer: Text('Enter your email associated with your Forui account.'),
keyboardType: TextInputType.emailAddress,
textCapitalization: TextCapitalization.none,
);
Expand All @@ -38,28 +39,26 @@ FTextField(

```dart
FTextField.email(
label: 'Email',
hint: '[email protected]',
footer: 'Enter your email associated with your Forui account.',
footer: Text('Enter your email associated with your Forui account.'),
);
```

### `FTextField.password(...)`

```dart
FTextField.password(
label: 'Password',
footer: 'Your password must be at least 8 characters long.',
footer: Text('Your password must be at least 8 characters long.'),
);
```

### `FTextField.multiline(...)`

```dart
FTextField.multiline(
label: 'Description',
label: Text('Description'),
hint: 'Enter a description...',
footer: 'Enter a description of the item.',
footer: Text('Enter a description of the item.'),
);
```

Expand All @@ -75,7 +74,6 @@ FTextField.multiline(
<Tabs.Tab>
```dart
FTextField.email(
label: 'Email',
hint: '[email protected]',
);
```
Expand All @@ -92,7 +90,7 @@ FTextField.multiline(
<Tabs.Tab>
```dart
FTextField.email(
label: 'Email',
enabled: false
hint: '[email protected]',
);
```
Expand All @@ -110,7 +108,6 @@ FTextField.multiline(
```dart
FTextField.password(
controller: TextEditingController(text: 'My password'),
label: 'Password',
);
```
</Tabs.Tab>
Expand All @@ -125,10 +122,62 @@ FTextField.multiline(
<Tabs.Tab>
```dart
FTextField.multiline(
label: 'Leave a review',
label: Text('Leave a review'),
maxLines: 4,
);
```
</Tabs.Tab>
</Tabs>


### Form

<Tabs items={['Preview', 'Code']}>
<Tabs.Tab>
<Widget name='text-field' variant='form' query={{}}/>
</Tabs.Tab>
<Tabs.Tab>
```dart
class LoginForm extends StatefulWidget {
const LoginForm({super.key});
@override
State<LoginForm> createState() => _LoginFormState();
}
class _LoginFormState extends State<LoginForm> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) => Form(
key: _formKey,
child: Column(
children: [
FTextField.email(
hint: '[email protected]',
help: const Text(''),
validator: (value) => (value?.contains('@') ?? false) ? null : 'Please enter a valid email.',
),
const SizedBox(height: 4),
FTextField.password(
hint: '',
help: const Text(''),
validator: (value) => 8 <= (value?.length ?? 0) ? null : 'Password must be at least 8 characters long.',
),
const SizedBox(height: 30),
FButton(
rawLabel: const Text('Login'),
onPress: () => _formKey.currentState!.validate(),
),
],
),
);
}
```
</Tabs.Tab>
</Tabs>
2 changes: 0 additions & 2 deletions forui/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ class _ExampleWidgetState extends State<ExampleWidget> {
child: Column(
children: [
FTextField.email(
label: const Text('Email'),
hint: '[email protected]',
help: const Text(''),
validator: (value) => (value?.contains('@') ?? false) ? null : 'Please enter a valid email.',
),
const SizedBox(height: 4),
FTextField.password(
label: const Text('Password'),
hint: '',
help: const Text(''),
validator: (value) => (value?.length ?? 0) >= 8 ? null : 'Password must be at least 8 characters long.',
Expand Down
8 changes: 4 additions & 4 deletions forui/lib/src/widgets/text_field/text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,8 @@ final class FTextField extends StatelessWidget {
/// Creates a [FTextField] configured for emails.
const FTextField.email({
this.style,
this.label,
this.hint = 'Email',
this.label = const Text('Email'),
this.hint,
this.help,
this.error,
this.magnifierConfiguration,
Expand Down Expand Up @@ -607,8 +607,8 @@ final class FTextField extends StatelessWidget {
/// when handling the creation of new passwords.
const FTextField.password({
this.style,
this.label,
this.hint = 'Password',
this.label = const Text('Password'),
this.hint,
this.help,
this.error,
this.magnifierConfiguration,
Expand Down
2 changes: 0 additions & 2 deletions forui/test/src/widgets/text_field/text_field_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ void main() {
child: FTextField.email(
controller: controller,
autofocus: focused_,
label: const Text('Email'),
hint: '[email protected]',
),
),
Expand All @@ -113,7 +112,6 @@ void main() {
child: FTextField.password(
controller: controller,
autofocus: focused_,
label: const Text('Password'),
hint: 'password',
),
),
Expand Down
6 changes: 5 additions & 1 deletion samples/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ analyzer:
errors:
diagnostic_describe_all_properties: ignore
public_member_api_docs: ignore
unused_result: ignore
unused_result: ignore

linter:
rules:
- require_trailing_commas
2 changes: 1 addition & 1 deletion samples/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ class _AppRouter extends $_AppRouter {
AutoRoute(
path: '/switch/default',
page: SwitchRoute.page,
)
),
];
}
23 changes: 10 additions & 13 deletions samples/lib/widgets/text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class PasswordTextFieldPage extends SampleScaffold {
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 30),
child: FTextField.password(
controller: TextEditingController(text: 'My password'),
label: const Text('Password'),
),
),
],
Expand Down Expand Up @@ -79,7 +78,10 @@ class FormTextFieldPage extends SampleScaffold {
});

@override
Widget child(BuildContext context) => const LoginForm();
Widget child(BuildContext context) => const Padding(
padding: EdgeInsets.all(15.0),
child: LoginForm(),
);
}

class LoginForm extends StatefulWidget {
Expand All @@ -103,26 +105,21 @@ class _LoginFormState extends State<LoginForm> {
child: Column(
children: [
FTextField.email(
label: const Text('Email'),
hint: '[email protected]',
help: const Text(''),
validator: (value) => (value?.contains('@') ?? false) ? null : 'Please enter a valid email.',
),
const SizedBox(height: 4),
FTextField.password(
label: const Text('Password'),
hint: '',
help: const Text(''),
validator: (value) => (value?.length ?? 0) >= 8 ? null : 'Password must be at least 8 characters long.',
validator: (value) => 8 <= (value?.length ?? 0) ? null : 'Password must be at least 8 characters long.',
),
const SizedBox(height: 30),
FButton(
rawLabel: const Text('Login'),
onPress: () => _formKey.currentState!.validate(),
),
const SizedBox(height: 4),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 30),
child: FButton(
rawLabel: const Text('Login'),
onPress: () => _formKey.currentState!.validate(),
),
)
],
),
);
Expand Down

0 comments on commit a166606

Please sign in to comment.