Skip to content

Commit 50d6f3a

Browse files
committed
Merge branch 'master' of github.com:IBM/carbon-components-angular into table
2 parents 7aa609d + aea73dc commit 50d6f3a

18 files changed

+501
-191
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@
5555
"license": "Apache-2.0",
5656
"author": "IBM",
5757
"peerDependencies": {
58-
"@angular/animations": "^6.1.0",
59-
"@angular/common": "^6.1.0",
60-
"@angular/compiler": "^6.1.0",
61-
"@angular/core": "^6.1.0",
62-
"@angular/forms": "^6.1.0",
63-
"@angular/http": "^6.1.0",
64-
"@angular/platform-browser": "^6.1.0",
65-
"@angular/platform-browser-dynamic": "^6.1.0",
58+
"@angular/animations": "^6.1.0 || ^7.0.0",
59+
"@angular/common": "^6.1.0 || ^7.0.0",
60+
"@angular/compiler": "^6.1.0 || ^7.0.0",
61+
"@angular/core": "^6.1.0 || ^7.0.0",
62+
"@angular/forms": "^6.1.0 || ^7.0.0",
63+
"@angular/http": "^6.1.0 || ^7.0.0",
64+
"@angular/platform-browser": "^6.1.0 || ^7.0.0",
65+
"@angular/platform-browser-dynamic": "^6.1.0 || ^7.0.0",
6666
"core-js": "^2.5.3",
6767
"rxjs": "^6.0.0",
6868
"zone.js": "^0.8.26",

src/button/button.stories.ts

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { storiesOf, moduleMetadata } from "@storybook/angular";
22
import { withNotes } from "@storybook/addon-notes";
33
import { action } from "@storybook/addon-actions";
4-
import { withKnobs, boolean, object } from "@storybook/addon-knobs/angular";
4+
import { withKnobs, select } from "@storybook/addon-knobs/angular";
55

66
import { ButtonModule } from "../";
77

@@ -14,31 +14,19 @@ storiesOf("Button", module)
1414
.addDecorator(withKnobs)
1515
.add("Basic", () => ({
1616
template: `
17-
<button ibmButton>A button</button>
17+
<button ibmButton [size]="size">A button</button>
1818
<br><br>
19-
<button ibmButton="secondary">A secondary button</button>
19+
<button ibmButton="secondary" [size]="size">A secondary button</button>
2020
<br><br>
21-
<button ibmButton="tertiary">A tertiary button</button>
21+
<button ibmButton="tertiary" [size]="size">A tertiary button</button>
2222
<br><br>
23-
<button ibmButton="ghost">A ghost button</button>
23+
<button ibmButton="ghost" [size]="size">A ghost button</button>
2424
<br><br>
25-
<button ibmButton="danger">A danger button</button>
25+
<button ibmButton="danger" [size]="size">A danger button</button>
2626
<br><br>
27-
<button ibmButton="danger--primary">A primary danger button</button>
28-
`
29-
}))
30-
.add("Small", () => ({
31-
template: `
32-
<button ibmButton size="sm">A button</button>
33-
<br><br>
34-
<button ibmButton="secondary" size="sm">A secondary button</button>
35-
<br><br>
36-
<button ibmButton="tertiary" size="sm">A tertiary button</button>
37-
<br><br>
38-
<button ibmButton="ghost" size="sm">A ghost button</button>
39-
<br><br>
40-
<button ibmButton="danger" size="sm">A danger button</button>
41-
<br><br>
42-
<button ibmButton="danger--primary" size="sm">A primary danger button</button>
43-
`
27+
<button ibmButton="danger--primary" [size]="size">A primary danger button</button>
28+
`,
29+
props: {
30+
size: select("Size of the buttons", ["normal", "sm"], "normal")
31+
}
4432
}));

src/code-snippet/code-snippet.stories.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { storiesOf, moduleMetadata } from "@storybook/angular";
2-
import { withKnobs } from "@storybook/addon-knobs/angular";
2+
import { withKnobs, select } from "@storybook/addon-knobs/angular";
33

44
import { CodeSnippetModule } from "..";
55

6-
76
const code = `import { storiesOf, moduleMetadata } from "@storybook/angular";
87
import { withKnobs, boolean } from "@storybook/addon-knobs/angular";
98
@@ -62,14 +61,9 @@ storiesOf("CodeSnippet", module).addDecorator(
6261
}
6362
}))
6463
.add("Inline", () => ({
65-
template: `Here is some <ibm-code-snippet display="inline">{{inlineCode}}</ibm-code-snippet> for you.`,
66-
props: {
67-
inlineCode
68-
}
69-
}))
70-
.add("Inline Light", () => ({
71-
template: `Here is some <ibm-code-snippet display="inline" theme="light">{{inlineCode}}</ibm-code-snippet> for you.`,
64+
template: `Here is some <ibm-code-snippet display="inline" [theme]="theme">{{inlineCode}}</ibm-code-snippet> for you.`,
7265
props: {
73-
inlineCode
66+
inlineCode,
67+
theme: select("Theme", ["dark", "light"], "dark")
7468
}
7569
}));

src/dropdown/dropdown.stories.ts

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { storiesOf, moduleMetadata } from "@storybook/angular";
22
import { withNotes } from "@storybook/addon-notes";
33
import { action } from "@storybook/addon-actions";
4-
import { withKnobs, boolean, object, text } from "@storybook/addon-knobs/angular";
4+
import { withKnobs, select, boolean, object, text } from "@storybook/addon-knobs/angular";
55

66
import { DropdownModule } from "../";
77

@@ -22,6 +22,7 @@ storiesOf("Dropdown", module)
2222
.add("Basic", () => ({
2323
template: `
2424
<ibm-dropdown
25+
[theme]="theme"
2526
placeholder="Select"
2627
[disabled]="disabled"
2728
(selected)="selected($event)"
@@ -38,30 +39,8 @@ storiesOf("Dropdown", module)
3839
{ content: "four" }
3940
]),
4041
selected: action("Selected fired for dropdown"),
41-
onClose: action("Dropdown closed")
42-
}
43-
}))
44-
.add("Light", () => ({
45-
template: `
46-
<ibm-dropdown
47-
theme="light"
48-
placeholder="Select"
49-
[disabled]="disabled"
50-
(selected)="selected($event)"
51-
(onClose)="onClose($event)">
52-
<ibm-dropdown-list [items]="items"></ibm-dropdown-list>
53-
</ibm-dropdown>
54-
`,
55-
props: {
56-
disabled: boolean("disabled", false),
57-
items: object("items", [
58-
{ content: "one" },
59-
{ content: "two" },
60-
{ content: "three" },
61-
{ content: "four" }
62-
]),
63-
selected: action("Selected fired for dropdown"),
64-
onClose: action("Dropdown closed")
42+
onClose: action("Dropdown closed"),
43+
theme: select("theme", ["dark", "light"], "dark")
6544
}
6645
}))
6746
.add("Multi-select", withNotes({ text: "Notes on multi select" })(() => ({
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface FileItem {
2+
file: File;
3+
state: "edit" | "upload" | "complete";
4+
uploaded: boolean;
5+
}
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
import {
2+
Component,
3+
Input,
4+
Output,
5+
ViewChild,
6+
EventEmitter,
7+
OnInit
8+
} from "@angular/core";
9+
import { NG_VALUE_ACCESSOR } from "@angular/forms";
10+
11+
import { I18n } from "../i18n/i18n.module";
12+
import { FileItem } from "./file-item.interface";
13+
14+
const noop = () => {};
15+
16+
@Component({
17+
selector: "ibm-file-uploader",
18+
template: `
19+
<strong class="bx--label">{{title}}</strong>
20+
<p class="bx--label-description">{{description}}</p>
21+
<div class="bx--file">
22+
<button
23+
ibmButton="secondary"
24+
(click)="fileInput.click()"
25+
[attr.for]="fileUploaderId">
26+
{{buttonText}}
27+
</button>
28+
<input
29+
#fileInput
30+
type="file"
31+
class="bx--file-input"
32+
[accept]="accept"
33+
[id]="fileUploaderId"
34+
[multiple]="multiple"
35+
(change)="onFilesAdded()"/>
36+
<div class="bx--file-container">
37+
<ibm-file *ngFor="let fileItem of files" [fileItem]="fileItem" (remove)="removeFile(fileItem)"></ibm-file>
38+
</div>
39+
</div>
40+
`,
41+
providers: [
42+
{
43+
provide: NG_VALUE_ACCESSOR,
44+
useExisting: FileUploader,
45+
multi: true
46+
}
47+
]
48+
})
49+
export class FileUploader implements OnInit {
50+
/**
51+
* Counter used to create unique ids for file-uploader components
52+
*/
53+
static fileUploaderCount = 0;
54+
/**
55+
* Accessible text for the button that opens the upload window.
56+
*
57+
* Defaults to the `FILE_UPLOADER.OPEN` value from the i18n service
58+
*/
59+
@Input() buttonText = this.i18n.get().FILE_UPLOADER.OPEN;
60+
/**
61+
* Text set to the title
62+
*/
63+
@Input() title: string;
64+
/**
65+
* Text set to the description
66+
*/
67+
@Input() description: string;
68+
/**
69+
* Specify the types of files that the input should be able to receive
70+
*/
71+
@Input() accept = [];
72+
/**
73+
* Set to `false` to tell the component to only accept a single file on upload.
74+
*
75+
* Defaults to `true`. Accepts multiple files.
76+
*/
77+
@Input() multiple = true;
78+
/**
79+
* Provides a unique id for the underlying <input> node
80+
*/
81+
@Input() fileUploaderId = `file-uploader-${FileUploader.fileUploaderCount}`;
82+
/**
83+
* Maintains a reference to the view DOM element of the underlying <input> node
84+
*/
85+
@ViewChild("fileInput") fileInput;
86+
/**
87+
* The list of files that have been submitted to be uploaded
88+
*/
89+
@Input() files: Set<FileItem>;
90+
@Output() filesChange = new EventEmitter<any>();
91+
92+
protected onTouchedCallback: () => void = noop;
93+
protected onChangeCallback: (_: Set<FileItem>) => void = noop;
94+
95+
constructor(protected i18n: I18n) {
96+
FileUploader.fileUploaderCount++;
97+
}
98+
99+
/**
100+
* Specifies the property to be used as the return value to `ngModel`
101+
*/
102+
get value(): Set<FileItem> {
103+
return this.files;
104+
}
105+
set value(v: Set<FileItem>) {
106+
if (v !== this.files) {
107+
this.files = v;
108+
this.onChangeCallback(v);
109+
}
110+
}
111+
112+
ngOnInit() {
113+
// overrides the undefined files value set by the user
114+
if (!this.files) {
115+
this.files = new Set();
116+
this.filesChange.emit(this.files);
117+
}
118+
}
119+
120+
onBlur() {
121+
this.onTouchedCallback();
122+
}
123+
124+
/**
125+
* Propagates the injected `value`.
126+
*/
127+
writeValue(value: Set<FileItem>) {
128+
if (value !== this.value) {
129+
this.files = value;
130+
}
131+
}
132+
133+
onFilesAdded() {
134+
const files = this.fileInput.nativeElement.files;
135+
for (let file of files) {
136+
const fileItem: FileItem = {
137+
uploaded: false,
138+
state: "edit",
139+
file: file
140+
};
141+
this.files.add(fileItem);
142+
this.filesChange.emit(this.files);
143+
}
144+
145+
this.value = this.files;
146+
}
147+
148+
removeFile(fileItem) {
149+
this.files.delete(fileItem);
150+
this.fileInput.nativeElement.value = "";
151+
this.filesChange.emit(this.files);
152+
}
153+
154+
/**
155+
* Registers the injected function to control the touch use of the `FileUploader`.
156+
*/
157+
registerOnTouched(fn: any) {
158+
this.onTouchedCallback = fn;
159+
}
160+
/**
161+
* Sets a method in order to propagate changes back to the form.
162+
*/
163+
registerOnChange(fn: any) {
164+
this.onChangeCallback = fn;
165+
}
166+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { NgModule } from "@angular/core";
2+
import { CommonModule } from "@angular/common";
3+
4+
import { FileUploader } from "./file-uploader.component";
5+
import { File } from "./file.component";
6+
import { ButtonModule } from "../button/button.module";
7+
import { LoadingModule } from "../loading/loading.module";
8+
9+
export { FileUploader } from "./file-uploader.component";
10+
11+
@NgModule({
12+
declarations: [FileUploader, File],
13+
exports: [FileUploader],
14+
imports: [CommonModule, ButtonModule, LoadingModule]
15+
})
16+
export class FileUploaderModule { }

0 commit comments

Comments
 (0)