Skip to content

Commit d342045

Browse files
committed
Add tests and documentation for TopButtonsPanel prop
1 parent 7d0cd23 commit d342045

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

README.md

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,41 @@ a smart, controller component that controls terminal state. For example:
2828
import React from 'react';
2929
import Terminal, { ColorMode, TerminalOutput } from 'react-terminal-ui';
3030
31-
const TerminalController = (props = {}) => {
31+
const TerminalController = () => {
3232
const [terminalLineData, setTerminalLineData] = useState([
3333
<TerminalOutput>Welcome to the React Terminal UI Demo!</TerminalOutput>
3434
]);
35-
// Terminal has 100% width by default so it should usually be wrapped in a container div
35+
3636
return (
3737
<div className="container">
38-
<Terminal name='React Terminal Usage Example' colorMode={ ColorMode.Light } onInput={ terminalInput => console.log(`New terminal input received: '${ terminalInput }'`) }>
39-
{ terminalLineData }
38+
<Terminal
39+
name='React Terminal Usage Example'
40+
colorMode={ColorMode.Light}
41+
onInput={terminalInput => console.log(`New terminal input received: '${terminalInput}'`)}
42+
>
43+
{terminalLineData}
4044
</Terminal>
4145
</div>
42-
)
46+
);
4347
};
48+
4449
```
4550

4651
## Component Props
4752

48-
| Name | Description |
49-
| ------------------- | ------------- |
50-
| name | Name of the terminal. Displays at the top of the rendered component. In the demo, the name is set to _React Terminal UI_. |
51-
| colorMode | Terminal color mode - either Light or Dark. Defaults to Dark. |
52-
| onInput | An optional callback function that is invoked when a user presses enter on the prompt. The function is passed the current prompt input. If the `onInput` prop is not passed, the prompt input line will not display in the terminal. |
53-
| startingInputValue | Starting input value. If this prop changes, any user-entered input will be overridden by this value. Defaults to the empty string (""). |
54-
| prompt | The prompt character. Defaults to '$'. |
55-
| height | Height of the terminal. Defaults to 600px. |
56-
| redBtnCallback | Optional callback function for the red button. If provided, the function will be invoked when the red button is clicked. |
57-
| yellowBtnCallback | Optional callback function for the yellow button. If provided, the function will be invoked when the yellow button is clicked. |
58-
| greenBtnCallback | Optional callback function for the green button. If provided, the function will be invoked when the green button is clicked. |
53+
| Name | Description |
54+
|------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
55+
| `name` | Name of the terminal. Displays at the top of the rendered component. In the demo, the name is set to React Terminal UI. |
56+
| `colorMode` | Terminal color mode - either Light or Dark. Defaults to Dark. |
57+
| `onInput` | An optional callback function that is invoked when a user presses enter on the prompt. The function is passed the current prompt input. If the onInput prop is not passed, the prompt input line will not display in the terminal. |
58+
| `startingInputValue` | Starting input value. If this prop changes, any user-entered input will be overridden by this value. Defaults to the empty string (""). |
59+
| `prompt` | The prompt character. Defaults to '$'. |
60+
| `height` | Height of the terminal. Defaults to 600px. |
61+
| `redBtnCallback` | Optional callback function for the red button. If provided, the function will be invoked when the red button is clicked. |
62+
| `yellowBtnCallback` | Optional callback function for the yellow button. If provided, the function will be invoked when the yellow button is clicked. |
63+
| `greenBtnCallback` | Optional callback function for the green button. If provided, the function will be invoked when the green button is clicked. |
64+
| `TopButtonsPanel` | Optional - way to control which buttons are displays in top buttons panel. Pass `TopButtonsPanel={()=> null}` to hide top buttons panel. |
65+
5966

6067
### Development
6168

src/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import React, {
55
KeyboardEvent,
66
ChangeEvent,
77
ReactNode,
8-
ReactNodeArray,
98
ReactElement
109
} from 'react';
1110
import TerminalInput from './linetypes/TerminalInput';

tests/index.spec.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,14 @@ describe('Terminal component', () => {
8989
const renderedLine = screen.getByText('cat file.txt');
9090
expect(renderedLine.className).toContain('react-terminal-line');
9191
});
92+
93+
test('Should render top button panel by default', () => {
94+
const { container } = render(<Terminal />);
95+
expect(container.querySelector('.react-terminal-window-buttons')).not.toBeNull();
96+
});
97+
98+
test('Should not render top button panel if null props passed', () => {
99+
const { container } = render(<Terminal TopButtonsPanel={()=> null} />);
100+
expect(container.querySelector('.react-terminal-window-buttons')).toBeNull();
101+
});
92102
});

0 commit comments

Comments
 (0)