Skip to content

Commit 813c7b3

Browse files
authored
Merge pull request #480 from telamonian/resizable-commit-box
resizable commit message input box
2 parents e932553 + ffcf9b9 commit 813c7b3

File tree

8 files changed

+70
-35
lines changed

8 files changed

+70
-35
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"nbdime": "~5.0.1",
6464
"react": "~16.8.4",
6565
"react-dom": "~16.8.4",
66+
"react-textarea-autosize": "^7.1.2",
6667
"typestyle": "^2.0.1"
6768
},
6869
"devDependencies": {
@@ -75,6 +76,7 @@
7576
"@types/jest": "^24",
7677
"@types/react": "~16.8.13",
7778
"@types/react-dom": "~16.0.5",
79+
"@types/react-textarea-autosize": "^4.3.5",
7880
"enzyme": "3.7.0",
7981
"enzyme-adapter-react-16": "1.7.0",
8082
"husky": "1.3.1",

src/components/CommitBox.tsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import { ISettingRegistry } from '@jupyterlab/coreutils';
2+
13
import * as React from 'react';
4+
import TextareaAutosize from 'react-textarea-autosize';
25
import { classes } from 'typestyle';
6+
37
import {
48
stagedCommitButtonDisabledStyle,
59
stagedCommitButtonReadyStyle,
@@ -12,6 +16,7 @@ import {
1216
export interface ICommitBoxProps {
1317
hasFiles: boolean;
1418
commitFunc: (message: string) => Promise<void>;
19+
settings: ISettingRegistry.ISettings;
1520
}
1621

1722
export interface ICommitBoxState {
@@ -73,16 +78,13 @@ export class CommitBox extends React.Component<
7378
className={stagedCommitStyle}
7479
onKeyPress={event => this.onKeyPress(event)}
7580
>
76-
<textarea
81+
<TextareaAutosize
7782
className={classes(textInputStyle, stagedCommitMessageStyle)}
7883
disabled={!this.props.hasFiles}
79-
placeholder={
80-
this.props.hasFiles
81-
? 'Input message to commit staged changes'
82-
: 'Stage your changes before commit'
83-
}
84-
value={this.state.value}
84+
minRows={2}
8585
onChange={this.handleChange}
86+
placeholder={this._placeholder()}
87+
value={this.state.value}
8688
/>
8789
<input
8890
className={this.commitButtonStyle(this.props.hasFiles)}
@@ -97,4 +99,16 @@ export class CommitBox extends React.Component<
9799
</form>
98100
);
99101
}
102+
103+
protected _placeholder = (): string => {
104+
if (this.props.settings.composite['simpleStaging']) {
105+
return this.props.hasFiles
106+
? 'Input message to commit selected changes'
107+
: 'Select changes to enable commit';
108+
} else {
109+
return this.props.hasFiles
110+
? 'Input message to commit staged changes'
111+
: 'Stage your changes before commit';
112+
}
113+
};
100114
}

src/components/FileList.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
512512
<CommitBox
513513
hasFiles={this.markedFiles.length > 0}
514514
commitFunc={this.commitAllMarkedFiles}
515+
settings={this.props.settings}
515516
/>
516517
<div>
517518
<GitStageSimple
@@ -531,6 +532,7 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
531532
<CommitBox
532533
hasFiles={this.props.stagedFiles.length > 0}
533534
commitFunc={this.commitAllStagedFiles}
535+
settings={this.props.settings}
534536
/>
535537
<div>
536538
<Staged />

src/style/BranchHeaderStyle.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,20 @@ export const branchListItemStyle = style({
8787
color: 'var(--jp-ui-font-color1)'
8888
});
8989

90+
// need to override font-size from user agent stylesheet
9091
export const stagedCommitButtonStyle = style({
9192
backgroundColor: 'var(--jp-brand-color1)',
9293
backgroundImage: 'var(--jp-checkmark)',
9394
backgroundSize: '100%',
9495
backgroundRepeat: 'no-repeat',
9596
backgroundPosition: 'center',
96-
color: 'white',
97-
height: '42px',
98-
width: '40px',
9997
border: '0',
100-
flex: '1 1 auto'
98+
color: 'white',
99+
flex: '1 1 auto',
100+
fontSize: 'var(--jp-ui-font-size1)',
101+
height: 'calc(2 * (1.25em - 1px))',
102+
padding: 'calc(var(--jp-code-padding) + 1px) 7px',
103+
width: '40px'
101104
});
102105

103106
export const stagedCommitButtonReadyStyle = style({
@@ -115,21 +118,22 @@ export const textInputStyle = style({
115118
export const stagedCommitStyle = style({
116119
resize: 'none',
117120
display: 'flex',
118-
alignItems: 'center',
121+
alignItems: 'flex-start',
119122
margin: '8px'
120123
});
121124

125+
// need to override font-size from user agent stylesheet
122126
export const stagedCommitMessageStyle = style({
123-
width: '75%',
124-
fontWeight: 300,
125-
height: '32px',
126-
overflowX: 'auto',
127+
backgroundColor: 'var(--jp-layout-color1)',
127128
border: 'var(--jp-border-width) solid var(--jp-border-color2)',
129+
color: 'var(--jp-ui-font-color0)',
130+
fontSize: 'var(--jp-ui-font-size1)',
131+
fontWeight: 300,
128132
flex: '20 1 auto',
133+
overflowX: 'auto',
134+
padding: 'var(--jp-code-padding)',
129135
resize: 'none',
130-
padding: '4px 8px',
131-
backgroundColor: 'var(--jp-layout-color1)',
132-
color: 'var(--jp-ui-font-color0)',
136+
width: '75%',
133137

134138
$nest: {
135139
'&:focus': {

src/style/GitStageStyle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const sectionAreaStyle = style({
2828
});
2929

3030
export const sectionHeaderLabelStyle = style({
31-
fontSize: 'var(--jp-ui-font-size)',
31+
fontSize: 'var(--jp-ui-font-size1)',
3232
flex: '1 1 auto',
3333
textOverflow: 'ellipsis',
3434
overflow: 'hidden',

src/style/GitWidgetStyle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ export const gitWidgetStyle = style({
66
minWidth: '300px',
77
color: 'var(--jp-ui-font-color1)',
88
background: 'var(--jp-layout-color1)',
9-
fontSize: 'var(--jp-ui-font-size0)'
9+
fontSize: 'var(--jp-ui-font-size1)'
1010
});

tests/test-components/CommitBox.spec.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ describe('CommitBox', () => {
1212
it('should update commit box state to be ready when changes are staged', () => {
1313
const box = new CommitBox({
1414
commitFunc: async () => {},
15-
hasFiles: true
15+
hasFiles: true,
16+
settings: { composite: {} } as any
1617
});
1718

1819
let actual = box.commitButtonStyle(true);
@@ -27,7 +28,8 @@ describe('CommitBox', () => {
2728
it('should update commit box state to be disabled when no changes are staged', () => {
2829
const box = new CommitBox({
2930
commitFunc: async () => {},
30-
hasFiles: true
31+
hasFiles: true,
32+
settings: { composite: {} } as any
3133
});
3234

3335
let actual = box.commitButtonStyle(false);
@@ -41,19 +43,15 @@ describe('CommitBox', () => {
4143
it('should be ready to commit with a message set.', () => {
4244
const box = new CommitBox({
4345
commitFunc: async () => {},
44-
hasFiles: true
46+
hasFiles: true,
47+
settings: { composite: {} } as any
4548
});
46-
box.setState(
47-
{
48-
value: 'message'
49-
},
50-
() => {
51-
let actual = box.commitButtonStyle(true);
49+
// can't use setState here, since the box hasn't actually mounted
50+
box.state = { value: 'message' };
5251

53-
let expected = stagedCommitButtonStyle;
54-
expect(actual).toEqual(expected);
55-
}
56-
);
52+
let actual = box.commitButtonStyle(true);
53+
let expected = stagedCommitButtonStyle;
54+
expect(actual).toEqual(expected);
5755
});
5856
});
5957
});

yarn.lock

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,13 @@
14761476
dependencies:
14771477
"@types/react" "*"
14781478

1479+
"@types/react-textarea-autosize@^4.3.5":
1480+
version "4.3.5"
1481+
resolved "https://registry.yarnpkg.com/@types/react-textarea-autosize/-/react-textarea-autosize-4.3.5.tgz#6c4d2753fa1864c98c0b2b517f67bb1f6e4c46de"
1482+
integrity sha512-PiDL83kPMTolyZAWW3lyzO6ktooTb9tFTntVy7CA83/qFLWKLJ5bLeRboy6J6j3b1e8h2Eec6gBTEOOJRjV14A==
1483+
dependencies:
1484+
"@types/react" "*"
1485+
14791486
"@types/react@*", "@types/react@~16.8.13", "@types/react@~16.8.18", "@types/react@~16.8.4":
14801487
version "16.8.25"
14811488
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.8.25.tgz#0247613ab58b1b11ba10fed662e1947c5f2bb89c"
@@ -5011,7 +5018,7 @@ prop-types-exact@^1.2.0:
50115018
object.assign "^4.1.0"
50125019
reflect.ownkeys "^0.2.0"
50135020

5014-
prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2:
5021+
prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2:
50155022
version "15.7.2"
50165023
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
50175024
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
@@ -5149,6 +5156,14 @@ react-test-renderer@^16.0.0-0:
51495156
react-is "^16.8.6"
51505157
scheduler "^0.17.0"
51515158

5159+
react-textarea-autosize@^7.1.2:
5160+
version "7.1.2"
5161+
resolved "https://registry.yarnpkg.com/react-textarea-autosize/-/react-textarea-autosize-7.1.2.tgz#70fdb333ef86bcca72717e25e623e90c336e2cda"
5162+
integrity sha512-uH3ORCsCa3C6LHxExExhF4jHoXYCQwE5oECmrRsunlspaDAbS4mGKNlWZqjLfInWtFQcf0o1n1jC/NGXFdUBCg==
5163+
dependencies:
5164+
"@babel/runtime" "^7.1.2"
5165+
prop-types "^15.6.0"
5166+
51525167
react-transition-group@^2.9.0:
51535168
version "2.9.0"
51545169
resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-2.9.0.tgz#df9cdb025796211151a436c69a8f3b97b5b07c8d"

0 commit comments

Comments
 (0)