Skip to content

Commit d827a66

Browse files
authored
feat(post-configuration-panel): allow input entry name of the post (#59)
1 parent 5e6de18 commit d827a66

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { ActionButton, ITextField, Label, Stack, TextField } from '@fluentui/react';
2+
import * as React from 'react';
3+
4+
export interface IPostEntryNameInputProps {
5+
entryName?: string;
6+
onChange?: (value: string) => void;
7+
}
8+
9+
export interface IPostEntryNameInputState {
10+
isCollapsed: boolean;
11+
}
12+
13+
export default class PostEntryNameInput extends React.Component<IPostEntryNameInputProps, IPostEntryNameInputState> {
14+
textFieldComp?: ITextField | null;
15+
constructor(props: IPostEntryNameInputProps) {
16+
super(props);
17+
18+
this.state = {
19+
isCollapsed: true,
20+
};
21+
}
22+
23+
public render() {
24+
return (
25+
<Stack tokens={{ childrenGap: 16 }}>
26+
<ActionButton
27+
styles={{
28+
root: {
29+
height: 'auto',
30+
paddingLeft: 0,
31+
borderLeft: 0,
32+
},
33+
}}
34+
onClick={() => this.setState({ isCollapsed: !this.state.isCollapsed })}
35+
>
36+
<Stack horizontal tokens={{ childrenGap: 2 }} verticalAlign='center'>
37+
<Label
38+
styles={{
39+
root: {
40+
paddingTop: 0,
41+
paddingBottom: 0,
42+
},
43+
}}
44+
>
45+
友好地址名(URL Slug)
46+
</Label>
47+
<ActionButton
48+
styles={{
49+
root: {
50+
height: 'auto',
51+
},
52+
}}
53+
iconProps={{ iconName: this.state.isCollapsed ? 'CirclePlus' : 'SkypeCircleMinus' }}
54+
/>
55+
</Stack>
56+
</ActionButton>
57+
{this.state.isCollapsed ? (
58+
<></>
59+
) : (
60+
<Stack tokens={{ childrenGap: 12 }}>
61+
<TextField
62+
componentRef={input => {
63+
this.textFieldComp = input;
64+
if (this.state.isCollapsed === false) {
65+
this.textFieldComp?.focus();
66+
}
67+
}}
68+
value={this.props.entryName}
69+
onChange={(_, value) => this.props.onChange?.call(this, value)}
70+
description='友好地址名,只能使用字母、数字、-连字符、_下划线,不超过150个字符'
71+
></TextField>
72+
</Stack>
73+
)}
74+
</Stack>
75+
);
76+
}
77+
}

ui/post-configuration/components/PostForm.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { webviewCommand } from '@models/webview-command';
1717
import { webviewMessage } from '@models/webview-message';
1818
import { InputSummary } from './InputSummary';
1919
import { IPostFormContext, PostFormContext } from './PostFormContext';
20+
import PostEntryNameInput from './PostEntryNameInput';
2021

2122
export interface IPostFormProps {
2223
post?: Post;
@@ -122,6 +123,10 @@ export class PostForm extends React.Component<IPostFormProps, IPostFormState> {
122123
categoryIds={this.state.siteCategoryId ? [this.state.siteCategoryId] : []}
123124
onChange={categoryId => this.setState({ siteCategoryId: categoryId })}
124125
/>
126+
<PostEntryNameInput
127+
entryName={this.state.entryName}
128+
onChange={value => this.setState({ entryName: value })}
129+
/>
125130
<ErrorResponse />
126131
<Stack horizontal tokens={{ childrenGap: 8 }}>
127132
<PrimaryButton

0 commit comments

Comments
 (0)