Skip to content

Commit

Permalink
Merge pull request #110 from cleavenworth/file_input
Browse files Browse the repository at this point in the history
Add support for File Input element type
  • Loading branch information
imryche authored Mar 5, 2024
2 parents d10bc27 + 883b0ea commit c6777d0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Here's the list of types of components and corresponding classes:
| rich_text_preformatted | RichTextPreformatted |
| rich_text_quote | RichTextQuote |
| rich_text_section | RichTextSection |
| file_input | FileInput |

### Composition objects

Expand Down
2 changes: 2 additions & 0 deletions blockkit/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
DatePicker,
DatetimePicker,
ExternalSelect,
FileInput,
Image,
MultiChannelsSelect,
MultiConversationsSelect,
Expand Down Expand Up @@ -154,6 +155,7 @@ def __init__(
DatetimePicker,
TimePicker,
NumberInput,
FileInput
]


Expand Down
19 changes: 19 additions & 0 deletions blockkit/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"RichTextQuote",
"RichTextSection",
"RichTextList",
"FileInput"
]


Expand Down Expand Up @@ -717,3 +718,21 @@ def __init__(
indent: Optional[int] = None,
):
super().__init__(elements=elements, style=style, indent=indent)

class FileInput(ActionableComponent):
type: str = "file_input"
filetypes: Optional[List[str]] = Field(None)
maxfiles: Optional[int] = Field(..., gt=0, le=10)

def __init__(
self,
*,
action_id: Optional[str] = None,
filetypes: Optional[List[str]] = None,
maxfiles: Optional[int] = None,
):
super().__init__(
action_id=action_id,
filetypes=filetypes,
maxfiles=maxfiles,
)
2 changes: 1 addition & 1 deletion blockkit/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ def validate_datetime(v: Union[int, datetime]) -> Optional[int]:
else:
_ = datetime.fromtimestamp(v)
return v
return v
return v
17 changes: 17 additions & 0 deletions tests/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
DatePicker,
DatetimePicker,
ExternalSelect,
FileInput,
Image,
MultiChannelsSelect,
MultiConversationsSelect,
Expand Down Expand Up @@ -1557,3 +1558,19 @@ def test_timepicker_excessive_action_id_raises_exception():
def test_timepicker_excessive_placeholder_raises_exception():
with pytest.raises(ValidationError):
TimePicker(placeholder=PlainText(text="p" * 151))

def test_builds_fileinput():
assert FileInput(
action_id="action_id",
filetypes=["file"],
maxfiles=1,
).build() == {
"type": "file_input",
"action_id": "action_id",
"filetypes": ["file"],
"maxfiles": 1,
}

def test_fileinput_excessive_maxfiles_raises_exception():
with pytest.raises(ValidationError):
FileInput(maxfiles=11)

0 comments on commit c6777d0

Please sign in to comment.