feat(truncate): add text truncation component and action

This commit is contained in:
Eric Liu 2021-02-19 07:40:19 -08:00
commit a51c300a79
13 changed files with 161 additions and 3 deletions

View file

@ -1,5 +1,5 @@
{
"total": 157,
"total": 158,
"components": [
{
"moduleName": "Accordion",
@ -10664,6 +10664,25 @@
"typedefs": [],
"rest_props": { "type": "Element", "name": "button" }
},
{
"moduleName": "Truncate",
"filePath": "src/Truncate/Truncate.svelte",
"props": [
{
"name": "direction",
"kind": "let",
"type": "\"end\" | \"front\"",
"value": "\"end\"",
"isFunction": false,
"constant": false,
"reactive": false
}
],
"slots": [{ "name": "__default__", "default": true, "slot_props": "{}" }],
"events": [],
"typedefs": [],
"rest_props": { "type": "Element", "name": "div" }
},
{
"moduleName": "UnorderedList",
"filePath": "src/UnorderedList/UnorderedList.svelte",

View file

@ -0,0 +1,37 @@
<script>
import { Truncate } from "carbon-components-svelte";
import { truncate } from "carbon-components-svelte/actions";
import Preview from "../../components/Preview.svelte";
</script>
This is a utility component that wraps the `.bx--text-truncate--*` CSS selector from `carbon-components` for single line text truncation.
### Default
By default, text will be clamped at the end of the line. Text is wrapped with a paragraph (`p`) element. Use the [truncate action](#usetruncate) to truncate text in other elements.
<Truncate>
Carbon Components Svelte is a Svelte component library that implements the Carbon Design System, an open source design system by IBM.
</Truncate>
### Direction (front)
Set `direction` to `"front"` to clamp the text from the front.
<Truncate direction="front">
Carbon Components Svelte is a Svelte component library that implements the Carbon Design System, an open source design system by IBM.
</Truncate>
### use:truncate
The `truncate` action can be used on other HTML elements.
Import path: `import { truncate } from "carbon-components-svelte/actions";`
<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={{ direction: "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

@ -38,6 +38,9 @@ function createImports(source) {
const ccs_imports = Array.from(inlineComponents.keys());
const icon_imports = Array.from(icons.keys());
if (ccs_imports.length === 0) return "";
// TODO: determine if action is used, and generate import accordingly
return `
<script>
import {${ccs_imports.join(",")}} from "carbon-components-svelte";