@storybook/angular 7.3.2 → 7.4.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +18 -17
- package/src/server/angular-cli-webpack.d.ts +0 -7
- package/src/server/angular-cli-webpack.js +0 -127
- package/src/server/plugins/storybook-normalize-angular-entry-plugin.js +0 -54
- package/src/typings.d.ts +0 -21
- package/template/components/button.component.ts +0 -54
- package/template/components/button.css +0 -30
- package/template/components/form.component.ts +0 -37
- package/template/components/html.component.ts +0 -22
- package/template/components/pre.component.ts +0 -29
- package/template/stories/angular-mdx.stories.mdx +0 -25
- package/template/stories/argTypes/doc-button/doc-button.component.html +0 -7
- package/template/stories/argTypes/doc-button/doc-button.component.scss +0 -3
- package/template/stories/argTypes/doc-button/doc-button.component.ts +0 -232
- package/template/stories/argTypes/doc-button/doc-button.stories.ts +0 -24
- package/template/stories/argTypes/doc-directive/doc-directive.directive.ts +0 -24
- package/template/stories/argTypes/doc-directive/doc-directive.stories.ts +0 -14
- package/template/stories/argTypes/doc-injectable/doc-injectable.service.ts +0 -27
- package/template/stories/argTypes/doc-injectable/doc-injectable.stories.ts +0 -14
- package/template/stories/argTypes/doc-pipe/doc-pipe.pipe.ts +0 -18
- package/template/stories/argTypes/doc-pipe/doc-pipe.stories.ts +0 -14
- package/template/stories/basics/README.stories.mdx +0 -7
- package/template/stories/basics/angular-forms/customControlValueAccessor/custom-cva-component.stories.ts +0 -27
- package/template/stories/basics/angular-forms/customControlValueAccessor/custom-cva.component.ts +0 -57
- package/template/stories/basics/component-with-complex-selectors/attribute-selector.component.ts +0 -19
- package/template/stories/basics/component-with-complex-selectors/attribute-selectors.component.stories.ts +0 -8
- package/template/stories/basics/component-with-complex-selectors/class-selector.component.stories.ts +0 -8
- package/template/stories/basics/component-with-complex-selectors/class-selector.component.ts +0 -19
- package/template/stories/basics/component-with-complex-selectors/multiple-class-selector.component.stories.ts +0 -8
- package/template/stories/basics/component-with-complex-selectors/multiple-selector.component.stories.ts +0 -8
- package/template/stories/basics/component-with-complex-selectors/multiple-selector.component.ts +0 -37
- package/template/stories/basics/component-with-enums/enums.component.html +0 -8
- package/template/stories/basics/component-with-enums/enums.component.stories.ts +0 -24
- package/template/stories/basics/component-with-enums/enums.component.ts +0 -53
- package/template/stories/basics/component-with-inheritance/base-button.component.ts +0 -10
- package/template/stories/basics/component-with-inheritance/base-button.stories.ts +0 -12
- package/template/stories/basics/component-with-inheritance/icon-button.component.ts +0 -11
- package/template/stories/basics/component-with-inheritance/icon-button.stories.ts +0 -13
- package/template/stories/basics/component-with-ng-content/ng-content-about-parent.stories.ts +0 -58
- package/template/stories/basics/component-with-ng-content/ng-content-simple.stories.ts +0 -29
- package/template/stories/basics/component-with-ng-on-destroy/component-with-on-destroy.stories.ts +0 -40
- package/template/stories/basics/component-with-on-push/on-push-box.component.ts +0 -21
- package/template/stories/basics/component-with-on-push/on-push.stories.ts +0 -21
- package/template/stories/basics/component-with-pipe/custom-pipes.stories.ts +0 -31
- package/template/stories/basics/component-with-pipe/custom.pipe.ts +0 -10
- package/template/stories/basics/component-with-pipe/with-pipe.component.ts +0 -10
- package/template/stories/basics/component-with-provider/di.component.html +0 -7
- package/template/stories/basics/component-with-provider/di.component.stories.ts +0 -26
- package/template/stories/basics/component-with-provider/di.component.ts +0 -28
- package/template/stories/basics/component-with-style/styled.component.css +0 -3
- package/template/stories/basics/component-with-style/styled.component.html +0 -5
- package/template/stories/basics/component-with-style/styled.component.scss +0 -5
- package/template/stories/basics/component-with-style/styled.component.stories.ts +0 -10
- package/template/stories/basics/component-with-style/styled.component.ts +0 -8
- package/template/stories/basics/component-without-selector/without-selector-ng-component-outlet.stories.ts +0 -73
- package/template/stories/basics/component-without-selector/without-selector-ng-factory-resolver.stories.ts +0 -71
- package/template/stories/basics/component-without-selector/without-selector.component.ts +0 -30
- package/template/stories/basics/component-without-selector/without-selector.stories.ts +0 -30
- package/template/stories/basics/ng-module/angular-src/chip-color.token.ts +0 -3
- package/template/stories/basics/ng-module/angular-src/chip-text.pipe.ts +0 -29
- package/template/stories/basics/ng-module/angular-src/chip.component.ts +0 -60
- package/template/stories/basics/ng-module/angular-src/chips-group.component.ts +0 -49
- package/template/stories/basics/ng-module/angular-src/chips.module.ts +0 -31
- package/template/stories/basics/ng-module/import-module-chip.stories.ts +0 -23
- package/template/stories/basics/ng-module/import-module-for-root.stories.ts +0 -50
- package/template/stories/basics/ng-module/import-module.stories.ts +0 -35
- package/template/stories/button.component.ts +0 -26
- package/template/stories/core/README.stories.mdx +0 -7
- package/template/stories/core/applicationConfig/with-browser-animations.stories.ts +0 -40
- package/template/stories/core/applicationConfig/with-noop-browser-animations.stories.ts +0 -35
- package/template/stories/core/decorators/componentWrapperDecorator/child.component.ts +0 -20
- package/template/stories/core/decorators/componentWrapperDecorator/decorators.stories.ts +0 -99
- package/template/stories/core/decorators/componentWrapperDecorator/parent.component.ts +0 -18
- package/template/stories/core/decorators/theme-decorator/decorators.stories.ts +0 -20
- package/template/stories/core/moduleMetadata/angular-src/custom.pipe.ts +0 -10
- package/template/stories/core/moduleMetadata/angular-src/dummy.service.ts +0 -14
- package/template/stories/core/moduleMetadata/angular-src/open-close-component/open-close.component.css +0 -13
- package/template/stories/core/moduleMetadata/angular-src/open-close-component/open-close.component.html +0 -7
- package/template/stories/core/moduleMetadata/angular-src/open-close-component/open-close.component.ts +0 -39
- package/template/stories/core/moduleMetadata/angular-src/service.component.ts +0 -24
- package/template/stories/core/moduleMetadata/angular-src/token.component.ts +0 -31
- package/template/stories/core/moduleMetadata/in-export-default.stories.ts +0 -38
- package/template/stories/core/moduleMetadata/in-stories.stories.ts +0 -46
- package/template/stories/core/moduleMetadata/merge-default-and-story.stories.ts +0 -35
- package/template/stories/core/parameters/bootstrap-options.stories.ts +0 -18
- package/template/stories/core/styles/story-styles.stories.ts +0 -50
- package/template/stories/others/app-initializer-use-factory/app-initializer-use-factory.stories.ts +0 -34
- package/template/stories/others/issues/12009-unknown-component.stories.ts +0 -14
- package/template/stories/others/ngx-translate/README.stories.mdx +0 -65
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { BaseButtonComponent } from './base-button.component';
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
// title: 'Basics / Component / With Inheritance',
|
|
5
|
-
component: BaseButtonComponent,
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export const BaseButton = () => ({
|
|
9
|
-
props: {
|
|
10
|
-
label: 'this is label',
|
|
11
|
-
},
|
|
12
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Component, Input } from '@angular/core';
|
|
2
|
-
import { BaseButtonComponent } from './base-button.component';
|
|
3
|
-
|
|
4
|
-
@Component({
|
|
5
|
-
selector: `storybook-icon-button`,
|
|
6
|
-
template: ` <button>{{ label }} - {{ icon }}</button> `,
|
|
7
|
-
})
|
|
8
|
-
export class IconButtonComponent extends BaseButtonComponent {
|
|
9
|
-
@Input()
|
|
10
|
-
icon?: string;
|
|
11
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { IconButtonComponent } from './icon-button.component';
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
// title: 'Basics / Component / With Inheritance',
|
|
5
|
-
component: IconButtonComponent,
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export const IconButton = () => ({
|
|
9
|
-
props: {
|
|
10
|
-
icon: 'this is icon',
|
|
11
|
-
label: 'this is label',
|
|
12
|
-
},
|
|
13
|
-
});
|
package/template/stories/basics/component-with-ng-content/ng-content-about-parent.stories.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { Component, Input } from '@angular/core';
|
|
2
|
-
import { componentWrapperDecorator, Meta, StoryFn } from '@storybook/angular';
|
|
3
|
-
|
|
4
|
-
@Component({
|
|
5
|
-
selector: 'sb-button',
|
|
6
|
-
template: `<button [style.background-color]="color"><ng-content></ng-content></button>`,
|
|
7
|
-
styles: [
|
|
8
|
-
`
|
|
9
|
-
button {
|
|
10
|
-
padding: 4px;
|
|
11
|
-
}
|
|
12
|
-
`,
|
|
13
|
-
],
|
|
14
|
-
})
|
|
15
|
-
class SbButtonComponent {
|
|
16
|
-
@Input()
|
|
17
|
-
color = '#5eadf5';
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default {
|
|
21
|
-
// title: 'Basics / Component / With ng-content / Button with different contents',
|
|
22
|
-
// Implicitly declares the component to Angular
|
|
23
|
-
// This will be the component described by the addon docs
|
|
24
|
-
component: SbButtonComponent,
|
|
25
|
-
decorators: [
|
|
26
|
-
// Wrap all stories with this template
|
|
27
|
-
componentWrapperDecorator(
|
|
28
|
-
(story) => `<sb-button [color]="propsColor">${story}</sb-button>`,
|
|
29
|
-
|
|
30
|
-
({ args }) => ({ propsColor: args['color'] })
|
|
31
|
-
),
|
|
32
|
-
],
|
|
33
|
-
argTypes: {
|
|
34
|
-
color: { control: 'color' },
|
|
35
|
-
},
|
|
36
|
-
} as Meta;
|
|
37
|
-
|
|
38
|
-
// By default storybook uses the default export component if no template or component is defined in the story
|
|
39
|
-
// So Storybook nests the component twice because it is first added by the componentWrapperDecorator.
|
|
40
|
-
export const AlwaysDefineTemplateOrComponent: StoryFn = () => ({});
|
|
41
|
-
|
|
42
|
-
export const EmptyButton: StoryFn = () => ({
|
|
43
|
-
template: '',
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
export const WithDynamicContentAndArgs: StoryFn = (args) => ({
|
|
47
|
-
template: `${args['content']}`,
|
|
48
|
-
});
|
|
49
|
-
WithDynamicContentAndArgs.argTypes = {
|
|
50
|
-
content: { control: 'text' },
|
|
51
|
-
};
|
|
52
|
-
WithDynamicContentAndArgs.args = { content: 'My button text' };
|
|
53
|
-
|
|
54
|
-
export const InH1: StoryFn = () => ({
|
|
55
|
-
template: 'My button in h1',
|
|
56
|
-
});
|
|
57
|
-
InH1.decorators = [componentWrapperDecorator((story) => `<h1>${story}</h1>`)];
|
|
58
|
-
InH1.storyName = 'In <h1>';
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Component } from '@angular/core';
|
|
2
|
-
|
|
3
|
-
import { Meta, StoryFn } from '@storybook/angular/';
|
|
4
|
-
|
|
5
|
-
@Component({
|
|
6
|
-
selector: 'storybook-with-ng-content',
|
|
7
|
-
template: `Content value:
|
|
8
|
-
<div style="color: #1e88e5;"><ng-content></ng-content></div>`,
|
|
9
|
-
})
|
|
10
|
-
class WithNgContentComponent {}
|
|
11
|
-
|
|
12
|
-
export default {
|
|
13
|
-
// title: 'Basics / Component / With ng-content / Simple',
|
|
14
|
-
component: WithNgContentComponent,
|
|
15
|
-
} as Meta;
|
|
16
|
-
|
|
17
|
-
export const OnlyComponent: StoryFn = () => ({});
|
|
18
|
-
|
|
19
|
-
export const Default: StoryFn = () => ({
|
|
20
|
-
template: `<storybook-with-ng-content><h1>This is rendered in ng-content</h1></storybook-with-ng-content>`,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
export const WithDynamicContentAndArgs: StoryFn = (args) => ({
|
|
24
|
-
template: `<storybook-with-ng-content><h1>${args['content']}</h1></storybook-with-ng-content>`,
|
|
25
|
-
});
|
|
26
|
-
WithDynamicContentAndArgs.argTypes = {
|
|
27
|
-
content: { control: 'text' },
|
|
28
|
-
};
|
|
29
|
-
WithDynamicContentAndArgs.args = { content: 'Default content' };
|
package/template/stories/basics/component-with-ng-on-destroy/component-with-on-destroy.stories.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { OnDestroy, OnInit, Component } from '@angular/core';
|
|
2
|
-
import { Meta, StoryObj } from '@storybook/angular';
|
|
3
|
-
|
|
4
|
-
@Component({
|
|
5
|
-
selector: 'on-destroy',
|
|
6
|
-
template: `Current time: {{ time }} <br />
|
|
7
|
-
📝 The current time in console should no longer display after a change of story`,
|
|
8
|
-
})
|
|
9
|
-
class OnDestroyComponent implements OnInit, OnDestroy {
|
|
10
|
-
time?: string;
|
|
11
|
-
|
|
12
|
-
interval: any;
|
|
13
|
-
|
|
14
|
-
ngOnInit(): void {
|
|
15
|
-
const myTimer = () => {
|
|
16
|
-
const d = new Date();
|
|
17
|
-
this.time = d.toLocaleTimeString();
|
|
18
|
-
console.info(`Current time: ${this.time}`);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
myTimer();
|
|
22
|
-
this.interval = setInterval(myTimer, 3000);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
ngOnDestroy(): void {
|
|
26
|
-
clearInterval(this.interval);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export default {
|
|
31
|
-
// title: 'Basics / Component / with ngOnDestroy',
|
|
32
|
-
component: OnDestroyComponent,
|
|
33
|
-
parameters: {
|
|
34
|
-
// disabled due to new Date()
|
|
35
|
-
storyshots: { disable: true },
|
|
36
|
-
chromatic: { disable: true },
|
|
37
|
-
},
|
|
38
|
-
} as Meta;
|
|
39
|
-
|
|
40
|
-
export const SimpleComponent: StoryObj = {};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Component, Input, ChangeDetectionStrategy, HostBinding } from '@angular/core';
|
|
2
|
-
|
|
3
|
-
@Component({
|
|
4
|
-
selector: 'storybook-on-push-box',
|
|
5
|
-
template: ` Word of the day: {{ word }} `,
|
|
6
|
-
styles: [
|
|
7
|
-
`
|
|
8
|
-
:host {
|
|
9
|
-
display: block;
|
|
10
|
-
padding: 1rem;
|
|
11
|
-
width: fit-content;
|
|
12
|
-
}
|
|
13
|
-
`,
|
|
14
|
-
],
|
|
15
|
-
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
16
|
-
})
|
|
17
|
-
export class OnPushBoxComponent {
|
|
18
|
-
@Input() word?: string;
|
|
19
|
-
|
|
20
|
-
@Input() @HostBinding('style.background-color') bgColor?: string;
|
|
21
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Meta, StoryFn } from '@storybook/angular';
|
|
2
|
-
import { OnPushBoxComponent } from './on-push-box.component';
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
// title: 'Basics / Component / With OnPush strategy',
|
|
6
|
-
component: OnPushBoxComponent,
|
|
7
|
-
argTypes: {
|
|
8
|
-
word: { control: 'text' },
|
|
9
|
-
bgColor: { control: 'color' },
|
|
10
|
-
},
|
|
11
|
-
args: {
|
|
12
|
-
word: 'The text',
|
|
13
|
-
bgColor: '#FFF000',
|
|
14
|
-
},
|
|
15
|
-
} as Meta;
|
|
16
|
-
|
|
17
|
-
export const ClassSpecifiedComponentWithOnPushAndArgs: StoryFn = (args) => ({
|
|
18
|
-
props: args,
|
|
19
|
-
});
|
|
20
|
-
ClassSpecifiedComponentWithOnPushAndArgs.storyName =
|
|
21
|
-
'Class-specified component with OnPush and Args';
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Meta, StoryFn, moduleMetadata } from '@storybook/angular';
|
|
2
|
-
|
|
3
|
-
import { CustomPipePipe } from './custom.pipe';
|
|
4
|
-
import { WithPipeComponent } from './with-pipe.component';
|
|
5
|
-
|
|
6
|
-
export default {
|
|
7
|
-
// title: 'Basics / Component / With Pipes',
|
|
8
|
-
component: WithPipeComponent,
|
|
9
|
-
decorators: [
|
|
10
|
-
moduleMetadata({
|
|
11
|
-
declarations: [CustomPipePipe],
|
|
12
|
-
}),
|
|
13
|
-
],
|
|
14
|
-
} as Meta;
|
|
15
|
-
|
|
16
|
-
export const Simple: StoryFn = () => ({
|
|
17
|
-
props: {
|
|
18
|
-
field: 'foobar',
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
export const WithArgsStory: StoryFn = (args) => ({
|
|
23
|
-
props: args,
|
|
24
|
-
});
|
|
25
|
-
WithArgsStory.storyName = 'With args';
|
|
26
|
-
WithArgsStory.argTypes = {
|
|
27
|
-
field: { control: 'text' },
|
|
28
|
-
};
|
|
29
|
-
WithArgsStory.args = {
|
|
30
|
-
field: 'Foo Bar',
|
|
31
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Args } from '@storybook/angular';
|
|
2
|
-
import { DiComponent } from './di.component';
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
// title: 'Basics / Component / With Provider',
|
|
6
|
-
component: DiComponent,
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const InputsAndInjectDependencies = () => ({
|
|
10
|
-
props: {
|
|
11
|
-
title: 'Component dependencies',
|
|
12
|
-
},
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
InputsAndInjectDependencies.storyName = 'inputs and inject dependencies';
|
|
16
|
-
|
|
17
|
-
export const InputsAndInjectDependenciesWithArgs = (args: Args) => ({
|
|
18
|
-
props: args,
|
|
19
|
-
});
|
|
20
|
-
InputsAndInjectDependenciesWithArgs.storyName = 'inputs and inject dependencies with args';
|
|
21
|
-
InputsAndInjectDependenciesWithArgs.argTypes = {
|
|
22
|
-
title: { control: 'text' },
|
|
23
|
-
};
|
|
24
|
-
InputsAndInjectDependenciesWithArgs.args = {
|
|
25
|
-
title: 'Component dependencies',
|
|
26
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Injector, ElementRef, Component, Input, InjectionToken, Inject } from '@angular/core';
|
|
2
|
-
import { stringify } from 'telejson';
|
|
3
|
-
|
|
4
|
-
export const TEST_TOKEN = new InjectionToken<string>('test');
|
|
5
|
-
|
|
6
|
-
@Component({
|
|
7
|
-
selector: 'storybook-di-component',
|
|
8
|
-
templateUrl: './di.component.html',
|
|
9
|
-
providers: [{ provide: TEST_TOKEN, useValue: 123 }],
|
|
10
|
-
})
|
|
11
|
-
export class DiComponent {
|
|
12
|
-
@Input()
|
|
13
|
-
title?: string;
|
|
14
|
-
|
|
15
|
-
constructor(
|
|
16
|
-
protected injector: Injector,
|
|
17
|
-
protected elRef: ElementRef,
|
|
18
|
-
@Inject(TEST_TOKEN) protected testToken: number
|
|
19
|
-
) {}
|
|
20
|
-
|
|
21
|
-
isAllDeps(): boolean {
|
|
22
|
-
return Boolean(this.testToken && this.elRef && this.injector && this.title);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
elRefStr(): string {
|
|
26
|
-
return stringify(this.elRef, { maxDepth: 1 });
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { StyledComponent } from './styled.component';
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
// title: 'Basics / Component / With StyleUrls',
|
|
5
|
-
component: StyledComponent,
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export const ComponentWithStyles = () => ({});
|
|
9
|
-
|
|
10
|
-
ComponentWithStyles.storyName = 'Component with styles';
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { OnInit, Type, Component, Injector, Input } from '@angular/core';
|
|
2
|
-
import { StoryFn, Meta, componentWrapperDecorator, moduleMetadata } from '@storybook/angular';
|
|
3
|
-
import { WithoutSelectorComponent, WITHOUT_SELECTOR_DATA } from './without-selector.component';
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
// title: 'Basics / Component / without selector / Custom wrapper *NgComponentOutlet',
|
|
7
|
-
component: WithoutSelectorComponent,
|
|
8
|
-
decorators: [
|
|
9
|
-
moduleMetadata({
|
|
10
|
-
entryComponents: [WithoutSelectorComponent],
|
|
11
|
-
}),
|
|
12
|
-
],
|
|
13
|
-
} as Meta;
|
|
14
|
-
|
|
15
|
-
// Advanced example with custom *ngComponentOutlet
|
|
16
|
-
|
|
17
|
-
@Component({
|
|
18
|
-
selector: 'ng-component-outlet-wrapper',
|
|
19
|
-
template: `<ng-container
|
|
20
|
-
*ngComponentOutlet="componentOutlet; injector: componentInjector; content: componentContent"
|
|
21
|
-
></ng-container>`,
|
|
22
|
-
})
|
|
23
|
-
class NgComponentOutletWrapperComponent implements OnInit {
|
|
24
|
-
@Input()
|
|
25
|
-
componentOutlet?: Type<unknown>;
|
|
26
|
-
|
|
27
|
-
@Input()
|
|
28
|
-
name?: string;
|
|
29
|
-
|
|
30
|
-
@Input()
|
|
31
|
-
color?: string;
|
|
32
|
-
|
|
33
|
-
componentInjector?: Injector;
|
|
34
|
-
|
|
35
|
-
componentContent = [
|
|
36
|
-
[document.createTextNode('Ng-content : Inspired by ')],
|
|
37
|
-
[document.createTextNode('https://angular.io/api/common/NgComponentOutlet')],
|
|
38
|
-
];
|
|
39
|
-
|
|
40
|
-
constructor(private readonly injector: Injector) {}
|
|
41
|
-
|
|
42
|
-
ngOnInit(): void {
|
|
43
|
-
this.componentInjector = Injector.create({
|
|
44
|
-
providers: [
|
|
45
|
-
{ provide: WITHOUT_SELECTOR_DATA, useValue: { color: this.color, name: this.name } },
|
|
46
|
-
],
|
|
47
|
-
parent: this.injector,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Live changing of args by controls does not work at the moment. When changing args storybook does not fully
|
|
53
|
-
// reload and therefore does not take into account the change of provider.
|
|
54
|
-
export const WithCustomNgComponentOutletWrapper: StoryFn = (args) => ({
|
|
55
|
-
props: args,
|
|
56
|
-
});
|
|
57
|
-
WithCustomNgComponentOutletWrapper.storyName = 'Custom wrapper *NgComponentOutlet';
|
|
58
|
-
WithCustomNgComponentOutletWrapper.argTypes = {
|
|
59
|
-
name: { control: 'text' },
|
|
60
|
-
color: { control: 'color' },
|
|
61
|
-
};
|
|
62
|
-
WithCustomNgComponentOutletWrapper.args = { name: 'Color', color: 'green' };
|
|
63
|
-
WithCustomNgComponentOutletWrapper.decorators = [
|
|
64
|
-
moduleMetadata({
|
|
65
|
-
declarations: [NgComponentOutletWrapperComponent],
|
|
66
|
-
}),
|
|
67
|
-
componentWrapperDecorator(NgComponentOutletWrapperComponent, (args) => ({
|
|
68
|
-
name: args.name,
|
|
69
|
-
|
|
70
|
-
color: args['color'],
|
|
71
|
-
componentOutlet: WithoutSelectorComponent,
|
|
72
|
-
})),
|
|
73
|
-
];
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AfterViewInit,
|
|
3
|
-
ComponentFactoryResolver,
|
|
4
|
-
Type,
|
|
5
|
-
Component,
|
|
6
|
-
Input,
|
|
7
|
-
ViewChild,
|
|
8
|
-
ViewContainerRef,
|
|
9
|
-
} from '@angular/core';
|
|
10
|
-
import { StoryFn, Meta, componentWrapperDecorator, moduleMetadata } from '@storybook/angular';
|
|
11
|
-
|
|
12
|
-
import { WithoutSelectorComponent } from './without-selector.component';
|
|
13
|
-
|
|
14
|
-
export default {
|
|
15
|
-
// title: 'Basics / Component / without selector / Custom wrapper ComponentFactoryResolver',
|
|
16
|
-
component: WithoutSelectorComponent,
|
|
17
|
-
decorators: [
|
|
18
|
-
moduleMetadata({
|
|
19
|
-
entryComponents: [WithoutSelectorComponent],
|
|
20
|
-
}),
|
|
21
|
-
],
|
|
22
|
-
} as Meta;
|
|
23
|
-
|
|
24
|
-
// Advanced example with custom ComponentFactoryResolver
|
|
25
|
-
|
|
26
|
-
@Component({ selector: 'component-factory-wrapper', template: '' })
|
|
27
|
-
class ComponentFactoryWrapperComponent implements AfterViewInit {
|
|
28
|
-
@ViewChild('dynamicInsert', { read: ViewContainerRef }) dynamicInsert: any;
|
|
29
|
-
|
|
30
|
-
@Input()
|
|
31
|
-
componentOutlet?: Type<unknown>;
|
|
32
|
-
|
|
33
|
-
@Input()
|
|
34
|
-
args: any;
|
|
35
|
-
|
|
36
|
-
constructor(
|
|
37
|
-
private viewContainerRef: ViewContainerRef,
|
|
38
|
-
private componentFactoryResolver: ComponentFactoryResolver
|
|
39
|
-
) {}
|
|
40
|
-
|
|
41
|
-
ngAfterViewInit() {
|
|
42
|
-
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(
|
|
43
|
-
this.componentOutlet!
|
|
44
|
-
);
|
|
45
|
-
const containerRef = this.viewContainerRef;
|
|
46
|
-
containerRef.clear();
|
|
47
|
-
const dynamicComponent = containerRef.createComponent(componentFactory);
|
|
48
|
-
Object.assign(dynamicComponent.instance as any, this.args);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Live changing of args by controls does not work at the moment. When changing args storybook does not fully
|
|
53
|
-
// reload and therefore does not take into account the change of provider.
|
|
54
|
-
export const WithComponentFactoryResolver: StoryFn = (args) => ({
|
|
55
|
-
props: args,
|
|
56
|
-
});
|
|
57
|
-
WithComponentFactoryResolver.storyName = 'Custom wrapper ComponentFactoryResolver';
|
|
58
|
-
WithComponentFactoryResolver.argTypes = {
|
|
59
|
-
name: { control: 'text' },
|
|
60
|
-
color: { control: 'color' },
|
|
61
|
-
};
|
|
62
|
-
WithComponentFactoryResolver.args = { name: 'Color', color: 'chartreuse' };
|
|
63
|
-
WithComponentFactoryResolver.decorators = [
|
|
64
|
-
moduleMetadata({
|
|
65
|
-
declarations: [ComponentFactoryWrapperComponent],
|
|
66
|
-
}),
|
|
67
|
-
componentWrapperDecorator(ComponentFactoryWrapperComponent, ({ args }) => ({
|
|
68
|
-
args,
|
|
69
|
-
componentOutlet: WithoutSelectorComponent,
|
|
70
|
-
})),
|
|
71
|
-
];
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Component, Inject, InjectionToken, Optional } from '@angular/core';
|
|
2
|
-
|
|
3
|
-
export const WITHOUT_SELECTOR_DATA = new InjectionToken<{ color: string; name: string }>(
|
|
4
|
-
'WITHOUT_SELECTOR_DATA'
|
|
5
|
-
);
|
|
6
|
-
|
|
7
|
-
@Component({
|
|
8
|
-
template: `My name in color :
|
|
9
|
-
<div [style.color]="color">{{ name }}</div>
|
|
10
|
-
<ng-content></ng-content> <ng-content></ng-content>`,
|
|
11
|
-
})
|
|
12
|
-
export class WithoutSelectorComponent {
|
|
13
|
-
color = '#1e88e5';
|
|
14
|
-
|
|
15
|
-
name = 'Joe Bar';
|
|
16
|
-
|
|
17
|
-
constructor(
|
|
18
|
-
@Inject(WITHOUT_SELECTOR_DATA)
|
|
19
|
-
@Optional()
|
|
20
|
-
data: {
|
|
21
|
-
color: string;
|
|
22
|
-
name: string;
|
|
23
|
-
} | null
|
|
24
|
-
) {
|
|
25
|
-
if (data) {
|
|
26
|
-
this.color = data.color;
|
|
27
|
-
this.name = data.name;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { StoryFn, Meta, moduleMetadata } from '@storybook/angular';
|
|
2
|
-
import { WithoutSelectorComponent, WITHOUT_SELECTOR_DATA } from './without-selector.component';
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
// title: 'Basics / Component / without selector',
|
|
6
|
-
component: WithoutSelectorComponent,
|
|
7
|
-
decorators: [
|
|
8
|
-
moduleMetadata({
|
|
9
|
-
entryComponents: [WithoutSelectorComponent],
|
|
10
|
-
}),
|
|
11
|
-
],
|
|
12
|
-
} as Meta;
|
|
13
|
-
|
|
14
|
-
export const SimpleComponent: StoryFn = () => ({});
|
|
15
|
-
|
|
16
|
-
// Live changing of args by controls does not work for now. When changing args storybook does not fully
|
|
17
|
-
// reload and therefore does not take into account the change of provider.
|
|
18
|
-
export const WithInjectionTokenAndArgs: StoryFn = (args) => ({
|
|
19
|
-
props: args,
|
|
20
|
-
moduleMetadata: {
|
|
21
|
-
providers: [
|
|
22
|
-
{ provide: WITHOUT_SELECTOR_DATA, useValue: { color: args['color'], name: args['name'] } },
|
|
23
|
-
],
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
WithInjectionTokenAndArgs.argTypes = {
|
|
27
|
-
name: { control: 'text' },
|
|
28
|
-
color: { control: 'color' },
|
|
29
|
-
};
|
|
30
|
-
WithInjectionTokenAndArgs.args = { name: 'Color', color: 'red' };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { PipeTransform, Pipe } from '@angular/core';
|
|
2
|
-
|
|
3
|
-
@Pipe({
|
|
4
|
-
name: 'chipText',
|
|
5
|
-
})
|
|
6
|
-
export class ChipTextPipe implements PipeTransform {
|
|
7
|
-
transform(value: string): string {
|
|
8
|
-
return Array.from(value)
|
|
9
|
-
.map((char) => this.accentVowel(char))
|
|
10
|
-
.join('');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
accentVowel(char: string): string {
|
|
14
|
-
switch (char) {
|
|
15
|
-
case 'a':
|
|
16
|
-
return 'á';
|
|
17
|
-
case 'e':
|
|
18
|
-
return 'é';
|
|
19
|
-
case 'i':
|
|
20
|
-
return 'í';
|
|
21
|
-
case 'o':
|
|
22
|
-
return 'ó';
|
|
23
|
-
case 'u':
|
|
24
|
-
return 'ú';
|
|
25
|
-
default:
|
|
26
|
-
return char;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { Component, Input, Output, EventEmitter, Inject, HostBinding } from '@angular/core';
|
|
2
|
-
import { CHIP_COLOR } from './chip-color.token';
|
|
3
|
-
|
|
4
|
-
@Component({
|
|
5
|
-
selector: 'storybook-chip',
|
|
6
|
-
template: `
|
|
7
|
-
<span class="text">{{ displayText | chipText }}</span>
|
|
8
|
-
<div class="remove" (click)="removeClicked.emit()">
|
|
9
|
-
<span class="x">✕</span>
|
|
10
|
-
</div>
|
|
11
|
-
`,
|
|
12
|
-
styles: [
|
|
13
|
-
`
|
|
14
|
-
:host {
|
|
15
|
-
display: inline-flex;
|
|
16
|
-
cursor: default;
|
|
17
|
-
align-items: center;
|
|
18
|
-
justify-content: center;
|
|
19
|
-
padding: 0.2rem 0.5rem;
|
|
20
|
-
border-radius: 1rem;
|
|
21
|
-
border: solid 0.1rem transparent;
|
|
22
|
-
}
|
|
23
|
-
:host:hover {
|
|
24
|
-
border-color: black;
|
|
25
|
-
}
|
|
26
|
-
.text {
|
|
27
|
-
font-family: inherit;
|
|
28
|
-
}
|
|
29
|
-
.remove {
|
|
30
|
-
margin-left: 1rem;
|
|
31
|
-
background-color: lightgrey;
|
|
32
|
-
border-radius: 50%;
|
|
33
|
-
width: 1rem;
|
|
34
|
-
height: 1rem;
|
|
35
|
-
text-align: center;
|
|
36
|
-
}
|
|
37
|
-
.remove:hover {
|
|
38
|
-
background-color: palevioletred;
|
|
39
|
-
}
|
|
40
|
-
.x {
|
|
41
|
-
display: inline-block;
|
|
42
|
-
color: #eeeeee;
|
|
43
|
-
text-align: center;
|
|
44
|
-
vertical-align: baseline;
|
|
45
|
-
line-height: 1rem;
|
|
46
|
-
}
|
|
47
|
-
`,
|
|
48
|
-
],
|
|
49
|
-
})
|
|
50
|
-
export class ChipComponent {
|
|
51
|
-
@Input() displayText?: string;
|
|
52
|
-
|
|
53
|
-
@Output() removeClicked = new EventEmitter();
|
|
54
|
-
|
|
55
|
-
@HostBinding('style.background-color') backgroundColor: string;
|
|
56
|
-
|
|
57
|
-
constructor(@Inject(CHIP_COLOR) chipColor: string) {
|
|
58
|
-
this.backgroundColor = chipColor;
|
|
59
|
-
}
|
|
60
|
-
}
|