Skip to content

Commit 82fb829

Browse files
Merge pull request #130 from electron/modern-add-version-dialog
feat: Modernize 'add local build' dialog
2 parents 6585590 + 3d64480 commit 82fb829

File tree

6 files changed

+96
-126
lines changed

6 files changed

+96
-126
lines changed

src/less/components/dialogs.less

+5-35
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
* {
1111
pointer-events: all;
1212
}
13-
14-
.generateTokenText svg {
15-
margin-right: 4px;
16-
}
1713
}
1814

1915
.darwin {
@@ -171,31 +167,6 @@
171167
&:focus {
172168
border-color: @foreground-2;
173169
}
174-
175-
&.hasError {
176-
border-color: #df3434;
177-
}
178-
}
179-
}
180-
181-
.error-text {
182-
margin: 0;
183-
font-size: 14px;
184-
color: #d73a49;
185-
}
186-
187-
.tokenDialog {
188-
.tokenSpinner {
189-
position: absolute;
190-
z-index: 3;
191-
top: 0;
192-
left: 0;
193-
width: 100%;
194-
height: 100%;
195-
background: rgba(0, 0, 0, 0.8);
196-
display: flex;
197-
align-items: center;
198-
justify-content: center;
199170
}
200171
}
201172

@@ -212,14 +183,13 @@
212183
opacity: 0.5;
213184
}
214185

215-
.add-version-dialog {
216-
label {
217-
white-space: normal;
218-
height: unset;
186+
.dialog-add-version {
187+
.bp3-file-input {
188+
width: 100%;
219189
}
220190

221-
input[type="file"] {
222-
display: none;
191+
.bp3-callout {
192+
margin-top: 1rem;
223193
}
224194
}
225195

src/renderer/components/add-version-dialog.tsx src/renderer/components/dialog-add-version.tsx

+41-45
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
import { Button, Callout, Dialog, FileInput, InputGroup, Intent } from '@blueprintjs/core';
13
import { observer } from 'mobx-react';
24
import * as path from 'path';
35
import * as React from 'react';
@@ -6,7 +8,6 @@ import * as semver from 'semver';
68
import { NpmVersion } from '../../interfaces';
79
import { getElectronNameForPlatform } from '../../utils/electron-name';
810
import { AppState } from '../state';
9-
import { Dialog } from './dialog';
1011

1112
export interface AddVersionDialogProps {
1213
appState: AppState;
@@ -47,8 +48,8 @@ export class AddVersionDialog extends React.Component<AddVersionDialogProps, Add
4748
*
4849
* @param {React.ChangeEvent<HTMLInputElement>} event
4950
*/
50-
public async onChangeFile(event: React.ChangeEvent<HTMLInputElement>) {
51-
const { files } = event.target;
51+
public async onChangeFile(event: React.FormEvent<HTMLInputElement>) {
52+
const { files } = event.target as any;
5253
const { binaryManager } = this.props.appState;
5354
const file = files && files[0] ? files[0] : undefined;
5455

@@ -120,54 +121,55 @@ export class AddVersionDialog extends React.Component<AddVersionDialogProps, Add
120121

121122
return [
122123
(
123-
<button
124-
className='button'
124+
<Button
125+
icon='add'
125126
key='submit'
126127
disabled={!canSubmit}
127128
onClick={this.onSubmit}
128-
>
129-
Add
130-
</button>
129+
text='Add'
130+
/>
131131
), (
132-
<button
133-
className='cancel'
132+
<Button
133+
icon='cross'
134134
key='cancel'
135135
onClick={this.onClose}
136-
>
137-
Cancel
138-
</button>
136+
text='Cancel'
137+
/>
139138
)
140139
];
141140
}
142141

143142
public render() {
144143
const { isAddVersionDialogShowing } = this.props.appState;
145-
const dirOptions = { webkitdirectory: 'true' };
144+
const inputProps = { webkitdirectory: 'true' };
145+
const { file } = this.state;
146+
147+
const text = file && file.path
148+
? file.path
149+
: `Select the folder containing ${getElectronNameForPlatform()}...`;
146150

147151
return (
148152
<Dialog
149-
isShowing={isAddVersionDialogShowing}
150-
isShowingBackdrop={true}
151-
buttons={this.buttons}
153+
isOpen={isAddVersionDialogShowing}
152154
onClose={this.onClose}
153-
isCentered={true}
154-
className='add-version-dialog'
155-
key='add-version-dialog'
155+
title='Add local Electron build'
156+
className='dialog-add-version'
156157
>
157-
<label
158-
htmlFor='custom-electron-version'
159-
className='force-button'
160-
>
161-
Select the folder containing {getElectronNameForPlatform()}
162-
</label>
163-
<input
164-
type='file'
165-
onChange={this.onChangeFile}
166-
id='custom-electron-version'
167-
name='custom-electron-version'
168-
{...dirOptions}
169-
/>
170-
{this.renderPath()}
158+
<div className='bp3-dialog-body'>
159+
<FileInput
160+
onInputChange={this.onChangeFile}
161+
id='custom-electron-version'
162+
inputProps={inputProps as any}
163+
text={text}
164+
/>
165+
<br />
166+
{this.renderPath()}
167+
</div>
168+
<div className='bp3-dialog-footer'>
169+
<div className='bp3-dialog-footer-actions'>
170+
{this.buttons}
171+
</div>
172+
</div>
171173
</Dialog>
172174
);
173175
}
@@ -182,16 +184,10 @@ export class AddVersionDialog extends React.Component<AddVersionDialogProps, Add
182184
: `We did not find a ${getElectronNameForPlatform()} in this folder...`;
183185

184186
return (
185-
<>
186-
<input
187-
readOnly={true}
188-
value={file.path}
189-
/>
190-
<p>
191-
{info}
192-
</p>
187+
<Callout>
188+
{info}
193189
{this.renderVersionInput()}
194-
</>
190+
</Callout>
195191
);
196192
}
197193

@@ -206,8 +202,8 @@ export class AddVersionDialog extends React.Component<AddVersionDialogProps, Add
206202
Please specify a version, used for typings and the name.
207203
Must be <code>semver</code> compliant.
208204
</p>
209-
<input
210-
className={isValidVersion ? '' : 'hasError'}
205+
<InputGroup
206+
intent={isValidVersion ? undefined : Intent.DANGER}
211207
value={version}
212208
onChange={this.onChangeVersion}
213209
placeholder='4.0.0'

src/renderer/components/dialogs.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { observer } from 'mobx-react';
22
import * as React from 'react';
33

44
import { AppState } from '../state';
5-
import { AddVersionDialog } from './add-version-dialog';
5+
import { AddVersionDialog } from './dialog-add-version';
66
import { TokenDialog } from './dialog-token';
77
import { WarningDialog } from './dialog-warning';
88
import { Settings } from './settings';

tests/renderer/components/__snapshots__/add-version-dialog-spec.tsx.snap

-44
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`AddVersionDialog component renders 1`] = `
4+
<Blueprint3.Dialog
5+
canOutsideClickClose={true}
6+
className="dialog-add-version"
7+
isOpen={true}
8+
onClose={[Function]}
9+
title="Add local Electron build"
10+
>
11+
<div
12+
className="bp3-dialog-body"
13+
>
14+
<Blueprint3.FileInput
15+
id="custom-electron-version"
16+
inputProps={
17+
Object {
18+
"webkitdirectory": "true",
19+
}
20+
}
21+
onInputChange={[Function]}
22+
text="Select the folder containing Electron.app..."
23+
/>
24+
<br />
25+
</div>
26+
<div
27+
className="bp3-dialog-footer"
28+
>
29+
<div
30+
className="bp3-dialog-footer-actions"
31+
>
32+
<Blueprint3.Button
33+
disabled={false}
34+
icon="add"
35+
key="submit"
36+
onClick={[Function]}
37+
text="Add"
38+
/>
39+
<Blueprint3.Button
40+
icon="cross"
41+
key="cancel"
42+
onClick={[Function]}
43+
text="Cancel"
44+
/>
45+
</div>
46+
</div>
47+
</Blueprint3.Dialog>
48+
`;

tests/renderer/components/add-version-dialog-spec.tsx tests/renderer/components/dialog-add-version-spec.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { shallow } from 'enzyme';
22
import * as React from 'react';
33

4-
import { AddVersionDialog } from '../../../src/renderer/components/add-version-dialog';
4+
import { AddVersionDialog } from '../../../src/renderer/components/dialog-add-version';
55
import { overridePlatform, resetPlatform } from '../../utils';
66

77
describe('AddVersionDialog component', () => {

0 commit comments

Comments
 (0)