mirror of
https://github.com/microsoft/frontend-bootcamp.git
synced 2026-01-26 14:56:42 +08:00
fluent theme
This commit is contained in:
41
package-lock.json
generated
41
package-lock.json
generated
@@ -3355,8 +3355,7 @@
|
|||||||
"ansi-regex": {
|
"ansi-regex": {
|
||||||
"version": "2.1.1",
|
"version": "2.1.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"aproba": {
|
"aproba": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
@@ -3377,14 +3376,12 @@
|
|||||||
"balanced-match": {
|
"balanced-match": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"brace-expansion": {
|
"brace-expansion": {
|
||||||
"version": "1.1.11",
|
"version": "1.1.11",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"balanced-match": "^1.0.0",
|
"balanced-match": "^1.0.0",
|
||||||
"concat-map": "0.0.1"
|
"concat-map": "0.0.1"
|
||||||
@@ -3399,20 +3396,17 @@
|
|||||||
"code-point-at": {
|
"code-point-at": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"concat-map": {
|
"concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"console-control-strings": {
|
"console-control-strings": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"core-util-is": {
|
"core-util-is": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
@@ -3529,8 +3523,7 @@
|
|||||||
"inherits": {
|
"inherits": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.3",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"ini": {
|
"ini": {
|
||||||
"version": "1.3.5",
|
"version": "1.3.5",
|
||||||
@@ -3542,7 +3535,6 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"number-is-nan": "^1.0.0"
|
"number-is-nan": "^1.0.0"
|
||||||
}
|
}
|
||||||
@@ -3557,7 +3549,6 @@
|
|||||||
"version": "3.0.4",
|
"version": "3.0.4",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"brace-expansion": "^1.1.7"
|
"brace-expansion": "^1.1.7"
|
||||||
}
|
}
|
||||||
@@ -3565,14 +3556,12 @@
|
|||||||
"minimist": {
|
"minimist": {
|
||||||
"version": "0.0.8",
|
"version": "0.0.8",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"minipass": {
|
"minipass": {
|
||||||
"version": "2.3.5",
|
"version": "2.3.5",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"safe-buffer": "^5.1.2",
|
"safe-buffer": "^5.1.2",
|
||||||
"yallist": "^3.0.0"
|
"yallist": "^3.0.0"
|
||||||
@@ -3591,7 +3580,6 @@
|
|||||||
"version": "0.5.1",
|
"version": "0.5.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"minimist": "0.0.8"
|
"minimist": "0.0.8"
|
||||||
}
|
}
|
||||||
@@ -3672,8 +3660,7 @@
|
|||||||
"number-is-nan": {
|
"number-is-nan": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"object-assign": {
|
"object-assign": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.1",
|
||||||
@@ -3685,7 +3672,6 @@
|
|||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"wrappy": "1"
|
"wrappy": "1"
|
||||||
}
|
}
|
||||||
@@ -3771,8 +3757,7 @@
|
|||||||
"safe-buffer": {
|
"safe-buffer": {
|
||||||
"version": "5.1.2",
|
"version": "5.1.2",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"safer-buffer": {
|
"safer-buffer": {
|
||||||
"version": "2.1.2",
|
"version": "2.1.2",
|
||||||
@@ -3808,7 +3793,6 @@
|
|||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"code-point-at": "^1.0.0",
|
"code-point-at": "^1.0.0",
|
||||||
"is-fullwidth-code-point": "^1.0.0",
|
"is-fullwidth-code-point": "^1.0.0",
|
||||||
@@ -3828,7 +3812,6 @@
|
|||||||
"version": "3.0.1",
|
"version": "3.0.1",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"ansi-regex": "^2.0.0"
|
"ansi-regex": "^2.0.0"
|
||||||
}
|
}
|
||||||
@@ -3872,14 +3855,12 @@
|
|||||||
"wrappy": {
|
"wrappy": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"yallist": {
|
"yallist": {
|
||||||
"version": "3.0.3",
|
"version": "3.0.3",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"dev": true,
|
"dev": true
|
||||||
"optional": true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -41,6 +41,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@uifabric/experiments": "^6.57.0",
|
"@uifabric/experiments": "^6.57.0",
|
||||||
|
"@uifabric/fluent-theme": "^0.14.1",
|
||||||
"express": "^4.16.4",
|
"express": "^4.16.4",
|
||||||
"immer": "^1.12.1",
|
"immer": "^1.12.1",
|
||||||
"office-ui-fabric-react": "^6.140.0",
|
"office-ui-fabric-react": "^6.140.0",
|
||||||
|
|||||||
9
step2-03/README.md
Normal file
9
step2-03/README.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# Step 2.2
|
||||||
|
|
||||||
|
Integrates Fabric
|
||||||
|
|
||||||
|
Learn about Basic Components
|
||||||
|
|
||||||
|
- Stack
|
||||||
|
- Text
|
||||||
|
- Show case some components
|
||||||
6
step2-03/index.html
Normal file
6
step2-03/index.html
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<div id="app"></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
87
step2-03/src/components/TodoApp.tsx
Normal file
87
step2-03/src/components/TodoApp.tsx
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Stack } from 'office-ui-fabric-react';
|
||||||
|
import { TodoFooter } from './TodoFooter';
|
||||||
|
import { TodoHeader } from './TodoHeader';
|
||||||
|
import { TodoList } from './TodoList';
|
||||||
|
import { Store } from '../store';
|
||||||
|
|
||||||
|
let index = 0;
|
||||||
|
|
||||||
|
export class TodoApp extends React.Component<any, Store> {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
todos: {},
|
||||||
|
filter: 'all'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
render() {
|
||||||
|
const { filter, todos } = this.state;
|
||||||
|
return (
|
||||||
|
<Stack horizontalAlign="center">
|
||||||
|
<Stack style={{ width: 400 }} gap={25}>
|
||||||
|
<TodoHeader addTodo={this._addTodo} setFilter={this._setFilter} filter={filter} />
|
||||||
|
<TodoList complete={this._complete} todos={todos} filter={filter} remove={this._remove} edit={this._edit} />
|
||||||
|
<TodoFooter clear={this._clear} todos={todos} />
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _addTodo = label => {
|
||||||
|
const { todos } = this.state;
|
||||||
|
const id = index++;
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
todos: { ...todos, [id]: { label } }
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
private _remove = id => {
|
||||||
|
const newTodos = { ...this.state.todos };
|
||||||
|
delete newTodos[id];
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
todos: newTodos
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
private _complete = id => {
|
||||||
|
const newTodos = { ...this.state.todos };
|
||||||
|
newTodos[id].completed = !newTodos[id].completed;
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
todos: newTodos
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
private _edit = (id, label) => {
|
||||||
|
const newTodos = { ...this.state.todos };
|
||||||
|
newTodos[id] = { ...newTodos[id], label };
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
todos: newTodos
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
private _clear = () => {
|
||||||
|
const { todos } = this.state;
|
||||||
|
const newTodos = {};
|
||||||
|
|
||||||
|
Object.keys(this.state.todos).forEach(id => {
|
||||||
|
if (!todos[id].completed) {
|
||||||
|
newTodos[id] = todos[id];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
todos: newTodos
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
private _setFilter = filter => {
|
||||||
|
this.setState({
|
||||||
|
filter: filter
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
23
step2-03/src/components/TodoFooter.tsx
Normal file
23
step2-03/src/components/TodoFooter.tsx
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Text } from '@uifabric/experiments';
|
||||||
|
import { Stack } from 'office-ui-fabric-react';
|
||||||
|
import { Store } from '../store';
|
||||||
|
import { DefaultButton } from 'office-ui-fabric-react';
|
||||||
|
|
||||||
|
interface TodoFooterProps {
|
||||||
|
clear: () => void;
|
||||||
|
todos: Store['todos'];
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TodoFooter = (props: TodoFooterProps) => {
|
||||||
|
const itemCount = Object.keys(props.todos).filter(id => !props.todos[id].completed).length;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack horizontal horizontalAlign="space-between">
|
||||||
|
<Text>
|
||||||
|
{itemCount} item{itemCount > 1 ? 's' : ''} left
|
||||||
|
</Text>
|
||||||
|
<DefaultButton onClick={() => props.clear()}>Clear Completed</DefaultButton>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
58
step2-03/src/components/TodoHeader.tsx
Normal file
58
step2-03/src/components/TodoHeader.tsx
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Text } from '@uifabric/experiments';
|
||||||
|
import { Stack } from 'office-ui-fabric-react';
|
||||||
|
import { Pivot, PivotItem, TextField, DefaultButton } from 'office-ui-fabric-react';
|
||||||
|
import { FilterTypes } from '../store';
|
||||||
|
|
||||||
|
interface TodoHeaderProps {
|
||||||
|
addTodo: (label: string) => void;
|
||||||
|
setFilter: (filter: FilterTypes) => void;
|
||||||
|
filter: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TodoHeaderState {
|
||||||
|
labelInput: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TodoHeader extends React.Component<TodoHeaderProps, TodoHeaderState> {
|
||||||
|
constructor(props: TodoHeaderProps) {
|
||||||
|
super(props);
|
||||||
|
this.state = { labelInput: undefined };
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<Stack>
|
||||||
|
<Stack horizontal horizontalAlign="center">
|
||||||
|
<Text variant="xxLarge">todos</Text>
|
||||||
|
</Stack>
|
||||||
|
|
||||||
|
<Stack horizontal>
|
||||||
|
<Stack.Item grow>
|
||||||
|
<TextField placeholder="What needs to be done?" value={this.state.labelInput} onChange={this.onChange} />
|
||||||
|
</Stack.Item>
|
||||||
|
<DefaultButton onClick={this.onAdd}>Add</DefaultButton>
|
||||||
|
</Stack>
|
||||||
|
|
||||||
|
<Pivot onLinkClick={this.onFilter}>
|
||||||
|
<PivotItem headerText="all" />
|
||||||
|
<PivotItem headerText="active" />
|
||||||
|
<PivotItem headerText="completed" />
|
||||||
|
</Pivot>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private onAdd = () => {
|
||||||
|
this.props.addTodo(this.state.labelInput);
|
||||||
|
this.setState({ labelInput: undefined });
|
||||||
|
};
|
||||||
|
|
||||||
|
private onChange = (evt: React.FormEvent<HTMLInputElement>, newValue: string) => {
|
||||||
|
this.setState({ labelInput: newValue });
|
||||||
|
};
|
||||||
|
|
||||||
|
private onFilter = (item: PivotItem) => {
|
||||||
|
this.props.setFilter(item.props.headerText as FilterTypes);
|
||||||
|
};
|
||||||
|
}
|
||||||
27
step2-03/src/components/TodoList.tsx
Normal file
27
step2-03/src/components/TodoList.tsx
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Stack } from 'office-ui-fabric-react';
|
||||||
|
import { TodoListItem } from './TodoListItem';
|
||||||
|
import { Store, FilterTypes } from '../store';
|
||||||
|
|
||||||
|
interface TodoListProps {
|
||||||
|
complete: (id: string) => void;
|
||||||
|
remove: (id: string) => void;
|
||||||
|
todos: Store['todos'];
|
||||||
|
filter: FilterTypes;
|
||||||
|
edit: (id: string, label: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TodoList = (props: TodoListProps) => {
|
||||||
|
const { filter, todos, complete, remove, edit } = props;
|
||||||
|
const filteredTodos = Object.keys(todos).filter(id => {
|
||||||
|
return filter === 'all' || (filter === 'completed' && todos[id].completed) || (filter === 'active' && !todos[id].completed);
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack gap={10}>
|
||||||
|
{filteredTodos.map(id => (
|
||||||
|
<TodoListItem key={id} id={id} todos={todos} complete={complete} remove={remove} edit={edit} />
|
||||||
|
))}
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
75
step2-03/src/components/TodoListItem.tsx
Normal file
75
step2-03/src/components/TodoListItem.tsx
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Stack, Checkbox, IconButton, TextField, DefaultButton } from 'office-ui-fabric-react';
|
||||||
|
import { Store } from '../store';
|
||||||
|
|
||||||
|
interface TodoListItemProps {
|
||||||
|
id: string;
|
||||||
|
todos: Store['todos'];
|
||||||
|
remove: (id: string) => void;
|
||||||
|
complete: (id: string) => void;
|
||||||
|
edit: (id: string, label: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TodoListItemState {
|
||||||
|
editing: boolean;
|
||||||
|
editLabel: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TodoListItem extends React.Component<TodoListItemProps, TodoListItemState> {
|
||||||
|
constructor(props: TodoListItemProps) {
|
||||||
|
super(props);
|
||||||
|
this.state = { editing: false, editLabel: undefined };
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { todos, id, complete, remove } = this.props;
|
||||||
|
const item = todos[id];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack horizontal verticalAlign="center" horizontalAlign="space-between">
|
||||||
|
{!this.state.editing && (
|
||||||
|
<>
|
||||||
|
<Checkbox label={item.label} checked={item.completed} onChange={() => complete(id)} />
|
||||||
|
<div>
|
||||||
|
<IconButton iconProps={{ iconName: 'Edit' }} className="clearButton" onClick={this.onEdit} />
|
||||||
|
<IconButton iconProps={{ iconName: 'Cancel' }} className="clearButton" onClick={() => remove(id)} />
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{this.state.editing && (
|
||||||
|
<Stack.Item grow>
|
||||||
|
<Stack horizontal>
|
||||||
|
<Stack.Item grow>
|
||||||
|
<TextField value={this.state.editLabel} onChange={this.onChange} />
|
||||||
|
</Stack.Item>
|
||||||
|
<DefaultButton onClick={this.onDoneEdit}>Save</DefaultButton>
|
||||||
|
</Stack>
|
||||||
|
</Stack.Item>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private onEdit = () => {
|
||||||
|
const { todos, id } = this.props;
|
||||||
|
const { label } = todos[id];
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
editing: true,
|
||||||
|
editLabel: this.state.editLabel || label
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
private onDoneEdit = () => {
|
||||||
|
this.props.edit(this.props.id, this.state.editLabel);
|
||||||
|
this.setState({
|
||||||
|
editing: false,
|
||||||
|
editLabel: undefined
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
private onChange = (evt: React.FormEvent<HTMLInputElement>, newValue: string) => {
|
||||||
|
this.setState({ editLabel: newValue });
|
||||||
|
};
|
||||||
|
}
|
||||||
10
step2-03/src/index.tsx
Normal file
10
step2-03/src/index.tsx
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import ReactDOM from 'react-dom';
|
||||||
|
import { TodoApp } from './components/TodoApp';
|
||||||
|
import { initializeIcons } from '@uifabric/icons';
|
||||||
|
|
||||||
|
// Initializes the UI Fabric icons that we can use
|
||||||
|
// Choose one from this list: https://developer.microsoft.com/en-us/fabric#/styles/icons
|
||||||
|
initializeIcons();
|
||||||
|
|
||||||
|
ReactDOM.render(<TodoApp />, document.getElementById('app'));
|
||||||
14
step2-03/src/store/index.ts
Normal file
14
step2-03/src/store/index.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
export type FilterTypes = 'all' | 'active' | 'completed';
|
||||||
|
|
||||||
|
export interface TodoItem {
|
||||||
|
label: string;
|
||||||
|
completed: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Store {
|
||||||
|
todos: {
|
||||||
|
[id: string]: TodoItem;
|
||||||
|
};
|
||||||
|
|
||||||
|
filter: FilterTypes;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user