-
Notifications
You must be signed in to change notification settings - Fork 106
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
feat: keyboard button builders #420
Conversation
Some nitpicks:
|
Maybe add |
Maybe add const keyboard = new Keyboard()
keyboard.addRow(....) sounds more natural |
Yes. By default, the last row will be half. By allowing the number of buttons on the first row to be specified, we can make the first row half. For 10 items, we can do
rather than
I added clone for these cases so one can do I expected
Same.
It's useful if you want to map an array of strings to a list of buttons that all are places in a single column. I encouter this quite often with |
I see no benefit, just flip the two values? By the way, should this return a copy, too? In other words, should we create |
What is the benefit of redundancy? |
just like you added The use cases are shifting from chaining const keyboard = Keyboard.from(initialData)
if (something) {
keyboard.row(someConditionalData)
} If this was new code, it would make a lot more sense to call it |
You're right, |
Forget about |
One use case that I'm thinking about rn is conditional buttons, e.g. const keyboard = Keyboard.from([[button]])
if (userLoggedIn) {
keyboard.append([[Keyboard.text('Profile')]])
}
|
I don't see the pattern that you're referring to. That sounds like you also want to rename it to |
Oh okay |
We could make it accept both |
Great idea! We could make |
Nice! Will do |
Speaking of const keyboard = Keyboard.chunk([a, b, c], 1) // [[a], [b], [c]]
const keyboard = Keyboard.chunkReverse([a, b, c, d, e], 3) // [[a, b], [c, d, e]] |
Those are just array helper methods, right? So they don't really create keyboards |
Maybe they do the transformation and then pass the result to |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #420 +/- ##
==========================================
+ Coverage 38.67% 41.35% +2.67%
==========================================
Files 16 16
Lines 4815 5035 +220
Branches 194 204 +10
==========================================
+ Hits 1862 2082 +220
Misses 2951 2951
Partials 2 2
☔ View full report in Codecov by Sentry. |
Co-authored-by: Dunkan <[email protected]>
[["a", "c", "d"], ["b", "e"], ["f"]], | ||
); | ||
const keyboard = Keyboard.from([["a", "b", "c"], ["d", "e"], ["f"]]); | ||
assertEquals(keyboard.toTransposed().toTransposed(), keyboard); |
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.
This is begging for a property-based test.
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.
We don't do those yet. We can consider adding new test setups in future PQs.
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.
LGTM 🎉
Co-authored-by: EdJoPaTo <[email protected]> Co-authored-by: Dunkan <[email protected]>
Adds keyboard button builders.
Keyboard.text("label")
Keyboard.from(array)
Keyboard.from(stringArray)
keyboard.clone()
keyboard.append(other0, other1, other2)
keyboard.toTransposed()
keyboard.toWrapped()
The same works for inline keyboards.
Closes #104.