@bgoodman/react-console-component
Advanced tools
Comparing version 1.0.2 to 1.0.3
import React from "react"; | ||
import { DefaultTheme } from "styled-components"; | ||
export interface Theme { | ||
font: { | ||
size: string; | ||
family: string; | ||
}; | ||
colors: { | ||
background: string; | ||
text: string; | ||
}; | ||
} | ||
interface ConsoleProps { | ||
@@ -9,3 +18,3 @@ prompt?: string; | ||
height?: string; | ||
theme?: DefaultTheme; | ||
theme?: Theme; | ||
} | ||
@@ -12,0 +21,0 @@ export const Console: ({ prompt, autoScroll, height, theme, ...props }: ConsoleProps) => React.JSX.Element; |
{ | ||
"name": "@bgoodman/react-console-component", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"publishConfig": { | ||
@@ -29,4 +29,3 @@ "access": "public" | ||
"scripts": { | ||
"build": "npx parcel build src/index.ts", | ||
"start": "npm run build && ./demo/start" | ||
"build": "npx parcel build src/index.ts" | ||
}, | ||
@@ -33,0 +32,0 @@ "peerDependencies": { |
@@ -5,2 +5,4 @@ # React Console Component | ||
> Try the demo [here](https://ben_goodman.gitlab.io/ui-components/react-console-component/). | ||
![An example using a Bash interpreter](https://gitlab.com/ben_goodman/ui-components/react-console-component/-/raw/main/docs/react-console.gif) | ||
@@ -27,7 +29,11 @@ | ||
const evalCmd = (cmd: string): Promise<string> => { | ||
// do something with the input command. | ||
const result = eval(cmd).toString() | ||
// return the result as a promise | ||
return Promise.resolve(result) | ||
const evalCmd = (cmd) => { | ||
try { | ||
// do something with the input command. | ||
const result = eval(cmd).toString() | ||
// return the result as a promise | ||
return Promise.resolve(result) | ||
} catch (err) { | ||
return Promise.resolve(err.toString()) | ||
} | ||
} | ||
@@ -59,10 +65,12 @@ | ||
| autoScroll | `boolean` | `true` | If true, the console will automatically scroll to the bottom when new content is added. | | ||
| theme | `DefaultTheme` | See 'Themes' section. | A custom theme to use for the console. If not provided, the default light theme will be used. | | ||
| theme | `Theme` | See 'Themes' section. | A custom theme to use for the console. If not provided, the default light theme will be used. | | ||
## Themes | ||
The console component uses the `styled-components` library to style the console. You can provide your own theme by passing a `DefaultTheme` object to the `theme` prop. For example, the default theme is defined as: | ||
The console component uses the `styled-components` library to style the console. You can provide your own theme by passing a `Theme` object to the `theme` prop. For example, the default theme is defined as: | ||
```ts | ||
const lightTheme: DefaultTheme = { | ||
import { type Theme } from '@bgoodman/react-console-component' | ||
const lightTheme: Theme = { | ||
font: { | ||
@@ -82,3 +90,3 @@ size: '16px', | ||
```ts | ||
const darkTheme: DefaultTheme = { | ||
const darkTheme: Theme = { | ||
font: { | ||
@@ -85,0 +93,0 @@ size: '16px', |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44078
463
104