feat(column)!: replace as with tag prop

This commit is contained in:
Eric Liu 2023-01-08 14:28:58 -08:00
commit 12dfff70fa
4 changed files with 40 additions and 55 deletions

View file

@ -613,8 +613,8 @@ export type ColumnBreakpoint = ColumnSize | ColumnSizeDescriptor;
### 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;Column let:props&gt;&lt;article {...props}&gt;...&lt;/article&gt;&lt;/Column&gt;) | | tag | No | <code>let</code> | No | <code>string</code> | <code>"div"</code> | Specify the element tag |
| 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 |
@ -629,8 +629,8 @@ export type ColumnBreakpoint = ColumnSize | ColumnSizeDescriptor;
### 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

@ -1294,11 +1294,11 @@
"filePath": "src/Grid/Column.svelte", "filePath": "src/Grid/Column.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., <Column let:props><article {...props}>...</article></Column>)", "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,
@ -1421,13 +1421,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": [
{ {

View file

@ -4,18 +4,10 @@
* @typedef {{span?: ColumnSize; offset: number;}} ColumnSizeDescriptor * @typedef {{span?: ColumnSize; offset: number;}} ColumnSizeDescriptor
* @typedef {ColumnSize | ColumnSizeDescriptor} ColumnBreakpoint * @typedef {ColumnSize | ColumnSizeDescriptor} ColumnBreakpoint
* @restProps {div} * @restProps {div}
* @slot {{props: { class: string; [key: string]: any; }}}
*/ */
/** /** Specify the element tag */
* @slot {{ props?: { class: string; } }} export let tag = "div";
*/
/**
* Set to `true` to render a custom HTML element
* Props are destructured as `props` in the default slot (e.g., <Column let:props><article {...props}>...</article></Column>)
*/
export let as = false;
/** Set to `true` to remove the gutter */ /** Set to `true` to remove the gutter */
export let noGutter = false; export let noGutter = false;
@ -98,22 +90,22 @@
class: [ class: [
$$restProps.class, $$restProps.class,
columnClass, columnClass,
!columnClass && "bx--col", aspectRatio && `bx--aspect-ratio--${aspectRatio}`,
noGutter && "bx--no-gutter",
noGutterLeft && "bx--no-gutter--left",
noGutterRight && "bx--no-gutter--right",
aspectRatio && `bx--aspect-ratio bx--aspect-ratio--${aspectRatio}`,
padding && "bx--col-padding",
] ]
.filter(Boolean) .filter(Boolean)
.join(" "), .join(" "),
}; };
</script> </script>
{#if as} <svelte:element
<slot props="{props}" /> this="{tag}"
{:else} {...props}
<div {...props}> class:bx--col="{!columnClass}"
class:bx--no-gutter="{noGutter}"
class:bx--no-gutter--left="{noGutterLeft}"
class:bx--no-gutter--right="{noGutterRight}"
class:bx--row-padding="{padding}"
class:bx--aspect-ratio="{aspectRatio}"
>
<slot /> <slot />
</div> </svelte:element>
{/if}

View file

@ -13,11 +13,10 @@ export type ColumnBreakpoint = ColumnSize | ColumnSizeDescriptor;
export interface ColumnProps export interface ColumnProps
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., <Column let:props><article {...props}>...</article></Column>) * @default "div"
* @default false
*/ */
as?: boolean; tag?: string;
/** /**
* Set to `true` to remove the gutter * Set to `true` to remove the gutter
@ -83,5 +82,5 @@ export interface ColumnProps
export default class Column extends SvelteComponentTyped< export default class Column extends SvelteComponentTyped<
ColumnProps, ColumnProps,
{}, {},
{ default: { props: { class: string; [key: string]: any } } } { default: {} }
> {} > {}