Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

refactoring: Introduces custom DropDown component and removes semantic-ui-react dependency (#557)

Guilherme Oenning6634d9f1faa4
diff --git a/package-lock.json b/package-lock.json
index 707d1c123..a73c85b8d 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -55,14 +55,6 @@
}
}
},
- "@babel/runtime": {
- "version": "7.0.0-rc.1",
- "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.0.0-rc.1.tgz",
- "integrity": "sha512-Nifv2kwP/nwR39cAOasNxzjYfpeuf/ZbZNtQz5eYxWTC9yHARU9wItFnAwz1GTZ62MU+AtSjzZPMbLK5Q9hmbg==",
- "requires": {
- "regenerator-runtime": "^0.12.0"
- }
- },
"@types/cheerio": {
"version": "0.22.8",
"resolved": "https://registry.npmjs.org/@types/cheerio/-/cheerio-0.22.8.tgz",
@@ -6164,11 +6156,6 @@
"verror": "1.10.0"
}
},
- "keyboard-key": {
- "version": "1.0.2",
- "resolved": "https://registry.npmjs.org/keyboard-key/-/keyboard-key-1.0.2.tgz",
- "integrity": "sha512-05cjQmw4ss/YuY2utmVim0wywDyBZGUivo8siLPkWinwGWtKlO8/4RGbPUqNycwlD3u/3D15eNRjnNAyaTDs8g=="
- },
"kind-of": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz",
@@ -6287,7 +6274,8 @@
"lodash": {
"version": "4.17.10",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz",
- "integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg=="
+ "integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==",
+ "dev": true
},
"lodash.assign": {
"version": "4.2.0",
@@ -8145,11 +8133,6 @@
"integrity": "sha512-1G6jJVDWrt0rK99kBjvEtziZNCICAuvIPkSiUFIQxVP06RCVpq3dmDo2oi6ABpYaDYaTRr67BEhL8r1wgEZZKg==",
"dev": true
},
- "regenerator-runtime": {
- "version": "0.12.1",
- "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz",
- "integrity": "sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg=="
- },
"regex-cache": {
"version": "0.4.4",
"resolved": "https://registry.npmjs.org/regex-cache/-/regex-cache-0.4.4.tgz",
@@ -8614,19 +8597,6 @@
"jquery": "x.*"
}
},
- "semantic-ui-react": {
- "version": "0.82.2",
- "resolved": "https://registry.npmjs.org/semantic-ui-react/-/semantic-ui-react-0.82.2.tgz",
- "integrity": "sha512-bAGubd82FDt7cSPozWfCtwyTtGz6ZSSWl0S6JeRk2dvhoAWJsYIHu5Wi7/fg7taDOUurl0iF20qJQomXdrkT5A==",
- "requires": {
- "@babel/runtime": "^7.0.0-beta.56",
- "classnames": "^2.2.5",
- "keyboard-key": "^1.0.1",
- "lodash": "^4.17.10",
- "prop-types": "^15.6.1",
- "shallowequal": "^1.0.2"
- }
- },
"semver": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz",
@@ -8708,11 +8678,6 @@
}
}
},
- "shallowequal": {
- "version": "1.1.0",
- "resolved": "https://registry.npmjs.org/shallowequal/-/shallowequal-1.1.0.tgz",
- "integrity": "sha512-y0m1JoUZSlPAjXVtPPW70aZWfIL/dSP7AFkRnniLCrK/8MDKog3TySTBmckD+RObVxH0v4Tox67+F14PdED2oQ=="
- },
"shebang-command": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz",
diff --git a/package.json b/package.json
index 97bd46874..cda7863d8 100644
--- a/package.json
+++ b/package.json
@@ -10,7 +10,6 @@
"react-textarea-autosize": "7.0.4",
"react-toastify": "4.1.0",
"semantic-ui-css": "2.3.3",
- "semantic-ui-react": "0.82.2",
"tslib": "1.9.3"
},
"devDependencies": {
diff --git a/public/components/common/DropDown.scss b/public/components/common/DropDown.scss
new file mode 100644
index 000000000..811ca5887
--- /dev/null
+++ b/public/components/common/DropDown.scss
@@ -0,0 +1,121 @@
+@import '~@fider/assets/styles/variables.scss';
+
+.c-dropdown {
+ position: relative;
+
+ &.is-inline {
+ display: inline-block;
+ .c-dropdown-menu {
+ width: auto;
+ border-radius: 5px;
+ margin-top: 5px;
+ }
+ }
+
+ &.is-open {
+ .c-dropdown-arrow {
+ border-color: transparent transparent $gray-dark;
+ border-width: 0 5px 5px;
+ }
+ }
+
+ .c-dropdown-control {
+ position: relative;
+ overflow: hidden;
+ background-color: $white;
+ border: 1px solid $gray-light;
+ border-radius: 3px;
+ box-sizing: border-box;
+ color: #333;
+ cursor: default;
+ outline: none;
+ padding: 8px 52px 8px 10px;
+ transition: all 200ms ease;
+
+ input {
+ border: none;
+ width: 100%;
+ }
+
+ .c-dropdown-placeholder {
+ color: $gray-light;
+ }
+
+ .c-dropdown-arrow {
+ border-color: $gray-dark transparent transparent;
+ border-style: solid;
+ border-width: 5px 5px 0;
+ content: ' ';
+ display: block;
+ height: 0;
+ margin-top: -ceil(2.5);
+ position: absolute;
+ right: 10px;
+ top: 14px;
+ width: 0
+ }
+
+ &:hover {
+ box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06);
+ }
+ }
+
+ .c-dropdown-menu {
+ background-color: $white;
+ border: 1px solid $gray-light;
+ box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06);
+ box-sizing: border-box;
+ margin-top: -1px;
+ overflow-y: auto;
+ position: absolute;
+ width: 100%;
+ top: 100%;
+ z-index: 1000;
+ min-width: -webkit-min-content;
+ min-width: -moz-min-content;
+ min-width: min-content;
+ max-height: 300px;
+ -webkit-overflow-scrolling: touch;
+
+ > * {
+ white-space: nowrap;
+ }
+
+ .c-dropdown-menu-header {
+ padding: 12px 10px;
+ text-transform: uppercase;
+ font-weight: 700;
+ font-size: .78571429em;
+ }
+
+ .c-dropdown-item {
+ box-sizing: border-box;
+ cursor: pointer;
+ display: block;
+ padding: 12px 10px;
+ line-height: $font-size;
+
+ &:last-child {
+ border-bottom-right-radius: 3px;
+ border-bottom-left-radius: 3px;
+ }
+
+ &:hover {
+ background-color: $gray-lightest;
+ }
+
+ &.is-selected {
+ background-color: $gray-lightest;
+ font-weight: 700;
+ }
+ }
+
+ .c-dropdown-noresults {
+ box-sizing: border-box;
+ color: $gray;
+ cursor: default;
+ display: block;
+ padding: 8px 10px;
+ }
+ }
+}
diff --git a/public/components/common/DropDown.tsx b/public/components/common/DropDown.tsx
new file mode 100644
index 000000000..0e36ed9d2
--- /dev/null
+++ b/public/components/common/DropDown.tsx
@@ -0,0 +1,182 @@
+import * as React from "react";
+import { findDOMNode } from "react-dom";
+import { classSet } from "@fider/services";
+
+import "./DropDown.scss";
+
+export interface DropDownItem {
+ value: any;
+ label: string;
+ render?: JSX.Element;
+}
+
+export interface DropDownProps {
+ className?: string;
+ defaultValue?: any;
+ items: DropDownItem[];
+ placeholder?: string;
+ searchable?: boolean;
+ inline?: boolean;
+ header?: string;
+ onChange?: (item: DropDownItem) => void;
+ onSearchChange?: (e: React.FormEvent<HTMLInputElement>) => void;
+ renderText?: (item?: DropDownItem) => JSX.Element | undefined;
+}
+
+export interface DropDownState {
+ isOpen: boolean;
+ selected?: DropDownItem;
+}
+
+export class DropDown extends React.Component<DropDownProps, DropDownState> {
+ private mounted = false;
+
+ constructor(props: DropDownProps) {
+ super(props);
+ this.state = {
+ selected: this.findItem(props.defaultValue, props.items),
+ isOpen: false
+ };
+ }
+
+ public componentDidMount() {
+ this.mounted = true;
+ }
+
+ public componentWillUnmount() {
+ this.mounted = false;
+ this.removeListeners();
+ }
+
+ private addListeners() {
+ document.addEventListener("click", this.handleDocumentClick, false);
+ document.addEventListener("touchend", this.handleDocumentClick, false);
+ }
+
+ private removeListeners() {
+ document.removeEventListener("click", this.handleDocumentClick, false);
+ document.removeEventListener("touchend", this.handleDocumentClick, false);
+ }
+
+ public handleMouseDown = (event: any) => {
+ if (event.type === "mousedown" && event.button !== 0) {
+ return;
+ }
+
+ event.stopPropagation();
+ event.preventDefault();
+
+ this.setState(
+ {
+ isOpen: true
+ },
+ this.addListeners
+ );
+ };
+
+ public findItem(value: any, items: DropDownItem[]): DropDownItem | undefined {
+ for (const item of items) {
+ if (item.value === value) {
+ return item;
+ }
+ }
+ return undefined;
+ }
+
+ public setSelected(selected: DropDownItem) {
+ const newState = {
+ selected,
+ isOpen: false
+ };
+ this.fireChangeEvent(newState);
+ this.setState(newState, this.removeListeners);
+ }
+
+ public fireChangeEvent(newState: DropDownState) {
+ if (newState.selected && newState.selected !== this.state.selected && this.props.onChange) {
+ this.props.onChange(newState.selected);
+ }
+ }
+
+ public renderItem = (item: DropDownItem) => {
+ const { label, value } = item;
+ const isSelected = this.state.selected && value === this.state.selected.value;
+ const className = classSet({
+ "c-dropdown-item": true,
+ "is-selected": isSelected
+ });
+
+ return (
+ <div
+ key={value}
+ className={className}
+ onMouseDown={this.setSelected.bind(this, item)}
+ onClick={this.setSelected.bind(this, item)}
+ >
+ {item.render ? item.render : label}
+ </div>
+ );
+ };
+
+ public buildItemList() {
+ const items = this.props.items.map(this.renderItem);
+
+ return (
+ <div className="c-dropdown-menu">
+ {this.props.header && <div className="c-dropdown-menu-header">{this.props.header}</div>}
+ <div className="c-dropdown-menu-items">
+ {items.length ? items : <div className={`c-dropdown-noresults`}>No results found</div>}
+ </div>
+ </div>
+ );
+ }
+
+ public handleDocumentClick = (event: any) => {
+ if (this.mounted) {
+ const node = findDOMNode(this);
+ if (node && !node.contains(event.target)) {
+ if (this.state.isOpen) {
+ this.setState(
+ {
+ isOpen: false
+ },
+ this.removeListeners
+ );
+ }
+ }
+ }
+ };
+
+ public render() {
+ const text = this.state.selected ? (
+ this.state.selected.label
+ ) : (
+ <span className="c-dropdown-placeholder">{this.props.placeholder}</span>
+ );
+
+ const search = <input type="text" autoFocus={true} onChange={this.props.onSearchChange} />;
+
+ const dropdownClass = classSet({
+ "c-dropdown": true,
+ [`${this.props.className}`]: this.props.className,
+ "is-open": this.state.isOpen,
+ "is-inline": this.props.inline
+ });
+
+ return (
+ <div className={dropdownClass}>
+ <div onMouseDown={this.handleMouseDown} onTouchEnd={this.handleMouseDown}>
+ {this.props.renderText ? (
+ <div className="c-dropdown-text">{this.props.renderText(this.state.selected)}</div>
+ ) : (
+ <div className="c-dropdown-control">
+ {this.state.isOpen && this.props.searchable ? search : <div>{text}</div>}
+ <span className="c-dropdown-arrow" />
+ </div>
+ )}
+ </div>
+ {this.state.isOpen && this.buildItemList()}
+ </div>
+ );
+ }
+}
diff --git a/public/components/common/index.tsx b/public/components/common/index.tsx
index beb8327fe..42b291cdd 100644
--- a/public/components/common/index.tsx
+++ b/public/components/common/index.tsx
@@ -27,8 +27,7 @@ export * from "./Loader";
export * from "./Logo";
export * from "./Toggle";
export * from "./FiderVersion";
+export * from "./DropDown";
+
import Textarea from "react-textarea-autosize";
export { Textarea };
-
-import { Dropdown, DropdownProps, DropdownItemProps, DropdownOnSearchChangeData } from "semantic-ui-react";
-export { Dropdown, DropdownProps, DropdownItemProps, DropdownOnSearchChangeData };
diff --git a/public/index.tsx b/public/index.tsx
index 06ed231ec..c5ea1b7f5 100644
--- a/public/index.tsx
+++ b/public/index.tsx
@@ -8,8 +8,6 @@ import { ToastContainer } from "react-toastify";
import "semantic-ui-css/components/reset.min.css";
import "semantic-ui-css/components/icon.min.css";
-import "semantic-ui-css/components/dropdown.min.css";
-import "semantic-ui-css/components/transition.min.css";
import "react-toastify/dist/ReactToastify.css";
import "@fider/assets/styles/main.scss";
diff --git a/public/pages/Home/Home.page.scss b/public/pages/Home/Home.page.scss
index f2dad216b..6d0119800 100644
--- a/public/pages/Home/Home.page.scss
+++ b/public/pages/Home/Home.page.scss
@@ -14,22 +14,6 @@
}
}
- .l-post-filter {
- .counter {
- font-size: 8px;
- background-color: $gray-lighter;
- color: $text-color;
- display: inline-block;
- min-width: 15px;
- padding: 0px 5px;
- margin-left: 5px;
- text-align: center;
- border-radius: 10px;
- vertical-align: top;
- font-weight: 600;
- }
- }
-
.l-tags-filter {
.selected.item {
background-color: transparent;
diff --git a/public/pages/Home/components/PostFilter.scss b/public/pages/Home/components/PostFilter.scss
new file mode 100644
index 000000000..9543148ab
--- /dev/null
+++ b/public/pages/Home/components/PostFilter.scss
@@ -0,0 +1,29 @@
+@import '~@fider/assets/styles/variables.scss';
+
+.l-post-filter {
+ .c-dropdown-text {
+ font-weight: bold;
+ cursor: pointer;
+ border-bottom: 1px dashed $gray-darker;
+ }
+
+ .c-dropdown-menu {
+ max-height: -webkit-max-content;
+ max-height: -moz-max-content;
+ max-height: max-content;
+ }
+
+ .counter {
+ font-size: 8px;
+ background-color: $gray-lighter;
+ color: $text-color;
+ display: inline-block;
+ min-width: 15px;
+ padding: 0px 5px;
+ margin-left: 5px;
+ text-align: center;
+ border-radius: 10px;
+ vertical-align: top;
+ font-weight: 600;
+ }
+}
\ No newline at end of file
diff --git a/public/pages/Home/components/PostFilter.tsx b/public/pages/Home/components/PostFilter.tsx
index 7004d40bf..d1ec410e9 100644
--- a/public/pages/Home/components/PostFilter.tsx
+++ b/public/pages/Home/components/PostFilter.tsx
@@ -1,8 +1,10 @@
import * as React from "react";
-import { Post, PostStatus, CurrentUser } from "@fider/models";
-import { Dropdown, DropdownItemProps, DropdownProps } from "@fider/components";
+import { PostStatus } from "@fider/models";
+import { DropDown, DropDownItem } from "@fider/components";
import { Fider } from "@fider/services";
+import "./PostFilter.scss";
+
interface PostFilterProps {
activeView: string;
countPerStatus: { [key: string]: number };
@@ -14,27 +16,31 @@ export class PostFilter extends React.Component<PostFilterProps, {}> {
super(props);
}
- private handleChangeView = (item: React.SyntheticEvent<HTMLElement>, data: DropdownProps) => {
- this.props.viewChanged(data.value as string);
+ private handleChangeView = (item: DropDownItem) => {
+ this.props.viewChanged(item.value as string);
+ };
+
+ public renderText = (item?: DropDownItem) => {
+ return <>{item!.label.toLowerCase()}</>;
};
public render() {
- const options: DropdownItemProps[] = [
- { text: "trending", value: "trending", content: "Trending" },
- { text: "recent", value: "recent", content: "Recent" },
- { text: "most wanted", value: "most-wanted", content: "Most Wanted" },
- { text: "most discussed", value: "most-discussed", content: "Most Discussed" }
+ const options: DropDownItem[] = [
+ { value: "trending", label: "Trending" },
+ { value: "recent", label: "Recent" },
+ { value: "most-wanted", label: "Most Wanted" },
+ { value: "most-discussed", label: "Most Discussed" }
];
if (Fider.session.isAuthenticated) {
- options.push({ text: "my votes", value: "my-votes", content: "My Votes" });
+ options.push({ value: "my-votes", label: "My Votes" });
}
PostStatus.All.filter(s => s.filterable && this.props.countPerStatus[s.value]).forEach(s => {
options.push({
- text: s.title.toLowerCase(),
+ label: s.title,
value: s.value,
- content: (
+ render: (
<span>
{s.title} <a className="counter">{this.props.countPerStatus[s.value]}</a>
</span>
@@ -48,14 +54,15 @@ export class PostFilter extends React.Component<PostFilterProps, {}> {
return (
<>
Show{" "}
- <Dropdown
+ <DropDown
className="l-post-filter"
header="What do you want to see?"
inline={true}
- options={options}
+ items={options}
+ renderText={this.renderText}
defaultValue={activeView}
onChange={this.handleChangeView}
- />
+ />{" "}
</>
);
}
diff --git a/public/pages/Home/components/TagsFilter.scss b/public/pages/Home/components/TagsFilter.scss
new file mode 100644
index 000000000..4503ee28b
--- /dev/null
+++ b/public/pages/Home/components/TagsFilter.scss
@@ -0,0 +1,13 @@
+@import '~@fider/assets/styles/variables.scss';
+
+.l-tags-filter {
+ .c-dropdown-text {
+ font-weight: 700;
+ cursor: pointer;
+ border-bottom: 1px dashed $gray-darker;
+ }
+ &.c-dropdown .c-dropdown-menu .c-dropdown-item.is-selected {
+ font-weight: normal;
+ background-color: transparent;
+ }
+}
\ No newline at end of file
diff --git a/public/pages/Home/components/TagsFilter.tsx b/public/pages/Home/components/TagsFilter.tsx
index 8eeb168c0..7337f22e7 100644
--- a/public/pages/Home/components/TagsFilter.tsx
+++ b/public/pages/Home/components/TagsFilter.tsx
@@ -1,7 +1,9 @@
import * as React from "react";
import { Tag } from "@fider/models";
import { ShowTag } from "@fider/components/ShowTag";
-import { Dropdown, DropdownProps } from "@fider/components";
+import { DropDown, DropDownItem } from "@fider/components";
+
+import "./TagsFilter.scss";
interface TagsFilterProps {
tags: Tag[];
@@ -21,28 +23,38 @@ export class TagsFilter extends React.Component<TagsFilterProps, TagsFilterState
};
}
- private onChange = (e: React.SyntheticEvent<HTMLElement>, data: DropdownProps) => {
+ private onChange = (item: DropDownItem) => {
let selected = [];
- const idx = this.state.selected.indexOf(data.value as string);
+ const idx = this.state.selected.indexOf(item.value as string);
if (idx >= 0) {
selected = this.state.selected.splice(idx, 1) && this.state.selected;
} else {
- selected = this.state.selected.concat(data.value as string);
+ selected = this.state.selected.concat(item.value as string);
}
this.setState({ selected });
this.props.selectionChanged(selected);
};
+ private renderText = () => {
+ const text =
+ this.state.selected.length === 0
+ ? "any tag"
+ : this.state.selected.length === 1
+ ? "1 tag"
+ : `${this.state.selected.length} tags`;
+ return <>{text}</>;
+ };
+
public render() {
if (this.props.tags.length === 0) {
return null;
}
- const options = this.props.tags.map(t => {
+ const items = this.props.tags.map(t => {
return {
value: t.slug,
- text: t.name,
- content: (
+ label: t.name,
+ render: (
<div className={this.state.selected.indexOf(t.slug) >= 0 ? "selected-tag" : ""}>
<i className="icon check" />
<ShowTag tag={t} size="mini" circular={true} />
@@ -52,23 +64,14 @@ export class TagsFilter extends React.Component<TagsFilterProps, TagsFilterState
};
});
- const text =
- this.state.selected.length === 0
- ? "any tag"
- : this.state.selected.length === 1
- ? "1 tag"
- : `${this.state.selected.length} tags`;
-
return (
<>
with{" "}
- <Dropdown
+ <DropDown
className="l-tags-filter"
- selectOnBlur={false}
- text={text}
- defaultValue="0"
inline={true}
- options={options}
+ items={items}
+ renderText={this.renderText}
onChange={this.onChange}
/>
</>
diff --git a/public/pages/ShowPost/components/PostSearch.tsx b/public/pages/ShowPost/components/PostSearch.tsx
index 29bb1155b..ccbe81394 100644
--- a/public/pages/ShowPost/components/PostSearch.tsx
+++ b/public/pages/ShowPost/components/PostSearch.tsx
@@ -1,7 +1,7 @@
import * as React from "react";
import { Post, PostStatus } from "@fider/models";
import { actions } from "@fider/services";
-import { Dropdown, DropdownProps, DropdownItemProps, DropdownOnSearchChangeData } from "@fider/components";
+import { DropDown, DropDownItem } from "@fider/components";
interface PostSearchProps {
exclude?: number[];
@@ -23,12 +23,12 @@ export class PostSearch extends React.Component<PostSearchProps, PostSearchState
this.search("");
}
- private onSearchChange = (e: React.SyntheticEvent<HTMLElement>, data: DropdownOnSearchChangeData) => {
- this.search(data.searchQuery);
+ private onSearchChange = (e: React.SyntheticEvent<HTMLInputElement>) => {
+ this.search(e.currentTarget.value);
};
- private onChange = (e: React.SyntheticEvent<HTMLElement>, data: DropdownProps) => {
- this.props.onChanged(parseInt(data.value as string, 10));
+ private onChange = (item: DropDownItem) => {
+ this.props.onChanged(item.value as number);
};
private search = (searchQuery: string) => {
@@ -44,36 +44,32 @@ export class PostSearch extends React.Component<PostSearchProps, PostSearchState
}, 200);
};
- private returnAll = (options: DropdownItemProps[], value: string) => options;
+ private returnAll = (options: DropDownItem[], value: string) => options;
public render() {
- const options = this.state.posts.map(i => {
- const status = PostStatus.Get(i.status);
+ const items = this.state.posts.map(p => {
+ const status = PostStatus.Get(p.status);
return {
- key: i.number,
- text: i.title,
- value: i.number,
- content: (
+ label: p.title,
+ value: p.number,
+ render: (
<>
<span className="votes">
<i className="caret up icon" />
- {i.votesCount}
+ {p.votesCount}
</span>
<span className={`status-label status-${status.value}`}>{status.title}</span>
- {i.title}
+ {p.title}
</>
)
};
});
return (
- <Dropdown
+ <DropDown
className="c-post-search"
- fluid={true}
- selectOnBlur={false}
- selection={true}
- search={this.returnAll}
- options={options}
+ searchable={true}
+ items={items}
placeholder="Search original post"
onChange={this.onChange}
onSearchChange={this.onSearchChange}
diff --git a/public/pages/ShowPost/components/ResponseForm.tsx b/public/pages/ShowPost/components/ResponseForm.tsx
index 632f4dd17..31026f2e5 100644
--- a/public/pages/ShowPost/components/ResponseForm.tsx
+++ b/public/pages/ShowPost/components/ResponseForm.tsx
@@ -82,7 +82,7 @@ export class ResponseForm extends React.Component<ResponseFormProps, ResponseFor
<Select
field="status"
label="Status"
- defaultValue={this.props.post.status.toString()}
+ defaultValue={this.state.status}
options={options}
onChange={this.setStatus}
/>
diff --git a/public/pages/UI/UIToolkit.page.tsx b/public/pages/UI/UIToolkit.page.tsx
index dd74b6f27..b29aa02cf 100644
--- a/public/pages/UI/UIToolkit.page.tsx
+++ b/public/pages/UI/UIToolkit.page.tsx
@@ -19,11 +19,12 @@ import {
TextArea,
RadioButton,
Select,
- SocialSignInButton,
+ Field,
SelectOption
} from "@fider/components";
import { User, UserRole, Tag } from "@fider/models";
import { notify, Failure } from "@fider/services";
+import { DropDown, DropDownItem } from "@fider/components";
const jonSnow: User = {
id: 0,
@@ -80,6 +81,13 @@ export class UIToolkitPage extends React.Component<{}, UIToolkitPageState> {
});
};
+ private renderText = (item?: DropDownItem) => {
+ if (item) {
+ return item.render;
+ }
+ return <span>...</span>;
+ };
+
public render() {
return (
<div id="p-ui-toolkit" className="page container">
@@ -347,6 +355,28 @@ export class UIToolkitPage extends React.Component<{}, UIToolkitPageState> {
onChange={this.notifyStatusChange}
/>
+ <Field label="Number">
+ <DropDown
+ items={[{ label: "One", value: "1" }, { label: "Two", value: "2" }, { label: "Three", value: "3" }]}
+ defaultValue={"1"}
+ placeholder="Select a number"
+ />
+ </Field>
+
+ <Field label="Color (custom render)">
+ <DropDown
+ items={[
+ { label: "Green", value: "green", render: <span style={{ color: "green" }}>Green</span> },
+ { label: "Red", value: "red", render: <span style={{ color: "red" }}>Red</span> },
+ { label: "Blue", value: "blue", render: <span style={{ color: "blue" }}>Blue</span> }
+ ]}
+ placeholder="Select a color"
+ inline={true}
+ header="What color do you like the most?"
+ renderText={this.renderText}
+ />
+ </Field>
+
<Button onClick={this.forceError}>Save</Button>
</Form>
diff --git a/webpack.config.js b/webpack.config.js
index 10f98a348..73cf8a966 100755
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -22,7 +22,7 @@ module.exports = {
mode: process.env.NODE_ENV || "development",
entry: {
main: "./public/index.tsx",
- vendor: [ "react", "react-dom", "semantic-ui-react", "tslib" ]
+ vendor: [ "react", "react-dom", "tslib" ]
},
output: {
path: __dirname + "/dist",