aboutsummaryrefslogtreecommitdiffstats
path: root/stories/ng2-component-lab/button.component.exp.ts
blob: 6c5fb0420bc37ec53a52027d38195e57d62017e2 (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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import { experimentOn } from '@islavi/ng2-component-lab';

const buttonTypes = ['primary', 'secondary', 'link', 'alert'];
const buttonSizes = ['large', 'medium', 'small', 'x-small', 'default'];
const experiment = experimentOn('Button');

experiment.group("Default button", [
    {
        id: "defaultButton",
        showSource: true,
        description: `Default button, does not need to supply type or size.
        <br>The size of the button set to 'default' so it will shrink or expand according to the content.
        `,
        context: {
            buttonClicked: ():void => {
                window.alert("OK");
            }
        },
        title: "Default button",
        template: `
            <sdc-button
                text="Default button long text"
                testId="longButton"
                (click)="buttonClicked()">
            </sdc-button>
            <sdc-button
                text="Sample button"
                (click)="buttonClicked()"
                [testId]="'defaultButtonTestId'"
               >
            </sdc-button>


            `
    }
]);

buttonTypes.forEach((buttonType) => {
    [false, true].forEach((buttonDisabled) => {
        experiment.group(`Button ${buttonType} ${buttonDisabled ? ' disabled' : ''}`, [   {
            id: `Button ${buttonType}${buttonDisabled ? ' disabled' : ''}`,
            showSource: true,
            context: {
                buttonClicked: ():void => {
                    window.alert("OK");
                }
            },
            title: `Button ${buttonType}${buttonDisabled ? ' disabled' : ''}`,
            template: buttonSizes.map((buttonSize) =>
                `
                <span style="display: inline-block;">
                <div>${buttonSize}</div><br>
                <sdc-button
                    text="Sample"
                    type="${buttonType}"
                    size="${buttonSize}"
                    (click)="buttonClicked()"
                    ${buttonDisabled ? ' [disabled]="true"' : ''}>
                </sdc-button>
                </span>
                `).join('\n')
        }
        ]);
    });
});

experiment.group("Buttons with icons", [
    {
        id: "buttonsWithIcons",
        showSource: true,
        description: `Buttons with icons forward`,
        context: {
            buttonClicked: (): void => {
                window.alert("OK");
            }
        },
        title: "Button with icons",
        template: `
            <sdc-button
                text="Default button long text"
                (click)="buttonClicked()"
                icon_name="settings-o"
                icon_position="left"
               >
            </sdc-button>

            <sdc-button
                text="Sample button"
                (click)="buttonClicked()"
                icon_name="plus-circle-o"
                icon_position="left"
                >
            </sdc-button>

            <sdc-button
                text="Sample button"
                 type="secondary"
                (click)="buttonClicked()"
                icon_name="plus-circle"
                icon_position="right"
                >
            </sdc-button>

            <sdc-button
                text="Sample button"
                type="secondary"
                (click)="buttonClicked()"
                icon_name="caret2-right-circle-o"
                icon_position="right"
              >
            </sdc-button>

           `
    }
]);

experiment.group("Buttons with spinners", [
    {
        id: "buttonsWithSpinnersRight",
        showSource: true,
        description: `Click the button to see the spinner shows for 2 seconds`,
        context: {
            buttonClicked: (button): void => {
                button.show_spinner = true;
                setTimeout(() => {button.show_spinner = false},2000);
            },
        },
        title: "Button with spinner on the right",
        template: `
            <sdc-button
                text="Click to show spinner"
                (click)="buttonClicked(button)"
                [show_spinner]="false"
                spinner_position="right"
                #button
               >
            </sdc-button>

           `
    },
    {
        id: "buttonsWithSpinnersLeft",
        showSource: true,
        description: `Click the button to see the spinner shows for 2 seconds`,
        context: {
            buttonClicked: (button): void => {
                button.show_spinner = true;
                setTimeout(() => {button.show_spinner = false},2000);
            },
        },
        title: "Button with spinner on the left",
        template: `
            <sdc-button
                text="Click to show spinner"
                (click)="buttonClicked(button)"
                spinner_position="left"
                #button
               >
            </sdc-button>

           `
    }
]);
export default experiment;