-
-
Notifications
You must be signed in to change notification settings - Fork 622
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
progress bar (WIP) #3
Conversation
I got this at one point as well... It took me a while to figure out the right babel settings for this project. This
|
Doh, wasn't exporting the component. I'll add a warning for that in a separate PR. |
@vadimdemedes I think this is ready to merge if you want it. To try it: |
lib/components/bar.js
Outdated
const max = Math.min(Math.floor(space * percent), space); | ||
for (let i = 0; i < max; i++) { | ||
str += char; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
char.repeat(max);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
index.js
Outdated
@@ -19,6 +20,7 @@ exports.Newline = Newline; | |||
exports.Indent = Indent; | |||
exports.Group = Group; | |||
exports.Text = Text; | |||
exports.Bar = Bar; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just Bar
is too ambiguous. ProgressBar
would be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
examples/progress.js
Outdated
/* @jsx h */ | ||
const {h, mount, Component, Text, Bar} = require('../'); | ||
|
||
const MAX = 20; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Max what? Would be nice if the variable name was more descriptive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried a different example.
} | ||
|
||
render() { | ||
const text = `Running `; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just inline this. Everything else is inline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used in two places, should I hard code the length?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, didn't notice that. Would be nice if the bar just calculated the left
thing automatically. Feels weird having to manually specify it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd have to know what else is on the line, or take the other content as a prop and render it itself, and it couldn't be custom components, and it might be a with multiple to have different colors.
It could have you either pass leftText (string) or leftSize (number), and if you pass leftText it'd render it. This seems confusing though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Ink should handle that for us. That's the behavior I expected. That would mean Ink would provide us the available screen space instead of us using process.stdout.columns
directly. Let's wait and see what @vadimdemedes thinks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good idea, I'd want that to be implemented natively too. Although I've been thinking and didn't come up with a way to solve this properly. Opened #5 to discuss this.
.babelrc
Outdated
] | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put the Babel config in package.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
docs/Bar.md
Outdated
@@ -0,0 +1,40 @@ | |||
The Bar component represents progress. See examples/progress.js for an example app. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a title: # Bar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. ProgressBar.
docs/ProgressBar.md
Outdated
|
||
## Props | ||
|
||
### char |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
char => character
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Nice work @brigand. This is looking very good :) |
@sindresorhus Thank you very much for reviewing and helping! @brigand Thanks to you as well for writing a great component. I'd love it, if you could release it as an individual project ( I want to have a list of useful Ink components in the readme, like Preact's (https://github.com/developit/preact#libraries--add-ons), and I'd be more than happy to include yours there :) |
Cool, done. |
Hey, cool project!
I'm working on adding a progress bar component, but getting a weird error:
Example file | Component file
Any ideas?