mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 11:36:36 +00:00
feat(truncate): add text truncation component and action
This commit is contained in:
parent
735c6a7f7e
commit
a51c300a79
13 changed files with 161 additions and 3 deletions
24
actions/truncate.js
Normal file
24
actions/truncate.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
* Svelte action that applies single-line text truncation to an element
|
||||
* @param {HTMLElement} node
|
||||
* @param {{ direction?: "end" | "front" }} params
|
||||
* @example
|
||||
* <script>
|
||||
* import { truncate } from "carbon-components-svelte/actions";
|
||||
* </script>
|
||||
*
|
||||
* <h1 use:truncate>...</h1>
|
||||
*/
|
||||
export function truncate(node, params = {}) {
|
||||
function toggleClass(front = false) {
|
||||
node.className = `bx--text-truncate--${front ? "front" : "end"}`;
|
||||
}
|
||||
|
||||
toggleClass(params.direction === "front");
|
||||
|
||||
return {
|
||||
update(params) {
|
||||
toggleClass(params.direction === "front");
|
||||
},
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue