mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-20 04:13:02 +00:00
refactor(truncate): rename "direction" prop to "clamp"
This commit is contained in:
parent
69dae01722
commit
abe5220ec2
7 changed files with 19 additions and 18 deletions
|
@ -1,24 +1,25 @@
|
|||
/**
|
||||
* Svelte action that applies single-line text truncation to an element
|
||||
* @param {HTMLElement} node
|
||||
* @param {{ direction?: "end" | "front" }} params
|
||||
* @param {{ clamp?: "end" | "front" }} params
|
||||
* @example
|
||||
* <script>
|
||||
* import { truncate } from "carbon-components-svelte/actions";
|
||||
* </script>
|
||||
*
|
||||
* <h1 use:truncate>...</h1>
|
||||
* <h1 use:truncate={{ clamp: "front" }}>...</h1>
|
||||
*/
|
||||
export function truncate(node, params = {}) {
|
||||
function toggleClass(front = false) {
|
||||
node.className = `bx--text-truncate--${front ? "front" : "end"}`;
|
||||
}
|
||||
|
||||
toggleClass(params.direction === "front");
|
||||
toggleClass(params.clamp === "front");
|
||||
|
||||
return {
|
||||
update(params) {
|
||||
toggleClass(params.direction === "front");
|
||||
toggleClass(params.clamp === "front");
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue