refactor(truncate): rename "direction" prop to "clamp"

This commit is contained in:
Eric Liu 2021-02-19 08:07:58 -08:00
commit abe5220ec2
7 changed files with 19 additions and 18 deletions

View file

@ -4285,7 +4285,7 @@ None.
| Prop name | Kind | Reactive | Type | Default value | Description | | Prop name | Kind | Reactive | Type | Default value | Description |
| :-------- | :--------------- | :------- | :-------------------------------- | ------------------ | ----------- | | :-------- | :--------------- | :------- | :-------------------------------- | ------------------ | ----------- |
| direction | <code>let</code> | No | <code>"end" &#124; "front"</code> | <code>"end"</code> | -- | | clamp | <code>let</code> | No | <code>"end" &#124; "front"</code> | <code>"end"</code> | -- |
### Slots ### Slots

View file

@ -1,24 +1,25 @@
/** /**
* Svelte action that applies single-line text truncation to an element * Svelte action that applies single-line text truncation to an element
* @param {HTMLElement} node * @param {HTMLElement} node
* @param {{ direction?: "end" | "front" }} params * @param {{ clamp?: "end" | "front" }} params
* @example * @example
* <script> * <script>
* import { truncate } from "carbon-components-svelte/actions"; * import { truncate } from "carbon-components-svelte/actions";
* </script> * </script>
* *
* <h1 use:truncate>...</h1> * <h1 use:truncate>...</h1>
* <h1 use:truncate={{ clamp: "front" }}>...</h1>
*/ */
export function truncate(node, params = {}) { export function truncate(node, params = {}) {
function toggleClass(front = false) { function toggleClass(front = false) {
node.className = `bx--text-truncate--${front ? "front" : "end"}`; node.className = `bx--text-truncate--${front ? "front" : "end"}`;
} }
toggleClass(params.direction === "front"); toggleClass(params.clamp === "front");
return { return {
update(params) { update(params) {
toggleClass(params.direction === "front"); toggleClass(params.clamp === "front");
}, },
}; };
} }

View file

@ -10669,7 +10669,7 @@
"filePath": "src/Truncate/Truncate.svelte", "filePath": "src/Truncate/Truncate.svelte",
"props": [ "props": [
{ {
"name": "direction", "name": "clamp",
"kind": "let", "kind": "let",
"type": "\"end\" | \"front\"", "type": "\"end\" | \"front\"",
"value": "\"end\"", "value": "\"end\"",
@ -10681,7 +10681,7 @@
"slots": [{ "name": "__default__", "default": true, "slot_props": "{}" }], "slots": [{ "name": "__default__", "default": true, "slot_props": "{}" }],
"events": [], "events": [],
"typedefs": [], "typedefs": [],
"rest_props": { "type": "Element", "name": "div" } "rest_props": { "type": "Element", "name": "p" }
}, },
{ {
"moduleName": "UnorderedList", "moduleName": "UnorderedList",

View file

@ -5,7 +5,7 @@
import Preview from "../../components/Preview.svelte"; import Preview from "../../components/Preview.svelte";
</script> </script>
This is a utility component that wraps the `.bx--text-truncate--*` CSS selector from `carbon-components` for single line text truncation. This utility component wraps the `.bx--text-truncate--*` CSS selectors from [carbon-components](https://github.com/carbon-design-system/carbon/blob/master/packages/components/src/globals/scss/_helper-classes.scss#L11) for single-line text truncation.
### Default ### Default
@ -15,11 +15,11 @@ By default, text will be clamped at the end of the line. Text is wrapped with a
Carbon Components Svelte is a Svelte component library that implements the Carbon Design System, an open source design system by IBM. Carbon Components Svelte is a Svelte component library that implements the Carbon Design System, an open source design system by IBM.
</Truncate> </Truncate>
### Direction (front) ### Clamp front
Set `direction` to `"front"` to clamp the text from the front. Set `clamp` to `"front"` to clamp the text from the front.
<Truncate direction="front"> <Truncate clamp="front">
Carbon Components Svelte is a Svelte component library that implements the Carbon Design System, an open source design system by IBM. Carbon Components Svelte is a Svelte component library that implements the Carbon Design System, an open source design system by IBM.
</Truncate> </Truncate>
@ -32,6 +32,6 @@ Import path: `import { truncate } from "carbon-components-svelte/actions";`
<h4 use: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. Carbon Components Svelte is a Svelte component library that implements the Carbon Design System, an open source design system by IBM.
</h4> </h4>
<h4 use:truncate={{ direction: "front" }}> <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. Carbon Components Svelte is a Svelte component library that implements the Carbon Design System, an open source design system by IBM.
</h4> </h4>

View file

@ -1,11 +1,11 @@
<script> <script>
/** @type {"end" | "front"}*/ /** @type {"end" | "front"}*/
export let direction = "end"; export let clamp = "end";
</script> </script>
<p <p
class:bx--text-truncate--end="{direction === 'end'}" class:bx--text-truncate--end="{clamp === 'end'}"
class:bx--text-truncate--front="{direction === 'front'}" class:bx--text-truncate--front="{clamp === 'front'}"
{...$$restProps} {...$$restProps}
> >
<slot /> <slot />

View file

@ -8,7 +8,7 @@
Carbon Design System, an open source design system by IBM. Carbon Design System, an open source design system by IBM.
</Truncate> </Truncate>
<Truncate direction="front"> <Truncate clamp="front">
Carbon Components Svelte is a Svelte component library that implements the Carbon Components Svelte is a Svelte component library that implements the
Carbon Design System, an open source design system by IBM. Carbon Design System, an open source design system by IBM.
</Truncate> </Truncate>
@ -17,7 +17,7 @@
Carbon Components Svelte is a Svelte component library that implements the Carbon Components Svelte is a Svelte component library that implements the
Carbon Design System, an open source design system by IBM. Carbon Design System, an open source design system by IBM.
</h4> </h4>
<h4 use:truncate="{{ direction: 'front' }}"> <h4 use:truncate="{{ clamp: 'front' }}">
Carbon Components Svelte is a Svelte component library that implements the Carbon Components Svelte is a Svelte component library that implements the
Carbon Design System, an open source design system by IBM. Carbon Design System, an open source design system by IBM.
</h4> </h4>

View file

@ -2,11 +2,11 @@
import { SvelteComponentTyped } from "svelte"; import { SvelteComponentTyped } from "svelte";
export interface TruncateProps export interface TruncateProps
extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap["div"]> { extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap["p"]> {
/** /**
* @default "end" * @default "end"
*/ */
direction?: "end" | "front"; clamp?: "end" | "front";
} }
export default class Truncate extends SvelteComponentTyped< export default class Truncate extends SvelteComponentTyped<