├── .editorconfig ├── .gitattributes ├── .github ├── funding.yml └── workflows │ └── main.yml ├── .gitignore ├── .npmrc ├── index.js ├── license ├── package.json ├── readme.md ├── screenshot.png ├── test.js ├── test.js.md └── test.js.snap /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.github/funding.yml: -------------------------------------------------------------------------------- 1 | github: sindresorhus 2 | open_collective: sindresorhus 3 | custom: https://sindresorhus.com/donate 4 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | - push 4 | - pull_request 5 | jobs: 6 | test: 7 | name: Node.js ${{ matrix.node-version }} 8 | runs-on: ubuntu-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | node-version: 13 | - 14 14 | - 12 15 | - 10 16 | - 8 17 | steps: 18 | - uses: actions/checkout@v2 19 | - uses: actions/setup-node@v1 20 | with: 21 | node-version: ${{ matrix.node-version }} 22 | - run: npm install 23 | - run: npm test 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | /dist.js 4 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import {Box as InkBox} from 'ink'; 3 | import PropTypes from 'prop-types'; 4 | import boxen from 'boxen'; 5 | 6 | const Box = props => ( 7 | boxen(text, props)}> 8 | {props.children} 9 | 10 | ); 11 | 12 | Box.propTypes = { 13 | children: PropTypes.oneOfType([ 14 | PropTypes.arrayOf(PropTypes.node), 15 | PropTypes.node 16 | ]).isRequired, 17 | borderColor: PropTypes.string, 18 | borderStyle: PropTypes.oneOfType([ 19 | PropTypes.oneOf([ 20 | 'single', 21 | 'double', 22 | 'round', 23 | 'singleDouble', 24 | 'doubleSingle', 25 | 'classic' 26 | ]), 27 | PropTypes.shape({ 28 | topLeft: PropTypes.string, 29 | topRight: PropTypes.string, 30 | bottomLeft: PropTypes.string, 31 | bottomRight: PropTypes.string, 32 | horizontal: PropTypes.string, 33 | vertical: PropTypes.string 34 | }) 35 | ]), 36 | dimBorder: PropTypes.bool, 37 | padding: PropTypes.oneOfType([ 38 | PropTypes.number, 39 | PropTypes.shape({ 40 | top: PropTypes.number, 41 | right: PropTypes.number, 42 | bottom: PropTypes.number, 43 | left: PropTypes.number 44 | }) 45 | ]), 46 | margin: PropTypes.oneOfType([ 47 | PropTypes.number, 48 | PropTypes.shape({ 49 | top: PropTypes.number, 50 | right: PropTypes.number, 51 | bottom: PropTypes.number, 52 | left: PropTypes.number 53 | }) 54 | ]), 55 | float: PropTypes.oneOf([ 56 | 'right', 57 | 'center', 58 | 'left' 59 | ]), 60 | backgroundColor: PropTypes.string, 61 | align: PropTypes.oneOf([ 62 | 'left', 63 | 'center', 64 | 'right' 65 | ]) 66 | }; 67 | 68 | module.exports = Box; 69 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Sindre Sorhus (sindresorhus.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ink-box", 3 | "version": "1.0.0", 4 | "description": "Styled box component for Ink", 5 | "license": "MIT", 6 | "repository": "sindresorhus/ink-box", 7 | "author": { 8 | "name": "Sindre Sorhus", 9 | "email": "sindresorhus@gmail.com", 10 | "url": "sindresorhus.com" 11 | }, 12 | "main": "dist.js", 13 | "engines": { 14 | "node": ">=8" 15 | }, 16 | "scripts": { 17 | "build": "babel index.js --out-file=dist.js", 18 | "prepublish": "npm run build", 19 | "pretest": "npm run build", 20 | "test": "xo && ava" 21 | }, 22 | "files": [ 23 | "dist.js" 24 | ], 25 | "keywords": [ 26 | "ink-component", 27 | "ink", 28 | "component", 29 | "box", 30 | "boxen", 31 | "boxes", 32 | "border", 33 | "react", 34 | "jsx", 35 | "terminal", 36 | "term", 37 | "console", 38 | "command-line" 39 | ], 40 | "dependencies": { 41 | "boxen": "^3.0.0", 42 | "prop-types": "^15.7.2" 43 | }, 44 | "devDependencies": { 45 | "@babel/cli": "^7.2.3", 46 | "@babel/core": "^7.3.3", 47 | "@babel/preset-react": "^7.0.0", 48 | "ava": "^1.3.1", 49 | "clear-module": "^3.1.0", 50 | "eslint-config-xo-react": "^0.19.0", 51 | "eslint-plugin-react": "^7.12.4", 52 | "eslint-plugin-react-hooks": "^1.4.0", 53 | "ink": "^2.0.0", 54 | "ink-testing-library": "^1.0.0", 55 | "react": "^16.8.2", 56 | "strip-ansi": "^5.0.0", 57 | "xo": "^0.24.0" 58 | }, 59 | "peerDependencies": { 60 | "ink": ">=2.0.0", 61 | "react": ">=16.8.0" 62 | }, 63 | "babel": { 64 | "presets": [ 65 | "@ava/stage-4", 66 | "@babel/preset-react" 67 | ] 68 | }, 69 | "xo": { 70 | "extends": [ 71 | "xo-react" 72 | ], 73 | "rules": { 74 | "react/require-default-props": "off", 75 | "react/no-unused-prop-types": "off" 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # ink-box 2 | 3 | > Styled box component for [Ink](https://github.com/vadimdemedes/ink) 4 | 5 | ![](screenshot.png) 6 | 7 | 8 | ## Install 9 | 10 | ``` 11 | $ npm install ink-box 12 | ``` 13 | 14 | 15 | ## Usage 16 | 17 | ```js 18 | import React from 'react'; 19 | import {render, Color} from 'ink'; 20 | import Box from 'ink-box'; 21 | 22 | render( 23 | 24 | I Love Unicorns 25 | 26 | ); 27 | ``` 28 | 29 | 30 | ## API 31 | 32 | ### `` 33 | 34 | Props are passed as options to [`boxen`](https://github.com/sindresorhus/boxen#options). 35 | 36 | 37 | ## Related 38 | 39 | - [ink-gradient](https://github.com/sindresorhus/ink-gradient) - Gradient color component for Ink 40 | - [ink-link](https://github.com/sindresorhus/ink-link) - Link component for Ink 41 | - [ink-big-text](https://github.com/sindresorhus/ink-big-text) - Awesome text component for Ink 42 | 43 | 44 | ## License 45 | 46 | MIT © [Sindre Sorhus](https://sindresorhus.com) 47 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sindresorhus/ink-box/2e798883b4b093d582adc42d330123163c03249a/screenshot.png -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import {serial as test} from 'ava'; 2 | import React from 'react'; 3 | import {Color} from 'ink'; 4 | import {render} from 'ink-testing-library'; 5 | import clearModule from 'clear-module'; 6 | import stripAnsi from 'strip-ansi'; 7 | 8 | test('render', t => { 9 | // TODO: Find out why this doesn't work to prevent color 10 | process.env.FORCE_COLOR = 0; 11 | clearModule('.'); 12 | const Box = require('.'); 13 | 14 | const {lastFrame} = render( 15 | 16 | I Love Unicorns 17 | 18 | ); 19 | console.log(lastFrame()); 20 | t.snapshot(stripAnsi(lastFrame())); 21 | 22 | delete process.env.FORCE_COLOR; 23 | }); 24 | -------------------------------------------------------------------------------- /test.js.md: -------------------------------------------------------------------------------- 1 | # Snapshot report for `test.js` 2 | 3 | The actual snapshot is saved in `test.js.snap`. 4 | 5 | Generated by [AVA](https://ava.li). 6 | 7 | ## render 8 | 9 | > Snapshot 1 10 | 11 | `╭─────────────────────╮␊ 12 | │ │␊ 13 | │ I Love Unicorns │␊ 14 | │ │␊ 15 | ╰─────────────────────╯` 16 | -------------------------------------------------------------------------------- /test.js.snap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sindresorhus/ink-box/2e798883b4b093d582adc42d330123163c03249a/test.js.snap --------------------------------------------------------------------------------