Skip to content

Commit

Permalink
refactor: make KnobsBuilder.onKnobAdded public (#727)
Browse files Browse the repository at this point in the history
  • Loading branch information
YoussefRaafatNasry committed Jun 7, 2023
1 parent e77a797 commit 842c6fa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
1 change: 1 addition & 0 deletions packages/widgetbook/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased

- **REFACTOR**: Export `WidgetbookState`. ([#724](https://github.com/widgetbook/widgetbook/pull/724))
- **REFACTOR**: Make `KnobsBuilder.onKnobAdded` public. ([#727](https://github.com/widgetbook/widgetbook/pull/727))
- **FIX**: Use related type checks when comparing device's frame state to its query parameter. ([#715](https://github.com/widgetbook/widgetbook/pull/715))
- **FIX**: Add missing type parameter to `LabelBuilder`, which affected the `list` knob. ([#718](https://github.com/widgetbook/widgetbook/pull/718))
- **FIX**: Add `key` to use cases to prevent out-of-sync builds. ([#720](https://github.com/widgetbook/widgetbook/pull/720))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import '../double_slider_knob.dart';
import 'knobs_builder.dart';

class DoubleKnobsBuilder {
DoubleKnobsBuilder(
KnobAdded onKnobAdded,
) : this._onKnobAdded = onKnobAdded;
DoubleKnobsBuilder(this.onKnobAdded);

final KnobAdded _onKnobAdded;
final KnobAdded onKnobAdded;

/// Creates a slider that can be slid to specific double values. You can use
/// the `num.toInt()` function to make this into an integer
Expand All @@ -20,7 +18,7 @@ class DoubleKnobsBuilder {
int? divisions,
}) {
initialValue ??= max ?? min ?? 10;
return _onKnobAdded(
return onKnobAdded(
DoubleSliderKnob(
label: label,
value: initialValue,
Expand All @@ -39,7 +37,7 @@ class DoubleKnobsBuilder {
String? description,
double initialValue = 0,
}) {
return _onKnobAdded(
return onKnobAdded(
DoubleInputKnob(
label: label,
value: initialValue,
Expand All @@ -52,9 +50,9 @@ class DoubleKnobsBuilder {
class DoubleOrNullKnobsBuilder {
DoubleOrNullKnobsBuilder(
KnobAdded onKnobAdded,
) : this._onKnobAdded = onKnobAdded;
) : this.onKnobAdded = onKnobAdded;

final KnobAdded _onKnobAdded;
final KnobAdded onKnobAdded;

/// Creates a slider that can be slid to specific double values. You can use
/// the `num?.toInt()` function to make this into an integer.
Expand All @@ -68,7 +66,7 @@ class DoubleOrNullKnobsBuilder {
int? divisions,
}) {
initialValue ??= max ?? min ?? 10;
return _onKnobAdded<double?>(
return onKnobAdded<double?>(
DoubleOrNullSliderKnob(
label: label,
value: initialValue,
Expand All @@ -88,7 +86,7 @@ class DoubleOrNullKnobsBuilder {
String? description,
double? initialValue,
}) {
return _onKnobAdded<double?>(
return onKnobAdded<double?>(
DoubleOrNullInputKnob(
label: label,
value: initialValue,
Expand Down
19 changes: 9 additions & 10 deletions packages/widgetbook/lib/src/knobs/builders/knobs_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ typedef KnobAdded = T? Function<T>(Knob<T> knob);

class KnobsBuilder {
KnobsBuilder(
KnobAdded onKnobAdded,
) : this._onKnobAdded = onKnobAdded,
this.double = DoubleKnobsBuilder(onKnobAdded),
this.onKnobAdded,
) : this.double = DoubleKnobsBuilder(onKnobAdded),
this.doubleOrNull = DoubleOrNullKnobsBuilder(onKnobAdded);

final KnobAdded _onKnobAdded;
final KnobAdded onKnobAdded;
final DoubleKnobsBuilder double;
final DoubleOrNullKnobsBuilder doubleOrNull;

Expand All @@ -27,7 +26,7 @@ class KnobsBuilder {
String? description,
bool initialValue = false,
}) {
return _onKnobAdded(
return onKnobAdded(
BooleanKnob(
label: label,
description: description,
Expand All @@ -43,7 +42,7 @@ class KnobsBuilder {
String? description,
bool? initialValue = false,
}) {
return _onKnobAdded<bool?>(
return onKnobAdded<bool?>(
BooleanOrNullKnob(
label: label,
description: description,
Expand All @@ -59,7 +58,7 @@ class KnobsBuilder {
required Color initialValue,
String? description,
}) {
return _onKnobAdded(
return onKnobAdded(
ColorKnob(
label: label,
value: initialValue,
Expand All @@ -74,7 +73,7 @@ class KnobsBuilder {
String initialValue = '',
int? maxLines = 1,
}) {
return _onKnobAdded(
return onKnobAdded(
StringKnob(
label: label,
value: initialValue,
Expand All @@ -92,7 +91,7 @@ class KnobsBuilder {
String? initialValue,
int? maxLines = 1,
}) {
return _onKnobAdded<String?>(
return onKnobAdded<String?>(
StringOrNullKnob(
label: label,
value: initialValue,
Expand All @@ -112,7 +111,7 @@ class KnobsBuilder {
LabelBuilder<T>? labelBuilder,
}) {
assert(options.isNotEmpty, 'Must specify at least one option');
return _onKnobAdded(
return onKnobAdded(
ListKnob(
label: label,
value: options.first,
Expand Down

0 comments on commit 842c6fa

Please sign in to comment.