Skip to content

Rewrite project in Typescript #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21,974 changes: 21,939 additions & 35 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"url": "https://github.com/saharmor/react-super-cmd/issues"
},
"scripts": {
"build-ts": "tsc",
"watch-ts": "tsc -w",
"build": "microbundle-crl --no-compress --format modern,cjs",
"start": "microbundle-crl watch --no-compress --format modern,cjs",
"prepare": "run-s build",
Expand All @@ -38,13 +40,14 @@
"deploy": "gh-pages -d example/build"
},
"peerDependencies": {
"react": "^16.13.0",
"react-dom": "^16.13.0",
"@material-ui/core": "^4.11.2",
"@material-ui/icons": "^4.11.2"
"@material-ui/icons": "^4.11.2",
"react": "^16.13.0",
"react-dom": "^16.13.0"
},
"devDependencies": {
"microbundle-crl": "^0.13.10",
"@material-ui/core": "^4.11.2",
"@material-ui/icons": "^4.11.2",
"babel-eslint": "^10.0.3",
"cross-env": "^7.0.2",
"eslint": "^6.8.0",
Expand All @@ -58,13 +61,12 @@
"eslint-plugin-react": "^7.17.0",
"eslint-plugin-standard": "^4.0.1",
"gh-pages": "^2.2.0",
"microbundle-crl": "^0.13.10",
"npm-run-all": "^4.1.5",
"prettier": "^2.0.4",
"react": "^16.13.0",
"react-dom": "^16.13.0",
"react-scripts": "^3.4.1",
"@material-ui/core": "^4.11.2",
"@material-ui/icons": "^4.11.2"
"react-scripts": "^3.4.1"
},
"files": [
"dist"
Expand All @@ -73,5 +75,7 @@
"directories": {
"example": "example"
},
"dependencies": {}
"dependencies": {
"typescript": "^5.2.2"
}
}
37 changes: 0 additions & 37 deletions src/AutocompleteCommandField.js

This file was deleted.

27 changes: 27 additions & 0 deletions src/AutocompleteCommandField/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import withStyles from '@material-ui/core/styles/withStyles'
import TextField from '@material-ui/core/TextField'
import { useStyles } from './styles'
import { Props } from './types'

const AutoCompleteCommandField = ({
classes,
fieldValue,
onChange,
onKeyPress,
}: Props) => (
<div className={classes.root}>
<TextField
className={classes.inputField}
fullWidth
onChange={onChange}
onKeyDown={onKeyPress}
value={fieldValue}
InputProps={{
className: classes.input,
disableUnderline: true,
}}
/>
</div>
)

export default withStyles(useStyles)(AutoCompleteCommandField)
23 changes: 23 additions & 0 deletions src/AutocompleteCommandField/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Theme, createStyles } from '@material-ui/core'

export const useStyles = (theme: Theme) => createStyles({
root: {
backgroundColor: '#212121',
display: 'flex',
width: '100%',
margin: '1.5rem 0',
},
inputField: {
flex: '1',
border: 'none',
boxShadow: 'inset 0.1875rem 0 0 #dcb865',
backgroundColor: 'inherit',
color: '#b7babe',
},
input: {
color: '#f1f2f2',
paddingLeft: '1.875rem',
fontSize: '1.3125rem',
lineHeight: '1.75rem',
}
})
10 changes: 10 additions & 0 deletions src/AutocompleteCommandField/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ChangeEvent, KeyboardEvent } from 'react'

export type Props = {
classes: {
[key: string]: string
}
fieldValue: string
onChange: (e: ChangeEvent<HTMLInputElement>) => void
onKeyPress: (e: KeyboardEvent<HTMLDivElement>) => void
}
77 changes: 0 additions & 77 deletions src/CommandRow.js

This file was deleted.

21 changes: 21 additions & 0 deletions src/CommandRow/Shortcut.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Grid, Typography, withStyles } from '@material-ui/core'
import { useStyles } from './styles'

const Shortcut = ({ className, shortcut }: {
className: string
shortcut: string
}) => (
<Grid container>
{shortcut.split(' ').map((keyboardKey: string) => (
<Grid item>
<Typography
className={className}
variant="body2"
align="center"
>{keyboardKey}</Typography>
</Grid>
))}
</Grid>
)

export default withStyles(useStyles)(Shortcut)
60 changes: 60 additions & 0 deletions src/CommandRow/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import {
ButtonBase,
Typography,
withStyles,
} from '@material-ui/core'
import Grid from '@material-ui/core/Grid'
import { useStyles } from './styles'
import Shortcut from './Shortcut'
import { Props } from './types'

const CommandRow = ({
classes,
command,
commandName,
isHighlighted,
onClick,
onHover,
onKeyPress,
}: Props) => {
const rootStyle = isHighlighted ? classes.rootHighlighted : classes.root
const shortcutToKeys = (shortcut: string) => (
<Shortcut
className={classes.shortcut}
shortcut={shortcut}
/>
)

return (
<ButtonBase
ref={command.ref}
className={rootStyle}
onClick={onClick}
onMouseEnter={() => onHover(commandName)}
onKeyPress={onKeyPress}
>
<Grid
item
container
className={classes.button}
justify="space-between"
>
<Grid item xs={10} md={8}>
<Grid container>
<Grid item className={classes.cmdIcon} xs={1}>{command.logo}</Grid>
<Grid>
<Typography variant="body1">{command.name}</Typography>
</Grid>
</Grid>
</Grid>
<Grid item>
{command.shortcut && shortcutToKeys(command.shortcut)}
</Grid>
</Grid>
</ButtonBase>
)
}

export * from './types'

export default withStyles(useStyles)(CommandRow)
35 changes: 35 additions & 0 deletions src/CommandRow/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Theme, createStyles } from '@material-ui/core'

export const useStyles = (theme: Theme) => createStyles({
root: {
textAlign: 'left',
color: '#b7babe',
minHeight: '60px',
padding: '20px 36px',
width: '100%',
},
rootHighlighted: {
minHeight: '60px',
padding: '20px 36px',
width: '100%',
textAlign: 'left',
backgroundColor: 'rgba(255, 255, 255, 0.1)',
color: '#ffffffe6',
},
button: {
flexGrow: 1,
},
cmdIcon: {
width: '20px',
height: '20px',
},
shortcut: {
background: 'rgba(255, 255, 255, 0.15)',
borderRadius: '3px',
maxHeight: '18px',
minWidth: '19px',
marginLeft: '4px',
padding: "1px 5px 5px 5px",
marginTop: "3px",
}
})
26 changes: 26 additions & 0 deletions src/CommandRow/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {
KeyboardEvent,
MouseEvent,
MutableRefObject,
ReactNode,
} from 'react'

export interface Command {
name: string
logo: ReactNode
callback?: () => void
shortcut: string
ref?: MutableRefObject<HTMLButtonElement | null>
}

export type Props = {
classes: {
[key: string]: string
},
command: Command
commandName: string
isHighlighted: boolean
onClick: (e: MouseEvent<HTMLButtonElement>) => void
onHover: (command: string) => void
onKeyPress: (e: KeyboardEvent<HTMLButtonElement>) => void
}
Loading