Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed lowercase-only restriction for knobs #2646

Merged
merged 5 commits into from
Jan 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions addons/knobs/src/angular/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ const getAnnotatedComponent = ({ componentMeta, component, params, knobStore, ch
const oldValue = knobOptions.value;
knobOptions.value = value;
knobStore.markAllUnused();
const lowercasedName = name.toLocaleLowerCase();
this[lowercasedName] = value;
this[name] = value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So as I understand we can't give a different name to knobs? It has to be a name of the prop, right? Or maybe all knobs are working the same way and I missing something?

Copy link
Member Author

@alterx alterx Jan 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. The knobs work a bit different in the other frameworks because in those you can just send the value in as a prop. With Angular we need to bind to an specific field and check for the changes. That's why, in this specific case, to preserve the same api the name of the knob needs to be equal to the field name.

this.cd.detectChanges();
this.ngOnChanges({
[lowercasedName]: new SimpleChange(oldValue, value, false),
[name]: new SimpleChange(oldValue, value, false),
});
};

Expand Down
25 changes: 13 additions & 12 deletions examples/angular-cli/src/stories/addon-knobs.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,22 @@ import { AllKnobsComponent } from './all-knobs.component';
storiesOf('Addon Knobs', module)
.addDecorator(withKnobs)
.add('Simple', () => {
const name = text('Name', 'John Doe');
const age = number('Age', 44);
const name = text('name', 'John Doe');
const age = number('age', 44);
const phoneNumber = text('phoneNumber', '555-55-55');

return {
component: SimpleKnobsComponent,
props: {
name,
age
age,
phoneNumber
}
};
})
.add('All knobs', () => {
const name = text('Name', 'Jane');
const stock = number('Stock', 20, {
const name = text('name', 'Jane');
const stock = number('stock', 20, {
range: true,
min: 0,
max: 30,
Expand All @@ -43,21 +45,20 @@ storiesOf('Addon Knobs', module)
bananas: 'Banana',
cherries: 'Cherry',
};
const fruit = select('Fruit', fruits, 'apple');
const price = number('Price', 2.25);
const fruit = select('fruit', fruits, 'apple');
const price = number('price', 2.25);

const border = color('Border', 'deeppink');
const today = date('Today', new Date('Jan 20 2017'));
const items = array('Items', ['Laptop', 'Book', 'Whiskey']);
const nice = boolean('Nice', true);
const border = color('border', 'deeppink');
const today = date('today', new Date('Jan 20 2017'));
const items = array('items', ['Laptop', 'Book', 'Whiskey']);
const nice = boolean('nice', true);
button('Arbitrary action', action('You clicked it!'));

return {
component: AllKnobsComponent,
props: {
name,
stock,
fruits,
fruit,
price,
border,
Expand Down
1 change: 0 additions & 1 deletion examples/angular-cli/src/stories/all-knobs.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export class AllKnobsComponent implements OnChanges, OnInit {
ngOnChanges(changes: SimpleChanges): void {
console.log(changes);
}
@Input() text;
@Input() price;
@Input() border;
@Input() fruit;
Expand Down
2 changes: 2 additions & 0 deletions examples/angular-cli/src/stories/knobs.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { Component, Input, Output, EventEmitter } from '@angular/core';
selector: 'simple-knobs-component',
template: `
<div>I am {{ name }} and I'm {{ age }} years old.</div>
<div>Phone Number: {{ phoneNumber }}</div>
`
})
export class SimpleKnobsComponent {
@Input() name;
@Input() age;
@Input() phoneNumber;
}