feat(truncate): integrate Truncate with v11 (#1958)

This commit is contained in:
Eric Liu 2024-04-21 12:58:38 -07:00 committed by GitHub
commit 97e6301758
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 57 additions and 41 deletions

View file

@ -4730,8 +4730,9 @@ export interface TreeNode {
### Props ### Props
| Prop name | Required | Kind | Reactive | Type | Default value | Description | | Prop name | Required | Kind | Reactive | Type | Default value | Description |
| :-------- | :------- | :--------------- | :------- | --------------------------------- | ------------------ | ----------- | | :-------- | :------- | :--------------- | :------- | ---------------------------------------- | ------------------ | -------------------------------- |
| clamp | No | <code>let</code> | No | <code>"end" &#124; "front"</code> | <code>"end"</code> | -- | | clamp | No | <code>let</code> | No | <code>"end" &#124; "front"</code> | <code>"end"</code> | Specify the truncation direction |
| tag | No | <code>let</code> | No | <code>keyof HTMLElementTagNameMap</code> | <code>"p"</code> | Specify the tag name |
### Slots ### Slots

View file

@ -14723,6 +14723,7 @@
{ {
"name": "clamp", "name": "clamp",
"kind": "let", "kind": "let",
"description": "Specify the truncation direction",
"type": "\"end\" | \"front\"", "type": "\"end\" | \"front\"",
"value": "\"end\"", "value": "\"end\"",
"isFunction": false, "isFunction": false,
@ -14730,13 +14731,25 @@
"isRequired": false, "isRequired": false,
"constant": false, "constant": false,
"reactive": false "reactive": false
},
{
"name": "tag",
"kind": "let",
"description": "Specify the tag name",
"type": "keyof HTMLElementTagNameMap",
"value": "\"p\"",
"isFunction": false,
"isFunctionDeclaration": false,
"isRequired": false,
"constant": false,
"reactive": false
} }
], ],
"moduleExports": [], "moduleExports": [],
"slots": [{ "name": "__default__", "default": true, "slot_props": "{}" }], "slots": [{ "name": "__default__", "default": true, "slot_props": "{}" }],
"events": [], "events": [],
"typedefs": [], "typedefs": [],
"rest_props": { "type": "Element", "name": "p" } "rest_props": { "type": "Element", "name": "svelte:element" }
}, },
{ {
"moduleName": "UnorderedList", "moduleName": "UnorderedList",

View file

@ -1,12 +1,24 @@
<script> <script>
/** @type {"end" | "front"}*/ // @ts-check
/**
* Specify the truncation direction
* @type {"end" | "front"}
*/
export let clamp = "end"; export let clamp = "end";
/**
* Specify the tag name
* @type {keyof HTMLElementTagNameMap}
*/
export let tag = "p";
</script> </script>
<p <svelte:element
this="{tag}"
class:bx--text-truncate-end="{clamp === 'end'}" class:bx--text-truncate-end="{clamp === 'end'}"
class:bx--text-truncate-front="{clamp === 'front'}" class:bx--text-truncate-front="{clamp === 'front'}"
{...$$restProps} {...$$restProps}
> >
<slot /> <slot />
</p> </svelte:element>

View file

@ -1,12 +1,9 @@
import type { Action } from "svelte/action";
interface TruncateOptions { interface TruncateOptions {
clamp?: "end" | "front"; clamp?: "end" | "front";
} }
export function TruncateAction( export declare const truncate: Action<HTMLElement, TruncateOptions>;
node: HTMLElement,
options?: TruncateOptions
): {
update: (options?: TruncateOptions) => void;
};
export default TruncateAction; export default truncate;

View file

@ -1,7 +1,9 @@
// @ts-check
/** /**
* Svelte action that applies single-line text truncation to an element * Svelte action that applies single-line text truncation to an element
* @typedef {{ clamp?: "end" | "front" }} TruncateOptions * @typedef {{ clamp?: "end" | "front" }} TruncateOptions
* @type {(node: HTMLElement, options?: TruncateOptions) => { update: (options?: TruncateOptions) => void; }} * @type {import ("svelte/action").Action<HTMLElement, TruncateOptions>}
* @example * @example
* <h1 use:truncate>...</h1> * <h1 use:truncate>...</h1>
* <h1 use:truncate={{ clamp: "front" }}>...</h1> * <h1 use:truncate={{ clamp: "front" }}>...</h1>

View file

@ -1,23 +1,10 @@
<script lang="ts"> <script lang="ts">
import { Truncate } from "../types"; import { Truncate, truncate } from "../types";
import { truncate } from "../types";
</script> </script>
<Truncate> <Truncate tag="div" clamp="front" aria-label="">
Carbon Components Svelte is a Svelte component library that implements the Carbon Components Svelte is a Svelte component library.
Carbon Design System, an open source design system by IBM.
</Truncate> </Truncate>
<Truncate clamp="front"> <div use:truncate></div>
Carbon Components Svelte is a Svelte component library that implements the <div use:truncate="{{ clamp: 'front' }}"></div>
Carbon Design System, an open source design system by IBM.
</Truncate>
<h4 use:truncate>
Carbon Components Svelte is a Svelte component library that implements the
Carbon Design System, an open source design system by IBM.
</h4>
<h4 use:truncate="{{ clamp: 'front' }}">
Carbon Components Svelte is a Svelte component library that implements the
Carbon Design System, an open source design system by IBM.
</h4>

View file

@ -1,14 +1,21 @@
import type { SvelteComponentTyped } from "svelte"; import type { SvelteComponentTyped } from "svelte";
import type { SvelteHTMLElements } from "svelte/elements"; import type { SvelteHTMLElements } from "svelte/elements";
type RestProps = SvelteHTMLElements["p"]; type RestProps = SvelteHTMLElements["svelte:element"];
export interface TruncateProps extends RestProps { export interface TruncateProps extends RestProps {
/** /**
* Specify the truncation direction
* @default "end" * @default "end"
*/ */
clamp?: "end" | "front"; clamp?: "end" | "front";
/**
* Specify the tag name
* @default "p"
*/
tag?: keyof HTMLElementTagNameMap;
[key: `data-${string}`]: any; [key: `data-${string}`]: any;
} }

View file

@ -1,12 +1,9 @@
import type { Action } from "svelte/action";
interface TruncateOptions { interface TruncateOptions {
clamp?: "end" | "front"; clamp?: "end" | "front";
} }
export function TruncateAction( export declare const truncate: Action<HTMLElement, TruncateOptions>;
node: HTMLElement,
options?: TruncateOptions
): {
update: (options?: TruncateOptions) => void;
};
export default TruncateAction; export default truncate;