Skip to content
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(file-uploader): add size prop to FileUploaderButton #1786

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions COMPONENT_INDEX.md
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,7 @@ None.
| labelTitle | No | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the label title.<br />Alternatively, use the named slot "labelTitle" (e.g., `&lt;span slot="labelTitle"&gt;...&lt;/span&gt;`) |
| labelDescription | No | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the label description.<br />Alternatively, use the named slot "labelDescription" (e.g., `&lt;span slot="labelDescription"&gt;...&lt;/span&gt;`) |
| kind | No | <code>let</code> | No | <code>import("../Button/Button.svelte").ButtonProps["kind"]</code> | <code>"primary"</code> | Specify the kind of file uploader button |
| size | No | <code>let</code> | No | <code>import("../Button/Button.svelte").ButtonProps["size"]</code> | <code>"small"</code> | Specify the size of the file uploader button |
| buttonLabel | No | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the button label |
| iconDescription | No | <code>let</code> | No | <code>string</code> | <code>"Provide icon description"</code> | Specify the ARIA label used for the status icons |
| name | No | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify a name attribute for the file button uploader input |
Expand Down Expand Up @@ -1299,6 +1300,7 @@ None.
| disabled | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to disable the input |
| disableLabelChanges | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to disable label changes |
| kind | No | <code>let</code> | No | <code>import("../Button/Button.svelte").ButtonProps["kind"]</code> | <code>"primary"</code> | Specify the kind of file uploader button |
| size | No | <code>let</code> | No | <code>import("../Button/Button.svelte").ButtonProps["size"]</code> | <code>"small"</code> | Specify the size of the file uploader button |
| role | No | <code>let</code> | No | <code>string</code> | <code>"button"</code> | Specify the label role |
| tabindex | No | <code>let</code> | No | <code>string</code> | <code>"0"</code> | Specify `tabindex` attribute |
| id | No | <code>let</code> | No | <code>string</code> | <code>"ccs-" + Math.random().toString(36)</code> | Set an id for the input element |
Expand Down
24 changes: 24 additions & 0 deletions docs/src/COMPONENT_API.json
Original file line number Diff line number Diff line change
Expand Up @@ -3830,6 +3830,18 @@
"constant": false,
"reactive": false
},
{
"name": "size",
"kind": "let",
"description": "Specify the size of the file uploader button",
"type": "import(\"../Button/Button.svelte\").ButtonProps[\"size\"]",
"value": "\"small\"",
"isFunction": false,
"isFunctionDeclaration": false,
"isRequired": false,
"constant": false,
"reactive": false
},
{
"name": "buttonLabel",
"kind": "let",
Expand Down Expand Up @@ -3983,6 +3995,18 @@
"constant": false,
"reactive": false
},
{
"name": "size",
"kind": "let",
"description": "Specify the size of the file uploader button",
"type": "import(\"../Button/Button.svelte\").ButtonProps[\"size\"]",
"value": "\"small\"",
"isFunction": false,
"isFunctionDeclaration": false,
"isRequired": false,
"constant": false,
"reactive": false
},
{
"name": "labelText",
"kind": "let",
Expand Down
17 changes: 13 additions & 4 deletions docs/src/pages/components/FileUploader.svx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@ By default, the file uploader only accepts one file.

Set `multiple` to `true` for multiple files to be accepted.

<FileUploaderButton labelText="Add files" />
<FileUploaderButton labelText="Add file" />

## Custom button kind
## Multiple files

By default, the `primary` button kind is used.
<FileUploaderButton multiple labelText="Add files" />

<FileUploaderButton kind="secondary" labelText="Add files" />
## Custom button kind, size

By default, the `primary` small button kind is used.

Use the `kind` and `size` props to customize the button.

<FileUploaderButton kind="secondary" size="field" />
<FileUploaderButton kind="tertiary" size="default" />
<FileUploaderButton kind="danger" size="lg" />
<FileUploaderButton kind="danger-tertiary" size="xl" />

## File uploader

Expand Down
7 changes: 7 additions & 0 deletions src/FileUploader/FileUploader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
*/
export let kind = "primary";

/**
* Specify the size of the file uploader button
* @type {import("../Button/Button.svelte").ButtonProps["size"]}
*/
export let size = "small";

/** Specify the button label */
export let buttonLabel = "";

Expand Down Expand Up @@ -137,6 +143,7 @@
name="{name}"
multiple="{multiple}"
kind="{kind}"
size="{size}"
on:change
on:change="{(e) => {
files = e.detail;
Expand Down
11 changes: 10 additions & 1 deletion src/FileUploader/FileUploaderButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
*/
export let kind = "primary";

/**
* Specify the size of the file uploader button
* @type {import("../Button/Button.svelte").ButtonProps["size"]}
*/
export let size = "small";

/** Specify the label text */
export let labelText = "Add file";

Expand Down Expand Up @@ -67,7 +73,6 @@
for="{id}"
tabindex="{disabled ? '-1' : tabindex}"
class:bx--btn="{true}"
class:bx--btn--sm="{true}"
class:bx--btn--disabled="{disabled}"
class:bx--btn--primary="{kind === 'primary'}"
class:bx--btn--secondary="{kind === 'secondary'}"
Expand All @@ -76,6 +81,10 @@
class:bx--btn--danger="{kind === 'danger'}"
class:bx--btn--danger-tertiary="{kind === 'danger-tertiary'}"
class:bx--btn--danger-ghost="{kind === 'danger-ghost'}"
class:bx--btn--sm="{size === 'small'}"
class:bx--btn--field="{size === 'field'}"
class:bx--btn--lg="{size === 'lg'}"
class:bx--btn--xl="{size === 'xl'}"
on:keydown
on:keydown="{({ key }) => {
if (key === ' ' || key === 'Enter') {
Expand Down
2 changes: 2 additions & 0 deletions tests/FileUploader.test.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<FileUploaderButton
kind="tertiary"
size="xl"
labelText="Add files"
on:change="{(e) => {
console.log(e.detail); // File[]
Expand All @@ -29,6 +30,7 @@

<FileUploader
kind="danger-ghost"
size="lg"
bind:this="{fileUploader}"
multiple
labelTitle="Upload files"
Expand Down
6 changes: 6 additions & 0 deletions types/FileUploader/FileUploader.svelte.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ export interface FileUploaderProps extends RestProps {
*/
kind?: import("../Button/Button.svelte").ButtonProps["kind"];

/**
* Specify the size of the file uploader button
* @default "small"
*/
size?: import("../Button/Button.svelte").ButtonProps["size"];

/**
* Specify the button label
* @default ""
Expand Down
6 changes: 6 additions & 0 deletions types/FileUploader/FileUploaderButton.svelte.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ export interface FileUploaderButtonProps extends RestProps {
*/
kind?: import("../Button/Button.svelte").ButtonProps["kind"];

/**
* Specify the size of the file uploader button
* @default "small"
*/
size?: import("../Button/Button.svelte").ButtonProps["size"];

/**
* Specify the label text
* @default "Add file"
Expand Down