aboutsummaryrefslogtreecommitdiffstats
path: root/stories/angular/loader.stories.ts
blob: ccc4152bde5d387c4c83e19785d0b2112ae01934 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import { storiesOf } from '@storybook/angular';
import { withKnobs, text, number, boolean, array, select, color, date, button } from '@storybook/addon-knobs';
import { withNotes } from '@storybook/addon-notes';
import { action, configureActions } from '@storybook/addon-actions';
import { moduleMetadata } from '@storybook/angular';
import { LoaderComponent, ButtonComponent, InputComponent, SvgIconComponent } from '../../src/angular/components';
import { FormElementsModule } from '../../src/angular/form-elements/form-elements.module';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';
import { LoaderService } from '../../src/angular/loader/loader.service';
import { LoaderSize } from '../../src/angular/loader/loader.component';

storiesOf('Loader', module)
  .addDecorator(withKnobs)
  .addDecorator(withNotes)
  .addDecorator(
    moduleMetadata({
      declarations: [
        LoaderComponent,
        ButtonComponent,
        InputComponent,
        SvgIconComponent
      ],
      imports: [
          CommonModule,
        FormsModule,
        ReactiveFormsModule
      ],
      providers: [
          LoaderService
      ]
    })
  )
  .add('Relative loader', () => {
    const _size = select('size', Object.values(LoaderSize), LoaderSize.large);
    const _name = text('name', 'RelativeLoader');
    const _active = boolean('active', false);

      return {
        props: {
            activateLogger: (loader) => {
                loader.activate();
                action('Loader activated')();
            },
            deactivateLogger: (loader) => {
                loader.deactivate();
                action('Loader deactivated')();
            },
            _size, _name, _active
        },
        template: `
        <h2>Loader visible: {{_active}}</h2>
        <sdc-loader #loader1 [size]="_size" [name]="_name" [(active)]="_active">
            <div style="border:1px solid black; padding:20px 100px;">
                <sdc-input label="Please Enter Value" required="true" [maxLength]="5"></sdc-input>
                <sdc-input label="Please Enter Value" required="true" [maxLength]="5"></sdc-input>
                <sdc-input label="Please Enter Value" required="true" [maxLength]="5"></sdc-input>
                <sdc-input label="Please Enter Value" required="true" [maxLength]="5"></sdc-input>
            </div>
        </sdc-loader >
        <div style="margin:10px 0px;">
            <sdc-button text="Show loader" (click)="activateLogger(loader1)"></sdc-button>
            <sdc-button text="Hide loader" (click)="deactivateLogger(loader1)"></sdc-button>
        </div>
        `
      }
    },
    { notes: `<h2>Relative loader</h2>
            Relative loader that wraps dom elements.
            Use the KNOBS tab to change values.`
    }
)
.add('Relative loader with service', () => {
    const _size = select('size', Object.values(LoaderSize), LoaderSize.large);
    const _name = text('name', 'RelativeLoader');
    const _active = boolean('active', false);

      return {
        props: {
            activateLogger: (loader) => {
                loader.activate();
                action('Loader activated')();
            },
            deactivateLogger: (loader) => {
                loader.deactivate();
                action('Loader deactivated')();
            },
            _size, _name, _active
        },
        template: `
        <h2>Loader visible: {{_active}}</h2>
        <sdc-loader #loader1 [size]="_size" [name]="_name" [(active)]="_active">
            <div style="border:1px solid black; padding:20px 100px;">
                <sdc-input label="Please Enter Value" required="true" [maxLength]="5"></sdc-input>
                <sdc-input label="Please Enter Value" required="true" [maxLength]="5"></sdc-input>
                <sdc-input label="Please Enter Value" required="true" [maxLength]="5"></sdc-input>
                <sdc-input label="Please Enter Value" required="true" [maxLength]="5"></sdc-input>
            </div>
        </sdc-loader >
        <div style="margin:10px 0px;">
            <sdc-button text="Show loader" (click)="activateLogger(loader1)"></sdc-button>
            <sdc-button text="Hide loader" (click)="deactivateLogger(loader1)"></sdc-button>
        </div>
        `
      }
    },
    { notes: `<h2>Relative loader</h2>
            Relative loader that wraps dom elements.
            Use the KNOBS tab to change values.`
    }
)








.add('General loader', () => {
    const _size = select('size', Object.values(LoaderSize), LoaderSize.large);
    const _name = text('name', 'global');
    const _global = boolean('global', true);

      return {
        props: {
            activateLogger: (loader) => {
                loader.loaderService.activate(loader.name);
                setTimeout(() => {
                    loader.loaderService.deactivate(loader.name);
                }, 2000);
                action('Global loader activated')();
            },
            _size, _name, _global
        },
        template: `
        <sdc-loader [global]="_global" [name]="_name" [size]="_size" #globalLoader></sdc-loader>
        <sdc-button text="Show global loader" (click)="activateLogger(globalLoader)"></sdc-button>
        `
      }
    },
    { notes: `<h2>General loader</h2>
            General loader to hide full screen.
            For this sample added setTimeout() function so the loader will deactivated after 2 seconds.
            Use the KNOBS tab to change values.`
    }
)