-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
– Add src – Add tests – Add README
- Loading branch information
0 parents
commit 4d006fd
Showing
234 changed files
with
7,999 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"env": { | ||
"node": true | ||
}, | ||
"extends": "airbnb-base", | ||
"rules": { | ||
"max-classes-per-file": "off", | ||
"no-useless-constructor": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.idea/ | ||
node_modules/ | ||
.DS_Store | ||
.env | ||
coverage/ | ||
*.plist | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Change Log | ||
|
||
## v0.1.0 - 2020-06-09 | ||
|
||
* Initial Release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Ray East | ||
|
||
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: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
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. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"name": "slack-block-builder", | ||
"version": "0.1.0", | ||
"description": "Lightweight, no-dependency JavaScript library for creating Slack Block Kit UIs, with a builder interface, inspired by SwiftUI.", | ||
"author": { | ||
"name": "Ray East", | ||
"url": "https://github.com/raycharius" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/raycharius/slack-block-builder" | ||
}, | ||
"homepage": "https://github.com/raycharius/slack-block-builder#readme", | ||
"bugs": { | ||
"url": "https://github.com/raycharius/slack-block-builder/issues" | ||
}, | ||
"files": [ | ||
"src/", | ||
"README.md" | ||
], | ||
"main": "./src/index.js", | ||
"license": "MIT", | ||
"keywords": [ | ||
"slack", | ||
"interactive-messages", | ||
"block-actions", | ||
"bot", | ||
"slack-bot", | ||
"modal", | ||
"block-kit", | ||
"swiftui", | ||
"bot", | ||
"modal", | ||
"message-builder", | ||
"block-builder", | ||
"slack-block-builder", | ||
"block-kit" | ||
], | ||
"scripts": { | ||
"test": "jest", | ||
"lint-fix": "eslint 'src/**/*.js' --fix", | ||
"lint-check": "eslint 'src/**/*.js'", | ||
"prettier-fix": "prettier --write 'src/**/*.js'", | ||
"prettier-check": "prettier --check 'src/**/*.js'" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^6.8.0", | ||
"eslint-config-airbnb-base": "^14.1.0", | ||
"eslint-plugin-import": "^2.20.2", | ||
"prettier-eslint-cli": "^5.0.0", | ||
"jest": "^26.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"printWidth": 120, | ||
"tabWidth": 2, | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "es5", | ||
"bracketSpacing": true, | ||
"arrowParens": "always" | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const { Builder } = require('../../utility/lib'); | ||
const { categories } = require('../../utility/constants'); | ||
|
||
class Bit extends Builder { | ||
constructor() { | ||
super(); | ||
|
||
this.category = categories.bit; | ||
} | ||
|
||
/** | ||
* Performs no alterations to the object. Meant to simulate a closing | ||
* HTML tag for those who prefer the look of such code. | ||
* | ||
* @return {this} The instance on which the method is called | ||
*/ | ||
|
||
end() { | ||
return this; | ||
} | ||
} | ||
|
||
module.exports = Bit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const Bit = require('./bit'); | ||
|
||
module.exports = { | ||
Bit, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
const { Bit } = require('./base'); | ||
const { SlackDto } = require('../utility/lib'); | ||
const { BuilderHelper } = require('../utility/helpers'); | ||
const { props, enumValues } = require('../utility/constants'); | ||
|
||
class ConfirmationDialogDto extends SlackDto { | ||
constructor(params) { | ||
super(); | ||
|
||
this.title = params.title; | ||
this.text = params.text; | ||
this.confirm = params.confirm; | ||
this.deny = params.deny; | ||
this.style = params.style; | ||
|
||
this.pruneAndFreeze(); | ||
} | ||
} | ||
|
||
class ConfirmationDialog extends Bit { | ||
constructor(params = {}) { | ||
super(); | ||
|
||
this.props.title = params.title; | ||
this.props.text = params.text; | ||
this.props.confirm = params.confirm; | ||
this.props.deny = params.deny; | ||
|
||
this.finalizeConstruction(); | ||
} | ||
|
||
/** | ||
* Sets the title displayed in the confirmation dialog | ||
* | ||
* **Slack Validation Rules:** | ||
* * **Required** ⚠ | ||
* * Max 100 characters | ||
* | ||
* {@link https://api.slack.com/reference/block-kit/composition-objects#confirm|View in Slack API Documentation} | ||
* | ||
* @param {string} string | ||
* @return {this} The instance on which the method is called | ||
*/ | ||
|
||
title(string) { | ||
return this.set(string, props.title); | ||
} | ||
|
||
/** | ||
* Sets the textual content of the confirmation dialog | ||
* | ||
* **Slack Validation Rules:** | ||
* * **Required** ⚠ | ||
* * Max 300 characters | ||
* | ||
* {@link https://api.slack.com/reference/block-kit/composition-objects#confirm|View in Slack API Documentation} | ||
* | ||
* @param {string} string | ||
* @return {this} The instance on which the method is called | ||
*/ | ||
|
||
text(string) { | ||
return this.set(string, props.text); | ||
} | ||
|
||
/** | ||
* Sets the copy for the button that confirms the action. | ||
* | ||
* **Slack Validation Rules:** | ||
* * **Required** ⚠ | ||
* * Max 30 characters | ||
* | ||
* {@link https://api.slack.com/reference/block-kit/composition-objects#confirm|View in Slack API Documentation} | ||
* | ||
* @param {string} string | ||
* @return {this} The instance on which the method is called | ||
*/ | ||
|
||
confirm(string) { | ||
return this.set(string, props.confirm); | ||
} | ||
|
||
/** | ||
* Sets the copy for the button that cancels the action. | ||
* | ||
* **Slack Validation Rules:** | ||
* * **Required** ⚠ | ||
* * Max 30 characters | ||
* | ||
* {@link https://api.slack.com/reference/block-kit/composition-objects#confirm|View in Slack API Documentation} | ||
* | ||
* @param {string} string | ||
* @return {this} The instance on which the method is called | ||
*/ | ||
|
||
deny(string) { | ||
return this.set(string, props.deny); | ||
} | ||
|
||
/** | ||
* Sets the 'style' parameter to 'primary', making the | ||
* | ||
* {@link https://api.slack.com/reference/block-kit/composition-objects#confirm|View in Slack API Documentation} | ||
* | ||
* @return {this} The instance on which the method is called | ||
*/ | ||
|
||
primary() { | ||
return this.set(enumValues.primary, props.style); | ||
} | ||
|
||
/** | ||
* Sets 'style' parameter to 'danger' | ||
* | ||
* {@link https://api.slack.com/reference/block-kit/composition-objects#confirm|View in Slack API Documentation} | ||
* | ||
* @return {this} The instance on which the method is called | ||
*/ | ||
|
||
danger() { | ||
return this.set(enumValues.danger, props.style); | ||
} | ||
|
||
/** | ||
* @private | ||
*/ | ||
|
||
build() { | ||
const augmentedProps = { | ||
text: BuilderHelper.getPlainTextObject(this.props.text), | ||
title: BuilderHelper.getPlainTextObject(this.props.title), | ||
confirm: BuilderHelper.getPlainTextObject(this.props.confirm), | ||
deny: BuilderHelper.getPlainTextObject(this.props.deny), | ||
}; | ||
|
||
return this.getResult(ConfirmationDialogDto, augmentedProps); | ||
} | ||
} | ||
|
||
module.exports = { | ||
ConfirmationDialogDto, | ||
ConfirmationDialog, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const { ConfirmationDialog, ConfirmationDialogDto } = require('./confirmation-dialog'); | ||
const { Option, OptionDto } = require('./option'); | ||
const { OptionGroup, OptionGroupDto } = require('./option-group'); | ||
|
||
const BitDto = { ConfirmationDialogDto, OptionDto, OptionGroupDto }; | ||
|
||
const getBits = (config) => { | ||
const getClass = (Class, params) => new Class(params, config); | ||
|
||
return { | ||
|
||
/** | ||
* Creates and returns a ConfirmationDialog Bit | ||
* | ||
* {@link https://api.slack.com/reference/block-kit/composition-objects#confirm|View in Slack API Documentation} | ||
* | ||
* @param {Object} [params] Constructor parameters | ||
* @param {string} [params.title] Sets the title displayed in the confirmation dialog | ||
* @param {string} [params.text] Sets the textual content of the confirmation dialog | ||
* @param {string} [params.confirm] Sets the text for the button that confirms the action. | ||
* @param {string} [params.deny]Sets the text for the button that cancels the action. | ||
* @return {ConfirmationDialog} An instance of ConfirmationDialog | ||
*/ | ||
|
||
ConfirmationDialog: (params) => getClass(ConfirmationDialog, params), | ||
|
||
/** | ||
* Creates and returns an Option Bit | ||
* | ||
* {@link https://api.slack.com/reference/block-kit/composition-objects#option|View in Slack API Documentation} | ||
* | ||
* @param {Object} [params] Constructor parameters | ||
* @param {string} [params.text] Sets the text displayed in the menu for the current Option | ||
* @param {string} [params.value] Sets the value passed to your app when this Option is clicked or submitted | ||
* @param {string} [params.description] Sets a description shown next to the Option in a RadioButton Element | ||
* @param {string} [params.url] Sets the URL to redirect the user to when this Option is clicked (in an OverflowMenu) | ||
* @return {Option} An instance of Option | ||
*/ | ||
|
||
Option: (params) => getClass(Option, params), | ||
|
||
/** | ||
* Creates and returns an OpotionGroup Bit | ||
* | ||
* {@link https://api.slack.com/reference/block-kit/composition-objects#option_group|View in Slack API Documentation} | ||
* | ||
* @param {Object} [params] Constructor parameters | ||
* @param {string} [params.label] Sets the label shown above the group of Options | ||
* @return {OptionGroup} An instance of OptionsGroup | ||
*/ | ||
|
||
OptionGroup: (params) => getClass(OptionGroup, params), | ||
}; | ||
}; | ||
|
||
module.exports = { | ||
ConfirmationDialog, | ||
Option, | ||
OptionGroup, | ||
BitDto, | ||
getBits, | ||
}; |
Oops, something went wrong.