feat(file-uploader): make labelTitle, labelDescription slottable (#1780)

This commit is contained in:
Eric Liu 2023-07-23 12:25:31 -07:00 committed by GitHub
commit 239f1b10e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 36 deletions

View file

@ -1250,24 +1250,27 @@ None.
### Props
| Prop name | Required | Kind | Reactive | Type | Default value | Description |
| :--------------- | :------- | :----------------- | :------- | ------------------------------------------------------------------------------------------ | --------------------------------------- | ----------------------------------------------------------- |
| files | No | <code>let</code> | Yes | <code>ReadonlyArray<File></code> | <code>[]</code> | Obtain a reference to the uploaded files |
| status | No | <code>let</code> | No | <code>"uploading" &#124; "edit" &#124; "complete"</code> | <code>"uploading"</code> | Specify the file uploader status |
| disabled | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to disable the file uploader |
| accept | No | <code>let</code> | No | <code>ReadonlyArray<string></code> | <code>[]</code> | Specify the accepted file types |
| multiple | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to allow multiple files |
| clearFiles | No | <code>const</code> | No | <code>() => void</code> | <code>() => { files = []; }</code> | Programmatically clear the uploaded files |
| labelDescription | No | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the label description |
| labelTitle | No | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the label title |
| kind | No | <code>let</code> | No | <code>"primary" &#124; "secondary" &#124; "tertiary" &#124; "ghost" &#124; "danger"</code> | <code>"primary"</code> | Specify the kind of 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 |
| Prop name | Required | Kind | Reactive | Type | Default value | Description |
| :--------------- | :------- | :----------------- | :------- | ------------------------------------------------------------------------------------------ | --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| files | No | <code>let</code> | Yes | <code>ReadonlyArray<File></code> | <code>[]</code> | Obtain a reference to the uploaded files |
| status | No | <code>let</code> | No | <code>"uploading" &#124; "edit" &#124; "complete"</code> | <code>"uploading"</code> | Specify the file uploader status |
| disabled | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to disable the file uploader |
| accept | No | <code>let</code> | No | <code>ReadonlyArray<string></code> | <code>[]</code> | Specify the accepted file types |
| multiple | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to allow multiple files |
| clearFiles | No | <code>const</code> | No | <code>() => void</code> | <code>() => { files = []; }</code> | Programmatically clear the uploaded files |
| 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>"primary" &#124; "secondary" &#124; "tertiary" &#124; "ghost" &#124; "danger"</code> | <code>"primary"</code> | Specify the kind of 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 |
### Slots
None.
| Slot name | Default | Props | Fallback |
| :--------------- | :------ | :---- | :------------------------------ |
| labelDescription | No | -- | <code>{labelDescription}</code> |
| labelTitle | No | -- | <code>{labelTitle}</code> |
### Events

View file

@ -3795,9 +3795,9 @@
"reactive": false
},
{
"name": "labelDescription",
"name": "labelTitle",
"kind": "let",
"description": "Specify the label description",
"description": "Specify the label title.\nAlternatively, use the named slot \"labelTitle\" (e.g., `<span slot=\"labelTitle\">...</span>`)",
"type": "string",
"value": "\"\"",
"isFunction": false,
@ -3807,9 +3807,9 @@
"reactive": false
},
{
"name": "labelTitle",
"name": "labelDescription",
"kind": "let",
"description": "Specify the label title",
"description": "Specify the label description.\nAlternatively, use the named slot \"labelDescription\" (e.g., `<span slot=\"labelDescription\">...</span>`)",
"type": "string",
"value": "\"\"",
"isFunction": false,
@ -3868,7 +3868,20 @@
}
],
"moduleExports": [],
"slots": [],
"slots": [
{
"name": "labelDescription",
"default": false,
"fallback": "{labelDescription}",
"slot_props": "{}"
},
{
"name": "labelTitle",
"default": false,
"fallback": "{labelTitle}",
"slot_props": "{}"
}
],
"events": [
{
"type": "dispatched",

View file

@ -37,12 +37,18 @@
files = [];
};
/** Specify the label description */
export let labelDescription = "";
/** Specify the label title */
/**
* Specify the label title.
* Alternatively, use the named slot "labelTitle" (e.g., `<span slot="labelTitle">...</span>`)
*/
export let labelTitle = "";
/**
* Specify the label description.
* Alternatively, use the named slot "labelDescription" (e.g., `<span slot="labelDescription">...</span>`)
*/
export let labelDescription = "";
/**
* Specify the kind of file uploader button
* @type {"primary" | "secondary" | "tertiary" | "ghost" | "danger"}
@ -103,20 +109,24 @@
on:mouseenter
on:mouseleave
>
{#if labelTitle}
{#if labelTitle || $$slots.labelTitle}
<p
class:bx--file--label="{true}"
class:bx--label-description--disabled="{disabled}"
>
{labelTitle}
<slot name="labelTitle">
{labelTitle}
</slot>
</p>
{/if}
{#if labelDescription}
{#if labelDescription || $$slots.labelDescription}
<p
class:bx--label-description="{true}"
class:bx--label-description--disabled="{disabled}"
>
{labelDescription}
<slot name="labelDescription">
{labelDescription}
</slot>
</p>
{/if}
<FileUploaderButton

View file

@ -35,17 +35,19 @@ export interface FileUploaderProps extends RestProps {
multiple?: boolean;
/**
* Specify the label description
* @default ""
*/
labelDescription?: string;
/**
* Specify the label title
* Specify the label title.
* Alternatively, use the named slot "labelTitle" (e.g., `<span slot="labelTitle">...</span>`)
* @default ""
*/
labelTitle?: string;
/**
* Specify the label description.
* Alternatively, use the named slot "labelDescription" (e.g., `<span slot="labelDescription">...</span>`)
* @default ""
*/
labelDescription?: string;
/**
* Specify the kind of file uploader button
* @default "primary"
@ -85,7 +87,7 @@ export default class FileUploader extends SvelteComponentTyped<
mouseleave: WindowEventMap["mouseleave"];
keydown: WindowEventMap["keydown"];
},
{}
{ labelDescription: {}; labelTitle: {} }
> {
/**
* Programmatically clear the uploaded files