Detach form components to a separate directory
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
@import "../../Component/Theme/Theme.scss";
|
||||
|
||||
$line-min-height: 24px;
|
||||
|
||||
div.combo-input {
|
||||
|
||||
div.value-view {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
min-height: $line-min-height;
|
||||
max-width: calc( 100% - 32px );
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding-left: 8px;
|
||||
white-space: nowrap;
|
||||
word-break: keep-all;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
|
||||
span {
|
||||
word-break: keep-all;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
div.list-button {
|
||||
width: $line-min-height;
|
||||
height: $line-min-height;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import { Component, createRef, ReactNode } from "react";
|
||||
import { Icon } from "@fluentui/react";
|
||||
import { PickerList, IDisplayItem } from "@Input/PickerList/PickerList";
|
||||
import { TextField, ITextFieldProps } from "@Input/TextField/TextField";
|
||||
import { Localization } from "@Component/Localization/Localization";
|
||||
import "./ComboInput.scss";
|
||||
interface IComboInputProps extends ITextFieldProps {
|
||||
allOption?: IDisplayItem[];
|
||||
value?: IDisplayItem;
|
||||
valueChange?: (value: IDisplayItem) => any;
|
||||
}
|
||||
|
||||
interface IComboInputState {
|
||||
isPickerVisible: boolean;
|
||||
}
|
||||
|
||||
class ComboInput extends Component<IComboInputProps, IComboInputState> {
|
||||
|
||||
public constructor(props: IComboInputProps) {
|
||||
super(props);
|
||||
this.state = {
|
||||
isPickerVisible: false
|
||||
}
|
||||
}
|
||||
|
||||
private pickerTarget = createRef<HTMLDivElement>();
|
||||
|
||||
private renderPicker() {
|
||||
return <PickerList
|
||||
target={this.pickerTarget}
|
||||
displayItems={(this.props.allOption ?? []).map((item) => {
|
||||
return item.key === this.props.value?.key ?
|
||||
{...item, mark: true} : item;
|
||||
})}
|
||||
clickDisplayItems={((item) => {
|
||||
if (this.props.valueChange) {
|
||||
this.props.valueChange(item);
|
||||
}
|
||||
this.setState({
|
||||
isPickerVisible: false
|
||||
})
|
||||
})}
|
||||
dismiss={() => {
|
||||
this.setState({
|
||||
isPickerVisible: false
|
||||
})
|
||||
}}
|
||||
/>
|
||||
}
|
||||
|
||||
public render(): ReactNode {
|
||||
return <>
|
||||
<TextField
|
||||
{...this.props}
|
||||
targetRef={this.pickerTarget}
|
||||
className="combo-input"
|
||||
keyI18n={this.props.keyI18n}
|
||||
onClick={() => {
|
||||
this.setState({
|
||||
isPickerVisible: true
|
||||
})
|
||||
}}
|
||||
>
|
||||
<div className="value-view">
|
||||
{
|
||||
this.props.value ?
|
||||
<Localization i18nKey={this.props.value.nameKey}/> :
|
||||
null
|
||||
}
|
||||
</div>
|
||||
<div className="list-button">
|
||||
<Icon iconName="ChevronDownMed"/>
|
||||
</div>
|
||||
</TextField>
|
||||
|
||||
{this.state.isPickerVisible ? this.renderPicker(): null}
|
||||
</>
|
||||
}
|
||||
}
|
||||
|
||||
export { ComboInput, IDisplayItem };
|
||||
Reference in New Issue
Block a user