aboutsummaryrefslogtreecommitdiffstats
path: root/stories/ng2-component-lab/components/svg-icons-table.component.ts
blob: 732650d93bcef19426227644b9c4004ddcf27872 (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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import { Component } from "@angular/core";
import { Mode, Placement, Size } from "../../../src/angular/common/enums";
import { SvgIconComponent } from "../../../src/angular/svg-icon/svg-icon.component";
import { IDropDownOption, DropDownOptionType, DropDownTypes } from "../../../src/angular/form-elements/dropdown/dropdown-models";

const options1: IDropDownOption[] = [
    {
        label: 'First Option',
        value: 'First Option',
    },
    {
        label: 'Second Option',
        value: 'Second Option',
    },
    {
        label: 'Third Option',
        value: 'Third Option',
        type: DropDownOptionType.Simple
    }
];

@Component({
    selector: "svg-icons-table",
    template: `
        <div class="icon-showcase">
            <div>
                <svg-icon [name]="selectedIcon" [mode]="defaultIconSettings.mode" [size]="defaultIconSettings.size"></svg-icon>
                Selected icon: <b *ngIf="selectedIcon">{{selectedIcon}}</b><i *ngIf="!selectedIcon">None</i>
            </div>

            <div class="icon-options-wrapper">

                <div class="icon-options">
                    <div class="icon-options-dropdowns">
                        <sdc-dropdown label="Mode" [selectedOption]="{'value': mode, 'label': mode}" [options]="modeOptions" (changed)="mode = $event.value"></sdc-dropdown>
                        <sdc-dropdown label="Label Placement" [selectedOption]="{'value': labelPlacement, 'label': labelPlacement}" [options]="labelPlacementOptions" [selectedOption]="labelPlacement" (changed)="labelPlacement = $event.value"></sdc-dropdown>
                        <sdc-dropdown label="Size" [selectedOption]="{'value': size, 'label': size}" [options]="sizeOptions" [selectedOption]="size" (changed)="size = $event.value"></sdc-dropdown>
                    </div>
                    <div class="icon-options-checkboxes-wrapper">
                        <div class="icon-options-checkboxes">
                            <sdc-checkbox label="Clickable" [checked]="clickable" (checkedChange)="clickable = $event"></sdc-checkbox>
                            <sdc-checkbox label="Disabled" [checked]="disabled" (checkedChange)="disabled = $event"></sdc-checkbox>
                        </div>
                        <div class="icon-options-label">
                            <sdc-input label="Label" [(value)]="label"></sdc-input>
                        </div>
                        <svg-icon-label [name]="selectedIcon" [mode]="mode" [size]="size" [clickable]="clickable" [disabled]="disabled" [label]="label" [labelPlacement]="labelPlacement"></svg-icon-label>
                    </div>
                </div>

                <div class="icon-code">
                    <pre>
                        &lt;svg-icon-label
                            [name]="{{selectedIcon}}"
                            [mode]="{{mode}}"
                            [size]="{{size}}"
                            [clickable]="{{clickable}}"
                            [disabled]="{{disabled}}"
                            [label]="{{label}}"
                            [labelPlacement]="{{labelPlacement}}"&gt;
                        &lt;/svg-icon-label&gt;
                    </pre>
                </div>
            </div>

        </div>
        <div class="svg-icons-table">
            <div *ngFor="let iconName of iconsNames" class="svg-icon-cell" [ngClass]="{'selected': selectedIcon === iconName}" (click)="selectIcon(iconName)">
                <svg-icon-label [name]="iconName" [label]="iconName" labelPlacement="right"></svg-icon-label>
            </div>
        </div>
`,
    styles: [`
    .svg-icons-table {
        display: flex;
        flex-flow: row wrap;
        justify-content: flex-start;
        align-items: stretch;
        overflow-y: auto;
    }
    .svg-icons-table .svg-icon-cell {
        border: 1px solid #999;
        padding: 5px;
        margin: 5px;
        width: 250px;
        overflow: hidden;
        display: flex;
        align-items: center;
        cursor: pointer;
    }
    .svg-icons-table .svg-icon-cell.selected {
        border-color: #1eb9f3;
        background-color: #1eb9f3;
    }
    .icon-showcase {
        margin: 20px 10px;
        padding: 10px;
        border: 1px solid #999;
        background: #eee;
    }
    .icon-options-wrapper {
        display: flex;
        flex-flow: row wrap;
        justify-content: flex-start;
        margin-top: 10px;
    }

    .icon-options-checkboxes-wrapper {
        display: flex;
        flex-flow: row;
        margin-top: 10px;
    }

    .icon-options-checkboxes {
        margin-top: 27px;
        margin-right: 30px;
    }

    .icon-options-label {
        margin-right: 30px;
    }

    .icon-code pre {
        user-select: text;
    }

    sdc-dropdown {
        display: inline-block;
        min-width: 160px;
    }

    sdc-dropdown .sdc-dropdown {
    }
`]
})
export class SvgIconsTableComponent {
    public iconsNames: string[];
    public selectedIcon: string;

    public modeOptions;
    public sizeOptions;
    public labelPlacementOptions;

    private mode: Mode;
    private size: Size;
    private labelPlacement: Placement;
    private clickable: boolean;
    private disabled: boolean;
    private label: string;

    private defaultIconSettings: {mode: Mode, size: Size};

    constructor() {
        this.iconsNames = Object.keys(SvgIconComponent.Icons);
        this.mode = null;
        this.size = Size.medium;
        this.clickable = false;
        this.disabled = false;
        this.defaultIconSettings = { mode: Mode.info, size: Size.small };

        this.modeOptions = [{value: null, label: 'NONE'}].concat(Object.keys(Mode).map((modeKey) => ({
            value: modeKey,
            label: Mode[modeKey]
        })));

        this.sizeOptions = Object.keys(Size).map((sizeKey) => ({
            value: sizeKey,
            label: Size[sizeKey]
        }));

        this.labelPlacementOptions = Object.keys(Placement).map((placementKey) => ({
            value: placementKey,
            label: Placement[placementKey]
        }));

        this.setDefaults();
    }

    private setDefaults = (): void => {
        this.label = 'Some label';
        this.selectedIcon = "attachment";
        this.mode = Mode.primary;
        this.labelPlacement = Placement.right;
    }

    public selectIcon(iconName) {
        this.selectedIcon = iconName;
    }
}