feat(row)!: replace as with tag prop

This commit is contained in:
Eric Liu 2023-01-08 14:22:52 -08:00
commit 1e31e71bcf
4 changed files with 36 additions and 57 deletions

View file

@ -3057,21 +3057,21 @@ None.
### Props ### Props
| Prop name | Required | Kind | Reactive | Type | Default value | Description | | Prop name | Required | Kind | Reactive | Type | Default value | Description |
| :------------ | :------- | :--------------- | :------- | -------------------- | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | :------------ | :------- | :--------------- | :------- | -------------------- | ------------------ | ---------------------------------------------------------- |
| as | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to render a custom HTML element<br />Props are destructured as `props` in the default slot (e.g., &lt;Row let:props&gt;&lt;section {...props}&gt;...&lt;/section&gt;&lt;/Row&gt;) | | tag | No | <code>let</code> | No | <code>string</code> | <code>"div"</code> | Specify the element tag |
| condensed | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to use the condensed variant | | condensed | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to use the condensed variant |
| narrow | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to use the narrow variant | | narrow | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to use the narrow variant |
| noGutter | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to remove the gutter | | noGutter | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to remove the gutter |
| noGutterLeft | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to remove the left gutter | | noGutterLeft | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to remove the left gutter |
| noGutterRight | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to remove the right gutter | | noGutterRight | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to remove the right gutter |
| padding | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to add top and bottom padding to all columns | | padding | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to add top and bottom padding to all columns |
### Slots ### Slots
| Slot name | Default | Props | Fallback | | Slot name | Default | Props | Fallback |
| :-------- | :------ | :-------------------------------------------------------------- | :------- | | :-------- | :------ | :---- | :------- |
| -- | Yes | <code>{ props: { class: string; [key: string]: any; } } </code> | -- | | -- | Yes | -- | -- |
### Events ### Events

View file

@ -9686,11 +9686,11 @@
"filePath": "src/Grid/Row.svelte", "filePath": "src/Grid/Row.svelte",
"props": [ "props": [
{ {
"name": "as", "name": "tag",
"kind": "let", "kind": "let",
"description": "Set to `true` to render a custom HTML element\nProps are destructured as `props` in the default slot (e.g., <Row let:props><section {...props}>...</section></Row>)", "description": "Specify the element tag",
"type": "boolean", "type": "string",
"value": "false", "value": "\"div\"",
"isFunction": false, "isFunction": false,
"isFunctionDeclaration": false, "isFunctionDeclaration": false,
"isRequired": false, "isRequired": false,
@ -9771,13 +9771,7 @@
} }
], ],
"moduleExports": [], "moduleExports": [],
"slots": [ "slots": [{ "name": "__default__", "default": true, "slot_props": "{}" }],
{
"name": "__default__",
"default": true,
"slot_props": "{ props: { class: string; [key: string]: any; } }"
}
],
"events": [], "events": [],
"typedefs": [], "typedefs": [],
"rest_props": { "type": "Element", "name": "div" } "rest_props": { "type": "Element", "name": "div" }

View file

@ -1,14 +1,10 @@
<script> <script>
/** /**
* @restProps {div} * @restProps {div}
* @slot {{ props: { class: string; [key: string]: any; } }}
*/ */
/** /** Specify the element tag */
* Set to `true` to render a custom HTML element export let tag = "div";
* Props are destructured as `props` in the default slot (e.g., <Row let:props><section {...props}>...</section></Row>)
*/
export let as = false;
/** Set to `true` to use the condensed variant */ /** Set to `true` to use the condensed variant */
export let condensed = false; export let condensed = false;
@ -27,28 +23,18 @@
/** Set to `true` to add top and bottom padding to all columns */ /** Set to `true` to add top and bottom padding to all columns */
export let padding = false; export let padding = false;
$: props = {
...$$restProps,
class: [
$$restProps.class,
"bx--row",
condensed && "bx--row--condensed",
narrow && "bx--row--narrow",
noGutter && "bx--no-gutter",
noGutterLeft && "bx--no-gutter--left",
noGutterRight && "bx--no-gutter--right",
padding && "bx--row-padding",
]
.filter(Boolean)
.join(" "),
};
</script> </script>
{#if as} <svelte:element
<slot props="{props}" /> this="{tag}"
{:else} class:bx--row="{true}"
<div {...props}> class:bx--row--condensed="{condensed}"
<slot /> class:bx--row--narrow="{narrow}"
</div> class:bx--no-gutter="{noGutter}"
{/if} class:bx--no-gutter--left="{noGutterLeft}"
class:bx--no-gutter--right="{noGutterRight}"
class:bx--row-padding="{padding}"
{...$$restProps}
>
<slot />
</svelte:element>

View file

@ -4,11 +4,10 @@ import type { SvelteComponentTyped } from "svelte";
export interface RowProps export interface RowProps
extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap["div"]> { extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap["div"]> {
/** /**
* Set to `true` to render a custom HTML element * Specify the element tag
* Props are destructured as `props` in the default slot (e.g., <Row let:props><section {...props}>...</section></Row>) * @default "div"
* @default false
*/ */
as?: boolean; tag?: string;
/** /**
* Set to `true` to use the condensed variant * Set to `true` to use the condensed variant
@ -50,5 +49,5 @@ export interface RowProps
export default class Row extends SvelteComponentTyped< export default class Row extends SvelteComponentTyped<
RowProps, RowProps,
{}, {},
{ default: { props: { class: string; [key: string]: any } } } { default: {} }
> {} > {}